-
-
Save davidalpert/403765 to your computer and use it in GitHub Desktop.
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
(function($) | |
{ | |
$.fn.myPlugin = function(optionsOrCommand, commandOptions) | |
{ | |
if (optionsOrCommand == 'someCommand') | |
{ | |
return this.each(function() | |
{ | |
this.myPlugin.someOtherFunction(); | |
}); | |
} | |
var opts = $.extend($.fn.myPlugin.defaults, optionsOrCommand); | |
return this.each(function() | |
{ | |
if (this.myPlugin) { return false; } | |
var $this = $(this); | |
var c = | |
{ | |
initialize: function() | |
{ | |
c.someOtherFunction(); | |
}, | |
someOtherFunction: function() | |
{ | |
} | |
} | |
this.myPlugin = c; | |
c.initialize(); | |
}); | |
}; | |
})(jQuery); | |
$.fn.myPlugin.defaults = | |
{ | |
someValue: 'aDefault', | |
}; | |
/* | |
by default you initialize it with a straightforward call: | |
$('something').myPlugin({settings}); | |
but you can also call specific actions after initialization via commands: | |
$('something').myPlugin('someCommand'); | |
or pass options to those commands: | |
$('something').myPlugin('someCommand', {options}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment