Skip to content
Browse files

example 3-13

  • Loading branch information...
1 parent 045453e commit e7815182c4924f6c99846c068882ba8486276d56 @jonathanstark committed
View
BIN ch03/.DS_Store
Binary file not shown.
View
2 ch03/android.css
@@ -76,7 +76,6 @@ ul li a:active, ul li a:hover {
top: 120px;
width: 200px;
}
-/*
#header div.leftButton {
font-weight: bold;
text-align: center;
@@ -97,4 +96,3 @@ ul li a:active, ul li a:hover {
#header div.leftButton.clicked {
-webkit-border-image: url(images/back_button_clicked.png) 0 8 0 14;
}
-*/
View
55 ch03/android.js
@@ -1,25 +1,38 @@
-$(document).ready(function(){
- loadPage();
+var hist = [];
+var startUrl = 'index.html';
+$(document).ready(function(){
+ loadPage(startUrl);
});
function loadPage(url) {
- $('body').append('<div id="progress">Loading...</div>');
- scrollTo(0,0);
- if (url == undefined) {
- $('#container').load('index.html #header ul', hijackLinks);
+ $('body').append('<div id="progress">Loading...</div>');
+ scrollTo(0,0);
+ if (url == startUrl) {
+ var element = ' #header ul';
} else {
- $('#container').load(url + ' #content', hijackLinks);
- }
-}
-function hijackLinks() {
- $('#container a').click(function(e){
- var url = e.target.href;
- if (url.match(window.location.hostname)) {
- e.preventDefault();
- loadPage(url);
- }
+ var element = ' #content';
+ }
+ $('#container').load(url + element, function(){
+ var title = $('h2').html() || 'Hello!';
+ $('h1').html(title);
+ $('h2').remove();
+ $('.leftButton').remove();
+ hist.unshift({'url':url, 'title':title});
+ if (hist.length > 1) {
+ $('#header').append('<div class="leftButton">'+hist[1].title+'</div>');
+ $('#header .leftButton').click(function(e){
+ $(e.target).addClass('clicked');
+ var thisPage = hist.shift();
+ var previousPage = hist.shift();
+ loadPage(previousPage.url);
+ });
+ }
+ $('#container a').click(function(e){
+ var url = e.target.href;
+ if (url.match(window.location.hostname)) {
+ e.preventDefault();
+ loadPage(url);
+ }
+ });
+ $('#progress').remove();
});
- var title = $('h2').html() || 'Hello!';
- $('h1').html(title);
- $('h2').remove();
- $('#progress').remove();
-}
+}
View
BIN ch03/images/.DS_Store
Binary file not shown.
View
BIN ch03/images/back_button.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN ch03/images/back_button_clicked.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e781518

Please sign in to comment.
Something went wrong with that request. Please try again.