Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the wrapper really ment to do and how to make it work when window is resized too? #116

Open
ctrlmaniac opened this issue Feb 24, 2016 · 0 comments

Comments

@ctrlmaniac
Copy link
Contributor

// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[ pluginName ] = function( options ) {
    return this.each( function() {
        if ( !$.data( this, "plugin_" + pluginName ) ) {
            $.data( this, "plugin_" +
                pluginName, new Plugin( this, options ) );
        }
    } );
};

I thought that this allowed to call the plugin multiple times on different objects, to keep the same functionality allowing to customize options for all elements the plugin is attached to.
However when in the plugin constructor I call a $( window ).resize( function() { // Code } ); and put some functions in it, it seems that the plugin doesn't work any more, especially if I use the functions in the extend functions. So I got rid of it and put everything in the main constructor. In this way the resize function works but custom options are overridden by the last elements, so all elements will behave like the last that has been called.

Why? Can you please help me better understand how to use this boilerplate?

here is my plugin test with its html page.

I am asking a similar question about the resize function and this boilerplate here, but that question still doesn't ask for multiple instantiations!

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

No branches or pull requests

1 participant