Skip to content

Instantly share code, notes, and snippets.

@lukemorton
Created January 6, 2011 21:08
Show Gist options
  • Save lukemorton/768584 to your computer and use it in GitHub Desktop.
Save lukemorton/768584 to your computer and use it in GitHub Desktop.
(($) ->
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)
(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