Created
February 14, 2012 03:14
-
-
Save corbanbrook/1823080 to your computer and use it in GitHub Desktop.
example of load mechanism on deeply chained async functions
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
| // load and process the manifest | |
| load.add("loading manifest", function() { self.manifest = new Pressly.Manifest(load.next); }, true); | |
| load.add("initialize viewport listeners", self.initializeViewportChangeListeners); | |
| load.add("create static section header layer", function() { | |
| // Static section header layer | |
| self.sectionLayer = new Pressly.Paging("#sections", { | |
| resettable: false, | |
| pageClass: "subpage", | |
| name: "sectionLayer", | |
| disableGestures: true, | |
| active: true, | |
| success: load.next // next thing in the list happens on success | |
| }); | |
| }, true); | |
| load.add("create page layer", function(sectionLayer) { | |
| sectionLayer.lock(); | |
| // Initial setup of the media query viewport styles so that pages can correctly measure themselves | |
| self.attachMediaQueryCSS(true); | |
| // Create layer for pages | |
| self.pageLayer = new Pressly.Paging("#pages", { | |
| resettable: true, | |
| manifestItems: self.manifest.find(".page"), | |
| navSource: "nav.sections", | |
| name: "pageLayer", | |
| trimmable: true, | |
| // Prepend header to pages | |
| prepend: function() { | |
| if (!this.isFullscreen()) { | |
| // Clone and sanitize the section header | |
| var sectionHeader = sections.find("#" + this.sectionId) | |
| .clone() | |
| .removeAttr("id") | |
| .removeAttr("data-index") | |
| .removeAttr("style") | |
| .removeClass("subpage"); | |
| sectionHeader.find("*").removeAttr("data-action"); | |
| sectionHeader.find(".modal").remove(); | |
| return sectionHeader; | |
| } | |
| }, | |
| // allow analytics | |
| tracker: function(eventParams){ | |
| self.track(eventParams); | |
| }, | |
| // The pageLayer has an active initial state | |
| active: true, | |
| success: load.next | |
| }); | |
| }, true); | |
| load.add("create the article layer", function(pageLayer) { | |
| // Initialize top section nav | |
| self.initSectionNav(); | |
| // Initialize the page nav based off of the generated pageLayer | |
| // | |
| // | |
| // | |
| // Turn off page nav for now while we get all the other regressions figured out | |
| // | |
| // | |
| // | |
| // self.initPageNav(pageLayer); | |
| // Create layer for articles | |
| self.articleLayer = new Pressly.Paging("#articles", { | |
| resettable: true, | |
| name: "articleLayer", | |
| manifestItems: self.manifest.find(".article"), | |
| disableGestures: true, | |
| tracker: function(eventParams){ | |
| self.track(eventParams); | |
| }, | |
| success: load.next | |
| }); | |
| }, true); | |
| load.add("initialize layer sync and finalize issue.", function(articleLayer) { | |
| self.initializeLayerSync(); | |
| self.initNavEvents(); | |
| if (!Pressly.Device.isTablet() && !Pressly.Device.isPhone() && Pressly.Keyboard) { | |
| Pressly.Keyboard.init(); | |
| } | |
| // Attach Media Query CSS to set initial viewport component sizes | |
| setTimeout(function() { self.attachMediaQueryCSS(); }, 1); | |
| // Initial snap to page after load finish | |
| if (self.options.jumpToPageAfterLoad) { | |
| setTimeout(function() { | |
| if (pageLayer.currentPage === 0) { | |
| pageLayer.snapToPage(self.options.jumpToPageAfterLoad); | |
| } | |
| }, (self.options.jumpToPageDelay || 2000)); | |
| } | |
| if(Pressly.Test){ | |
| var tester = new Pressly.Test(); | |
| tester.findTests(); | |
| } | |
| }); | |
| load.run(); // Load in order |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment