Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root = global ? window
- (( $ )->
- class MyInternalClass
- defaultOptions: {
- }
- teardown: ()->
- $(@element).unbind("destroyed",
- this.teardown);
- this.unbind()
- $.removeData(@element,
- "myPlugin");
- unbind: ()->
- myMethod: ()->
- init: ()->
- # Initialization
- constructor: (@element, options)->
- @settings = $.extend(true, {}, @defaultOptions, options)
- $(@element).bind("destroyed",$.proxy(this.teardown, this));
- $.fn.myPlugin = (methodOrSettings) ->
- if (typeof(methodOrSettings) == 'string')
- argsMethod = Array.prototype.slice.call(arguments, 1)
- this.each(() ->
- if (methodOrSettings && typeof(methodOrSettings) == 'string')
- instance = $(this).data("myPlugin")
- if (methodOrSettings == 'myMethod')
- instance.myMethod.apply(instance,argsMethod)
- else
- if (!$(this).data("myPlugin"))
- instance = new MyInternalClass(this,methodOrSettings)
- instance.init()
- $(this).data("myPlugin",instance)
- )
- )( jQuery );
Add Comment
Please, Sign In to add comment