Skip to content

Commit c103be8

Browse files
author
zhangxinxu
committed
no id page back
if first page has no id, it can also go back.
1 parent d3ca50a commit c103be8

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobilebone",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Bone main for mobile web APP with a sigle page mode.",
55
"main": "src/mobilebone.js",
66
"directories": {

src/mobilebone.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*
4141
* @type string
4242
**/
43-
Mobilebone.VERSION = '2.0.1';
43+
Mobilebone.VERSION = '2.0.2';
4444

4545
/**
4646
* Whether catch attribute of href from element with tag 'a'
@@ -726,7 +726,8 @@
726726
if (hasInited == true) return 'Don\'t repeat initialization!';
727727
var hash = location.hash.replace("#&", "#"), ele_in = null;
728728
if (hash == "" || hash == "#") {
729-
this.transition(document.querySelector("." + this.classPage));
729+
store._initPage = document.querySelector("." + this.classPage);
730+
this.transition(store._initPage);
730731
} else if (isSimple.test(hash) == true && (ele_in = document.querySelector(hash)) && ele_in.classList.contains(this.classPage)) { // 'ele_in' must be a page element
731732
this.transition(ele_in);
732733
} else {
@@ -908,10 +909,14 @@
908909
* page change when history change
909910
**/
910911
window.addEventListener("popstate", function() {
911-
var hash = location.hash.replace("#&", "").replace("#", "");
912-
if (hash == "") return;
913-
914-
var page_in = store[hash];
912+
var hash = location.hash.replace("#&", "").replace("#", ""), page_in = null;
913+
if (hash == "") {
914+
// if no hash, get init page as 'page_in'
915+
page_in = store._initPage;
916+
if (!page_in) return;
917+
} else {
918+
page_in = store[hash];
919+
}
915920

916921
if (!page_in) {
917922
if(isSimple.test(hash) == false) {

test/history/ajax-page.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
</head>
66

77
<body>
8-
<div class="page out"><a href="#pageHome" data-rel="back">返回</a></div>
8+
<div class="page out"><a href="javascript:" data-rel="back">返回</a></div>
99
</body>
1010
</html>

test/history/history.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</head>
1010

1111
<body>
12-
<div id="pageHome" class="page out">
12+
<div class="page out">
1313
<ul>
1414
<li><a href="#page1">浏览器返回测试-页面1</a></li>
1515
<li><a href="#page2">浏览器返回测试-页面2</a></li>
@@ -22,9 +22,9 @@
2222
<li><a href="../index.html" data-ajax="false">&laquo; 返回测试引导首页</a></li>
2323
</ul>
2424
</div>
25-
<div id="page1" class="page out"><a href="#pageHome" data-rel="back">&laquo;返回1</a></div>
26-
<div id="page2" class="page out"><a href="#pageHome" data-rel="back">&laquo;返回2</a></div>
27-
<div id="page3" class="page out"><a href="#pageHome" data-rel="back">&laquo;返回3</a></div>
25+
<div id="page1" class="page out"><a href="javascript:" data-rel="back">&laquo;返回1</a></div>
26+
<div id="page2" class="page out"><a href="javascript:" data-rel="back">&laquo;返回2</a></div>
27+
<div id="page3" class="page out"><a href="javascript:" data-rel="back">&laquo;返回3</a></div>
2828

2929
<script src="../../src/mobilebone.js"></script>
3030
</body>

0 commit comments

Comments
 (0)