foundation-sites: jQuery.foundation() is not a function
I am using foundation-sites plugins in my existing project, and after updating foundation to 6.4.1 $(document).foundation(); returns an ‘is not a function error’.
But issue was solved by calling Foundation.addToJquery($); beforehand.
So question: is it a bug or a feature?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 27 (15 by maintainers)
@justrhysism You can import a single plugin straight from that plugin’s file (e.g.
import { Reveal } from 'foundation-sites/js/foundation.reveal';If you’re doing stuff by hand, it may well be straightforward for you to do the instantiation yourself using a direct constructor (e.g.
var thisReveal = new Reveal($('#my-reveal'), options)).Or if you want to use the jquery helper (e.g.
$(document).foundation()) you’d want to do something like:Let me know if this makes sense or what doesn’t… really want to make the docs for this better.
Hi @kball So I am using npm(npm v. 5.1.0) for installing foundation-sites. Below is a part of my packages.json file:
In my index.js file I import all necessary foundation modules, like so:
And the mentioned problem (foundation is not a function) occurs when I try to call
$(document).foundation();function.But as I mentioned before, if I run
Foundation.addToJquery($);function first, then I can initiate foundation framework.Thank you! I’ve been trying to figure this out for weeks and
Foundation.addToJquery($);finally did the job.I have a question. In bower_components/foundation-sites/js, there is a folder called “entries” with “foundation.js” and “foundation.plugins.js”. How are these meant to be used?
I’m new to module bundling, and my setup is basically Gulp, Browserify, and Babelify. Been having a pretty hard time understanding how to approach bundling as the documentation already assumes a solid understanding. Help in this area would be really great.
Thanks for you timely response @kball, much appreciated.
Ah right - yes, being able to use the plugin directly is much nicer.
For thread followers:
I’m using Foundation with Vue, and it’s good practice (particularly for event listeners) to “clean up” in Vue’s
beforeDestroy()lifecycle method. I noticed that there’s a_destroy()method on the class, but being prefixed with an underscore_seems to indicate that it’s private. Is there any reason this method is private? Or is this something which involves greater discussion and I should open another Github issue?