Skip to content

Commit 8518507

Browse files
author
zhangxinxu
committed
some fixed
fixed some problem by test mobile visit
1 parent 41e4f67 commit 8518507

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

src/mobilebone.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* mobilebone.js
33
* by zhangxinxu(.com) 2014-09-26
44
* https://github.com/zhangxinxu/mobilebone
5-
* bone of slide for mobile web app
5+
* bone of switch for mobile web app
66
**/
77

88
(function(root, factory) {
@@ -138,9 +138,12 @@
138138

139139
// do callback when come in first time
140140
var onpagefirstinto = params_in.onpagefirstinto;
141-
if (typeof onpagefirstinto == "string") onpagefirstinto = params_in.root[onpagefirstinto];
142-
if (!store[pageid] && typeof onpagefirstinto == "function") {
143-
onpagefirstinto(pageInto, pageOut, options.response);
141+
if (!store[pageid]) {
142+
if (typeof onpagefirstinto == "string" && params_in.root[onpagefirstinto]) {
143+
params_in.root[onpagefirstinto](pageInto, pageOut, options.response);
144+
} else if (typeof onpagefirstinto == "function") {
145+
onpagefirstinto(pageInto, pageOut, options.response);
146+
}
144147
}
145148

146149
// do callback when animation start/end
@@ -150,13 +153,17 @@
150153
return matchs.toUpperCase();
151154
});
152155

153-
if (typeof animition == "string") animition = params_in.root[animition];
154-
155-
if (!store[pageid] && typeof animition == "function") {
156-
pageInto.addEventListener(isWebkit? webkitkey: animationkey, function() {
157-
animition(this, this.classList.contains("in")? "into": "out");
158-
});
159-
}
156+
if (!store[pageid]) {
157+
if (typeof animition == "string" && params_in.root[animition]) {
158+
pageInto.addEventListener(isWebkit? webkitkey: animationkey, function() {
159+
params_in.root[animition](this, this.classList.contains("in")? "into": "out");
160+
});
161+
} else if (typeof animition == "function") {
162+
pageInto.addEventListener(isWebkit? webkitkey: animationkey, function() {
163+
animition(this, this.classList.contains("in")? "into": "out");
164+
});
165+
}
166+
}
160167
});
161168

162169
// history
@@ -388,7 +395,7 @@
388395
params.response = response;
389396
Mobilebone.createPage(Mobilebone.jsonHandle(response), trigger_or_options, params);
390397
} catch (e) {
391-
params.message = "JSON解析出现错误:" + e.message;
398+
params.message = "JSON parse error:" + e.message;
392399
params.error.call(params, xhr, xhr.status);
393400
}
394401
} else if (params.dataType == "unknown") {
@@ -409,6 +416,7 @@
409416
}
410417
params.success.call(params, response, xhr.status);
411418
} else {
419+
params.message = "The status code exception!";
412420
params.error.call(params, xhr, xhr.status);
413421
}
414422

@@ -417,6 +425,13 @@
417425
// hide loading
418426
ele_mask.style.display = "none";
419427
}
428+
429+
xhr.onerror = function(e) {
430+
params.message = "Illegal request!";
431+
params.error.call(params, xhr, xhr.status);
432+
// hide loading
433+
ele_mask.style.display = "none";
434+
}
420435
xhr.send(null);
421436
};
422437

@@ -468,6 +483,7 @@
468483
Mobilebone.handleTapEvent = function(event) {
469484
// get target and href
470485
var target = event.target || event.touches[0], href = target.href;
486+
471487
if (!href && (target = target.getParentElementByTag("a"))) {
472488
href = target.href;
473489
}
@@ -531,7 +547,9 @@
531547
Mobilebone.ajax(target);
532548
}
533549
event.preventDefault();
534-
}
550+
} else {
551+
// console.log('pass thought');
552+
}
535553
};
536554

537555

test/ajax-json/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<body>
1212
<div id="pageHome" class="page out" data-title="ajax请求JSON">
1313
<ul>
14-
<li><a href="json-success.txt" data-dataType="json">点击加载JSON数据</a></li>
14+
<li><a href="json-success.txt" data-dataType="json" data-ajax="true" data-error="requestError">点击加载JSON数据, github会挂</a></li>
1515
</ul>
1616
<ul>
1717
<li><a href="json-error.html" data-datatype="json" data-error="requestError">加载JSON失败,404, 可回调</a></li>

test/complex/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<body>
1212
<div class="header out" data-role="header">
1313
<h1>微信</h1>
14-
<a href="javascript:" class="icon-add">添加</a>
15-
<a href="javascript:" class="icon-search">搜索</a>
14+
<a href="../index.html" class="icon-add" data-ajax="false">添加</a>
15+
<a href="../index.html" class="icon-search" data-ajax="false">搜索</a>
1616
</div>
1717
<div id="pageHome" class="page out" data-title="微信">
1818
<div class="content">

test/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h3>&nbsp;下面链接都是直接刷新跳转</h3>
1616
<li><a href="ajax-html/index.html" data-ajax="false">ajax请求HTML</a></li>
1717
<li><a href="ajax-json/index.html" data-ajax="false">ajax请求JSON并构建页面</a></li>
1818
<li><a href="callback/index.html" data-ajax="false">回调方法测试</a></li>
19-
<li><a href="tranisition/index.html" data-ajax="false">其他类型的切换动画演示</a></li>
19+
<li><a href="transition/index.html" data-ajax="false">其他类型的切换动画演示</a></li>
2020
<li><a href="fixed-header-footer/index.html" data-ajax="false">固定的头部和底部</a></li>
2121
<li><a href="modular-load/index.html" data-ajax="false">seajs等模块化加载演示</a></li>
2222
<li><a href="backbone/index.html" data-ajax="false">backbone组合示例</a></li>

0 commit comments

Comments
 (0)