一些框架封装

ajax封装:

A.Ajax.doAjax = function (vo)
    {
        var url = vo.url,            //url
            onsuccess = vo.onsuccess, //成功回调函数
            onfailure = vo.onfailure, //成功回调函数
            fdata = vo.params,        //传递参数
            method = vo.method,        //post get
            sdata = vo.sdata,        //post数据
            asyn = vo.asyn;            //是否异步
           
        fdata = (fdata === undefined)? null: fdata;
        method = method || "GET";
        sdata = (sdata === undefined)? null: sdata;
        asyn = (asyn === undefined)? true: asyn;
        onfailure = (onfailure === undefined)? null: onfailure;

        var X = new bajax_object();
        if(asyn){
            X.onreadystatechange = function(){
                if (X.readyState == 4) {
                    if((X.status  >= 200 && X.status  < 300) || X.status  == 0){
//                        if()
                            onsuccess(X, fdata);
//                        };
                       
                    }else{
                        if(onfailure != null){
                            onfailure(X,fdata);
                        }
                        return;
                    };
                }
            };
        }

        X.open(method, url, asyn);
        X.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        X.send(fdata);

        if(asyn) return X;
        else callback(X, fdata);
    }

 

// 兼容IE与其它浏览器(From Sajax.php v0.12)
    var bajax_object = function()
    {
        var aj;
        var _msxmlhttp = new Array(
            'Msxml2.XMLHTTP.5.0',
            'Msxml2.XMLHTTP.4.0',
            'Msxml2.XMLHTTP.3.0',
            'Msxml2.XMLHTTP',
            'Microsoft.XMLHTTP');
        for(var i = 0; i < _msxmlhttp.length; i++) {
            try {
                if(aj = new ActiveXObject(_msxmlhttp[i])) break;
            } catch (e) {
                aj = null;
            }
        }
        if(!aj && typeof XMLHttpRequest != "undefined")
            aj = new XMLHttpRequest();
        if(!aj)
            alert("Could not create connection object.");

        return aj;
    }

 

AUI.add('aui-notification', function(A) {

    A.namespace("Notification");
    var Notification,
        Note,
        _proVO = {},
        _funMap = {};

    Notification = function (config) {
        Notification.superclass.constructor.apply( this, arguments );
    };
    Note = A.Notification;

   
    var spy = function(obj){
        var arr = [];
        if(obj != null){
            for(var itm in obj){
                var value = obj[itm];
                if(typeof value == "function"){
                    value = "function(){...}";
                }else if(typeof value == "object" && value != null){
                    value = "{...}";
                }
                arr.push(itm + "/t= " + value);
            }
        }
        return arr.join("/r/n");
    }

    /*
     *  说明:注册通知
     *
     */
    var extend = function(destination, source) {
        for (var property in source)
            destination[property] = source[property];
        return destination;
    }

    Note.register = function(id,name,porName){
        if(_proVO[porName] == null){
            _proVO[porName] = {};
        }

        if(_proVO[porName][name] == null){
            _proVO[porName][name] = {};
        }

        if (_proVO[porName][name].id == null)
        {
            _proVO[porName][name].id = [];
        }

        _proVO[porName][name].id.push(id);
    }

    /*
     *  说明:发送通知
     *
     */
    Note.send = function(name, vo, porName){
        //调试时用
        var proVO = _proVO[porName];
        if(_proVO[porName] == null){
            alert("模板未加载");
            return ;
        }
        var noteMap = _proVO[porName][name];
        if(_proVO[porName][name] == null){
            alert("通知名未定义");
            return ;
        }

        if (_proVO[porName][name].vo == null)
        {
            _proVO[porName][name].vo = {}
        }
        extend(_proVO[porName][name].vo,vo);
    }

    //根据组件名通知名返回id
    Note.getVO = function(name, porName){
        var proVO = _proVO[porName];
        if(proVO == null){
            alert("模板为加载");
            return ;
        }
        var noteMap = proVO[name];
        if(noteMap == null){
            alert("通知名未定义");
            return ;
        }

        return noteMap.vo;
    }

    //获取页面的回调参数集合
    Note.getFuns = function(obj,porName){
        if(_funMap[porName] == null){
            _funMap[porName] = {};
        }
        extend(_funMap[porName], obj);
    }
   
    //处理回调方法
    Note.handler = function(funName,porName){
        if(_funMap[porName] == null){
            alert("模板为加载")
            return ;
        }
        if(_funMap[porName][funName] == null){
            alert("回调函数未定义")
            return ;
        }
        _funMap[porName][funName]();
    }

    Note.remove = function(porName){
        if(_funMap[porName] == null){
            return ;
        }
        delete _funMap[porName];
    }
   

}, '1.0.1');

 

前台通知组件,用于组件之间数据存储,适用于模块式开发

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值