Last active
August 29, 2015 14:23
-
-
Save blvp/650dab604847849819cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * 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