jQuery.modalDialog_wev8.js
4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
*jQuery modalDialog plugin v0.1
* author:张凡杭
* Date:2011/10/25
*/
(function($){
$.fn.modalDialog=function(){
var defaults={
_dwidth:'550px',//宽度
_dheight:'550px',//高度
_url:'about:blank',//窗口地址
_param : "",//js参数
_scroll:"no",//滚动条
_dialogArguments:"",//
_callBack:callBack,
_beforeShow:beforeShow,
_displayTemplate:"#b{name}",
_displaySelector:"",
_required:"no",
_displayText:"",
value:"",
_initEnd:initEnd,
_editable:"yes",
_trimLeftComma:"no"//当存在左边逗号时去掉逗号
};
$this=$(this);//当前节点
if($this.length>1){
$this.each(function(){
$(this).modalDialog();
});
return;
}
$this.before("<button class='browser Browser' type='button' id='"+($this.attr("id")||$this.attr("name"))+"Btn"+"'></button>");
$this.css("display","none");
// /alert($this.attr("_displayText"));
if($this.attr("_editable")=="no"){
$this.prev().hide();
$this.attr("readonly","true");
}
if($this.attr("_required")=="yes"&&!$.trim($this.val())){
$this.after("<span id='"+($this.attr("id")?$this.attr("id"):$this.attr("name"))+"Span' ><img align='absMiddle' src='/images/BacoError_wev8.gif'/></span>");
}else{
$this.after("<span id='"+($this.attr("id")?$this.attr("id"):$this.attr("name"))+"Span' ></span>");
}
if($this.val()!=""){
var tem=$this.attr("_displayTemplate")?$this.attr("_displayTemplate"):defaults._displayTemplate;
tem=tem.replace(new RegExp("(#b{id})","g"),$this.val());
tem=tem.replace(new RegExp("(#b{name})","g"),$this.attr("_displayText")?$this.attr("_displayText"):"");
tem=tem.replace(/#b\{([\w]+)\}/g,$this.attr("_displayText")?$this.attr("_displayText"):"");
$this.next().html(tem);
}
if($this.attr("_initEnd")){
try{
eval($this.attr("_initEnd"))();
}catch (e) {
}
}
$this.removeAttr("class");
var opts;
//var opts = $.extend(defaults, options);
$this.prev().click(function(e){
target=e.srcElement||e.target;
opts=(function($this,defaults){
options={};
for(var item in defaults){
if($this.attr(item)!=undefined){
options[item]=$this.attr(item);
}
}
opts = $.extend(defaults, options);
var iTop = (window.screen.availHeight-30-parseInt(opts._dheight))/2+"px"; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-parseInt(opts._dwidth))/2+"px"; //获得窗口的水平位置;
opts.top=iTop;
opts.left=iLeft;
return opts;
})($(target).next(),defaults);
try{
eval(opts._beforeShow)(opts,e);
}catch (e) {
//eval(opts._callBack);
}
datas=window.showModalDialog(opts._url,opts._dialogArguments,"addressbar=no;status=0;scroll="+opts._scroll+";dialogHeight="+opts._dheight+";dialogWidth="+opts._dwidth+";dialogLeft="+opts.left+";dialogTop="+opts.top+";resizable=0;center=1;");
templateOperation(datas,e);
try{
eval(opts._callBack)(datas,e);
}catch (e) {
//eval(opts._callBack);
}
});
function callBack(datas,e){};
function beforeShow(opts,e){
if(opts.value!=""){
var tempUrl;
if(opts._url.indexOf("url=")!=-1){
tempUrl=opts._url.substr(opts._url.indexOf("url="));
}else{
tempUrl=opts._url;
}
if(tempUrl.indexOf("?")!=-1){
if (opts._param) {
opts._url+= "&" + opts._param + "=" + opts.value;
} else if(tempUrl.indexOf("?selectedids=")!=-1){
opts._url+=opts.value;
} else {
opts._url+="&selectedids="+opts.value;
}
}else{
if (opts._param) {
opts._url+= "?" + opts._param + "=" + opts.value;
} else {
opts._url+="?selectedids="+opts.value;
}
}
}
};
function templateOperation(datas,e){
valFiled=$(e.srcElement||e.target).next();
if (datas&&datas.id!=""&&datas.id!=0){
var resourceids = datas.id;
var sHtml = "";
ids=resourceids.split(",");
var tags=new Array();
for(var tag in datas){
tags.push(tag);
}
for(var i=0;i<ids.length;i++){
if(ids[i]=="") continue;
curHtml=opts._displayTemplate;
for(var j=0;j<tags.length;j++){
curHtml=curHtml.replace(new RegExp("(#b{"+tags[j]+"})","g"),datas[tags[j]].split(",")[i]);
}
sHtml += " "+curHtml;
}
$(valFiled).next().html(sHtml);
if(resourceids!=""&&resourceids.charAt(0)==","){
resourceids=resourceids.substr(1);
}
valFiled.val(resourceids);
}
else if(datas){
valFiled.val("");
if(opts._required=="yes"){
$(valFiled).next().html("<img align='absMiddle' src='/images/BacoError_wev8.gif'/>");
}else{
$(valFiled).next().html("");
}
};
};
function initEnd(){
};
$.fn.modalDialog.templateOperation=templateOperation;
$.fn.modalDialog.defaults=defaults;
};
})(jQuery);