Created
June 29, 2016 18:53
-
-
Save kirkportas/82bd5cbc68e0ce1b9d3b5b49a8a880e0 to your computer and use it in GitHub Desktop.
This file contains 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
DEBUG=true; // Global Debug Var | |
// This could be "var DEMO_APP =", using window.DEMO_APP implies that other files will join to this window variable. | |
// This DEMO_APP var will contain the entire JS application. | |
window.DEMO_APP = { | |
// Simple router of page names & Template file locations | |
// This lets us refer to a template with an easy-to-use name like 'landing' | |
pageRouter: { 'landing': 'www/templates/landing.hbs' }, | |
init: function() { | |
if (DEBUG) { console.log("DEMO_APP: init()"); } | |
// Define landing page context for template | |
// 'context' is a Handlebars term, and could also be thought of as 'config' or 'template_params' | |
var context={ | |
placeholder: "Add items to list", | |
tasks: DEMO_APP.tasks.getTasks() // Checks goes thru Tasks=>Api if first load | |
}; | |
// Call a re-usable method that places content on the webpage | |
this.renderPage("landing", context, "#landing-content") | |
}, | |
// This method will be used throughout the app to modify and update content in the Webpage. | |
renderPage: function (templateName, context, selector) { | |
if (DEBUG) { console.log('rendering page: templateName: ' + templateName + ', context: ' +context+ ', selector: '+ selector); } | |
// Get template from compiled JST object, pass in received context (just from init() for now) | |
// 'JST' is a default variable from Handlebars, and is accessed like so: JST[ 'dir/templatename.hbs' ]( params ) | |
templateHtml = JST[ DEMO_APP.pageRouter[templateName] ]( context ); | |
// Add compiled HTML to page, in defined selector. | |
$(selector).html(templateHtml); | |
// Update <html> dom object to track 'active' page. | |
$('html').attr('data-activepage', templateName); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment