Dogfalo / materialize

Materialize, a CSS Framework based on Material Design
https://materializecss.com
MIT License
38.86k stars 4.74k forks source link

$(...).pushpin is not a function #2849

Closed jessor closed 8 years ago

jessor commented 8 years ago

I'm initializing Pushpin in a WordPress theme like this:

(function($){
  $(function(){
    $(".button-collapse").sideNav();  // works
    $('#tribe-events-bar').pushpin(); // error: $(...).pushpin is not a function
   });
})(jQuery);  

Removing the wrapping $(document).ready(function() { }); in materialize.js fixes this.

Kail0 commented 8 years ago

Well, you can try jQuery(document).ready(function(){ }); instead of $(document).ready(function() { });

then you can use $ inside your function

ad. Make sure you hooked the new version of jQuery, I had problems with wordpress's default one.

gnicol-bzh commented 8 years ago

The problem seems to be the (not needed) $(document).ready(function() { ... }); inside pushpin.js.

CF $(…).pushpin is not a function - reactJs, Materializecss

gnicol-bzh commented 8 years ago

I'm having the issue with just:

(function($) {
    'use strict';

    $('.side-menu-wrapper').pushpin({ 
        top: $('.side-menu-wrapper').offset().top 
    });

    //[other js init...]

})(jQuery);

in my main.js file.

And it works well when I remove the ready() in pushpin.js.

As far as I'm concerned, I don't understand why the whole function is wrapped in a ready event, especially when wrapped in a (function ($) { }( jQuery )). It won't work if this ready event is already fired when pushpin.js/materialize.js is loaded. Only the init part of the script should be wrapped in a ready or load event.

acburst commented 8 years ago

Yes this was definitely a bug on our part, not sure how that happened.

Fixed in bc257335f5259966125444e78e624b7b71a4c78b

Thanks for pointing this out