Created
August 14, 2012 19:32
-
-
Save Rockncoder/3352018 to your computer and use it in GitHub Desktop.
The new Kernel no need for .live()
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
| var RocknCoder = RocknCoder || {}; | |
| RocknCoder.Pages = RocknCoder.Pages || {}; | |
| // put all of the page events into one string | |
| RocknCoder.PageEvents = "pagebeforeshow pageshow pagebeforechange pagechange pagebeforehide pagehide"; | |
| // the kernel remains unchanged | |
| RocknCoder.Pages.Kernel = function (event) { | |
| var that = this, | |
| eventType = event.type, | |
| pageName = $(this).attr("data-rockncoder-jspage"); | |
| if (RocknCoder && RocknCoder.Pages && pageName && RocknCoder.Pages[pageName] && RocknCoder.Pages[pageName][eventType]) { | |
| RocknCoder.Pages[pageName][eventType].call(that); | |
| } | |
| }; | |
| RocknCoder.Pages.Events = (function () { | |
| $("div[data-rockncoder-jspage]").on( | |
| RocknCoder.PageEvents, | |
| RocknCoder.Pages.Kernel | |
| ); | |
| }()); | |
| RocknCoder.Pages.Evs = (function () { | |
| // we bind to the document's pageload event | |
| $(document).bind( | |
| 'pageload', | |
| function (event, obj) { | |
| console.log("event = " + event.type); | |
| $("div[data-rockncoder-jspage]") | |
| // to make sure we aren't double hooking events clear them all | |
| .off(RocknCoder.PageEvents) | |
| // then hook them all (the newly loaded page is in DOM at this point) | |
| .on(RocknCoder.PageEvents, RocknCoder.Pages.Kernel); | |
| } | |
| ); | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment