Created
June 29, 2016 18:39
-
-
Save kirkportas/52d6e17f59ab993788b980bbfc7dd561 to your computer and use it in GitHub Desktop.
Devblog 1 - JS Architecture
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Kirk <3 JS</title> | |
<meta charset="utf-8"/> | |
<link rel="stylesheet" type="text/css" href="css/index.css"/> | |
<!-- Jquery + Handlebars --> | |
<script type="text/javascript" src="lib/jquery-2.2.4.min.js"></script> | |
<script type="text/javascript" src="lib/handlebars-v4.0.5.js"></script> | |
<!-- Bootstrap 3.3.6 --> | |
<link rel="stylesheet" type="text/css" href="lib/bootstrap-3.3.6/css/bootstrap.min.css" /> | |
<script type="text/javascript" src="lib/bootstrap-3.3.6/js/bootstrap.min.js"></script> | |
<!-- Compiled templates --> | |
<script type="text/javascript" src="compiled/templates.js"></script> | |
<!-- Home-rolled modules --> | |
<script type="text/javascript" src="js/core.js"></script> | |
<script type="text/javascript" src="js/models/task.js"></script> | |
<script type="text/javascript" src="js/api.js"></script> | |
<script type="text/javascript" src="js/tasks.js"></script> | |
</head> | |
<body> | |
<!-- Bootstrap container and an initial row --> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-12"> | |
<div class="col-md-4"> | |
<img id="logo_l" src="img/logo.jpg" /> | |
</div> | |
<div class="col-md-4"> | |
<!-- This is the targeted div for a Single-Page App --> | |
<div id="landing-content"> | |
<!-- Default display in case of Handlebars error --> | |
<h3> Oh my your handlebars didn't compile! </h3> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- END Main Page --> | |
<!-- Init Demo App --> | |
<script> | |
$(function () { DEMO_APP.init(); }); | |
</script> | |
</body> | |
</html> |
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
/** app/js/api.js **/ | |
var DEMO_APP = window.DEMO_APP || {}; | |
DEMO_APP.api = { | |
use_localstorage: true, | |
loadTasks: function() { | |
var tasks; | |
if(this.use_localstorage == true) { | |
if (localStorage.task_items) { | |
tasks = JSON.parse(localStorage.task_items); | |
} else { | |
if (DEBUG) { console.log('No tasks available in localStorage'); } | |
tasks = [ new Task({'title': "Write Code"}), | |
new Task({'title': "Push Code" }), | |
new Task({'title': "Install Sublime3"}) ] | |
} | |
} else { | |
// Load from API or other datastore | |
console.error('No API Available. For demo, '+ | |
'DEMO_APP.api.use_localstorage must be true'); | |
} | |
return tasks; | |
}, | |
// This is a simple overwrite, not an append. | |
saveTasks: function(task_items) { | |
if (DEBUG) { console.log('api.saveTasks()'); } | |
if(this.use_localstorage == true) { | |
localStorage.task_items = JSON.stringify(task_items); // Cache the results | |
} else { | |
// Save to API or other datastore | |
console.error('No API Available. For demo, '+ | |
'DEMO_APP.api.use_localstorage must be true'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment