Skip to content

Instantly share code, notes, and snippets.

@gaoguoxin
Forked from dharFr/jquery.pluginName.coffee
Created December 6, 2013 07:38
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 gaoguoxin/7819976 to your computer and use it in GitHub Desktop.
Save gaoguoxin/7819976 to your computer and use it in GitHub Desktop.
###*
* jQuery pluginName plugin v0.1
* ==========================
* see http://docs.jquery.com/Plugins/Authoring
*
* plugin description goes here
* author your.name@email.com
###
(($) ->
# Private functions
privateFunc = () ->
console.log "private"
# Public Functions
methods =
init: () ->
console.log 'init'
@each ->
$this = $(@)
data = $this.data 'pluginName'
if not data
### Do more stuff here ###
$(@).data 'pluginName'
target: $this
return
destroy: () ->
@each ->
$this = $(@)
data = $this.data 'pluginName'
data.pluginName.remove()
$this.removeData 'pluginName'
return
$.fn.pluginName = (method) ->
# Method calling logic
if methods[method]
methods[method].apply this, Array.prototype.slice.call arguments, 1
else if typeof method is 'object' or !method
methods.init.apply this, arguments
else
$.error "jQuery.pluginName: Method #{ method } does not exist on jQuery.pluginName"
return
)(jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment