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

📄 util.js.svn-base

📁 dwr demo DWR的一个实例。。DWR的一个实例
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
/** * @private Default cell creation function */dwr.util._defaultCellCreator = function(options) {  return document.createElement("td");};/** * Remove all the children of a given node. * @see http://getahead.org/dwr/browser/tables */dwr.util.removeAllRows = function(ele, options) {  ele = dwr.util._getElementById(ele, "removeAllRows()");  if (ele == null) return;  if (!options) options = {};  if (!options.filter) options.filter = function() { return true; };  if (!dwr.util._isHTMLElement(ele, ["table", "tbody", "thead", "tfoot"])) {    dwr.util._debug("removeAllRows() can only be used with table, tbody, thead and tfoot elements. Attempt to use: " + dwr.util._detailedTypeOf(ele));    return;  }  var child = ele.firstChild;  var next;  while (child != null) {    next = child.nextSibling;    if (options.filter(child)) {      ele.removeChild(child);    }    child = next;  }};/** * dwr.util.byId(ele).className = "X", that we can call from Java easily. */dwr.util.setClassName = function(ele, className) {  ele = dwr.util._getElementById(ele, "setClassName()");  if (ele == null) return;  ele.className = className;};/** * dwr.util.byId(ele).className += "X", that we can call from Java easily. */dwr.util.addClassName = function(ele, className) {  ele = dwr.util._getElementById(ele, "addClassName()");  if (ele == null) return;  ele.className += " " + className;};/** * dwr.util.byId(ele).className -= "X", that we can call from Java easily * From code originally by Gavin Kistner */dwr.util.removeClassName = function(ele, className) {  ele = dwr.util._getElementById(ele, "removeClassName()");  if (ele == null) return;  var regex = new RegExp("(^|\\s)" + className + "(\\s|$)", 'g');  ele.className = ele.className.replace(regex, '');};/** * dwr.util.byId(ele).className |= "X", that we can call from Java easily. */dwr.util.toggleClassName = function(ele, className) {  ele = dwr.util._getElementById(ele, "toggleClassName()");  if (ele == null) return;  var regex = new RegExp("(^|\\s)" + className + "(\\s|$)");  if (regex.test(ele.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.org/dwr/??? */dwr.util.cloneNode = function(ele, options) {  ele = dwr.util._getElementById(ele, "cloneNode()");  if (ele == null) return null;  if (options == null) options = {};  var clone = ele.cloneNode(true);  if (options.idPrefix || options.idSuffix) {    dwr.util._updateIds(clone, options);  }  else {    dwr.util._removeIds(clone);  }  ele.parentNode.insertBefore(clone, ele);  return clone;};/** * @private Update all of the ids in an element tree */dwr.util._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*/) {      dwr.util._updateIds(child, options);    }  }};/** * @private Remove all the Ids from an element */dwr.util._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*/) {      dwr.util._removeIds(child);    }  }};/** * Clone a template node and its embedded template child nodes according to * cardinalities (of arrays) in supplied data.   */dwr.util.cloneNodeForValues = function(templateEle, data, options) {  templateEle = dwr.util._getElementById(templateEle, "cloneNodeForValues()");  if (templateEle == null) return null;  if (options == null) options = {};  var idpath;  if (options.idPrefix != null)    idpath = options.idPrefix;  else    idpath = templateEle.id || "";   return dwr.util._cloneNodeForValuesRecursive(templateEle, data, idpath, options);};/** * @private Recursive helper for cloneNodeForValues().  */dwr.util._cloneNodeForValuesRecursive = function(templateEle, data, idpath, options) {  // Incoming array -> make an id for each item and call clone of the template   // for each of them  if (dwr.util._isArray(data)) {    var clones = [];    for (var i = 0; i < data.length; i++) {      var item = data[i];      var clone = dwr.util._cloneNodeForValuesRecursive(templateEle, item, idpath + "[" + i + "]", options);      clones.push(clone);    }    return clones;  }  else  // Incoming object (not array) -> clone the template, add id prefixes, add   // clone to DOM, and then recurse into any array properties if they contain   // objects and there is a suitable template  if (dwr.util._isObject(data) && !dwr.util._isArray(data)) {    var clone = templateEle.cloneNode(true);    if (options.updateCloneStyle && clone.style) {      for (var propname in options.updateCloneStyle) {        clone.style[propname] = options.updateCloneStyle[propname];      }    }    dwr.util._replaceIds(clone, templateEle.id, idpath);    templateEle.parentNode.insertBefore(clone, templateEle);    dwr.util._cloneSubArrays(data, idpath, options);    return clone;  }  // It is an error to end up here so we return nothing  return null;};/** * @private Substitute a leading idpath fragment with another idpath for all  * element ids tree, and remove ids that don't match the idpath.  */dwr.util._replaceIds = function(ele, oldidpath, newidpath) {  if (ele.id) {    var newId = null;    if (ele.id == oldidpath) {      newId = newidpath;    }    else if (ele.id.length > oldidpath.length) {      if (ele.id.substr(0, oldidpath.length) == oldidpath) {        var trailingChar = ele.id.charAt(oldidpath.length);        if (trailingChar == "." || trailingChar == "[") {          newId = newidpath + ele.id.substr(oldidpath.length);        }      }    }    if (newId) {      ele.setAttribute("id", newId);    }    else {      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*/) {      dwr.util._replaceIds(child, oldidpath, newidpath);    }  }};/** * @private Finds arrays in supplied data and uses any corresponding template  * node to make a clone for each item in the array.  */dwr.util._cloneSubArrays = function(data, idpath, options) {  for (prop in data) {    var value = data[prop];    // Look for potential recursive cloning in all array properties    if (dwr.util._isArray(value)) {      // Only arrays with objects are interesting for cloning      if (value.length > 0 && dwr.util._isObject(value[0])) {        var subTemplateId = idpath + "." + prop;        var subTemplateEle = dwr.util.byId(subTemplateId);        if (subTemplateEle != null) {          dwr.util._cloneNodeForValuesRecursive(subTemplateEle, value, subTemplateId, options);        }      }    }    // Continue looking for arrays in object properties    else if (dwr.util._isObject(value)) {      dwr.util._cloneSubArrays(value, idpath + "." + prop, options);    }  }}/** * @private Helper to turn a string into an element with an error message */dwr.util._getElementById = function(ele, source) {  var orig = ele;  ele = dwr.util.byId(ele);  if (ele == null) {    dwr.util._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. */dwr.util._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 (dwr.util._isArray(nodeName)) {      var match = false;      for (var i = 0; i < nodeName.length && !match; i++) {        if (test == nodeName[i].toLowerCase()) {          match =  true;        }      }      return match;    }    dwr.util._debug("dwr.util._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" */dwr.util._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 Object detector. Excluding null from objects. */dwr.util._isObject = function(data) {  return (data && typeof data == "object");};/** * @private Array detector. Note: instanceof doesn't work with multiple frames. */dwr.util._isArray = function(data) {  return (data && data.join);};/** * @private Date detector. Note: instanceof doesn't work with multiple frames. */dwr.util._isDate = function(data) {  return (data && data.toUTCString) ? true : false;};/** * @private Used by setValue. Gets around the missing functionallity in IE. */dwr.util._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(dwr.util._importNode(doc, importedNode.childNodes[i], true));    }  }  return newNode;};/** @private Used internally when some message needs to get to the programmer */dwr.util._debug = function(message, stacktrace) {  var written = false;  try {    if (window.console) {      if (stacktrace && window.console.trace) window.console.trace();      window.console.log(message);      written = true;    }    else if (window.opera && window.opera.postError) {      window.opera.postError(message);      written = true;    }  }  catch (ex) { /* ignore */ }  if (!written) {    var debug = document.getElementById("dwr-debug");    if (debug) {      var contents = message + "<br/>" + debug.innerHTML;      if (contents.length > 2048) contents = contents.substring(0, 2048);      debug.innerHTML = contents;    }  }};

⌨️ 快捷键说明

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