📄 util.js
字号:
String.prototype.trim=function()
{
return this.replace(/(^\s*)|(\s*$)/g,"");
}
String.prototype.ltrim=function()
{
return this.replace(/(^\s*)/g,"");
}
String.prototype.rtrim=function()
{
return this.replace(/(\s*$)/g,"");
}
String.prototype.rlen=function()
{
return this.replace(/[^\x00-\xff]/g,"ss").length;
}
String.prototype.equals=function(val)
{
if(this==val.toString())
return true;
else
return false;
}
String.prototype.equalicase=function(val)
{
if(this.toLowerCase()==val.toString().toLowerCase())
return true;
else
return false;
}
Number.prototype.equals=function(val)
{
if(this.toString().equals(val))
return true;
else
return false;
}
String.prototype.child=function(iLen)
{
if(this.replace(/[^\x00-\xff]/g,"ss").length <= iLen){
return this;
}
var str = "";
var l = 0;
var schar;
for(var i=0; schar=this.charAt(i); i=i+1){
str += schar;
l += (schar.match(/[^\x00-\xff]/) != null ? 2 : 1);
if(l >= iLen){
break;
}
}
return str;
}
/**
One dimension array sort
type parameters
0 By Letter sort (defult)
1 By Size for number array
2 By Pingying for chinese words array
3 Disarrange sometimes need to disarrange the array
4 By search parameter str sort,the most matching is sort in front
*/
Array.prototype.SortBy=function(type,str){
switch (type)
{
case 0:this.sort();
break;
case 1:this.sort(function(a,b){
return a-b;
});
break;
case 2:this.sort(function(a,b){
if(a.length>b.length)
return 1;
else if(a.length==b.length)
return a.localeCompare(b);
else
return -1;
});
break;
case 3:this.sort(function(){
return Math.random()>0.5?-1:1;
});
break;
case 4:this.sort(function(a,b){
return a.indexOf(str)==-1?1:-1;
});
break;
default:this.sort();
}
}
function $E(obj)
{
return document.getElementsByName(obj);
}
var $e=$E;
var $objects=$E;
function getObjsByType(typeName)
{
typeName=typeName.toLowerCase();
var buf=document.getElementsByTagName(typeName);
var result=[];
for(var i=0;i<buf.length;i=i+1)
{
if(typeName.equalicase(buf[i].type))
result[result.length]=buf[i];
}
return result;
}
function $(objTarget)
{
var obj=null;
if(typeof objTarget=="object")
obj=objTarget;
if(typeof objTarget=="string")
obj=document.getElementById(objTarget);
if(typeof obj=="object")
return obj;
else{
alert("Cann't find the Object:"+objTarget);
return "undefined";
}
}
function $V(objTarget)
{
var obj=$(objTarget);
if(obj=="undefined"){
return "";
}
else{
var type=obj.type;
if(type==undefined){
var tagName=obj.tagName.toLowerCase();
if(tagName.equals("div")||tagName.equals("span"))
return obj.innerHTML;
else
return "";
}
type=type.toLowerCase();
if(type.equals("text")||type.equals("textarea")||type.equals("hidden")||type.equals("password")||type.equals("select-one")||type.equals("radio")||type.equals("checkbox")){
return obj.value;
}
else{
return obj.innerHTML;
}
}
}
var $v=$V;
function $disable(obj,isDisable)
{
obj=$(obj);
if(obj=='undefined')
return ;
if(arguments.length==1)
{
obj.disabled=true;
}
else
{
if(isDisable)
obj.disabled=true;
else
obj.disabled=false;
}
}
function $equal(obj1,obj2)
{
if($(obj1)=='undefined')
return ;
if($(obj2)=='undefined')
return ;
if(arguments.length!=2)
{
alert("Arguments Error!")
return false;
}
if($v(obj1)==$v(obj2))
{
return true;
}
else
return false;
}
function $Bind(objTarget,val,isCoveredOrDefault){
var obj=$(objTarget);
var arglen=arguments.length;
//The param defined as follows:
/**
valItemType -1 Is not a value
valItemType 1 Is Single type
valItemType 2 Is Array type
*/
var valItemType=-1;
if((typeof val=="undefined")){
valItemType=-1;
}
else if(val instanceof Array){
valItemType=2;
}
else
valItemType=1;
if(valItemType==-1)
return ;
var type=obj.type;
if(typeof type=="undefined"){
type="others";
}
type=type.toString().toLowerCase();
if(typeof obj=="undefined"){
//Add TODO code here.
}
else if(arglen==2){
if(type.equals("text")||type.equals("textarea")||type.equals("hidden")||type.equals("password")||type.equals("radio")||type.equals("checkbox")){
if(valItemType==1){
obj.value=val;
}
else if(valItemType==2){
obj.value=val.join(",");
}
}
else if(type.equals("select-one")){
if(valItemType==1){
obj.length=0;
obj.options[0]=new Option(val,val,true,true);
}
else if(valItemType==2){
var step=2;
obj.length=0;
var curSize=val.length;
for(var i=0;i<curSize/step;i++){
obj.options[obj.length]=new Option(val[i*step+1],val[i*step],true,false);
}
}
}
else{
if(valItemType==1){
obj.innerHTML=val;
}
else if(valItemType==2){
obj.innerHTML=val.join(",");
}
}
}
else if(arglen==3){
if(typeof isCoveredOrDefault=="undefined")
isCoveredOrDefault=true;
var type=obj.type.toString().toLowerCase();
if(type.equals("text")||type.equals("textarea")||type.equals("hidden")||type.equals("password")||type.equals("radio")||type.equals("checkbox")){
if(valItemType==1){
if(isCoveredOrDefault)
obj.value=val;
else
obj.value+=val;
}
else if(valItemType==2){
if(isCoveredOrDefault)
obj.value=val.join(",");
else
obj.value+=val.join(",");
}
}
else if(type.equals("select-one")){
if(valItemType==1){
obj.length=0;
if(isCoveredOrDefault.equals(val))
obj.options[0]=new Option(val,val,true,true);
else
obj.options[0]=new Option(val,val,true,false);
}
else if(valItemType==2){
var step=2;
obj.length=0;
obj.options[0]=new Option("","",true,false);
var curSize=val.length;
for(var i=0;i<curSize/step;i++){
obj.options[obj.length]=new Option(val[i*step+1],val[i*step],true,false);
}
for(var i=0;i<obj.length;i++)
{
var vals=obj.options[i].value;
if(vals.equals(isCoveredOrDefault))
{
obj.selectedIndex=i;
obj.options[i].style.cssText="color:#0000FF;";
break;
}
}
}
}
else{
if(valItemType==1){
if(isCoveredOrDefault)
obj.innerHTML=val;
else
obj.innerHTML+=val;
}
else if(valItemType==2){
if(isCoveredOrDefault)
obj.innerHTML=val.join(",");
else
obj.innerHTML+=val.join(",");
}
}
}
}
var $bind=$Bind;
function toHTML(str)
{
obj=document.createElement("SPAN");
obj.innerHTML=str;
return obj.innerText;
}
function getDiv(id)
{
obj=document.createElement("DIV");
obj.setAttribute("id",id.toString());
document.body.appendChild(obj);
}
function getPosLeft(object)
{
var obj=$(object);
if(obj==null)
return 0;
var left=0;
while(obj.tagName!="BODY")
{
left+=obj.offsetLeft;
obj=obj.offsetParent;
}
return left;
}
function getPosTop(object)
{
var obj=$(object);
if(obj==null)
return 0;
var tmp=obj.offsetHeight;
var top=obj.offsetHeight;
while(obj.tagName!="BODY")
{
top+=obj.offsetTop;
obj=obj.offsetParent;
}
return top;
}
function getObjectWidth(object)
{
var obj=$(object);
if(obj==null)
return 0;
var wid=obj.style.posWidth;
return wid;
}
function getObjectHeight(object)
{
var obj=$(object);
if(obj==null)
return 0;
var hig=obj.style.posHeight;
return hig;
}
function showDoPanelLinePos(itemObj,content)
{
obj=document.createElement("DIV");
obj.setAttribute("id","__panel_do_");
obj.style.cssText="position:absolute; top:"+ (getPosTop(itemObj)) +"px; left:"+ (getPosLeft(itemObj)) +"px;padding: 10px;background-color: #E9F4FF;border: 1px solid #3A6EA5;";
obj.innerHTML=content;
_hideallselpanel();
document.body.appendChild(obj);
return obj;
}
function delDoPanelLine(itemObj)
{
itemObj.parentNode.removeChild(itemObj);
_showallselpanel();
}
function _hideallselpanel()
{
var obj=document.getElementsByTagName("select");
for(var i=0;i<obj.length;i=i+1)
{
obj[i].style.visibility="hidden";
}
}
function _showallselpanel()
{
var obj=document.getElementsByTagName("select");
for(var i=0;i<obj.length;i=i+1)
{
obj[i].style.visibility="visible";
}
}
function imgformatout(obj,fw,fh,typeId)
{
var imgItem=document.createElement("img");
imgItem.src=obj.src;
if(arguments.length==4)
obj.style.display="none";
if(arguments.length==1)
return ;
var sw=imgItem.width;
var sh=imgItem.height
var w;
var h;
if((sw/sh)>(fw/fh))
{
if(sw>fw)
{
w=fw;
h=w*sh/sw;
}
else
{
w=sw;
h=sh;
}
}
else
{
if(sh>fh)
{
h=fh;
w=h*sw/sh;
}
else
{
w=sw;
h=sh;
}
}
obj.width=w;
obj.height=h;
if(arguments.length==4)
obj.style.display="block";
}
function $showO(objTarget){
var obj=$(objTarget);
if(obj!=null)
obj.style.display="block";
}
function $hideO(objTarget){
var obj=$(objTarget);
if(obj!=null)
obj.style.display="none";
}
var $show=$showO;
var $hide=$hideO;
var Class = {create:function () {
return function () {
this.init.apply(this, arguments);
};
}};
Object.extend = function(destination, source) {
for (property in source) {
destination[property] = source[property];
}
return destination;
}
var DqbbFactory = Class.create();
DqbbFactory.prototype = {
init: function(async, events) {
this.gateway = "/CSTP_HR_PROC/dqbb";
this.transport = null;
if (typeof(async) == 'undefined') {
this.async = true;
} else {
this.async = async;
}
this.currentCallback = new Function();
this.setEvents(events);
},
setEvents: function(events) {
this.events = {
onFinish: new Function()
};
Object.extend(this.events, events || {});
},
dqbbCall: function(service, params, callback) {
var idx = service.indexOf(".");
var serviceId = service.substring(0,idx);
var method = service.substring(idx+1,service.length);
var newUrl = this.gateway+"/ajax_service/"+serviceId;
var call = new DqbbFactory.Call(method);
for (var i = 0; i < params.length; i++) {
call.addParameter(params[i]);
}
this._remoteCall(newUrl, call, callback);
},
_remoteCall: function(url, call, callback) {
this.transport = XmlHttp.create();
this.transport.open("POST", url, this.async);
this.transport.send(call.xml());
this.currentCallback = callback;
if (this.async) {
this.transport.onreadystatechange = this.onStateChange.bind(this);
} else {
this.response();
}
},
onStateChange: function(){
if (this.transport.readyState == 4) {
this.response();
}
},
response : function() {
if (this.transport.status == '200') {
var xmlDoc=this.transport.responseXML.documentElement;
var nodeList=xmlDoc.getElementsByTagName("itemInfo");
var isList=xmlDoc.getElementsByTagName("isList")[0].text;
var reply = new DqbbFactory.Reply(nodeList,isList);
this.currentCallback(reply);
this.events["onFinish"](reply);
} else {
//Add Do Error code here
}
}
}
DqbbFactory.Call = Class.create();
DqbbFactory.Call.prototype = {
init: function(methodname){
this.method = methodname;
this.params = [];
},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -