Skip to content

Instantly share code, notes, and snippets.

@jrosebr1
Created January 13, 2012 16:22
Show Gist options
  • Save jrosebr1/1607311 to your computer and use it in GitHub Desktop.
Save jrosebr1/1607311 to your computer and use it in GitHub Desktop.
Using jQTouch to Remember the Last Visited Page.
// initialize the jQTouch variable and the current hash, then grab
// the app history from local storage
var jQT = null;
var currentHash = null;
var hist = localStorage.getItem("app_history");
// if the history is null, then reset the history list to include
// just 'home'
if (hist == null){
hist = ["home"];
}
// otherwise, the history exists, so split it into a list
else{
hist = hist.split(",");
}
// wait until the DOM is ready
$(document).ready(function(){
// only process the history if there are entries
if (hist.length > 0){
// loop over the history
for (i = 0; i < hist.length - 1; i++){
// create an element for the DOM and then load the
// content
$("#jqt").append("<div id='" + hist[i] + "'></div>");
$("#" + hist[i]).load("/your/path/to/html/" + hist[i] + ".html");
}
// change the location hash
document.location.hash = "#" + hist[0];
}
// setup jQTouch
jQT = $.jQTouch({
"icon": "/images/icon.png",
"icon4": "/images/icon.png",
"startupScreen": "/images/startup.png",
"useFastTouch": false});
});
$(document).bind("pageAnimationEnd", function(){
// check to see if the current hash does not match the location
// hash
if (currentHash != document.location.hash){
// grab the current hash
currentHash = document.location.hash;
// check to see if the current hash is already in the history
// list
if (currentHash.replace("#", "") != hist[0]){
// update the history
hist.unshift(currentHash.replace("#", ""));
}
// update the local storage with the history
localStorage.setItem("app_history", hist);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment