Skip to content

Commit b53f555

Browse files
committed
Merge pull request #148 from zhangxinxu/develop
global function and context
2 parents 9674a61 + 3480b12 commit b53f555

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
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.6",
3+
"version": "2.5.7",
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
*
4747
* @type string
4848
**/
49-
Mobilebone.VERSION = '2.5.6';
49+
Mobilebone.VERSION = '2.5.7';
5050

5151
/**
5252
* Whether catch attribute of href from element with tag 'a'
@@ -335,9 +335,9 @@
335335
// v2.5.5 add for fix issues #138
336336
if (!pageInto.firstintoBind) {
337337
if (typeof onpagefirstinto == "string" && params_in.root[onpagefirstinto]) {
338-
params_in.root[onpagefirstinto](pageInto, pageOut, options);
338+
params_in.root[onpagefirstinto].call(params_in.root, pageInto, pageOut, options);
339339
} else if (typeof onpagefirstinto == "function") {
340-
onpagefirstinto(pageInto, pageOut, options);
340+
onpagefirstinto.call(params_in.root, pageInto, pageOut, options);
341341
}
342342
// capture form submit
343343
slice.call(pageInto.querySelectorAll("form")).forEach(function(form) {
@@ -370,11 +370,11 @@
370370
// bind animation events
371371
if (typeof animition == "string" && params_in.root[animition]) {
372372
pageInto.addEventListener(animateEventName, function() {
373-
params_in.root[animition](this, this.classList.contains("in")? "into": "out", options);
373+
params_in.root[animition].call(params_in.root, this, this.classList.contains("in")? "into": "out", options);
374374
});
375375
} else if (typeof animition == "function") {
376376
pageInto.addEventListener(animateEventName, function() {
377-
animition(this, this.classList.contains("in")? "into": "out", options);
377+
animition.call(params_in.root, this, this.classList.contains("in")? "into": "out", options);
378378
});
379379
}
380380
}

test/callback/index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,17 @@ <h2>主页</h2>
7575
// 2. page2因为root=window, 因此上下文为window
7676
// 3. 页面3则是 callback_page.test_obj
7777
// 需要注意的是,如果存在回调合并的情况,其公用同一个上下文this, 值同上规则
78-
console.log("全局回调上下文this: ");
78+
console.log("全局回调上下文this: " + this.time);
7979
console.log(this);
8080
};
8181

82+
Mobilebone.onpagefirstinto = function(pageinto) {
83+
console.log("global: onpagefirstinto");
84+
};
85+
86+
Mobilebone.animationstart = function(page) {
87+
console.log("global: animationstart");
88+
};
8289

8390
window.callback_page = function(page) {
8491
// 按钮居中

0 commit comments

Comments
 (0)