js 开发互联网机顶盒前端之页面逻辑三

 

/**
* Dare Utilities library.
* @constructor
*/
Dare.Util = function () {
  this.className = "Dare.Util";
  this.rdashAlpha = /-([a-z])/ig
 

};

Dare.extend(Dare.Util,Dare);

Dare.Util.prototype.fcamelCase = function( all, letter ) {
    return letter.toUpperCase();
};
Dare.Util.prototype.camelCase = function( string ) {
    dareUtil.debug(string.match(this.rdashAlpha));
    return string.replace( this.rdashAlpha, this.fcamelCase );
};
 

Dare.Util.prototype.$ = function (id) {
  return document.getElementById(id);
};
Dare.Util.prototype.getElementValue = function (elementObject) {
  return elementObject.value;
};
Dare.Util.prototype.setElementValue = function (elementObject, value) {
  elementObject.value = value;
};

Dare.Util.prototype.getElementText = function (elementObject) {
  return elementObject.innerHTML;
};
Dare.Util.prototype.setElementText = function (elementObject, text) {
  elementObject.innerHTML = text;
};

Dare.Util.prototype.clearOptions = function (selectElement) {
  selectElement.options.length = 0;
};
Dare.Util.prototype.addOption = function (selectElement, text, value) {
  selectElement.options.add(new Option(text, value));
};
Dare.Util.prototype.addOptions = function (selectElement, list) {
  for (var i = 0; i < list.length; i++) {
    this.addOption(selectElement, list[i], list[i]);
  }
};
Dare.Util.prototype.selectOption = function (selectElement, text, value) {
  selectElement.selectedIndex = -1;
  for (var i = 0; i < selectElement.options.length; i++) {
    if ((text && (selectElement.options[i].text == text)) || (value && (selectElement.options[i].value == value))) {
      selectElement.options[i].selected = true;
      break;
    }
  }
};
Dare.Util.prototype.getOptionText = function (selectElement) {
  return selectElement.options[selectElement.selectedIndex].text;
};
Dare.Util.prototype.encodeUtf8 = function (selectElement) {
  var s = escape(selectElement);
  var sa = s.split("%");
  var retV = "";
  if (sa[0] != "") {
    retV = sa[0];
  }
  for (var i = 1; i < sa.length; i++) {
    if (sa[i].substring(0, 1) == "u") {
      retV += Hex2Utf8(Str2Hex(sa[i].substring(1, 5)));

    }
    else retV += "%" + sa[i];
  }

  return retV;
};

Dare.Util.prototype.getOptionValue = function (selectElement) {
  return selectElement.options[selectElement.selectedIndex].value;
};
Dare.Util.prototype.hideDomObj = function (obj) {
  if (obj) obj.style.display = 'none';
};
Dare.Util.prototype.showDomObj = function (obj) {
  if (obj) obj.style.display = 'block';
};
Dare.Util.prototype.isHidden = function (obj) {
  if (!obj) return true;
  return obj.style.display == 'none';
};
//取得文件名
Dare.Util.prototype.getFileTitleName = function (str, len) {
  var filename = this.getFileName(str);


  var reg = /[0-9]*\.[A-Za-z0-9]{3}$/g;
  var d = filename.match(reg);
  filename = filename.replace(d + "", "")

  //reg =  /\.[A-Za-z]{3}$/g;
  //d = filename.match(reg);
  filename = filename.replace(d + "", "")


  return this.substr(filename, len);
};
Dare.Util.prototype.iFrameResize = function (id, width, height) {

  //alert(document.body.scrollHeight); //弹出当前页面的高度
  var obj = document.getElementById(id);  //取得页面IFrame对象
  //alert(obj.height); //弹出页面中IFrame中设置的高度
  obj.height = height;  //调整页面中IFrame的高度为此页面的高度
  obj.width = width;
};
//截取长度,没有省略号
Dare.Util.prototype.substr = function (str, len) {
  var newLength = 0;
  var newStr = "";
  var validword = mailto:'~1234567890-=!@#$%^&amp;*()_+QWERTYUIOP{}|ASDFGHJKL:&quot;ZXCVBNM<>?qwertyuiop[]\asdfghjkl;\'zxcvbnm,./';
  var singleChar = "";
  var strLength = str.length;
  for (var i = 0; i < strLength; i++) {
    singleChar = str.substr(i, 1);
    if (validword.indexOf(singleChar) == -1) {
      newLength += 2;
    } else {
      newLength++;
    }
    if (newLength > len) {
      break;
    }
    newStr += singleChar;
  }
  if (newLength > len) {
    newStr += "";
  }
  return newStr;
  return newStr;
};
/**
* 截取长度
* @param {Object} str
* @param {Object} len
*/
Dare.Util.prototype.trimstr = function (str, len) {

  var newLength = 0;
  var newStr = "";
  var validword = mailto:'~1234567890-=!@#$%^&amp;*()_+QWERTYUIOP{}|ASDFGHJKL:&quot;ZXCVBNM<>?qwertyuiop[]\asdfghjkl;\'zxcvbnm,./';
  var singleChar = "";
  var strLength = str.length;
  for (var i = 0; i < strLength; i++) {
    singleChar = str.substr(i, 1);
    if (validword.indexOf(singleChar) == -1) {
      newLength += 2;
    } else {
      newLength++;
    }
    if (newLength > len) {
      break;
    }
    newStr += singleChar;
  }
  if (newLength > len) {
    newStr += "..";
  }
  return newStr;
};
Dare.Util.prototype.trimPath = function(path,MAXLENGTH){
  var length = this.getChStrLength(path);
  //
  var trim = false;
  while(length > MAXLENGTH){
    //alert(path +" -----");
    path =  path.substring(path.substring(1).indexOf("/")+1);
    //alert(path);
    length = this.getChStrLength(path);
    trim = true;
  }
  if(trim) path = "..."+path;
  return path;
};
/**
* 获取名称长度
* @param {Object} str
*/
Dare.Util.prototype.getChStrLength = function (str) {

  var newLength = 0;
  var newStr = "";
  var validword = mailto:'~1234567890-=!@#$%^&amp;*()_+QWERTYUIOP{}|ASDFGHJKL:&quot;ZXCVBNM<>?qwertyuiop[]\asdfghjkl;\'zxcvbnm,./';
  var singleChar = "";
  var strLength = str.length;
  for (var i = 0; i < strLength; i++) {
    singleChar = str.substr(i, 1);
    if (validword.indexOf(singleChar) == -1) {
      newLength += 2;
    }
    else {
      newLength++;
    }
  }
  return newLength;
};
Dare.Util.prototype.padLeft = function (str, lenght) {
  if (str.length >= lenght)
    return str;
  else
    return this.padLeft("0" + str, lenght);
};
Dare.Util.prototype.padRight = function (str, lenght) {
  if (str.length >= lenght)
    return str;
  else
    return this.padRight(str + "0", lenght);
};
/**
* 格式化时长 62 -- 01:02
* @param {Object} str
*/
Dare.Util.prototype.getDuring = function (str) {
  if (str.indexOf(":") >= 0) return str;
  var t = parseInt(str);
  return this.padLeft(parseInt(t / 60) + "", 2) + ":" + this.padLeft(t % 60 + "", 2);
}
/**
 * 是否目录
 * @param {Object} path
 */
