Skip to content

Instantly share code, notes, and snippets.

@blvp
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save blvp/650dab604847849819cf to your computer and use it in GitHub Desktop.

Select an option

Save blvp/650dab604847849819cf to your computer and use it in GitHub Desktop.
/**
* Created by blvp on 09.06.15.
*/
var extend = {
Page: function (prototypeProps) {
return function (staticOptions) {
return {
initialize: function () {
_.extend(this, prototypeProps);
_.extend(this, staticOptions);
_.extend(this, _.object(_.map(this.components, function(selector, key){return [key, $(selector)];})));
this.refresh();
},
refresh: function () {
function registerFunction(that, eventhandler) {
return function (evt) {
evt.that = that;
evt.$el = $(evt.currentTarget);
that[eventhandler](evt);
}
}
var events = this.delegatedEvents;
var that = this;
if (events) {
_.each(events, function (eventHandler, eventUnparsed) {
var eventParsed = eventUnparsed.split(" ");
if (eventParsed.length < 2) {
console.warn("delegatedEvent: [ " + eventUnparsed + " ] should contain event pairs");
}
var eventType = eventParsed[0],
eventSelector = eventParsed[1];
$(eventSelector).on(eventType, registerFunction(that, eventHandler))
});
} else {
console.warn("no delegated Events for current page");
}
}
}
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment