Skip to content

Commit 22d6fe0

Browse files
committed
Merge pull request #131 from zhangxinxu/develop
fix captureLink=false data-ajax fail bug
2 parents 93a3408 + 763fe22 commit 22d6fe0

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
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.5.2",
3+
"version": "2.5.3",
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: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*
4444
* @type string
4545
**/
46-
Mobilebone.VERSION = '2.5.2';
46+
Mobilebone.VERSION = '2.5.3';
4747

4848
/**
4949
* Whether catch attribute of href from element with tag 'a'
@@ -944,30 +944,30 @@
944944
var eventName = "click", $ = root.$ || root.jQuery || root.Zepto;
945945
if ($ && $.fn && $.fn.tap && ('ontouchstart' in window == true)) eventName = "tap";
946946

947-
if (this.captureLink == true) {
948-
if ($ && $.fn && $.fn.on) {
949-
// for some unknown 'tap' plugin
950-
$(document).on(eventName, this.handleTapEvent);
951-
} else {
952-
document.addEventListener(eventName, this.handleTapEvent);
953-
}
954-
if (eventName == "tap") {
955-
// zepto tap event.preventDefault can't prevent default click-events
956-
document.addEventListener("click", function(event) {
957-
var target = event.target;
958-
if (!target) return;
959-
if (target.tagName.toLowerCase() != "a" && !(target = target.getParentElementByTag("a"))) {
960-
return;
961-
}
962-
var ajax = target.getAttribute("data-ajax"), href = target.href;
963-
// if not ajax request
964-
if (target.getAttribute("data-rel") == "external"
965-
|| ajax == "false"
966-
|| (href.replace("://", "").split("/")[0] !== location.href.replace("://", "").split("/")[0] && ajax != "true")
967-
) return;
968-
event.preventDefault();
969-
});
970-
}
947+
if ($ && $.fn && $.fn.on) {
948+
// for some unknown 'tap' plugin
949+
$(document).on(eventName, this.handleTapEvent);
950+
} else {
951+
document.addEventListener(eventName, this.handleTapEvent);
952+
}
953+
954+
if (eventName == "tap") {
955+
// zepto tap event.preventDefault can't prevent default click-events
956+
document.addEventListener("click", function(event) {
957+
var target = event.target;
958+
if (!target) return;
959+
if (target.tagName.toLowerCase() != "a" && !(target = target.getParentElementByTag("a"))) {
960+
return;
961+
}
962+
var ajax = target.getAttribute("data-ajax"), href = target.href;
963+
// if not ajax request
964+
if (target.getAttribute("data-rel") == "external"
965+
|| ajax == "false"
966+
|| (href.replace("://", "").split("/")[0] !== location.href.replace("://", "").split("/")[0] && ajax != "true")
967+
|| (this.captureLink == false && ajax != "true")
968+
) return;
969+
event.preventDefault();
970+
});
971971
}
972972
// Important:
973973
// In ios7+, swipe the edge of page will navigate Safari
@@ -1010,7 +1010,6 @@
10101010
if ((!href || /a/i.test(target.tagName) == false) && (target = target.getParentElementByTag("a"))) {
10111011
href = target.href;
10121012
}
1013-
10141013
// the page that current touched or actived
10151014
var self_page = document.querySelector(".in." + Mobilebone.classPage);
10161015

@@ -1075,14 +1074,13 @@
10751074
event.preventDefault();
10761075
return;
10771076
}
1078-
10791077
if (/^javascript/.test(href)) {
10801078
if (back == false) return;
10811079
} else {
10821080
external = external || (href.replace("://", "").split("/")[0] !== location.href.replace("://", "").split("/")[0]);
10831081
if ((external == true || capture == false) && target.getAttribute("data-ajax") != "true") return;
10841082
}
1085-
1083+
10861084
// judge that if it's a ajax request
10871085
if (/^#/.test(target.getAttribute("href")) == true) {
10881086
// hash slide

test/ajax-html/b.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<div class="page out" data-onpagefirstinto="page_b_first">
99
<ul>
1010
<li><a href="c.html">此为b页面,点击加载c页面</a></li>
11+
<li><a id="link" href="http://www.zhangxinxu.com/sp/char.html">跳转测试,点击新页面</a></li>
1112
</ul>
1213
</div>
1314
</body>

test/ajax-html/index.html

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li><a href="ajax-without-page.html" data-title="纯a标签元素返回页面">点击加载-返回不含page, 自动创建page</a></li>
2424
</ul>
2525
<ul>
26-
<li><a href="root-reload.php?id=1">根地址不缓存1</a></li>
26+
<li><a href="root-reload.php?id=1" data-ajax="true">根地址不缓存1</a></li>
2727
<li><a href="root-reload.php?id=2">根地址不缓存2</a></li>
2828
<li><a href="root-reload.php?id=3">根地址不缓存3</a></li>
2929
<li><a href="root-reload.php?id=4">根地址不缓存4</a></li>
@@ -43,8 +43,8 @@
4343
<script src="../../src/mobilebone.js"></script>
4444
<script src="../../src/mobilebone.js"></script>
4545
<!-- 厂子的frozenjs兼容测试 -->
46-
<!--<script src="../base-slide/zepto.js"></script>
47-
<script src="../base-slide/frozen.js"></script>-->
46+
<script src="../base-slide/zepto.js"></script>
47+
<script src="../base-slide/frozen.js"></script>
4848
<script>
4949
var optionsTest = function(elein, eleout, options) {
5050
// ajax过场回调options参数测试
@@ -67,13 +67,23 @@
6767
};
6868

6969
var page_b_first = function() {
70-
console.log("first?");
70+
// console.log("first?");
71+
$("#link").on("tap", function() {
72+
location.href = this.href;
73+
});
7174
};
7275
var page_root_first = function() {
7376
// console.log("root?");
7477
};
7578

7679
Mobilebone.evalScript = true;
80+
81+
// 此为captureLink测试
82+
// Mobilebone.captureLink = false;
83+
84+
/*$("a").tap(function() {
85+
console.log("taped");
86+
});*/
7787
</script>
7888
</body>
7989
</html>

test/ajax-html/root-reload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="page out" data-callback="root_reload" data-onpagefirstinto="page_root_first">
99
<p>document.getElementById("idShow").innerHTML是:<strong id="idShow">&nbsp;</strong>,应该结果是<strong id="idShould"><?php echo $_GET['id']; ?></strong>.</p>
1010
<ul>
11-
<li><a href="#pageHome" id="scriptTest" data-rel="back">返回</a></li>
11+
<li><a href="#pageHome" id="scriptTest" data-rel="back" data-ajax="true">返回</a></li>
1212
</ul>
1313
<script>
1414
document.getElementById("scriptTest").style.backgroundColor = "#" + (Math.random() + "").slice(-6);

0 commit comments

Comments
 (0)