Created
February 5, 2014 11:14
-
-
Save gabssnake/8821413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* // 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