Dare.Util.prototype.isDirectory = function(path)
{
  return (path.lastIndexOf('/')== path.length -1);
}
Dare.Util.prototype.getFileName = function (path) {
  if (path.lastIndexOf('/') == path.length - 1) {
    path = path.substring(0,path.length-1);
    return path.substring(path.lastIndexOf('/') + 1)+"/";//path.substring(0,path.length-1);
  }
  return path.substring(path.lastIndexOf('/') + 1);
};
/**
* 文件长度换算 1024 =1kb
* @param {Object} size
*/
Dare.Util.prototype.fileSizeInt2Str = function (size) {

  var tempValue = parseFloat(size);
  tempValue = (isNaN(tempValue)) ? 0 : tempValue;
  if (tempValue >= 1024 * 1204 * 1024 * 1024) {
    tempValue = parseInt(tempValue / 1024 / 1024 / 1024 / 102.4) / 10 + 'TB';
  }
  else if (tempValue >= 1024 * 1204 * 1024) {
    tempValue = parseInt(tempValue / 1024 / 1024 / 102.4) / 10 + 'GB';
  }
  else if (tempValue >= 1024 * 1204) {
    tempValue = parseInt(tempValue / 1024 / 102.4) / 10 + 'MB';
  }
  else if (tempValue >= 1024) {
    tempValue = parseInt(tempValue / 102.4) / 10 + 'KB';
  }
  else {
    tempValue = parseInt(tempValue) + 'B';
  }
  return (tempValue);
}
/**
* 文件长度换算成整数 1kb = 1024
* @param {Object} str
*/
Dare.Util.prototype.fileSizeStr2Int = function (str) {
  str = str.toLowerCase().replace('b', '')
  var unit = str.substring(str.length - 1);
  switch (unit) {
    case '': return parseInt(str); break;
    case 'k': return parseInt(str) * 1024; break;
    case 'm': return parseInt(str) * 1024 * 1024; break;
    case 'g': return parseInt(str) * 1024 * 1024 * 1024; break;
    default: return parseInt(str); break;
  }
};
/**
* 文件长度换算成整数 1000b = 1000
* @param {Object} str
*/
Dare.Util.prototype.formatFileSize = function (str) {
  str = str.toLowerCase().replace('b', '')
  return Math.ceil(str);

};
/**
* 文件大小排序
* @param {Object} jsonobj
* @param {Object} sortvalue1 1 或-1
* @param {Object} sortvalue  1 或-1
*/
Dare.Util.prototype.sortSize = function (jsonobj, sortvalue1, sortvalue) {
  if (jsonobj.length <= 1) return;
  jsonobj.sort(
     function (a, b) {
       var a1 = a["size"]
       if (!a1)
         a1 = a["volumn"];

       var b1 = b["size"];
       if (!b1)
         b1 = b["volumn"];

       return a1 > b1 ? sortvalue1 : a1 == b1 ? 0 : sortvalue
     }
   )
};
Dare.Util.prototype.sortBy = function (jsonobj, sortname, sortDirection) {
  if (jsonobj.length <= 1) return;
  var sortvalue = sortDirection == "asc" ? 1 : -1;
  var sortvalue1 = parseInt((-1) * sortvalue);

  switch (sortname) {
    case 'type':
      jsonobj.sort(function (a, b) {
        return a["type"] > b["type"] ? sortvalue1 : a["type"] == b["type"] ? 0 : sortvalue
      });
      break;
    case 'name':
      jsonobj.sort(
       function (a, b) { return a["chname"] > b["chname"] ? sortvalue1 : a["chname"] == b["chname"] ? 0 : sortvalue }
      );
      break;
    case 'date':
      jsonobj.sort(function (a, b) {
        return a["date"] > b["date"] ? sortvalue1 : a["date"] == b["date"] ? 0 : sortvalue
      });
      break;
    case 'datetime':
      jsonobj.sort(function (a, b) {
        return a["datetime"] > b["datetime"] ? sortvalue1 : a["datetime"] == b["datetime"] ? 0 : sortvalue
      });
      break;
    case 'size':
      jsonobj.sort(function (a, b) {
        return a["size"] > b["size"] ? sortvalue1 : a["size"] == b["size"] ? 0 : sortvalue
      });
      break;
    case 'selected':
      jsonobj.sort(function (a, b) {
        return a["selected"] > b["selected"] ? sortvalue1 : a["selected"] == b["selected"] ? 0 : sortvalue
      });
  }

};
/**
 * 获取当前文件路径
 * @param {Object} file
 */
Dare.Util.prototype.getFilePath = function(file){
  //alert(file.lastIndexOf('/'));
  return file.substr(0,file.lastIndexOf('/')+1);
}
/**
* 获取上级目录 c:/document 返回c: ,c: 返回""
* @param {Object} path
*/
Dare.Util.prototype.getUpperPath = function (path) {
  if(path == '/')return;
  if(this.isDirectory(path)){
    path = path.substring(path, path.length - 1);
  }
  path = this.getFilePath(path);
  if (path.lastIndexOf('/' == path.length - 1)) {
    path = path.substring(path, path.length - 1);
  }

  var j = path.lastIndexOf('/');
  return path.substr(0, j+1);
};
/**
* 缩放、上升、擦除、下降、展开、淡入淡出
* @param {Object} type
* @param {Element} id
*/
Dare.Util.prototype.picEffect = function (type, id) {
  switch (type) {
    case 0: //比例     scale
      Dare.FX.scale(id, { duration: 2000, restoreAfterFinish: true });
      break;
    case 1: //上升moveup
      var options = {
        x: 0,
        y: -630,
        duration: 10000,
        interval: 100,
        restoreAfterFinish: true
      };
      Dare.FX.move(id, options);
      break;
    case 2: //擦除"mask"
      Dare.FX.mask(id, { startOrigin: "50% 50%" });
      break;
    case 3: //下降movedown
      var options = {
        x: 0,
        y: 430,
        duration: 10000,
        interval: 100,
        restoreAfterFinish: true
      };
      Dare.FX.move(id, options);
      break;

    case 4: //展开"expand"
      var options = {
        duration: 5000,
        interval: 100,
        restoreAfterFinish: true
      };
      Dare.FX.expand(id, options);
      break;

    case 5: //淡入fadIn
      Dare.FX.fadeIn(id, { duration: 5000, restoreAfterFinish: true });
      break;
    case 6: //淡出"fadOut"
      Dare.FX.fadeOut(id, { duration: 5000, restoreAfterFinish: true });
      break;
    case 7: //透明"opacity"
      Dare.FX.opacity(id, { from: 100, to: 0, duration: 5000, restoreAfterFinish: true });
      break;
    case 8: //合上"collapse"
      var options = {
        duration: 5000,
        interval: 100,
        restoreAfterFinish: true
      };
      Dare.FX.collapse(id, options);
      break;
    case 9: //放大并逐渐消失"zoomOut"
      var opts = {
        to: 0.1,
        from: 1,
        duration: 5000,
        restoreAfterFinish: true
      };
      Dare.FX.zoomOut(id, opts);
      break;
    case 10: //心跳闪现效果  "pulsate"
      Dare.FX.pulsate(id, 5);
      break;

  }
};

/**
* @function each
* @author
* @param list 集合 fn 函数
* @return null
*/
Dare.Util.prototype.each = function (list, fn) {
  var ln = list.length;
  for (var i = 0; i < ln; i++) {
    fn(list[i], i);
  }
};

/**
* @function secondsToMMSS MM:SS
* @author
* @param seconds
* @return string
*/
Dare.Util.prototype.secondsToMMSS = function (seconds) {
  var mm;
  var ss;
  if (seconds <= 0) {
    return '00:00';
  }
  //得到分
  mm = seconds / 60 | 0;
  //得到秒
  ss = parseInt(seconds) - mm * 60;
  if (parseInt(mm) < 10) {
    mm = '0' + mm;
  }
  if (ss < 10) {
    ss = '0' + ss;
  }
  return mm + ':' + ss;
};
/**
* @function mmssToSeconds
* @author
* @param mmss
* @return int
*/
Dare.Util.prototype.mmssToSeconds = function (ms) {
  if (ms.length == 0) {
    return 0;
  }
  var msArray = ms.split(':');
  var mm = parseInt(msArray[0]);
  var ss = parseInt(msArray[1]);
  var totalSeconds = mm * 60 + ss;
  return totalSeconds;
};
/**
* @function secondsToHHMMSS HH:MM:SS
* @author
* @param seconds
* @return string
*/
Dare.Util.prototype.secondsToHHMMSS = function (seconds) {
  var hh;
  var mm;
  var ss;
  if (seconds <= 0) {
    return '00:00:00';
  }
  //得到小时
  hh = seconds / 3600 | 0;
  seconds = parseInt(seconds) - hh * 3600;
  if (parseInt(hh) < 10) {
    hh = '0' + hh;
  }
  //得到分
  mm = seconds / 60 | 0;
  //得到秒
  ss = parseInt(seconds) - mm * 60;
  if (parseInt(mm) < 10) {
    mm = '0' + mm;
  }
  if (ss < 10) {
    ss = '0' + ss;
  }
  return hh + ':' + mm + ':' + ss;
};
/**
* @function hhmmssToSeconds
* @author
* @param mmss
* @return int
*/
Dare.Util.prototype.hhmmssToSeconds = function (hms) {
  if (hms.length == 0) {
    return 0;
  }
  var msArray = hms.split(':');
  var hh = parseInt(msArray[0]);
  var mm = parseInt(msArray[1]);
  var ss = parseInt(msArray[2]);
  var totalSeconds = hh * 3600 + mm * 60 + ss;
  return totalSeconds;
};
/**
* @function clearTimer 清除定时器
* @param null
* @return null
*/
Dare.Util.prototype.clearTimeOutTimer = function (timer) {
  if (timer != null) { clearTimeOut(timer); }
};
/**
* @function clearInterval 清除定时器
* @param null
* @return null
*/
Dare.Util.prototype.clearIntervalTimer = function (timer) {
  if (timer != null) { clearInterval(timer); }
};
/**
* @function evalTrend 动态调用全局函数
* @author
* @param fn 全局函数
* @return null
*/
Dare.Util.prototype.evalTrend = function (fn) {
  eval(fn);
};
Dare.Util.prototype.thumbnailScale = function (srcWidth, srcHeight) {
  var w = srcWidth;
  var h = srcHeight;
  var resizeScale = {};
  var newWidth = 0;
  var newHeight = 0;
  var maxWidth = 200;
  var maxHeight = 200;
  var srcScale = w / h;
  var maxScale = maxWidth / maxHeight;

  if (srcScale >= maxScale) {
    if (w > maxWidth) {
      newWidth = maxWidth;
      newHeight = (maxWidth * h) / w;
    }
    else {
      newWidth = w;
      newHeight = h;
    }
  }
  else {
    if (h > maxHeight) {
      newWidth = (maxHeight * w) / h;
      newHeight = maxHeight;
    }
    else {
      newWidth = w;
      newHeight = h;
    }
  }
  // this.$("divDebug").innerText = newHeight +"  "+newWidth;
  resizeScale = { width: parseInt(newWidth), height: parseInt(newHeight) };
  return resizeScale;
}
/**
* @function playScaleZoom 播放比例
* @author
* @param srcWidth, srcHeight, screenMode
* @return null
*/
Dare.Util.prototype.playScaleZoom = function (srcWidth, srcHeight, screenMode) {
  var w = srcWidth;
  var h = srcHeight;
  var newWidth = 0;
  var newHeight = 0;
  var x = 0;
  var y = 0;
  var kx = 0;
  var ky = 0;
  var maxWidth = 0;
  var maxHeight = 0;
  var resizeScale = {};
  var wScale = 0;
  var hScale = 0;

  switch (screenMode) {
    case 0:
      maxWidth = 1000;
      maxHeight = 400;
      kx = 75;
      ky = 50;
      break;
    case 1:
      maxWidth = 1140;
      maxHeight = 630;
      break;
    default:
      break;
  }

  wScale = (maxWidth * 100) / w;
  hScale = (maxHeight * 100) / h;

  if (wScale > hScale) {
    newHeight = maxHeight;
    y = 0;
    newWidth = maxHeight * w / h;
    x = (maxWidth - newWidth) / 2;
    if (x < 0) x = 0;
    if (newWidth > maxWidth) newWidth = maxWidth;
  }
  else {
    newWidth = maxWidth;
    x = 0;
    newHeight = maxWidth * h / w;
    y = (maxHeight - newHeight) / 2;
    if (y < 0) y = 0;
    if (newHeight > maxHeight) newHeight = maxHeight;
  }
  if (screenMode == 0) {
    x += kx;
    y += ky;
  }
  resizeScale = { pointx: parseInt(x), pointy: parseInt(y), width: parseInt(newWidth), height: parseInt(newHeight) };
  return resizeScale;
};
/**
* @function playScale 播放比例
* @author
* @param srcWidth, srcHeight, screenMode
* @return null
*/
Dare.Util.prototype.playScale = function (srcWidth, srcHeight, screenMode) {
  var w = srcWidth;
  var h = srcHeight;
  var newWidth = 0;
  var newHeight = 0;
  var x = 0;
  var y = 0;
  var maxWidth = 0;
  var maxHeight = 0;
  var resizeScale = {};
  var maxScale = 0;
  var srcScale = 0;

  switch (screenMode) {
    case 0:
      maxWidth = 1000;
      maxHeight = 400;
      x = 75;
      y = 50;
      break;
    case 1:
      maxWidth = 1140;
      maxHeight = 630;
      break;
    default:
      break;
  }

  srcScale = w / h;
  maxScale = maxWidth / maxHeight;

  if (srcScale >= maxScale) {
    if (w > maxWidth) {
      newWidth = maxWidth;
      newHeight = (maxWidth * h) / w;
    }
    else {
      newWidth = w;
      newHeight = h;
    }
  }
  else {
    if (h > maxHeight) {
      newWidth = (maxHeight * w) / h;
      newHeight = maxHeight;
    }
    else {
      newWidth = w;
      newHeight = h;
    }
  }

  x = (parseInt(maxWidth / 2) + x) - parseInt(newWidth / 2);
  y = (parseInt(maxHeight / 2) + y) - parseInt(newHeight / 2);
  resizeScale = { pointx: x, pointy: y, width: parseInt(newWidth), height: parseInt(newHeight) };
  return resizeScale;
};
Dare.Util.prototype.checkString = function (str, pattern, replacement, type) {
  switch (type) {
    case 0:
      return pattern.test(str); //测试string是否含有匹配结果,有返回true,否则返回false;
    case 1:
      return str.match(pattern); //根据pattern进行正则匹配,如果匹配到,返回匹配结果,如匹配不到返回null
    case 2:
      return str.search(pattern); //根据pattern进行正则匹配,如果匹配到一个结果,则返回它的索引数;否则返回-1
    case 3:
      return str.replace(pattern, replacement); //根据pattern进行正则匹配,把匹配结果替换为replacement
    case 4:
      return str.split(pattern); //根据pattern进行正则分割,返回一个分割的数组
    default:
      return null;
  }
};
/********************************************************************/
/* Function: changeTimeFormat                                       */
/* Description: 转换时间格式,yyyy-mm-dd hh:mm:ss                    */
/* Parameters: parameter 输入的时间字符串(Sun Aug 30 13:09:52 2009)  */
/*********************************************************************/
Dare.Util.prototype.changeTimeFormat = function (parameter) {
  var timeStr = parameter.split(' ');
  var monthStr = 'JanFebMarAprMayJunJulAugSepOctNovDec';
  var monthVol = doubleDigit(monthStr.indexOf(timeStr[1]) / 3 + 1);
  var dateStr = timeStr[4] + '-' + monthVol + '-' + doubleDigit(timeStr[2]);
  var tempStr = new Array();
  tempStr[0] = dateStr;
  tempStr[1] = timeStr[3];
  return (tempStr);
}
Dare.Util.prototype.getGlobalVar = function (cmdStr) {
  var jsonStr = new String();
  if (Dare.isiPanel) {
    jsonStr = iPanel.getGlobalVar(cmdStr)
  } else {
    switch (cmdStr) {
      case "localePath":
        jsonStr = "en";
        break;
      case "skinPath":
        jsonStr = "default";
        break;
      default:
        jsonStr = '[{ name: "", time: "" }]';
        break;
    }
  }
  return jsonStr;
};
Dare.Util.prototype.setGlobalVar = function (cmdStr, paramObject) {
  //alert("Dare.isiPanel:"+Dare.isiPanel);
  if (Dare.isiPanel) {
    iPanel.setGlobalVar(cmdStr, paramObject);
  } else {

  }
};
//--------------弹出对话框begin----------------//
/**
* @function showBOX 显示盒子
* @author
* @param e
* @return null
*/
Dare.Util.prototype.showBOX = function (e) {
  //alert(e);
  if (document.getElementById(e) == null) { return; }
  //alert(e);
  this.layoutBox(e);
  window.onresize = function () { layoutBox(e); } //改变窗体重新调整位置
  window.onscroll = function () { layoutBox(e); } //滚动窗体重新调整位置
};
/**
* @function removeBox 移除盒子
* @author
* @param e
* @return null
*/
Dare.Util.prototype.removeBox = function (e) {
  document.getElementById('overBox').style.display = "none";
  document.getElementById(e).style.display = "none";

  window.onscroll = null;
  window.onresize = null;
};
/**
* @function layoutBox 调整盒子
* @author
* @param e
* @return null
*/
Dare.Util.prototype.layoutBox = function (e) {
  var a = document.getElementById(e);

  //判断是否新建遮掩层
  if (document.getElementById('overbox') == null) {
    var overlay = document.createElement("div");
    overlay.setAttribute('id', 'overBox');
    a.parentNode.appendChild(overlay);
  }
  //取客户端左上坐标,宽,高
  var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  var clientWidth = document.documentElement.clientWidth;
  var clientHeight = document.documentElement.clientHeight;
  var box = document.getElementById('overbox');
  box.style.left = scrollLeft + 'px';
  box.style.top = scrollTop + 'px';
  box.style.width = clientWidth + 'px';
  box.style.height = clientHeight + 'px';
  box.style.display = "";

  //Popup窗口定位
  a.style.position = 'absolute';
  a.style.zIndex = 101;
  a.style.display = "";
  document.getElementById('setting').style.display = "block";
  a.style.left = '180px;'
  a.style.top = '180px;'
};
Dare.Util.prototype.debug = function (log_txt) {
  if (window.console != undefined) {
    console.debug(log_txt);
    console.trace(log_txt);
  } else {
    alert(log_txt);
  }
};
Dare.Util.prototype.getJsonObjectLength = function (obj) {
  var i = 0;
  for (var item in obj) {
    i++;
  }
  return i;
};
Dare.Util.prototype.checkIsIP = function (ip) {
  var result = false;
  var re = /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
  if (re.test(ip)) {
    result = true;
  }
  else {
    result = false;
  }
  return result;
};
Dare.Util.prototype.trimDot = function (value) {
  var str = '';
  if (value.length != 0) {
    str = value.replace(/[.]/g, '');
  }
  return str;
};
Dare.Util.prototype.joinDot = function (value) {
  var arr = [];
  if (value.length != 0) {
    for (var i = 0; i < 4; i++) {
      arr[i] = value.substr(i * 3, 3);
    }
  }
  return arr.join('.');
};
Dare.Util.prototype.joinDotArr = function (value) {
  var arr = [];
  if (value.length != 0) {
    for (var i = 0; i < 4; i++) {
      arr[i] = value.substr(i * 3, 3);
    }
  }
  return arr;
};

/**
* Instantialize dareUtil as a Dare.Util object. Use it as global unique single instance.
* @return {object} The instance dareUtil.
*/
var dareUtil = new Dare.Util();

 

 

posted @ 2011-08-20 15:59  火腿骑士  阅读(219)  评论(0)    收藏  举报