⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util-js.js

📁 一个简单的java邮件系统源码
💻 JS
📖 第 1 页 / 共 3 页
字号:
  return tr;
};

/**
 * @private Default row creation function
 */
DWRUtil._defaultRowCreator = function(options) {
  return document.createElement("tr");
};

/**
 * @private Default cell creation function
 */
DWRUtil._defaultCellCreator = function(options) {
  return document.createElement("td");
};

/**
 * Remove all the children of a given node.
 * @see http://getahead.ltd.uk/dwr/browser/tables
 */
DWRUtil.removeAllRows = function(ele) {
  ele = DWRUtil._getElementById(ele, "removeAllRows()");
  if (ele == null) return;
  if (!DWRUtil._isHTMLElement(ele, ["table", "tbody", "thead", "tfoot"])) {
    DWRUtil.debug("removeAllRows() can only be used with table, tbody, thead and tfoot elements. Attempt to use: " + DWRUtil._detailedTypeOf(ele));
    return;
  }
  while (ele.childNodes.length > 0) {
    ele.removeChild(ele.firstChild);
  }
};

/**
 * $(ele).className = "X", that we can call from Java easily
 */
DWRUtil.setClassName = function(ele, className) {
  ele = DWRUtil._getElementById(ele, "setClassName()");
  if (ele == null) return;
  ele.className = className;
};

/**
 * $(ele).className += "X", that we can call from Java easily.
 */
DWRUtil.addClassName = function(ele, className) {
  ele = DWRUtil._getElementById(ele, "addClassName()");
  if (ele == null) return;
  ele.className += " " + className;
};

/**
 * $(ele).className -= "X", that we can call from Java easily
 * From code originally by Gavin Kistner
 */
DWRUtil.removeClassName = function(ele, className) {
  ele = DWRUtil._getElementById(ele, "removeClassName()");
  if (ele == null) return;
  var regex = new RegExp("(^|\\s)" + className + "(\\s|$)", 'g');
  ele.className = ele.className.replace(regex, '');
};

/**
 * $(ele).className |= "X", that we can call from Java easily.
 */
DWRUtil.toggleClassName = function(ele, className) {
  ele = DWRUtil._getElementById(ele, "toggleClassName()");
  if (ele == null) return;
  var regex = new RegExp("(^|\\s)" + className + "(\\s|$)");
  if (regex.test(element.className)) {
    ele.className = ele.className.replace(regex, '');
  }
  else {
    ele.className += " " + className;
  }
};

/**
 * Clone a node and insert it into the document just above the 'template' node
 * @see http://getahead.ltd.uk/dwr/???
 */
DWRUtil.cloneNode = function(ele, options) {
  ele = DWRUtil._getElementById(ele, "cloneNode()");
  if (ele == null) return;
  if (options == null) options = {};
  var clone = ele.cloneNode(true);
  if (options.idPrefix || options.idSuffix) {
    DWRUtil._updateIds(clone, options);
  }
  else {
    DWRUtil._removeIds(clone);
  }
  ele.parentNode.insertBefore(clone, ele);
  return clone;
};

/**
 * @private Update all of the ids in an element tree
 */
DWRUtil._updateIds = function(ele, options) {
  if (options == null) options = {};
  if (ele.id) {
    ele.setAttribute("id", (options.idPrefix || "") + ele.id + (options.idSuffix || ""));
  }
  var children = ele.childNodes;
  for (var i = 0; i < children.length; i++) {
    var child = children.item(i);
    if (child.nodeType == 1 /*Node.ELEMENT_NODE*/) {
      DWRUtil._updateIds(child, options);
    }
  }
};

/**
 * @private Remove all the Ids from an element
 */
DWRUtil._removeIds = function(ele) {
  if (ele.id) ele.removeAttribute("id");
  var children = ele.childNodes;
  for (var i = 0; i < children.length; i++) {
    var child = children.item(i);
    if (child.nodeType == 1 /*Node.ELEMENT_NODE*/) {
      DWRUtil._removeIds(child);
    }
  }
};

/**
 * @private Helper to turn a string into an element with an error message
 */
DWRUtil._getElementById = function(ele, source) {
  var orig = ele;
  ele = $(ele);
  if (ele == null) {
    DWRUtil.debug(source + " can't find an element with id: " + orig + ".");
  }
  return ele;
};

/**
 * @private Is the given node an HTML element (optionally of a given type)?
 * @param ele The element to test
 * @param nodeName eg "input", "textarea" - check for node name (optional)
 *         if nodeName is an array then check all for a match.
 */
DWRUtil._isHTMLElement = function(ele, nodeName) {
  if (ele == null || typeof ele != "object" || ele.nodeName == null) {
    return false;
  }
  if (nodeName != null) {
    var test = ele.nodeName.toLowerCase();
    if (typeof nodeName == "string") {
      return test == nodeName.toLowerCase();
    }
    if (DWRUtil._isArray(nodeName)) {
      var match = false;
      for (var i = 0; i < nodeName.length && !match; i++) {
        if (test == nodeName[i].toLowerCase()) {
          match =  true;
        }
      }
      return match;
    }
    DWRUtil.debug("DWRUtil._isHTMLElement was passed test node name that is neither a string or array of strings");
    return false;
  }
  return true;
};

/**
 * @private Like typeOf except that more information for an object is returned other than "object"
 */
DWRUtil._detailedTypeOf = function(x) {
  var reply = typeof x;
  if (reply == "object") {
    reply = Object.prototype.toString.apply(x); // Returns "[object class]"
    reply = reply.substring(8, reply.length-1);  // Just get the class bit
  }
  return reply;
};

/**
 * @private Array detector. Work around the lack of instanceof in some browsers.
 */
DWRUtil._isArray = function(data) {
  return (data && data.join) ? true : false;
};

/**
 * @private Date detector. Work around the lack of instanceof in some browsers.
 */
DWRUtil._isDate = function(data) {
  return (data && data.toUTCString) ? true : false;
};

/**
 * @private Used by setValue. Gets around the missing functionallity in IE.
 */
DWRUtil._importNode = function(doc, importedNode, deep) {
  var newNode;

  if (importedNode.nodeType == 1 /*Node.ELEMENT_NODE*/) {
    newNode = doc.createElement(importedNode.nodeName);

    for (var i = 0; i < importedNode.attributes.length; i++) {
      var attr = importedNode.attributes[i];
      if (attr.nodeValue != null && attr.nodeValue != '') {
        newNode.setAttribute(attr.name, attr.nodeValue);
      }
    }

    if (typeof importedNode.style != "undefined") {
      newNode.style.cssText = importedNode.style.cssText;
    }
  }
  else if (importedNode.nodeType == 3 /*Node.TEXT_NODE*/) {
    newNode = doc.createTextNode(importedNode.nodeValue);
  }

  if (deep && importedNode.hasChildNodes()) {
    for (i = 0; i < importedNode.childNodes.length; i++) {
      newNode.appendChild(DWRUtil._importNode(doc, importedNode.childNodes[i], true));
    }
  }

  return newNode;
};

/** The array of current debug items */
DWRUtil._debugDisplay = [];

/** What is the maximum length of the debug items array */
DWRUtil._debugMaxLength = 50;

/**
 * Used internally when some message needs to get to the programmer
 */
DWRUtil.debug = function(message) {
  var debug = $("dwr-debug");
  if (debug) {
    while (DWRUtil._debugDisplay.length >= DWRUtil._debugMaxLength) {
      DWRUtil._debugDisplay.shift();
    }
    DWRUtil._debugDisplay.push(message);
    var contents = "";
    for (var i = 0; i < DWRUtil._debugDisplay.length; i++) {
      contents += DWRUtil._debugDisplay[i] + "<br/>";
    }
    DWRUtil.setValue("dwr-debug", contents);
  }
  else if (window.console) window.console.log(message);
  else if (window.opera && window.opera.postError) window.opera.postError(message);
  //else if (window.navigator.product == "Gecko") window.dump(message + "\n");
  alert(message);
};


/////下面开始属于EasyAjax的属性
EasyAjaxUtil={};
EasyAjaxUtil.showPageInfo=function(tag)
{
if(!this.pageList)
{
this.pageList={rowCount:0,pages:0,pageSize:15,currentPage:1,result:null};
}
var currentPage=this.pageList.currentPage;
var  pages=this.pageList.pages;
var s="第<strong>"+currentPage+"</strong>页 共<strong>"+pages+"</strong>页<span>[共<b>"+this.pageList.rowCount+"</b>条记录]</span>   分页:";
if (currentPage > 1) {
			s += "<a href=# onclick='return EasyAjaxUtil.gotoPage(1)'>首页</a> ";
			s += "<a href=# onclick='return EasyAjaxUtil.gotoPage(" + (currentPage - 1)
					+ ")'>上一页</a> ";
		}
		var beginPage = currentPage - 3 < 1 ? 1 : currentPage - 3;
		if (beginPage < pages) {
			s += "第 ";
			for (var i = beginPage, j = 0; i <= pages && j < 6; i++, j++) {
				if (i == currentPage)
					s += "<font color=red>" + i + "</font> ";
				else
					s += "<a href=# onclick='return EasyAjaxUtil.gotoPage(" + i + ")'>" + i
							+ "</a> ";
			}
			s += "页 ";
		}
if (currentPage < pages) {
s += "<a href=# onclick='return EasyAjaxUtil.gotoPage(" + (currentPage + 1)
					+ ")'>下一页</a> ";
			s += "<a href=# onclick='return EasyAjaxUtil.gotoPage(" +pages + ")'>末页</a> ";
		}
		s+=" 转到指定页:<input type=text id='directGotoSomePage' size=2 class='form_text'> <input type=button onclick=EasyAjaxUtil.gotoPage($('directGotoSomePage').value) value='跳转' class='button'>";
if(!tag)tag=$("pageInfo");
tag.innerHTML=s;
}
EasyAjaxUtil.gotoPage=function(i)
{
if(i<1)
{
alert("页码必须大于0");
return;
}
if(i>this.pageList.pages)
{alert("页码不能超过"+this.pageList.pages);return;}
if(!this.queryPage)this.queryPage=this._defaultQueryPage;
this.queryPage(i);
}
EasyAjaxUtil._defaultQueryPage=function(i)
{
if(this.listData)this.listData(i);
}
EasyAjaxUtil.getCalendar=function(objId)
{

	var obj=$(objId);
    if (!obj){
	  //如果是文本框的onmousedown世间是由脚本绑定的,且没有参数  modified by qiuchun
	  if (event.srcElement){
	    var pchild = event.srcElement;
	    if (pchild.type && pchild.type.toLowerCase() == "text")
	      obj = pchild;
	  }
	}
	var x=event.screenX;
	var y=event.screenY;
	var result=window.showModalDialog('/include/Calendar.htm','Calendar',"dialogLeft:"+x+"px;dialogTop:"+y+"px;dialogWidth:195px;dialogHeight:200px;help:no;status:no");	
	if(result!=null)
	obj.value=result;
		//eval(arguments[0]+".value=result");		
	return false;
}
EasyAjaxUtil.loadPage=function(url,pars)
{
var resultId="main";
if(arguments.length>2 && (typeof arguments[arguments.length-1])=="string")
{
resultId=arguments[arguments.length-1];
}
var myAjax = new Ajax.Updater({success: resultId},url,{
						evalScripts:true, 
						parameters: pars, 
						method: 'POST'
					});
}
EasyAjaxUtil.loadStaticPage=function(url)
{
var callBack=null;
var resultId="main";
if(arguments.length>1 && (typeof arguments[arguments.length-1])=="function")
{
callBack=arguments[arguments.length-1];
}
if(arguments.length>2 && (typeof arguments[arguments.length-2])=="string")
{
resultId=arguments[arguments.length-2];
}
$(resultId).innerHTML="<font color=blue>正在加载数据,请稍候...</font>";
var myAjax = new Ajax.Request("loadPage.ejf?url="+url,{
						evalScripts:true, 						
						method: 'POST',
						onComplete:function(req){
						$(resultId).innerHTML="完成加载!";						
						Element.update(resultId,req.responseText);
						if(callBack!=null)callBack.call(this);
						}
					});
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -