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

📄 util.js.svn-base

📁 dwr demo DWR的一个实例。。DWR的一个实例
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
      messageZone.style.right = "0px";      messageZone.style.background = "red";      messageZone.style.color = "white";      messageZone.style.fontFamily = "Arial,Helvetica,sans-serif";      messageZone.style.padding = "4px";      disabledZone.appendChild(messageZone);      var text = document.createTextNode(loadingMessage);      messageZone.appendChild(text);      dwr.util._disabledZoneUseCount = 1;    }    else {      dwr.util.byId('messageZone').innerHTML = loadingMessage;      disabledZone.style.visibility = 'visible';      dwr.util._disabledZoneUseCount++;    }  });  dwr.engine.setPostHook(function() {    dwr.util._disabledZoneUseCount--;    if (dwr.util._disabledZoneUseCount == 0) {      dwr.util.byId('disabledZone').style.visibility = 'hidden';    }  });};/** * Set a global highlight handler */dwr.util.setHighlightHandler = function(handler) {  dwr.util._highlightHandler = handler;};/** * An example highlight handler */dwr.util.yellowFadeHighlightHandler = function(ele) {  dwr.util._yellowFadeProcess(ele, 0);};dwr.util._yellowFadeSteps = [ "d0", "b0", "a0", "90", "98", "a0", "a8", "b0", "b8", "c0", "c8", "d0", "d8", "e0", "e8", "f0", "f8" ];dwr.util._yellowFadeProcess = function(ele, colorIndex) {  ele = dwr.util.byId(ele);  if (colorIndex < dwr.util._yellowFadeSteps.length) {    ele.style.backgroundColor = "#ffff" + dwr.util._yellowFadeSteps[colorIndex];    setTimeout("dwr.util._yellowFadeProcess('" + ele.id + "'," + (colorIndex + 1) + ")", 200);  }  else {    ele.style.backgroundColor = "transparent";  }};/** * An example highlight handler */dwr.util.borderFadeHighlightHandler = function(ele) {  ele.style.borderWidth = "2px";  ele.style.borderStyle = "solid";  dwr.util._borderFadeProcess(ele, 0);};dwr.util._borderFadeSteps = [ "d0", "b0", "a0", "90", "98", "a0", "a8", "b0", "b8", "c0", "c8", "d0", "d8", "e0", "e8", "f0", "f8" ];dwr.util._borderFadeProcess = function(ele, colorIndex) {  ele = dwr.util.byId(ele);  if (colorIndex < dwr.util._borderFadeSteps.length) {    ele.style.borderColor = "#ff" + dwr.util._borderFadeSteps[colorIndex] + dwr.util._borderFadeSteps[colorIndex];    setTimeout("dwr.util._borderFadeProcess('" + ele.id + "'," + (colorIndex + 1) + ")", 200);  }  else {    ele.style.backgroundColor = "transparent";  }};/** * A focus highlight handler */dwr.util.focusHighlightHandler = function(ele) {  try {    ele.focus();  }  catch (ex) { /* ignore */ }};/** @private the current global highlight style */dwr.util._highlightHandler = null;/** * Highlight that an element has changed */dwr.util.highlight = function(ele, options) {  if (options && options.highlightHandler) {    options.highlightHandler(dwr.util.byId(ele));  }  else if (dwr.util._highlightHandler != null) {    dwr.util._highlightHandler(dwr.util.byId(ele));  }};/** * Set the value an HTML element to the specified value. * @see http://getahead.org/dwr/browser/util/setvalue */dwr.util.setValue = function(ele, val, options) {  if (val == null) val = "";  if (options == null) options = {};  if (dwr.util._shouldEscapeHtml(options) && typeof(val) == "string") {    val = dwr.util.escapeHtml(val);  }  var orig = ele;  if (typeof ele == "string") {    ele = dwr.util.byId(ele);    // We can work with names and need to sometimes for radio buttons, and IE has    // an annoying bug where getElementById() returns an element based on name if    // it doesn't find it by id. Here we don't want to do that, so:    if (ele && ele.id != orig) ele = null;  }  var nodes = null;  if (ele == null) {    // Now it is time to look by name    nodes = document.getElementsByName(orig);    if (nodes.length >= 1) ele = nodes.item(0);  }  if (ele == null) {    dwr.util._debug("setValue() can't find an element with id/name: " + orig + ".");    return;  }  // All paths now lead to some update so we highlight a change  dwr.util.highlight(ele, options);  if (dwr.util._isHTMLElement(ele, "select")) {    if (ele.type == "select-multiple" && dwr.util._isArray(val)) dwr.util._selectListItems(ele, val);    else dwr.util._selectListItem(ele, val);    return;  }  if (dwr.util._isHTMLElement(ele, "input")) {    if (ele.type == "radio" || ele.type == "checkbox") {      if (nodes && nodes.length >= 1) {        for (var i = 0; i < nodes.length; i++) {          var node = nodes.item(i);          if (node.type != ele.type) continue;          if (dwr.util._isArray(val)) {            node.checked = false;            for (var j = 0; j < val.length; j++)              if (val[i] == node.value) node.checked = true;          }          else {            node.checked = (node.value == val);          }        }      }      else ele.checked = (val == true);    }    else ele.value = val;    return;  }  if (dwr.util._isHTMLElement(ele, "textarea")) {    ele.value = val;    return;  }  // If the value to be set is a DOM object then we try importing the node  // rather than serializing it out  if (val.nodeType) {    if (val.nodeType == 9 /*Node.DOCUMENT_NODE*/) val = val.documentElement;    val = dwr.util._importNode(ele.ownerDocument, val, true);    ele.appendChild(val);    return;  }  // Fall back to innerHTML  ele.innerHTML = val;};/** * @private Find multiple items in a select list and select them. Used by setValue() * @param ele The select list item * @param val The array of values to select */dwr.util._selectListItems = function(ele, val) {  // We deal with select list elements by selecting the matching option  // Begin by searching through the values  var found  = false;  var i;  var j;  for (i = 0; i < ele.options.length; i++) {    ele.options[i].selected = false;    for (j = 0; j < val.length; j++) {      if (ele.options[i].value == val[j]) {        ele.options[i].selected = true;      }    }  }  // If that fails then try searching through the visible text  if (found) return;  for (i = 0; i < ele.options.length; i++) {    for (j = 0; j < val.length; j++) {      if (ele.options[i].text == val[j]) {        ele.options[i].selected = true;      }    }  }};/** * @private Find an item in a select list and select it. Used by setValue() * @param ele The select list item * @param val The value to select */dwr.util._selectListItem = function(ele, val) {  // We deal with select list elements by selecting the matching option  // Begin by searching through the values  var found = false;  var i;  for (i = 0; i < ele.options.length; i++) {    if (ele.options[i].value == val) {      ele.options[i].selected = true;      found = true;    }    else {      ele.options[i].selected = false;    }  }  // If that fails then try searching through the visible text  if (found) return;  for (i = 0; i < ele.options.length; i++) {    if (ele.options[i].text == val) {      ele.options[i].selected = true;    }    else {      ele.options[i].selected = false;    }  }};/** * Read the current value for a given HTML element. * @see http://getahead.org/dwr/browser/util/getvalue */dwr.util.getValue = function(ele, options) {  if (options == null) options = {};  var orig = ele;  if (typeof ele == "string") {    ele = dwr.util.byId(ele);    // We can work with names and need to sometimes for radio buttons, and IE has    // an annoying bug where getElementById() returns an element based on name if    // it doesn't find it by id. Here we don't want to do that, so:    if (ele && ele.id != orig) ele = null;  }  var nodes = null;  if (ele == null) {    // Now it is time to look by name    nodes = document.getElementsByName(orig);    if (nodes.length >= 1) ele = nodes.item(0);  }  if (ele == null) {    dwr.util._debug("getValue() can't find an element with id/name: " + orig + ".");    return "";  }  if (dwr.util._isHTMLElement(ele, "select")) {    // Using "type" property instead of "multiple" as "type" is an official     // client-side property since JS 1.1    if (ele.type == "select-multiple") {      var reply = new Array();      for (var i = 0; i < ele.options.length; i++) {        var item = ele.options[i];        if (item.selected) {          var valueAttr = item.getAttributeNode("value");          if (valueAttr && valueAttr.specified) {            reply.push(item.value);          }          else {            reply.push(item.text);          }        }      }      return reply;    }    else {      var sel = ele.selectedIndex;      if (sel != -1) {        var item = ele.options[sel];        var valueAttr = item.getAttributeNode("value");        if (valueAttr && valueAttr.specified) {          return item.value;        }        return item.text;      }      else {        return "";      }    }  }  if (dwr.util._isHTMLElement(ele, "input")) {    if (ele.type == "radio") {      if (nodes && nodes.length >= 1) {        for (var i = 0; i < nodes.length; i++) {          var node = nodes.item(i);          if (node.type == ele.type) {            if (node.checked) return node.value;          }        }      }      return ele.checked;    }    if (ele.type == "checkbox") {      if (nodes && nodes.length >= 1) {        var reply = [];        for (var i = 0; i < nodes.length; i++) {          var node = nodes.item(i);          if (node.type == ele.type) {            if (node.checked) reply.push(node.value);          }        }        return reply;      }      return ele.checked;    }    return ele.value;  }  if (dwr.util._isHTMLElement(ele, "textarea")) {    return ele.value;  }  if (dwr.util._shouldEscapeHtml(options)) {    if (ele.textContent) return ele.textContent;    else if (ele.innerText) return ele.innerText;  }  return ele.innerHTML;};/** * getText() is like getValue() except that it reads the text (and not the value) from select elements * @see http://getahead.org/dwr/browser/util/gettext */dwr.util.getText = function(ele) {  ele = dwr.util._getElementById(ele, "getText()");  if (ele == null) return null;  if (!dwr.util._isHTMLElement(ele, "select")) {    dwr.util._debug("getText() can only be used with select elements. Attempt to use: " + dwr.util._detailedTypeOf(ele) + " from  id: " + orig + ".");    return "";  }  // This is a bit of a scam because it assumes single select  // but I'm not sure how we should treat multi-select.  var sel = ele.selectedIndex;  if (sel != -1) {    return ele.options[sel].text;  }  else {    return "";  }};/** * Given a map, or a recursive structure consisting of arrays and maps, call  * setValue() for all leaf entries and use intermediate levels to form nested * element ids. * @see http://getahead.org/dwr/browser/util/setvalues */dwr.util.setValues = function(data, options) {  var prefix = "";  if (options && options.prefix) prefix = options.prefix;  if (options && options.idPrefix) prefix = options.idPrefix;

⌨️ 快捷键说明

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