EasyUI封装+扩展


1.封装 

 1.1 messager.alert

//使用方法:
//
    var msg = new msgAlert("警告", '不能这样操作');
//
    msg.warning();
function msgAlert(title, msg) {
    
this.title = title;
    
this.msg = msg;
}
msgAlert.prototype.error 
= function () {
    $.messager.alert(
this.title, this.msg, 'error');
}
msgAlert.prototype.question 
= function () {
    $.messager.alert(
this.title, this.msg, 'question');
}
msgAlert.prototype.info 
= function () {
    $.messager.alert(
this.title, this.msg, 'info');
}
msgAlert.prototype.warning 
= function () {
    $.messager.alert(
this.title, this.msg, 'warning');
}

v2.0 

//$.messager.alert
//      var msg = new easyui.messager.alert("警告", '不能增加记录。');
//      msg.warning();
easyui.messager.alert = function (title, msg) {
    
this.title = title;
    
this.msg = msg;
    
//实例方法,可以放到外面
    easyui.messager.alert.prototype.error = function () {
        $.messager.alert(
this.title, this.msg, 'error');
    }
    easyui.messager.alert.prototype.question 
= function () {
        $.messager.alert(
this.title, this.msg, 'question');
    }
    easyui.messager.alert.prototype.info 
= function () {
        $.messager.alert(
this.title, this.msg, 'info');
    }
    easyui.messager.alert.prototype.warning 
= function () {
        $.messager.alert(
this.title, this.msg, 'warning');
    }
}

 实例方法放到外面写法:

easyui.messager.alert.prototype = {
    error:
function () {
        $.messager.alert(
this.title, this.msg, 'error');
    },
    question:
function () {
        $.messager.alert(
this.title, this.msg, 'question');
    },
    info:
function () {
        $.messager.alert(
this.title, this.msg, 'info');
    },
    warning:
function () {
        $.messager.alert(
this.title, this.msg, 'warning');
    }
}

 

 

  1.2 messager.show

//使用方法:
//
   var msg = new msgShow("提示", "删除成功!");
//
   msg.fade();
function msgShow(title, msg, timeout,showSpeed, width, height) {
    
var p = {
        title: title,
        msg: msg,
        timeout: timeout,
        showSpeed: showSpeed,
        width: width,
        height: height,
        showType: 
'show'
    }
    
//实例方法
    msgShow.prototype.show = function () {
        $.messager.show(p);
    }
    msgShow.prototype.slide 
= function () {
        p.showType 
= 'slide'
        $.messager.show(p);
    }
    msgShow.prototype.fade 
= function () {
        p.showType 
= 'fade'
        $.messager.show(p);
    }
//    //静态方法,不需要创建实例
//
    this.show = function () {
//
        $.messager.show(p);
//
    }
//
    this.slide = function () {
//
        p.showType = 'slide'
//
        $.messager.show(p);
//
    }
//
    this.fade = function () {
//
        p.showType = 'fade'
//
        $.messager.show(p);
//
    }
}

 v2.0

//messager.show
//
   var msg = new easyui.messager.show("提示", "删除成功!");
//
   msg.fade();
easyui.messager.show =function(title, msg, timeout, showSpeed, width, height) {
    
var p = {
        title: title,
        msg: msg
    }
    
if (arguments.length > 2) { p.timeout = timeout; }
    
if (arguments.length > 3) { p.showSpeed = showSpeed; }
    
if (arguments.length > 4) { p.width = width; }
    
if (arguments.length > 5) { p.height = height; }
    
//静态方法
    this.show = function () {
        p.showType 
= 'show';
        $.messager.show(p);
    }
    
this.slide = function () {
        p.showType 
= 'slide';
        $.messager.show(p);
    }
    
this.fade = function () {
        p.showType 
= 'fade';
        $.messager.show(p);
    }

v2.0需要用到模拟命名空间的实现:

var Namespace = new Object();
Namespace.register 
= function (path) {
    
var arr = path.split(".");
    
var ns = "";
    
for (var i = 0; i < arr.length; i++) {
        
if (i > 0) ns += ".";
        ns 
+= arr[i];
        eval(
"if(typeof(" + ns + ") == 'undefined') " + ns + " = new Object();");
    }
}
//用法:
Namespace.register(
"easyui.messager");

 

  1.3 easyui.datagrid 

var easyui = easyui || {};
easyui.datagrid 
= easyui.datagrid || {}; 

   1.3.1 表头居中

easyui.datagrid.headcenter = function () {
    $(
".datagrid-header .datagrid-cell").css('text-align''center').css('color''#173967');
}

 调用:

datagrid的onLoadSuccess事件中写:
    easyui.datagrid.headcenter();
 

 

 

 

 

2.扩展

 未完待续...

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2011-05-03 15:40  undefined?  阅读(3514)  评论(3编辑  收藏  举报