|
@ -159,8 +159,16 @@ define(["jcl", "base64", "mobileExpand", "bizMobileExpand"], function (Wade, Bas
|
159
|
159
|
}
|
160
|
160
|
};
|
161
|
161
|
})();
|
|
162
|
|
|
163
|
// 生成一个10位随机数,不一定有10位,后3位是0
|
|
164
|
function getRandomId() {
|
|
165
|
// 取随机数 * 当前时间戳结果的中间7位整数 + 三位自增长
|
|
166
|
// 乘1000是让生成的数值尽量有10位
|
|
167
|
return (Math.round(Math.random() * Date.now() * 1000)) % Math.pow(10, 7) * 1000;
|
|
168
|
}
|
|
169
|
|
162
|
170
|
//全局变量
|
163
|
|
var callbackId = 0;
|
|
171
|
var callbackId = getRandomId();
|
164
|
172
|
var callbacks = {};//用来存放成功和失败的js回调函数
|
165
|
173
|
var callbackDefine = {};//用来存放自定义的js回调函数
|
166
|
174
|
var globalErrorKey = null;//全局错误关键字,定位错误
|
|
@ -190,11 +198,11 @@ define(["jcl", "base64", "mobileExpand", "bizMobileExpand"], function (Wade, Bas
|
190
|
198
|
IpuMobile.execute = execute;
|
191
|
199
|
|
192
|
200
|
var androidExecute = function (action, args, error, success) {
|
193
|
|
//执行android方法时,带入到android底层的key值为,回调方法实际的key值 + 用于在top上索引本iframe的IpuMobile的唯一标识。
|
194
|
|
//在android底层,如果发现回调函数的key值包含这个特殊的串。那么将解析这个key。并且取出加回调函数key的后半部分,作为在top上索引本iframe相对应的IpuMobile对象的唯一依据。
|
|
201
|
//执行android方法时,带入到android底层的key值为,回调方法实际的key值 + 用于在top上索引本iframe的WadeMobile的唯一标识。
|
|
202
|
//在android底层,如果发现回调函数的key值包含这个特殊的串。那么将解析这个key。并且取出加回调函数key的后半部分,作为在top上索引本iframe相对应的WadeMobile对象的唯一依据。
|
195
|
203
|
var tmpKey = action + callbackId++;
|
196
|
|
if (window._IpuMobileSet_Key_ != undefined) {
|
197
|
|
tmpKey += window._IpuMobileSet_Key_;
|
|
204
|
if (window._WadeMobileSet_Key_ != undefined) {
|
|
205
|
tmpKey += window._WadeMobileSet_Key_;
|
198
|
206
|
}
|
199
|
207
|
var callbackKey = globalErrorKey = tmpKey;
|
200
|
208
|
if (success || error) {
|
|
@ -440,6 +448,7 @@ define(["jcl", "base64", "mobileExpand", "bizMobileExpand"], function (Wade, Bas
|
440
|
448
|
// window.frames[window.frames.length - 1].window.alert(name);
|
441
|
449
|
// iframe.parentNode.removeChild(iframe);
|
442
|
450
|
// }
|
|
451
|
// 原来这个代码为解决iOS特殊问题,部分项目这个alert导致出现新的问题(假死?),且移除后未发现新问题,所以移除
|
443
|
452
|
|
444
|
453
|
//动态执行js方法
|
445
|
454
|
function _eval(code, action) {
|
|
@ -508,39 +517,39 @@ define(["jcl", "base64", "mobileExpand", "bizMobileExpand"], function (Wade, Bas
|
508
|
517
|
return IpuMobile;
|
509
|
518
|
});
|
510
|
519
|
|
511
|
|
//让top对象上,保持有一个当前iframe里面的IpuMobile对象的引用。
|
512
|
|
//注意:在iframe中,_IpuMobileSet_Key_+时间戳表示一个key,此key作为了在top对象上索引iframe中的IpuMobile的依据。
|
|
520
|
//让top对象上,保持有一个当前iframe里面的WadeMobile对象的引用。
|
|
521
|
//注意:在iframe中,_WadeMobileSet_Key_+时间戳表示一个key,此key作为了在top对象上索引iframe中的WadeMobile的依据。
|
513
|
522
|
//将保持引用的key值存入到当前ifame的window对象上。
|
514
|
523
|
(function () {
|
515
|
524
|
//屏蔽所有浏览器
|
516
|
525
|
if (window.navigator.userAgent.indexOf("IpuMobile\/") == -1) {
|
517
|
|
console.log("<IpuMobileSet> \"IpuMobile\/\" string does not exist in the userAgent. return.");
|
|
526
|
console.log("<WadeMobileSet> \"IpuMobile\/\" string does not exist in the userAgent. return.");
|
518
|
527
|
return;
|
519
|
528
|
}
|
520
|
529
|
|
521
|
530
|
if (top != window) {
|
522
|
|
if (top.IpuMobileSet == undefined) {
|
523
|
|
top.IpuMobileSet = {};
|
|
531
|
if (top.WadeMobileSet == undefined) {
|
|
532
|
top.WadeMobileSet = {};
|
524
|
533
|
}
|
525
|
|
for (var key in top.IpuMobileSet) {
|
|
534
|
for (var key in top.WadeMobileSet) {
|
526
|
535
|
try {
|
527
|
|
if (key.indexOf("_IpuMobileSet_Key_") != -1 && (!top.IpuMobileSet[key] || (top.IpuMobileSet[key].canRemoved && top.IpuMobileSet[key].canRemoved()))) {
|
|
536
|
if (key.indexOf("_WadeMobileSet_Key_") != -1 && (!top.WadeMobileSet[key] || (top.WadeMobileSet[key].canRemoved && top.WadeMobileSet[key].canRemoved()))) {
|
528
|
537
|
console.log("(top set)delete:" + key);
|
529
|
|
delete top.IpuMobileSet[key];
|
|
538
|
delete top.WadeMobileSet[key];
|
530
|
539
|
console.log("(top set)delete success :" + key);
|
531
|
540
|
}
|
532
|
541
|
} catch (e) {
|
533
|
|
console.log("a error(IpuMobile) : " + e);
|
|
542
|
console.log("a error(WadeMobile) : " + e);
|
534
|
543
|
console.log("(top set)delete:" + key);
|
535
|
|
delete top.IpuMobileSet[key];
|
|
544
|
delete top.WadeMobileSet[key];
|
536
|
545
|
console.log("(top set)delete success :" + key);
|
537
|
546
|
}
|
538
|
547
|
}
|
539
|
|
var key = "_IpuMobileSet_Key_" + new Date().getTime();
|
540
|
|
window._IpuMobileSet_Key_ = key;
|
541
|
|
console.log("in an iframe, window.IpuMobile object is referenced top.IpuMobileSet." + key);
|
542
|
|
top.IpuMobileSet[key] = window.IpuMobile;
|
543
|
|
window.IpuMobile.canRemoved = function () {
|
|
548
|
var key = "_WadeMobileSet_Key_" + new Date().getTime();
|
|
549
|
window._WadeMobileSet_Key_ = key;
|
|
550
|
console.log("in an iframe, window.WadeMobile object is referenced top.WadeMobileSet." + key);
|
|
551
|
top.WadeMobileSet[key] = window.WadeMobile;
|
|
552
|
window.WadeMobile.canRemoved = function () {
|
544
|
553
|
return !window;
|
545
|
554
|
};
|
546
|
555
|
}
|