Last active
October 10, 2015 14:17
-
-
Save nicholasstephan/3703081 to your computer and use it in GitHub Desktop.
JS: 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 (factory) { | |
if (typeof define === 'function' && define.amd) { | |
define(['jquery'], factory); | |
} else { | |
factory(jQuery); | |
} | |
}(function ($) { | |
"use strict"; | |
/* DEFINITION */ | |
var YourPlugin = function() { | |
}; | |
YourPlugin.prototype = { | |
}; | |
/* jQuery PLUGIN */ | |
$.fn.yourPlugin = function (option) { | |
return this.each(function () { | |
var $this = $(this), | |
data = $this.data('yourplugin'), | |
options = $.extend({}, $.fn.yourPlugin.defaults, typeof option == 'object' && option); | |
if(!data) | |
$this.data('yourplugin', (data = new YourPlugin(this, options))); | |
if(typeof option == 'string') | |
data[option](); | |
}); | |
}; | |
$.fn.yourPlugin.defaults = { | |
}; | |
$.fn.yourPlugin.Constructor = YourPlugin; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment