Guest User

Untitled

a guest
Nov 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. root = global ? window
  2.  
  3. (( $ )->
  4.  
  5. class MyInternalClass
  6.  
  7. defaultOptions: {
  8. }
  9.  
  10. teardown: ()->
  11. $(@element).unbind("destroyed",
  12. this.teardown);
  13.  
  14. this.unbind()
  15.  
  16. $.removeData(@element,
  17. "myPlugin");
  18.  
  19. unbind: ()->
  20.  
  21. myMethod: ()->
  22.  
  23. init: ()->
  24. # Initialization
  25.  
  26. constructor: (@element, options)->
  27. @settings = $.extend(true, {}, @defaultOptions, options)
  28.  
  29. $(@element).bind("destroyed",$.proxy(this.teardown, this));
  30.  
  31. $.fn.myPlugin = (methodOrSettings) ->
  32.  
  33. if (typeof(methodOrSettings) == 'string')
  34. argsMethod = Array.prototype.slice.call(arguments, 1)
  35.  
  36. this.each(() ->
  37. if (methodOrSettings && typeof(methodOrSettings) == 'string')
  38.  
  39. instance = $(this).data("myPlugin")
  40.  
  41. if (methodOrSettings == 'myMethod')
  42. instance.myMethod.apply(instance,argsMethod)
  43. else
  44. if (!$(this).data("myPlugin"))
  45. instance = new MyInternalClass(this,methodOrSettings)
  46. instance.init()
  47. $(this).data("myPlugin",instance)
  48. )
  49.  
  50. )( jQuery );
Add Comment
Please, Sign In to add comment