Last active
August 29, 2015 13:55
-
-
Save k-maru/8690148 to your computer and use it in GitHub Desktop.
Bootstrap Plugin Base
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
//change "Plugin" | |
function Plugin(element, options){ | |
this._element = element; | |
this._options = options; | |
} | |
//change "Plugin" | |
Plugin.nullValue = {}; | |
//change "pluginName" | |
$.fn.pluginName = function (methodOrOptions) { | |
var args = arguments, | |
firstResult, | |
chainResult = this.each(function () { | |
if (typeof firstResult !== "undefined") { | |
return; | |
} | |
var target = $(this), | |
//change "namespace.pluginName" | |
data = target.data("namespace.pluginName"), | |
methodArgs; | |
if (!data) { | |
//change "namespace.pluginName" & "Plugin" | |
target.data("namespace.pluginName", (data = new Plugin(target, methodOrOptions))); | |
} | |
if (typeof methodOrOptions === "string") { | |
methodArgs = [data]; | |
Array.prototype.push.apply(methodArgs, Array.prototype.slice.call(args, 1)); | |
firstResult = data[methodOrOptions].apply(target, methodArgs); | |
} | |
}); | |
//change "Plugin" | |
return firstResult === Plugin.nullValue ? (void 0) : (firstResult || chainResult); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment