Skip to content

Commit bf11c8d

Browse files
committed
Merge pull request #14 from zhangxinxu/develop
avoid querySelector error
2 parents 694884b + cd27a12 commit bf11c8d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
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": "1.1.4",
3+
"version": "1.1.5",
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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
var array = [];
2424
var slice = array.slice;
2525

26+
// Is it a simple selector, from jQuery
27+
var isSimple = /^.[^:#\[\.,]*$/
28+
2629
var supportHistory = "pushState" in history &&
2730
"replaceState" in history &&
2831
// When running inside a FF iframe, calling replaceState causes an error
@@ -38,7 +41,7 @@
3841
*
3942
* @type string
4043
**/
41-
Mobilebone.VERSION = '1.1.4';
44+
Mobilebone.VERSION = '1.1.5';
4245

4346
/**
4447
* Whether bind events when dom ready
@@ -689,7 +692,7 @@
689692
var hash = location.hash.replace("#&", "#"), ele_in = null;
690693
if (hash == "" || hash == "#") {
691694
this.transition(document.querySelector("." + this.classPage));
692-
} else if (/&/.test(hash) == false && (ele_in = document.querySelector(hash)) && ele_in.classList.contains(this.classPage)) { // 'ele_in' must be a page element
695+
} else if (isSimple.test(hash) == true && (ele_in = document.querySelector(hash)) && ele_in.classList.contains(this.classPage)) { // 'ele_in' must be a page element
693696
this.transition(ele_in);
694697
} else {
695698
// as a ajax
@@ -845,14 +848,14 @@
845848
var hash = location.hash.replace("#&", "").replace("#", "");
846849
if (hash == "") return;
847850

848-
var page_in = store[hash] || document.querySelector(location.hash), page_out = document.querySelector(".in." + Mobilebone.classPage);
851+
var page_in = store[hash] || null, page_out = document.querySelector(".in." + Mobilebone.classPage);
849852

853+
if (page_in == null && isSimple.test("#" + hash)) page_in = document.querySelector("#" + hash);
850854
if (page_in && page_in == page_out) return;
851-
852855

853856
// hash ↔ id
854857
if (store[hash] && Mobilebone.pushStateEnabled) {
855-
Mobilebone.transition(store[hash], document.querySelector(".in." + Mobilebone.classPage), Mobilebone.isBack(page_in, page_out), {
858+
Mobilebone.transition(page_in, document.querySelector(".in." + Mobilebone.classPage), Mobilebone.isBack(page_in, page_out), {
856859
history: false
857860
});
858861
}

0 commit comments

Comments
 (0)