Created
January 6, 2011 21:08
-
-
Save lukemorton/768584 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
(($) -> | |
class Plugin | |
constructor: (@element, @settings) -> | |
console.log @element | |
@element.bind | |
'click' : @started | |
'blur' : @stopped | |
started: (e) => @settings.start.call @element, e | |
stopped: (e) => @settings.stop.call @element, e | |
$.plugin = | |
globalSettings: | |
start : -> @fadeOut() | |
stop : -> @fadeIn() | |
$.fn.plugin = (settings = {}) -> | |
settings = $.extend {}, $.plugin.globalSettings, settings | |
@each -> new Plugin $(@), settings | |
)(@jQuery) |
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
(function ($) { | |
var Plugin = function (element, settings) { | |
this.element = element; | |
this.settings = settings; | |
this.element.bind({ | |
'click' : $.proxy(this.started, this), | |
'blur' : $.proxy(this.stopped, this) | |
}); | |
}; | |
Plugin.prototype.started = function (e) { | |
return this.settings.start.call(this.element, e); | |
}; | |
Plugin.prototype.stopped = function (e) { | |
return this.settings.stop.call(this.element, e); | |
}; | |
$.plugin = { | |
globalSettings: { | |
start : function () { | |
return this.fadeOut(); | |
}, | |
stop : function () { | |
return this.fadeIn(); | |
} | |
} | |
}; | |
$.fn.plugin = function (settings) { | |
var settings = $.extend({}, $.plugin.globalSettings, settings || {}); | |
return this.each(function () { | |
new Plugin($(this), settings); | |
}); | |
}; | |
}(this.jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment