📄 util.js
字号:
return; } for (var prop in data) { value = dwr.util._getValueFrom(data[prop], arguments[2]); text = dwr.util._getValueFrom(data[prop], arguments[3]); if (text || value) ele.options[ele.options.length] = new Option(text, value); } } else { if (!useOptions) { dwr.util._debug("dwr.util.addOptions can only create select lists from objects."); return; } for (var prop in data) { if (typeof data[prop] != "function") { if (arguments[2]) ele.options[ele.options.length] = new Option(prop, data[prop]); else ele.options[ele.options.length] = new Option(data[prop], prop); } } } // All error routes through this function result in a return, so highlight now dwr.util.highlight(ele, null); // TODO: forward options instead of null };/** * @private Get the data from an array function for dwr.util.addOptions */dwr.util._getValueFrom = function(data, method) { if (method == null) return data; else if (typeof method == 'function') return method(data); else return data[method];};/** * Remove all the options from a select list (specified by id) * @see http://getahead.ltd.uk/dwr/browser/lists */dwr.util.removeAllOptions = function(ele) { ele = dwr.util._getElementById(ele, "removeAllOptions()"); if (ele == null) return; var useOptions = dwr.util._isHTMLElement(ele, "select"); var useLi = dwr.util._isHTMLElement(ele, ["ul", "ol"]); if (!useOptions && !useLi) { dwr.util._debug("removeAllOptions() can only be used with select, ol and ul elements. Attempt to use: " + dwr.util._detailedTypeOf(ele)); return; } if (useOptions) { ele.options.length = 0; } else { while (ele.childNodes.length > 0) { ele.removeChild(ele.firstChild); } }};/** * Create rows inside a the table, tbody, thead or tfoot element (given by id). * @see http://getahead.ltd.uk/dwr/browser/tables */dwr.util.addRows = function(ele, data, cellFuncs, options) { ele = dwr.util._getElementById(ele, "addRows()"); if (ele == null) return; if (!dwr.util._isHTMLElement(ele, ["table", "tbody", "thead", "tfoot"])) { dwr.util._debug("addRows() can only be used with table, tbody, thead and tfoot elements. Attempt to use: " + dwr.util._detailedTypeOf(ele)); return; } if (!options) options = {}; if (!options.rowCreator) options.rowCreator = dwr.util._defaultRowCreator; if (!options.cellCreator) options.cellCreator = dwr.util._defaultCellCreator; var tr, rowNum; if (dwr.util._isArray(data)) { for (rowNum = 0; rowNum < data.length; rowNum++) { options.rowData = data[rowNum]; options.rowIndex = rowNum; options.rowNum = rowNum; options.data = null; options.cellNum = -1; tr = dwr.util._addRowInner(cellFuncs, options); if (tr != null) ele.appendChild(tr); } } else if (typeof data == "object") { rowNum = 0; for (var rowIndex in data) { options.rowData = data[rowIndex]; options.rowIndex = rowIndex; options.rowNum = rowNum; options.data = null; options.cellNum = -1; tr = dwr.util._addRowInner(cellFuncs, options); if (tr != null) ele.appendChild(tr); rowNum++; } } dwr.util.highlight(ele, options);};/** * @private Internal function to draw a single row of a table. */dwr.util._addRowInner = function(cellFuncs, options) { var tr = options.rowCreator(options); if (tr == null) return null; for (var cellNum = 0; cellNum < cellFuncs.length; cellNum++) { var func = cellFuncs[cellNum]; if (typeof func == 'function') options.data = func(options.rowData, options); else options.data = func || ""; options.cellNum = cellNum; var td = options.cellCreator(options); if (td != null) { if (options.data != null) { if (dwr.util._isHTMLElement(options.data)) td.appendChild(options.data); else { if (dwr.util._shouldEscapeHtml(options) && typeof(options.data) == "string") { td.innerHTML = dwr.util.escapeHtml(options.data); } else { td.innerHTML = options.data; } } } tr.appendChild(td); } } return tr;};/** * @private Default row creation function */dwr.util._defaultRowCreator = function(options) { return document.createElement("tr");};/** * @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.ltd.uk/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(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/??? */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); } }};/** * @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. */dwr.util._isArray = function(data) { return (data && data instanceof Array);};/** * @private Date detector. */dwr.util._isDate = function(data) { return (data && data instanceof Date);};/** * @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 + -