Last active
January 26, 2016 16:11
-
-
Save siggysamson/e1108b4bd8b8e93c0494 to your computer and use it in GitHub Desktop.
Simple jQuery plugin boilerplate (https://github.com/jquery-boilerplate/jquery-boilerplate)
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
(function($) { | |
"use strict"; | |
// Create the defaults once | |
var pluginName = "defaultPluginName"; | |
var defaults = { | |
propertyName: "value" | |
}; | |
// The actual plugin constructor | |
function Plugin (element, options) { | |
this.$element = $(element); | |
this.settings = $.extend( {}, defaults, options ); | |
this.init(); | |
} | |
$.extend(Plugin.prototype, { | |
init: function () { | |
// initial plugin call | |
}, | |
yourOtherFunction: function () { | |
// some logic | |
} | |
}); | |
$.fn[pluginName] = function (options) { | |
return this.each(function() { | |
if (!$.data(this, "plugin_" + pluginName)) { | |
$.data(this, "plugin_" + pluginName, new Plugin(this, options)); | |
} | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment