Skip to content

Instantly share code, notes, and snippets.

@gabssnake
Created February 5, 2014 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabssnake/8821413 to your computer and use it in GitHub Desktop.
Save gabssnake/8821413 to your computer and use it in GitHub Desktop.
/*
* // to set options per instance
* $('#elem').classlider({ message: 'Goodbye World!' });
* // to instantiate with simple Javascript
* var instance = new Classlider(
* document.getElementById('elem'),
* { message: 'Goodbye World!' }
* ).init();
* // to set global defaults
* Classlider.defaults.message = 'Goodbye World!';
*/
;(function( $, window, document, undefined ){
function MyPlugin( element, options ){
this.element = element;
this.$element = $(element);
this.options = options;
this.init();
}
MyPlugin.prototype = {
defaults: {
message: "Hello world!"
},
init: function() {
this.config = $.extend({}, this.defaults, this.options);
var self = this;
self.yourOtherFunction();
console.log("inited");
return self;
},
yourOtherFunction: function() {
var self = this;
console.log( self.config.message );
}
};
// export for jQuery
var pluginName = "my_plugin";
$.fn[ pluginName ] = function ( options ) {
return this.each(function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" + pluginName, new MyPlugin( this, options ) );
}
});
};
// MyPlugin.defaults = MyPlugin.prototype.defaults;
// window.MyPlugin = MyPlugin;
})( jQuery, window , document );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment