-
-
Save gaoguoxin/7819976 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
###* | |
* 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