Created
June 10, 2012 02:04
-
-
Save jaypeeZero/2903574 to your computer and use it in GitHub Desktop.
Views unexpectedly leaving stack in BackStack
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
/// TEMPLATING /// | |
tpl = { | |
// Hash of preloaded templates for the app | |
templates: {}, | |
// Recursively pre-load all the templates for the app. | |
// This implementation should be changed in a production environment. All the template files should be | |
// concatenated in a single file. | |
loadTemplates: function (names, callback) { | |
var that = this; | |
var loadTemplate = function (index) { | |
var name = names[index]; | |
var data = $.ajax({ type: 'GET', url: 'templates/' + name + '.html', async: false }).responseText; | |
that.templates[name] = data; | |
index++; | |
if (index < names.length) { | |
loadTemplate(index); | |
} else { | |
callback(); | |
} | |
}; | |
loadTemplate(0); | |
}, | |
// Get template by name from hash of preloaded templates | |
get:function (name) { | |
var temp = this.templates[name]; | |
return temp; | |
} | |
}; | |
// Initializing BackStack.StackNavigator for the #container div | |
var stackNavigator = new BackStack.StackNavigator({ | |
el: '#container' | |
}); |
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></title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> | |
<link rel="stylesheet" href="css/bootstrap.css"> | |
<link rel="stylesheet" href="css/bootstrap-responsive.css"> | |
<link rel="stylesheet" href="css/style.css"> | |
<!-- Frameworks and Libraries --> | |
<script src="js/frameworksandlibraries/jquery.min.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/frameworksandlibraries/underscore.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/frameworksandlibraries/backbone.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/frameworksandlibraries/cordova-1.7.0rc1.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/frameworksandlibraries/lawnchair.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/frameworksandlibraries/webkit-sqlite.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/frameworksandlibraries/callbacks.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/frameworksandlibraries/backstack.js" type="text/javascript" charset="utf-8"></script> | |
<!-- Our system files --> | |
<script src="js/views/splash.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/models/user.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/views/login.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/models/project.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/views/projectoverview.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/views/notes.js" type="text/javascript" charset="utf-8"></script> | |
<script src="js/app.js" type="text/javascript" charset="utf-8"></script> <!-- This should be loaded AFTER View and Model files --> | |
<!-- Functions specific to this page --> | |
<script type="text/javascript" charset="utf-8"> | |
function onBodyLoad() { | |
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)) { | |
document.addEventListener("deviceready", onDeviceReady, false); | |
} else { | |
onDeviceReady(); //this is a desktop browser | |
} | |
} | |
var onDeviceReady = function() { | |
tpl.loadTemplates(['login', 'projectoverview', 'splash', 'notes', 'addproject', 'participants', 'addparticipant', 'tasks', 'addtask', 'timesheet', 'timeentry', 'attachments', 'addlink', 'uploaddocument', 'settings', 'usersettings', 'projectsettings'], | |
function () { | |
stackNavigator.on("viewChanging", function(e) { | |
console.log("view changing"); | |
console.log(e); | |
}, false); | |
stackNavigator.on("viewChanged", function(e) { | |
console.log("view changed"); | |
console.log(e); | |
}, false); | |
stackNavigator.on("viewActivate", function(e) { | |
console.log("view activated"); | |
console.log(e); | |
}, false); | |
stackNavigator.on("viewDeactivate", function(e) { | |
console.log("view deactivated"); | |
console.log(e); | |
}, false); | |
stackNavigator.pushView(SplashPage); | |
}); | |
}; | |
$(document).ready(function(){ | |
// Runs before "onDeviceReady" | |
}); | |
</script> | |
</head> | |
<body class="" onload="onBodyLoad()"> | |
<div id="container"> | |
index | |
</div> | |
</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
<div id="container"> | |
Notes are here | |
</div> |
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
var NotesPage = Backbone.View.extend({ | |
el: "#container", | |
initialize: function() { | |
this.template = _.template(tpl.get("notes")); | |
}, | |
render: function() { | |
$(this.el).html(this.template({})); | |
return this; | |
} | |
}); |
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
<div id="container"> | |
<div class="navbar boxheading"><h3>Overview</h3></div> | |
<div class="container"> | |
<div class="row-fluid"> | |
<div class="span2 btn-icon"> | |
<a href="#notes" class="btn_icon square"> | |
<img src="images/glyphicons/glyphicons_309_comments.png" /> | |
<div>Notes</div> | |
</a> | |
</div> | |
<div class="span2 btn-icon"> | |
<a href="#tasks" class="btn_icon square"> | |
<img src="images/glyphicons/glyphicons_150_check.png" /> | |
<div>Tasks</div> | |
</a> | |
</div> | |
</div> | |
</div> | |
</div> |
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
var OverviewPage = Backbone.View.extend({ | |
el: "#container", | |
events: { | |
"click a.btn_icon": "icon_clicked" | |
}, | |
initialize: function() { | |
this.template = _.template(tpl.get("projectoverview")); // tpl is an object that grabs html files via jQuery .ajax function | |
}, | |
render: function() { | |
$(this.el).html(this.template(this.model.toJSON())); | |
return this; | |
}, | |
icon_clicked: function(e) { | |
e.preventDefault(); | |
switch (e.currentTarget.hash) { | |
case "#notes": | |
stackNavigator.pushView(new NotesPage({})); | |
break; | |
} | |
} | |
}); |
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
Loading | |
<br /> | |
<img src="css/images/ajax-loader.gif" /> |
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
var SplashPage = Backbone.View.extend({ | |
initialize:function(){ | |
this.template = _.template(tpl.get("splash")); | |
}, | |
render:function(){ | |
$(this.el).html(this.template()); | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment