Repository navigation
Expand file tree
/
Copy pathroadui.core.js
More file actions
325 lines (307 loc) · 9.67 KB
/
Copy pathroadui.core.js
File metadata and controls
325 lines (307 loc) · 9.67 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
RoadUI = function () { };
RoadUI.Core = {
allFrames: [],
getAllFrames: function (frame)
{
if (!frame)
{
frame = top;
this.allFrames.push(frame);
}
var frames = frame.frames;
for (var i = 0; i < frames.length; i++)
{
this.allFrames.push(frames[i]);
this.getAllFrames(frames[i]);
}
},
newid: function (isMiddline)
{
var guid = "";
isMiddline = isMiddline == undefined ? true : isMiddline;
for (var i = 1; i <= 32; i++)
{
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
if (isMiddline && (i == 8 || i == 12 || i == 16 || i == 20))
{
guid += "-";
}
}
return guid;
},
rooturl: function ()
{
var curWwwPath = window.document.location.href;
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
var localhostPaht = curWwwPath.substring(0, pos);
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
//alert(projectName);
return projectName + "/";
},
query: function (name)
{
var search = document.location.search;
var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
var matcher = pattern.exec(search);
var items = null;
if (null != matcher)
{
try
{
items = decodeURIComponent(decodeURIComponent(matcher[1]));
} catch (e)
{
try
{
items = decodeURIComponent(matcher[1]);
} catch (e)
{
items = matcher[1];
}
}
}
return items;
},
open: function (url, width, height, name)//弹出居中窗口
{
//弹出窗口的宽度
var iWidth = width || 700;
//弹出窗口的高度
var iHeight = height || 500;
var y = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
var x = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
return window.open(url, name || "newwindow_" + RoadUI.Core.newid(false), 'height=' + iHeight + ',width=' + iWidth + ',top=' + y + ',left=' + x + ',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no');
},
accDiv: function (arg1, arg2)//返回值:arg1除以arg2的精确结果
{
var t1 = 0, t2 = 0, r1, r2;
try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
with (Math)
{
r1 = Number(arg1.toString().replace(".", ""))
r2 = Number(arg2.toString().replace(".", ""))
return (r1 / r2) * pow(10, t2 - t1);
}
},
accMul: function (arg1, arg2)//返回值:arg1乘以 arg2的精确结果
{
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
try { m += s1.split(".")[1].length } catch (e) { }
try { m += s2.split(".")[1].length } catch (e) { }
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
},
accAdd: function (arg1, arg2)// 返回值:arg1加上arg2的精确结果
{
var r1, r2, m, c;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
c = Math.abs(r1 - r2);
m = Math.pow(10, Math.max(r1, r2))
if (c > 0)
{
var cm = Math.pow(10, c);
if (r1 > r2)
{
arg1 = Number(arg1.toString().replace(".", ""));
arg2 = Number(arg2.toString().replace(".", "")) * cm;
}
else
{
arg1 = Number(arg1.toString().replace(".", "")) * cm;
arg2 = Number(arg2.toString().replace(".", ""));
}
}
else
{
arg1 = Number(arg1.toString().replace(".", ""));
arg2 = Number(arg2.toString().replace(".", ""));
}
return (arg1 + arg2) / m
},
accSub: function (arg1, arg2)// 返回值:arg1减去arg2的精确结果
{
var r1, r2, m, n;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2));
//last modify by deeka
//动态控制精度长度
n = (r1 >= r2) ? r1 : r2;
return ((arg1 * m - arg2 * m) / m).toFixed(n);
},
intDiv: function (number1, number2)//整除
{
var num1 = Math.round(number1);
var num2 = Math.round(number2);
var result = num1 / num2;
if (result >= 0)
{
result = Math.floor(result);
}
else
{
result = Math.ceil(result);
}
return result;
}
};
RoadUI.Xml = {
getXmlDom: function ()
{
var xmldoc;
if (window.ActiveXObject)
{
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
}
else
{
if (document.implementation && document.implementation.createDocument)
{
xmldoc = document.implementation.createDocument("", "doc", null);
}
}
return xmldoc;
},
loadXML: function (xml)
{
var xmldoc = RoadUI.Xml.getXmlDom();
xmldoc.async = false;
try
{
xmldoc.loadXML(xml);
}
catch (e)
{
xmldoc = new DOMParser().parseFromString(xml, "text/xml");
}
return xmldoc;
},
getElementValue: function (elements)
{
return elements && elements.length > 0 && elements[0].firstChild ? elements[0].firstChild.nodeValue : "";
}
};
String.prototype.isInteger = function ()
{
return (new RegExp(/^\d+$/).test(this));
};
String.prototype.isNumber = function (value, element)
{
return (new RegExp(/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/).test(this));
};
String.prototype.trim = function ()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
};
String.prototype.isNullOrEmpty =function()
{
return !this || this.length == 0 || this.trim().length == 0;
};
String.prototype.startWith = function (pattern)
{
return this.indexOf(pattern) === 0;
};
String.prototype.endWith = function (pattern)
{
var d = this.length - pattern.length;
return d >= 0 && this.lastIndexOf(pattern) === d;
};
String.prototype.encodeTXT = function ()
{
return (this).replaceAll('&', '&').replaceAll("<", "<").replaceAll(">", ">").replaceAll(" ", " ");
};
String.prototype.isMail = function ()
{
return (new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(this.trim()));
};
String.prototype.isPhone = function ()
{
return (new RegExp(/(^([0-9]{3,4}[-])?\d{3,8}(-\d{1,6})?$)|(^\([0-9]{3,4}\)\d{3,8}(\(\d{1,6}\))?$)|(^\d{3,8}$)/).test(this));
};
String.prototype.isUrl = function ()
{
return (new RegExp(/^[a-zA-z]+:\/\/([a-zA-Z0-9\-\.]+)([-\w .\/?%&=:]*)$/).test(this));
};
String.prototype.isExternalUrl = function ()
{
return this.isUrl() && this.indexOf("://" + document.domain) == -1;
};
String.prototype.replaceAll = function (s1,s2)
{
var str = this;
while (str.indexOf(s1) != -1)
{
str = str.replace(s1, s2);
}
return str;
};
Date.prototype.format = function (format)
{
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
}
if (/(y+)/.test(format))
{
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o)
{
if (new RegExp("(" + k + ")").test(format))
{
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
};
Array.prototype.unique = function ()
{
var res = [];
var json = {};
for (var i = 0; i < this.length; i++)
{
if (!json[this[i]])
{
res.push(this[i]);
json[this[i]] = 1;
}
}
return res;
};
var currentFocusObj = null; //当前焦点对象
function initElement($elements, type)
{
if (!$elements || $elements.size() == 0)
{
return;
}
var cssType = type;
$elements.addClass(cssType + "1")
.bind("mouseover", function ()
{
$(this).removeClass().addClass(cssType + "2");
}).bind("mouseout", function ()
{
if (currentFocusObj == null || $(this).get(0) !== currentFocusObj)
{
$(this).removeClass().addClass(cssType + "1");
}
}).bind("focus", function ()
{
if (currentFocusObj != null)
{
var css = $(currentFocusObj).attr("class").replace("1", "").replace("2", "");
$(currentFocusObj).removeClass().addClass(css + "1");
}
$(this).removeClass().addClass(cssType + "2");
currentFocusObj = $(this).get(0);
});
}