Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

foundation not a function (offcanvas) #393

Closed
jimlongo56 opened this issue Jul 28, 2015 · 2 comments
Closed

foundation not a function (offcanvas) #393

jimlongo56 opened this issue Jul 28, 2015 · 2 comments

Comments

@jimlongo56
Copy link
Contributor

Hi, I've been trying to get past this one for a while.

I load jquery in the head followed by Modernizr.
In the footer I load foundation.js (which includes offcanvas when grunt build is run).
Right at the end, just before the end of the file I have the following.

<script>
jQuery(function($, undefined) {
    $(document).foundation({
        offcanvas: {
            open_method: 'overlap_single', // [ move | overlap_single | overlap ]
            close_on_click: true
        }
    });
});
</script> 

I always get the javascript error Uncaught TypeError: $(...).foundation is not a function

I've tried disabling other plugins, loading offcanvas separately (after removing it from grunt build), wrapping the footer script in more wrapper functions, etc.,

Any ideas on how to make this work. My offcanvas menu doesn't close when an item is clicked (my menu items are mainly anchor tags within the main page).

@jerstew
Copy link

jerstew commented Aug 4, 2015

I can't say much without seeing it in action, but maybe this is related?

Uncaught TypeError: undefined is not a function (via Foundation forums)

I'd also be happy to troubleshoot this if you have a dev site set up somewhere.

@jimlongo56
Copy link
Contributor Author

I seem to have solved this by adding the following just before the closing
implicitly initializing foundation and FastClick (not by including them in foundation.js), and wrapping everyone in IIFEs

<script>
    jQuery(function($, undefined) {
        $(document).foundation({
            offcanvas: {
                open_method: 'overlap_single', 
                close_on_click: true
            }
        });
    });
</script>
<script>jQuery(document).foundation();</script>
<script>jQuery(function( $ ){ FastClick.attach(document.body); });</script>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants