Last active
September 11, 2015 16:47
-
-
Save Swivelgames/1ceaac67ac95a85f8619 to your computer and use it in GitHub Desktop.
jQuery Plugin
This file contains hidden or 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
;(function($,window,document,undefined) { | |
var PluginConfig = { | |
"name": "PluginName", | |
"defaults": { | |
"propertyName": "value" | |
} | |
}; | |
var Plugin = function(element, options) { | |
this.settings = $.extend( {}, this._defaults, options ); | |
this.element = element; | |
this.init(); | |
}; | |
$.extend(Plugin.prototype, { | |
_name: PluginConfig.name, | |
_defaults: PluginConfig.defaults, | |
init: function() { | |
console.log("meow"); | |
this.anotherMethod(); | |
}, | |
anotherMethod: function() { | |
console.log(this.element); | |
} | |
}); | |
// Selector Passed! | |
$.fn[ PluginConfig.name ] = function(options) { | |
this.each(function() { | |
if ( !$.data( this, "plugin_" + pluginName ) ) { | |
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) ); | |
} | |
}); | |
// chain jQuery functions | |
return this; | |
}; | |
// No Selector Passed! | |
$[ PluginConfig.name ] = function(options) { | |
return 'foobar'; | |
}; | |
})( jQuery, window, document ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment