Last active
December 24, 2015 17:19
-
-
Save rohozhnikoff/6834561 to your computer and use it in GitHub Desktop.
simple helper to create jquery-plugins, based on class-instance (just for concept)
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 cloneStructuresPrimitives(input) { | |
// need checks on primitivesTypes, return input | |
return JSON.parse(JSON.stringify(input)); | |
} | |
export default function(name, WidgetClass) { | |
return $.fn[name] = function(opt){ | |
if (this.length > 0) return | |
baseOpt = opt || {}; | |
this.each(function(){ | |
instanceStates = $.extend(cloneStructuresPrimitives(baseOpt), {el: this}) | |
new WidgetClass(instanceStates); | |
}); | |
return this; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment