Skip to content

Commit 694884b

Browse files
committed
Merge pull request #12 from zhangxinxu/develop
Develop
2 parents 1409922 + 5ab5c36 commit 694884b

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
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.3",
3+
"version": "1.1.4",
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: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* @type string
4040
**/
41-
Mobilebone.VERSION = '1.1.3';
41+
Mobilebone.VERSION = '1.1.4';
4242

4343
/**
4444
* Whether bind events when dom ready
@@ -76,7 +76,14 @@
7676
Mobilebone.rootTransition = root;
7777

7878
/**
79-
* className for mark page element
79+
* Whether merge(vs cover) global callback and local callback
80+
*
81+
* @type boolean
82+
**/
83+
Mobilebone.mergeCallback = true;
84+
85+
/**
86+
* for mark page element
8087
*
8188
* @type string
8289
**/
@@ -133,6 +140,7 @@
133140
onpagefirstinto: this.onpagefirstinto,
134141
animationstart: this.animationstart,
135142
animationend: this.animationend,
143+
fallback: this.fallback,
136144
callback: this.callback
137145
}, params = function(element) {
138146
if (!element || !element.getAttribute) return {};
@@ -141,14 +149,39 @@
141149

142150
// rules as follow:
143151
// data-* > data-params > options > defaults
144-
["title", "root", "form", "onpagefirstinto", "callback", "animationstart", "animationend"].forEach(function(key) {
152+
["title", "root", "form"].forEach(function(key) {
153+
145154
_params[key] = element.getAttribute("data-" + key) || _dataparams[key] || options[key] || defaults[key];
146155
});
147156

148157
if (typeof _params.root == "string") {
149158
_params.root = Mobilebone.getFunction(_params.root);
150159
}
151160

161+
["onpagefirstinto", "callback", "fallback", "animationstart", "animationend"].forEach(function(key) {
162+
if (Mobilebone.mergeCallback == true && typeof defaults[key] == "function") {
163+
// merge global callback
164+
var local_function_key = element.getAttribute("data-" + key) || _dataparams[key];
165+
if (typeof _params.root[local_function_key] == "function") {
166+
_params[key] = function() {
167+
defaults[key].apply(null, arguments);
168+
_params.root[local_function_key].apply(null, arguments);
169+
}
170+
} else if (typeof options[key] == "function") {
171+
_params[key] = function() {
172+
defaults[key].apply(null, arguments);
173+
options[key].apply(null, arguments);
174+
}
175+
} else {
176+
_params[key] = defaults[key];
177+
}
178+
} else {
179+
// replace global callback
180+
_params[key] = element.getAttribute("data-" + key) || _dataparams[key] || options[key] || defaults[key];
181+
}
182+
});
183+
184+
152185
return _params;
153186
};
154187

@@ -162,7 +195,10 @@
162195
pageOut.classList.remove("in");
163196
// if reverse direction
164197
pageOut.classList[back? "add": "remove"]("reverse");
165-
198+
// do fallback every time
199+
var fallback = params_out.fallback;
200+
if (typeof fallback == "string") fallback = params_out.root[fallback];
201+
if (typeof fallback == "function") fallback(pageInto, pageOut, options.response);
166202
}
167203
if (pageInto != null && pageInto.classList) {
168204
// for title change

test/callback/index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ <h2>主页</h2>
1919
<li><a href="#page1">页面1</a></li>
2020
<li><a href="#page2">页面2</a></li>
2121
<li><a href="#page3">页面3</a></li>
22+
<li><a href="#page4">页面4 - mergeCallback测试</a></li>
2223
</ul>
2324
<ul>
2425
<li><a href="../index.html" data-ajax="false">&laquo; 返回测试引导首页</a></li>
@@ -37,6 +38,11 @@ <h2>主页</h2>
3738
<a href="#pageHome" data-rel="back">&laquo;返回3</a>
3839
<p class="text-shadow">预期效果为每次动画载入随机灰度背景色</p>
3940
</div>
41+
<div id="page4" class="page out" data-root="window" data-fallback="fallbackJoin">
42+
<a href="#pageHome" data-rel="back">&laquo;返回4</a>
43+
<div><input type="checkbox" id="mergeCallback" checked style="width:16px; height:16px;"><label for="mergeCallback">mergeCallback为true</label></div>
44+
<p></p>
45+
</div>
4046

4147
<script src="../../src/mobilebone.js"></script>
4248
<script>
@@ -74,6 +80,23 @@ <h2>主页</h2>
7480
};
7581

7682
Mobilebone.rootTransition = FUN;
83+
84+
var flag_fallback = "not";
85+
Mobilebone.fallback = function(pagein, pageout) {
86+
if (pageout.id == "page4") {
87+
flag_fallback = "page4";
88+
} else {
89+
flag_fallback = "not";
90+
}
91+
};
92+
var fallbackJoin = function(pagein, pageout) {
93+
flag_fallback += '-merge';
94+
pageout.querySelector("p").innerHTML = flag_fallback;
95+
};
96+
97+
document.getElementById("mergeCallback").onclick = function() {
98+
Mobilebone.mergeCallback = Boolean(this.checked);
99+
};
77100
</script>
78101
</body>
79102
</html>

test/complex/js/wechat.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ Mobilebone.onpagefirstinto = function(pageinto) {
88
ele_screen_shot.width = window.innerWidth;
99
ele_screen_shot.height = Math.round(ele_screen_shot.width * 2405 / 720);
1010
}
11-
12-
11+
1312
// bind custom scroll events for content
1413
var weChatScroll = new IScroll(pageinto.querySelector(".content"), {
1514
tap: true
1615
});
17-
pageinto.addEventListener('tap', Mobilebone.handleTapEvent, false);
16+
/Android/i.test(navigator.userAgent) && pageinto.addEventListener('tap', Mobilebone.handleTapEvent, false);
1817
};
1918

2019
Mobilebone.callback = function(pageinto, pageout) {

0 commit comments

Comments
 (0)