Permalink
Browse files

simplified caching check in pageshow; fixed navbar highlighting for c…

…ached pages
  • Loading branch information...
1 parent 3e67ca0 commit f72c3d5ac42f48ca66b9393c94ec42cb21345df7 @dgeb committed Nov 4, 2011
Showing with 22 additions and 26 deletions.
  1. +4 −4 a.html
  2. +10 −14 app.js
  3. +4 −4 b.html
  4. +4 −4 c.html
View
8 a.html
@@ -10,13 +10,13 @@
<script src="app.js"></script>
</head>
<body>
-<div data-role="page" data-dom-cache="false">
+<div data-role="page" data-id="a">
<div data-role="header">
<div data-role="navbar">
<ul>
- <li><a href="a.html" class="ui-btn-active">A</a></li>
- <li><a href="b.html">B</a></li>
- <li><a href="c.html">C</a></li>
+ <li><a href="a.html" id="a">A</a></li>
+ <li><a href="b.html" id="b">B</a></li>
+ <li><a href="c.html" id="c">C</a></li>
</ul>
</div>
</div>
View
24 app.js
@@ -1,8 +1,4 @@
-//$(document).bind("mobileinit", function() {
-// $.mobile.page.prototype.options.domCache = true;
-//});
-
-$(document).bind('pagecreate',function(event, ui) {
+$(document).bind("pagecreate", function(event, ui) {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
@@ -11,15 +7,15 @@ $(document).bind('pagecreate',function(event, ui) {
if (seconds < 10) seconds = "0" + seconds;
var page = $(event.target);
- page.find('.load-time').text(hours + ":" + minutes + ":" + seconds);
+ page.find(".load-time").text(hours + ":" + minutes + ":" + seconds);
});
-$(document).bind('pageshow',function(event, ui) {
- var prevPage = ui.prevPage ;
- if (ui.prevPage && !shouldPageBeCached(ui.prevPage))
- ui.prevPage.remove();
-});
+$(document).bind("pageshow", function(event, ui) {
+ var prevPage = ui.prevPage;
+ if (prevPage && prevPage.attr("data-dom-cache") != "true")
+ prevPage.remove();
-function shouldPageBeCached(page) {
- return page.attr("data-dom-cache") != "false" || $.mobile.page.prototype.options.domCache;
-}
+ // highlight the current nav button (necessary when re-loading cached pages)
+ var page = $(event.target);
+ page.find("#" + page.attr("data-id")).addClass("ui-btn-active");
+});
View
8 b.html
@@ -10,13 +10,13 @@
<script src="app.js"></script>
</head>
<body>
-<div data-role="page" data-dom-cache="false">
+<div data-role="page" data-id="b">
<div data-role="header">
<div data-role="navbar">
<ul>
- <li><a href="a.html">A</a></li>
- <li><a href="b.html" class="ui-btn-active">B</a></li>
- <li><a href="c.html">C</a></li>
+ <li><a href="a.html" id="a">A</a></li>
+ <li><a href="b.html" id="b">B</a></li>
+ <li><a href="c.html" id="c">C</a></li>
</ul>
</div>
</div>
View
8 c.html
@@ -10,13 +10,13 @@
<script src="app.js"></script>
</head>
<body>
-<div data-role="page" data-dom-cache="true">
+<div data-role="page" data-id="c" data-dom-cache="true">
<div data-role="header">
<div data-role="navbar">
<ul>
- <li><a href="a.html">A</a></li>
- <li><a href="b.html">B</a></li>
- <li><a href="c.html" class="ui-btn-active">C</a></li>
+ <li><a href="a.html" id="a">A</a></li>
+ <li><a href="b.html" id="b">B</a></li>
+ <li><a href="c.html" id="c">C</a></li>
</ul>
</div>
</div>

0 comments on commit f72c3d5

Please sign in to comment.