Skip to content

Instantly share code, notes, and snippets.

@giginet
Created December 9, 2011 05:28
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 giginet/1450317 to your computer and use it in GitHub Desktop.
Save giginet/1450317 to your computer and use it in GitHub Desktop.
class SkeltonjQueryPlugin
constructor : (@pluginName) ->
plugin = @
$.fn[@pluginName] = (method) ->
if method and plugin[method]?
return plugin[method].apply @, Array::slice.call(arguments, 1)
else if typeof method is 'object' or not method
return plugin['init'].apply @, arguments
else
$.error "Method #{method} does not exist on jQuery.#{plugin.pluginName}()."
@
init : (custom) ->
@options = $.extend true, @options, custom
@
options : {
}
class SamplejQueryPlugin extends SkeltonjQueryPlugin
init : (custom) ->
super
@
options : {
message : 'hello'
}
method : (argment) ->
console.log argment
new SamplejQueryPlugin('sample')
$ ->
$('#sample').sample()
$('#sample').sample('method', 'fizzbuzz')
$('#sample').sample('method2', 'fizzbuzz')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment