Skip to content

Instantly share code, notes, and snippets.

@artlili
Last active May 1, 2019 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlili/2dc658d00a417090949dc4fedde3c03c to your computer and use it in GitHub Desktop.
Save artlili/2dc658d00a417090949dc4fedde3c03c to your computer and use it in GitHub Desktop.
jQuery plugin start
(($, window, undefined) => {
let pluginName = 'plugin_name',
document = window.document,
settings = {
}
class Plugin {
constructor(element, options) {
this.element = element;
this.$window = $(window);
this.options = $.extend( {}, settings, options) ;
this.settings = settings;
this.name = pluginName;
this.init()
}
init() {
console.log('Plugin init');
}
}
$.fn[pluginName] = function(options) {
const plugin = new Plugin( this, options )
return this.each(() => {
if (!$.data(this, `plugin_${pluginName}`)) {
$.data(this, `plugin_${pluginName}`, plugin);
}
});
}
})(jQuery, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment