24小时热门版块排行榜    

Znn3bq.jpeg
查看: 1111  |  回复: 0

foom19961125

新虫 (初入文坛)

[求助] 有人能看懂这个吗

//
//  CXJSBridge.js
//  CXJSBridge
//
//  Created by Chao Xing on 12-3-1.
//  Copyright (c) 2012年 Chao Xing Technology Co., Ltd. All rights reserved.
//

(function(context){
    function bridgeCall(src,callback) {
                iframe = document.createElement("iframe";
                iframe.style.display = "none";
                iframe.src = src;
                var cleanFn = function(state){
                   console.log(state)
                    try {
                        iframe.parentNode.removeChild(iframe);
                    } catch (error) {}
                    if(callback) callback();
                };
        iframe.onload = cleanFn;
                document.documentElement.appendChild(iframe);
        }
       
    function JSBridge()
    {
            this.device="ios";
        this.callbackDict = {};
        this.notificationIdCount = 0;
        this.notificationDict = {};
        
        var that = this;
        context.document.addEventListener('DOMContentLoaded',function(){
            bridgeCall('jsbridge://NotificationReady',that.trigger('jsBridgeReady',{}));
        },false);
    }
   
    JSBridge.prototype = {
        constructor: JSBridge,
        //send notification to WebView
        postNotification: function(name, userInfo){
                if(this.device == 'android'){
                        androidjsbridge.postNotification(name, JSON.stringify(userInfo));
                } else {
                    this.notificationIdCount++;
                   
                    this.notificationDict[this.notificationIdCount] = {name:name, userInfo:userInfo};
       
                    bridgeCall('jsbridge://PostNotificationWithId-' + this.notificationIdCount);
                }
        },
        //pop the notification in the cache
        popNotificationObject: function(notificationId){
            var result = JSON.stringify(this.notificationDict[notificationId]);
            delete this.notificationDict[notificationId];
            return result;
        },
        //trigger the js event
        trigger: function(name, userInfo) {
            if(this.callbackDict[name]){
                var callList = this.callbackDict[name];
               
                for(var i=0,len=callList.length;i<len;i++){
                    callList(userInfo);
                }
            }
        },
        setDevice:function(device){
                        this.device = device;
                        try{context._jsBridgeReady();}catch(e){}
                },
        //bind js event
        bind: function(name, callback){
            if(!this.callbackDict[name]){
                //create the array
                this.callbackDict[name] = [];
            }
            this.callbackDict[name].push(callback);
        },
        //unbind js event
        unbind: function(name, callback){
            if(arguments.length == 1){
                delete this.callbackDict[name];
            } else if(arguments.length > 1) {
                if(this.callbackDict[name]){
                    var callList = this.callbackDict[name];
                    
                    for(var i=0,len=callList.length;i<len;i++){
                        if(callList == callback){
                            callList.splice(i,1);
                            break;
                        }
                    }
                }
                if(this.callbackDict[name].length == 0){
                    delete this.callbackDict[name];
                }
            }            
        }        
    };
     
    context.jsBridge = new JSBridge();
   
})(window);

发自小木虫Android客户端
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 foom19961125 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 调剂 +10 只叙离别辞 2026-04-09 12/600 2026-04-11 20:57 by 逆水乘风
[考研] 求调剂 +11 翩翩一书生 2026-04-09 11/550 2026-04-11 19:57 by 逆水乘风
[考研] 352 求调剂 +6 yzion 2026-04-11 8/400 2026-04-11 16:24 by 明月此时有
[考研] 085506-求调剂-285分 +3 雷欧飞踢 2026-04-08 3/150 2026-04-11 08:37 by zhq0425
[材料工程] 材料调剂推荐 +8 蛋糕x2 2026-04-07 8/400 2026-04-10 23:13 by Ftglcn90
[考研] 一志愿0703化学招61最终排名62化学求调剂 +24 招61排名62 2026-04-07 28/1400 2026-04-10 16:15 by yx54321
[考研] 298求调剂 +13 钉叮咚冬瓜 2026-04-09 13/650 2026-04-10 15:49 by jiajinhpu
[考研] 青岛科技大学材料学院,环境学院调剂补录4月10日以前都可以 +3 1青科大。 2026-04-09 5/250 2026-04-10 09:58 by 翩翩一书生
[考研] 347材料专硕求调剂 +19 zj8215216 2026-04-06 19/950 2026-04-10 09:36 by 690616278
[考研] 085601初试330分找调剂 +10 流心奶黄包l 2026-04-09 10/500 2026-04-10 08:14 by Sammy2
[考研] 材料专硕(0856) 339分求调剂 +9 哈哈哈鹅哈哈哈 2026-04-09 10/500 2026-04-09 20:01 by Orcid
[考研] 086004 求调剂 309 +7 Yin DY 2026-04-08 7/350 2026-04-09 13:59 by Delta2012
[考研] 招收有机化学、化工,药学,食品灯专业学生 +3 yrfhjgdj 2026-04-08 3/150 2026-04-09 10:15 by QYQX_123
[考研] 308求调剂 +17 墨墨漠 2026-04-06 17/850 2026-04-09 09:25 by 壹往無前
[考研] 264求调剂 +11 麦小叮当 2026-04-07 11/550 2026-04-08 16:05 by 一只好果子?
[考研] 275 求调剂 +8 Lei812514 2026-04-07 8/400 2026-04-08 12:46 by chemisry
[考研] 336求调剂,一志愿中科大 +9 墨彧 yuyu 2026-04-06 9/450 2026-04-08 11:24 by 想读书的菌菌
[考研] 323求调剂 +3 林zlu 2026-04-07 4/200 2026-04-07 23:21 by lbsjt
[考研] 信工所11408 340分 本科西安交大自动化 +3 moontrek 2026-04-06 3/150 2026-04-07 09:56 by chongya
[考研] 求助 +3 卡卡东88 2026-04-06 4/200 2026-04-06 15:28 by going home
信息提示
请填处理意见