Last active
May 1, 2019 15:17
-
-
Save artlili/2dc658d00a417090949dc4fedde3c03c to your computer and use it in GitHub Desktop.
jQuery plugin start
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
(($, 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