博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
common.js js中常用方法
阅读量:5132 次
发布时间:2019-06-13

本文共 30383 字,大约阅读时间需要 101 分钟。

 

 //创建CSS样式段

//classid: CSS样式段ID

//font: 字体
//size: 字体大小
//color: 字体颜色
//style: 字体风格
function FCMakeCSSClass(classid, color, style, font, size) {
 return "." + classid + " {/n/tcolor: " + color + ";/n"
  + (style.indexOf("b") < 0 ? "" : "/tfont-weight: bold;/n")
  + (style.indexOf("i") < 0 ? "" : "/tfont-style: italic;/n")
  + (style.indexOf("u") < 0 ? "" : "/ttext-decoration: underline;/n")
  + (font == null ? "" : "/tfont-family: " + font + ";/n")
  + (size == null ? "" : "/tfont-size: " + size + ";/n")
  + "}/n";
}
//--------------------------------------------------------------

//创建指定语言的CSS样式,返回转换好的CSS代码,如果语言不存在则返回null

//lang: 语法加亮规则的语言ID
//font: 所用字体,如果为对象,就用每个对象成员对应相应的classid
//size: 所用字体的大小,如果为对象,就用每个对象成员对应相应的classid
function FCMakeCSS(lang, font, size) {
 var syntax = FCSyntaxDef[lang];
 if (syntax == null) return null;
 var fontList = font instanceof Object;
 var sizeList = size instanceof Object;
 //定义普通文本样式
 var css = FCMakeCSSClass(lang + "_Default", syntax.color, syntax.style,
  fontList ? font.comment : font, sizeList ? size.comment : size);
 //定义注释样式
 if (syntax.comments.length > 0) {
  css += FCMakeCSSClass(lang + "_Comments", syntax.cmtcolor, syntax.cmtstyle,
   fontList ? font.comment : font, sizeList ? size.comment : size);
 }
 //定义块样式
 for (var classid in syntax.blocks) {
  var block = syntax.blocks[classid];
  css += FCMakeCSSClass(lang + "_" + classid, block.color, block.style,
   fontList ? font[classid] : font, sizeList ? size[classid] : size);
 }
 //定义关键词样式
 for (var classid in syntax.keywords) {
  var group = syntax.keywords[classid];
  css += FCMakeCSSClass(lang + "_" + classid, group.color, group.style,
   fontList ? font[classid] : font, sizeList ? size[classid] : size);
 }
 return css;
}
//--------------------------------------------------------------

//转换源代码到HTML加亮代码,返回转换后代码,如果语言不存在则返回null

//srcCode: 需要被转换的源代码
//lang: 转换所用的语法加亮规则的语言ID
function FCTranslate(srcCode, lang) {
 var syntax = FCSyntaxDef[lang];
 if (syntax == null) return null;
 var src = srcCode.split("/n");

 var encode = FCHtmlEncode;

 //定义普通文本加亮词缀
 var affix = FCMakeAffix(lang + "_Default", syntax.color, syntax.style);
 var defPref = affix.prefix, defSuff = affix.suffix;
 //定义注释加亮词缀
 var comments = syntax.comments;
 if (comments.length > 0) {
  var affix = FCMakeAffix(lang + "_Comments", syntax.cmtcolor, syntax.cmtstyle);
  var cmtPref = affix.prefix, cmtSuff = affix.suffix;
 }
 //定义块加亮词缀
 var blkBegin = [], blkEnd = [], blkEsc = [], blkLines = [], blkPref = [], blkSuff = [];
 for (var classid in syntax.blocks) {
  var block = syntax.blocks[classid];
  blkBegin.push(block.begin);
  blkEnd.push(block.end);
  blkEsc.push(block.escape);
  blkLines.push(block.lines);
  var affix = FCMakeAffix(lang + "_" + classid, block.color, block.style);
  blkPref.push(affix.prefix);
  blkSuff.push(affix.suffix);
 }
 //定义关键词加亮词缀表
 var keywords = [], kwPref = [], kwSuff = [];
 for (var classid in syntax.keywords) {
  var group = syntax.keywords[classid];
  keywords.push(group.list);
  var affix = FCMakeAffix(lang + "_" + classid, group.color, group.style);
  kwPref.push(affix.prefix);
  kwSuff.push(affix.suffix);
 }
 //断词转换
 var delim = syntax.delimiters;
 for (var index = 0, index2 = 0; index < src.length; index++, index2++) {
  var code = src[index];
  var htmlCode = "";
  for (var pos1 = 0, pos2 = 0, ch = null, flag = 0; ch != ""; pos2++) {
   ch = code.substr(pos2, 1);
   if (ch != "" && flag == 0 && delim.indexOf(ch) < 0) continue;
   //如果为持续文本则继续,否则截断(flag:0文本,1空格,2标点)
   if (pos2 <= pos1) {
    flag = ch.match(/s/g) ? 1 : 2;
    continue;
   }
   var word = code.substr(pos1, pos2 - pos1); //截取词
   if (flag == 1) { //空格
    htmlCode += word;
   } else {
    if (flag == 2) { //标点
     //判别注释
     for (var i in comments) {
      if (code.substr(pos1, comments[i].length) != comments[i]) continue;
      htmlCode += cmtPref + encode(code.substr(pos1)) + cmtSuff;
      word = "";
      break;
     }
     if (word == "") break;
     //判别块
     for (var i in blkBegin) {
      if (code.substr(pos1, blkBegin[i].length) != blkBegin[i]) continue;
      var end = blkEnd[i], esc = blkEsc[i];
      for (pos2 = pos1 + blkBegin[i].length; pos2 = code.indexOf(end, pos2);) {
       if (pos2 < 0) {
        if (blkLines[i] && index < src.length - 1) {
         pos2 = code.length + 2;
         code += "/n" + src[++index];
         continue;
        }
        htmlCode += blkPref[i] + encode(code.substr(pos1)) + blkSuff[i];
        word = "";
        break;
       } else if (esc == null || code.substr(pos2 - esc.length, esc.length) != esc) {
        pos2 += end.length;
        break;
       }
       pos2 += end.length;
      }
      if (pos2 >= 0) {
       htmlCode += blkPref[i] + encode(code.substr(pos1, pos2 - pos1)) + blkSuff[i];
       flag = 0;
       pos1 = pos2;
       pos2--;
       word = "0";
      }
      break;
     }
     if (word == "") break;
     else if (word == "0") continue;
    }
    //关键字加亮
    var w = encode(word);
    for (var i in keywords) {
     if (keywords[i].toLowerCase().indexOf(" " + word.toLowerCase() + " ") < 0) continue;
     htmlCode += kwPref[i] + w + kwSuff[i];
     word = "";
     break;
    }
    if (word != "") htmlCode += w;
   }
   flag = delim.indexOf(ch) < 0 ? 0 : ch.match(/s/g) ? 1 : 2;
   pos1 = pos2;
  }
  src[index2] = htmlCode;
 }
 src.splice(index2, src.length);
 return defPref + src.join("/n") + defSuff;
}
//--------------------------------------------------------------
function FCHtmlEncode(str) {
 return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
//**************加入到收藏夹ff,ie,opera
function addBookmark(title,url)
{
    if (window.sidebar)
    { 
        window.sidebar.addPanel(title, url,""); 
    }
    else if( document.all )
    {
        window.external.AddFavorite( url, title);
    }
    else if( window.opera && window.print )
    {return true;}
}
 
 //   根据年、月返回天数   
/* 
    function  GetDay(varYear,varMonth)   
  {   
          var lngDay;    
    varYear = parseInt(varYear);
    varMonth   =   parseInt(varMonth) ;  
    
          switch   (varMonth)   {   
          case   1   :   
          case   3   :   
          case   5   :   
          case   7   :   
          case   8   :   
          case   10   :   
          case   12   :   
                  lngDay   =   31 ;  
                  break   ;
          case   4   :   
          case   6   :   
          case   9   :   
          case   11   :   
                  lngDay   =   30 ;  
                  break   ;
          case   2   :   
                  if   ((varYear   %   4   ==   0   &&   varYear   %   100   !=   0)   ||   (varYear   %   400   ==   0))   
                          lngDay   =   29  ; 
                  else   
                          lngDay   =   28   ;
                  break   
          }   //   switch   
    
    
          return   lngDay  ; 
  }
  */

 //or 根据年、月返回天数   

/* 
  function getYearMonthDayNum(year,month)
 {
  var dayNum = [31,28,31,30,31,30,31,31,30,31,30,31];
  if(new Date(year,1,29).getDate()==29)
   {
  dayNum[1] = 29;
   }
  return dayNum[month-1];
 }
 */
//   日期是否正确   
  /* 
  function CheckDate(obj)   
  {   
   var strDate,arrDate;
   var lngYear,lngMonth,lngDay;
   var strReg; 
   var strError;     
   strError = "" ;  
   strReg = /^/d{4}-/d{2}-/d{2}$/;
   strDate = obj.value;
   arrDate = strDate.split("-");
   if (strReg.test(strDate))   
    {   
    lngYear = parseInt(arrDate[0],10); 
    lngMonth = parseInt(arrDate[1],10);  
    lngDay = parseInt(arrDate[2], 10);    
    // alert(lngYear   +   ","   +   lngMonth   +   ","   +   lngDay)   
    // return   
    }       
   if (!strReg.test(strDate))
   {   
   strError = "格式错误!/n正确格式: yyyy-mm-dd";
   }   
   else if(lngMonth<1||lngMonth>12)
   {   
   strError = "月份应在01-12之间!"   
   }   
   else if (lngDay<1||lngDay>GetDay(lngYear,lngMonth))
    {   
   strError = "天数应在01-"+ GetDay(lngYear,lngMonth)+"之间!";   
    }       
   if (strError != "")
    {   
    alert(strError);   
    obj.select() ; 
    obj.focus();  
    }   
  }
  */
//查找网页内宽度太大的图片进行缩放以及PNG纠正
 function ReImgSize(){
  for (i=0;i<document.images.length;i++)
   {
   if (document.all){
 if (document.images[i].width>500)
  {
       document.images[i].width="500"
       document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
    }
   }
  else{
 if (document.images[i].width>400) {
   document.images[i].title="在新窗口打开图片"
   document.images[i].style.cursor="pointer"
   document.images[i].οnclick=function(e){window.open(this.src)}
 }
  }
  }
 }
 //引用js/css文件;
function include(path,type,title){
 var s,i,t;
 if(arguments.length < 1){
  return ;
 }
 if(arguments.length == 1){
  type = "js";
 }
 switch(type.toLowerCase()){
  case "css":
    t = document.getElementsByTagName("link");
    for(i=0;i<t.length;i++){
     if(t[i].href && t[i].href.indexOf(path)!=-1){
      return;
     }
    }
    s=document.createElement("link");
    s.rel="alternate stylesheet";
    s.type="text/css";
    s.href=path;
    s.title=title;
    s.disabled=false;
    break;
  case "js":
  case "javascript":
  default:
    t = document.getElementsByTagName("script");
    for(i=0;i<t.length;i++){
     if(t[i].src && t[i].src.indexOf(path)!=-1){
      return;
     }
    }
    s=document.createElement("script");
    s.type="text/javascript";
    s.src=path;
   break;
 }
 var h=document.getElementsByTagName("head")[0];
 h.appendChild(s);
}
//AccessKey 转换For IE Design By PuterJam
  var NKey=new Array()
  var KeyCode=new Array()
  var KeyInit=false
//======== keyCode ============
  KeyCode["1"]=49
  KeyCode["2"]=50
  KeyCode["3"]=51
  KeyCode["["]=219
  KeyCode["]"]=221
  KeyCode[","]=188
  KeyCode["."]=190
  var EKey="abcdefghijklmnopqrstuwvxyz"
  for (i=0;i<26;i++){
    KeyCode[EKey.substr(i,1)]=65+i
  }
  
  function PressKey(){
  if (document.all) {
    for (i=0;i<NKey.length;i++){
     if (window.event.altKey && window.event.keyCode==NKey[i].Code) {NKey[i].Object.blur();NKey[i].Object.click()}
    }

 }

  }
  
  function AccessKey(Code,Object){
   this.Code=Code
   this.Object=Object
  }

  function initAccessKey(){
  if (document.all && !KeyInit) {
     for (i=0;i<document.links.length;i++){
       if (document.links[i].accessKey) {
         NKey[NKey.length]=new AccessKey(KeyCode[document.links[i].accessKey.toLowerCase()],document.links[i])
       }
     }
  }
  KeyInit=true
  }

//初始化JS代码

function initJS(){
 ReImgSize(); //自动缩放代码 
 initAccessKey();  //转换AccessKey For IE
}
//让Mozilla支持innerText
try{
 HTMLElement.prototype.__defineGetter__
 (
 "innerText",
 function ()
 {
  var anyString = "";

  var childS = this.childNodes;

   for(var i=0; i<childS.length; i++)
   {
    if(childS[i].nodeType==1)
    anyString += childS[i].tagName=="BR" ? '/n' : childS[i].innerText;
    else if(childS[i].nodeType==3)
    anyString += childS[i].nodeValue;
   }
   return anyString;
 }
 ); 
}
catch(e){}

//判断是否是IE

function isIE(){
 if (navigator.appName!="Microsoft Internet Explorer") {return false}
 return true
}
//显示隐藏主题
function TopicShow(e,TopicID){
  e.className=(e.className=="BttnC")?"BttnE":"BttnC"
  document.getElementById(TopicID).style.display=(e.className=="BttnC")?"":"none"
  ReImgSize()
}
//打开新窗口
function popnew(url,title,width,height){
    var w = 1024;
    var h = 768;

    if (document.all || document.layers){

        w = screen.availWidth;
        h = screen.availHeight;
    }

    var leftPos = (w/2-width/2);

    var topPos = (h/2.3-height/2.3);

    window.open(url,title,"width="+width+",height="+height+",top="+topPos+",left="+leftPos+",scrollbars=no,resizable=no,status=no")

}
//运行代码
function runEx(cod1)  {
  cod=document.getElementById(cod1)
   var code=cod.value;
   if (code!=""){
    var newwin=window.open('','','');  
    newwin.opener = null 
    newwin.document.write(code);  
    newwin.document.close();
 }
}
//复制代码
function doCopy(ID) { 
 if (document.all){
   textRange = document.getElementById(ID).createTextRange(); 
   textRange.execCommand("Copy"); 
 }
 else{
   alert("此功能只能在IE上有效")
 }
}
var MediaTemp=new Array()
function MediaShow(strType,strID,strURL,intWidth,intHeight)
{
 var tmpstr
 if (MediaTemp[strID]==undefined) MediaTemp[strID]=false; else MediaTemp[strID]=!MediaTemp[strID];
 if(MediaTemp[strID]){
   if ( document.all ) {
           document.getElementById(strID).outerHTML = '<div id="'+strID+'"></div>'
   }
   else
   {
           document.getElementById(strID).innerHTML = ''
   }

  document.images[strID+"_img"].src="images/mm_snd.gif"   

  document.getElementById(strID+"_text").innerHTML="在线播放" 
 }else{
  document.images[strID+"_img"].src="images/mm_snd_stop.gif"   
  document.getElementById(strID+"_text").innerHTML="关闭在线播放"
  switch(strType){
   case "swf":
    tmpstr='<div style="height:6px;overflow:hidden"></div><object codebase="" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+intWidth+'" height="'+intHeight+'"><param name="movie" value="'+strURL+'" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="'+strURL+'" quality="high" pluginspage="" type="application/x-shockwave-flash" width="'+intWidth+'" height="'+intHeight+'" /></object>';
    break;
   case "wma":
    tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"  id="MediaPlayer" width="450" height="70"><param name=""howStatusBar" value="-1"><param name="AutoStart" value="False"><param name="Filename" value="'+strURL+'"></object>';
    break;
   case "wmv":
    tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="" type="application/x-oleobject" standby="Loading..." width="'+intWidth+'" height="'+intHeight+'"><param name="FileName" VALUE="'+strURL+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="" src="'+strURL+'" autostart="true" width="'+intWidth+'" height="'+intHeight+'" /></object>';
    break;
   case "rm":
    tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="'+intHeight+'"><param name="SRC" value="'+strURL+'" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="'+strURL+'" nojava="true" controls="ImageWindow" console="one" width="'+intWidth+'" height="'+intHeight+'"></object>'+
                '<br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+strURL+'" nojava="true" controls="StatusBar" console="one" width="'+intWidth+'" height="24" /></object>'+'<br /><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+intWidth+'" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+strURL+'" nojava="true" controls="ControlPanel" console="one" width="'+intWidth+'" height="24" autostart="true" loop="false" /></object>';
    break;
   case "ra":
    tmpstr='<div style="height:6px;overflow:hidden"></div><object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" id="RAOCX" width="450" height="60"><param name="_ExtentX" value="6694"><param name="_ExtentY" value="1588"><param name="AUTOSTART" value="true"><param name="SHUFFLE" value="0"><param name="PREFETCH" value="0"><param name="NOLABELS" value="0"><param name="SRC" value="'+strURL+'"><param name="CONTROLS" value="StatusBar,ControlPanel"><param name="LOOP" value="0"><param name="NUMLOOP" value="0"><param name="CENTER" value="0"><param name="MAINTAINASPECT" value="0"><param name="BACKGROUNDCOLOR" value="#000000"><embed src="'+strURL+'" width="450" autostart="true" height="60"></embed></object>';
    break;
   case "qt":
    tmpstr='<div style="height:6px;overflow:hidden"></div><embed src="'+strURL+'" autoplay="true" loop="false" controller="true" playeveryframe="false" cache="false" scale="TOFIT" bgcolor="#000000" kioskmode="false" targetcache="false" pluginspage="" />';
  }
  document.getElementById(strID).innerHTML = tmpstr;
 }
  document.getElementById(strID+"_href").blur()
}
function hideObject(objectId)
{
 var obj=getObject(objectId);
    
 if(obj&&obj.style)
 {
  obj.style.display="none";     
  return true
 }
 return false
}

function showObject(objectId)

{
 var obj=getObject(objectId);
 if(obj&&obj.style)
 {
  obj.style.display="";
  return true
 }
 return false
}
// 增加一个名为 trim 的函数作为
// String 构造函数的原型对象的一个方法。
String.prototype.trim = function() {
 return this.replace(/(^/s*)|(/s*$)/g, "");   // 用正则表达式将前后空格
}
/*
eg:
var s = "    leading and trailing spaces    "; // 有空格的字符串
window.alert(s + "(" + s.length + ")");
s = s.trim();                                  // 删除前后空格
window.alert(s + "(" + s.length + ")");
*/

//字符处理;

//去左右空格; 
function trim(s){
  return rtrim(ltrim(s)); 
}
//去左空格; 
function ltrim(s){
  return s.replace( /^/s*/, ""); 
//去右空格; 
function rtrim(s){ 
  return s.replace( //s*$/, ""); 
}
//验证信息;
//空字符值; 
function isEmpty(s){
 s = trim(s); 
 return s.length == 0; 
}

function Trim(TRIM_VALUE){
 if(TRIM_VALUE.length < 1){
  return"";
 }
 TRIM_VALUE = RTrim(TRIM_VALUE);
 TRIM_VALUE = LTrim(TRIM_VALUE);
 if(TRIM_VALUE==""){
  return "";
 }
 else{
  return TRIM_VALUE;
 }
} //End Function

function RTrim(VALUE){

 var w_space = String.fromCharCode(32);
 var v_length = VALUE.length;
 var strTemp = "";
 if(v_length < 0){
  return"";
 }
 var iTemp = v_length -1;

 while(iTemp > -1){

  if(VALUE.charAt(iTemp) == w_space){
  }
  else{
   strTemp = VALUE.substring(0,iTemp +1);
   break;
  }
  iTemp = iTemp-1;

 } //End While

 return strTemp;

} //End Function

function LTrim(VALUE){

 var w_space = String.fromCharCode(32);
 if(v_length < 1){
  return"";
 }
 var v_length = VALUE.length;
 var strTemp = "";
 var iTemp = 0;

 while(iTemp < v_length){

  if(VALUE.charAt(iTemp) == w_space){
   }
   else{
    strTemp = VALUE.substring(iTemp,v_length);
    break;
  }
  iTemp = iTemp + 1;
 } //End While
 return strTemp;
} //End Function

//Email;

function isEmail(s){
 s = trim(s); 
  var p = /^[_/.0-9a-z-]+@([0-9a-z][0-9a-z-]+/.){1,4}[a-z]{2,3}$/i; 
  return p.test(s);
}
//数字; 
function isNumber(s){
 return !isNaN(s); 
}
//颜色值; 
function isColor(s){ 
 s = trim(s); 
 if (s.length !=7) return false; 
 return s.search(//#[a-fA-F0-9]{6}/) != -1; 
}
//手机号码; 
function isMobile(s){ 
 s = trim(s); 
 var p = /13/d{9}/; 
 return p.test(s);
}
//身份证;
function isCard(s){ 
 s = trim(s); 
 var p = /^/d{15}(/d{2}[xX0-9])?$/; 
 return p.test(s);
}
//URL;
function isURL(s){
 s = trim(s).toLowerCase();
 var p = /^[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^<>/"/"])*$/;
 return p.test(s);
}
//Phone;
function isPhone(s){
 s = trim(s);
 var p = /^((/(/d{3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}$/;
 return p.test(s);
}
//Zip;
function isZip(s){
 s = trim(s);
 var p = /^[1-9]/d{5}$/;
 return p.test(s);
}
//Double;
function isDouble(s){
 s = trim(s);
 var p = /^[-/+]?/d+(/./d+)?$/;
 return p.test(s);
}
//Integer;
function isInteger(s){
 s = trim(s);
 var p = /^[-/+]?/d+$/;
 return p.test(s);
}
//English;
function isEnglish(s){
 s = trim(s);
 var p = /^[A-Za-z]+$/;
 return p.test(s);
}
//中文;
function isChinese(s){
 s = trim(s);
 var p = /^[/u0391-/uFFE5]+$/;
 return p.test(s);
}
//双字节
function isDoubleChar(s){
 var p = /^[^/x00-/xff]+$/;
 return p.test(s);
}
//含有中文字符
function hasChineseChar(s){
 var p = /[^/x00-/xff]/;
 return p.test(s);
}
function hasAccountChar(s){
 var p = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,15}$/;
 return p.test(s);
}
function limitLen(s,Min,Max){
 s=trim(s);
 if(s=="") return false;
 if((s.length<Min)||(s.length>Max))
  return false;
 else
  return true;
}
//功能;
//延时事件;
function setDeferEvent(type,action,time){
 if (trim(time).length == 0) time = 1;
 if (typeof(time)!="number") time = 1;
 
 switch(type.toLowerCase()){
  case "go":
   window.setTimeout("window.location='"+ action +"'",time);
   break;
  case "alert":
   window.setTimeout("alert('"+ action +"')",time);
   break;
  case "js":
  case "javascript":
   window.setTimeout("'"+ action.toString() +"'",time);
   break;
  default:
   alert("Nothing will do!");
   break
 }  
}
function addLoadListener(handler){
 if (typeof window.addEventListener != 'undefined')
  window.addEventListener('load', handler, false);
 else if (typeof document.addEventListener != 'undefined')
  document.addEventListener('load', handler, false);
 else if (typeof window.attachEvent != 'undefined')
  window.attachEvent('onload', handler);
};
function addEventListener(element, eventType, handler, capture)
{
 try
 {
  if (element.addEventListener)
   element.addEventListener(eventType, handler, capture);
  else if (element.attachEvent)
   element.attachEvent("on" + eventType, handler);
 }
 catch (e) {}
};

function removeEventListener(element, eventType, handler, capture)

{
 try
 {
  if (element.removeEventListener)
   element.removeEventListener(eventType, handler, capture);
  else if (element.detachEvent)
   element.detachEvent("on" + eventType, handler);
 }
 catch (e) {}
};
//Image;
function preloadImages(){
 var d = document;
 if(d.images){
  if(!d.p_i_a) d.p_i_a = new Array();
  var i,j=d.p_i_a.length,a=arguments;
  for(i=0;i<a.length;i++){
   d.p_i_a[j]= new Image();
   d.p_i_a[j++].src = a[i];
  }
 }
}
//Ajax功能;
function loadAjaxElement(e,u,p,f,l){
 if(arguments.length < 3){
  return ;
 }
 o = $(e);
 o.innerHTML = l;
 p = $H(p).toQueryString();
 new Ajax.Updater(      
                    {success: e},
                    u,
                    {method: 'get', parameters: p, onFailure: f});
}
function loadAjaxData(u,p,s,f){
 if(arguments.length < 3){
  return ;
 }
 p = $H(p).toQueryString();
 new Ajax.Request(      
                    u,
                    {method: 'get', parameters: p, onSuccess:s,onFailure: f});
}
function sendAjaxElement(e,u,p,f,l){
 if(arguments.length < 3){
  return ;
 }
 o = $(e);
 o.innerHTML = l;
 p = $H(p).toQueryString();
 new Ajax.Updater(      
                    {success: e},
                    u,
                    {method: 'post', parameters: p, onFailure: f});
}
function sendAjaxData(u,p,s,f){
 if(arguments.length < 3){
  return ;
 }
 p = $H(p).toQueryString();
 new Ajax.Request(      
                    u,
                    {method: 'post', parameters: p, onSuccess:s,onFailure: f});
}

 

 

function CheckPost(){

  try{
 if (Trim(document.forms[0].title.value)=="") {
   alert("标题不能为空,请写日志标题!")
   document.forms[0].title.focus()
   return false
  }
 }
  catch(e){}

  try{

    if (document.getElementById("P2").checked) {
     if (!CheckDate(document.forms[0].PubTime.value)){
        alert("日期格式不正确!/n格式:yyyy-mm-dd hh:mm:ss") 
     return false
     }
     else
     {
      document.forms[0].PubTime.value=CheckDate(document.forms[0].PubTime.value)
     }
    }
  }
  catch(e){}

  try{

   if (GetMessageLength()==0){
   alert("内容不能为空!")
   return false
   }
  }
  catch(e){
 if (Trim(document.forms[0].Message.value)=="") {
   alert("内容不能为空!")
   document.forms[0].Message.focus()
   return false
 }
  }
   try{document.forms[0].SaveArticle.disabled=true}catch(e){}
   try{document.forms[0].SaveDraft.disabled=true}catch(e){}
   try{document.forms[0].ReturnButton.disabled=true}catch(e){}
   try{document.forms[0].CancelEdit.disabled=true}catch(e){e}
   try{document.forms[0].DelArticle.disabled=true}catch(e){}
return true
}

   function CheckDate(str){

        var reg = /^(/d{1,4})(-|//)(/d{1,2})/2(/d{1,2}) (/d{1,2}):(/d{1,2}):(/d{1,2})$/; 
        var r = str.match(reg); 
        if(r==null)return false; 
        var d= new Date(r[1],r[3]-1,r[4],r[5],r[6],r[7]); 
        return (d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds());
   }

function GetMessageLength()
{
 var oEditor = FCKeditorAPI.GetInstance('Message') ;
 var oDOM = oEditor.EditorDocument ;
 var iLength ;

 if ( document.all )  // If Internet Explorer.

 {
  iLength = oDOM.body.innerText.length ;
 }
 else     // If Gecko.
 {
  var r = oDOM.createRange() ;
  r.selectNodeContents( oDOM.body ) ;
  iLength = r.toString().length ;
 }
// oEditor.InsertHtml('')
return iLength

function SetFont(size){

 document.getElementById("logPanel").style.fontSize=size
}
//引用
function addQuote(usr,content){
 try{
 if (document.getElementById("editorbody").style.display=="none") showUBB("Message");
    document.forms["frm"].Message.value="[quote="+usr+"]"+document.getElementById(content).innerText+"[/quote]"
 document.forms["frm"].Message.focus();
 }catch(e){}
}

//插入上传附件

function addUploadItem(type,path,memberDown){
 var EditType=""
 try{
   var oEditor = parent.FCKeditorAPI.GetInstance('Message')
   EditType="FCkEditor"
   var hrefLen=location.href.lastIndexOf("/")
      var Fhref=location.href.substr(0,hrefLen+1)
      path=Fhref+path
 }
 catch(e){
   EditType="UBBEditor"
 }
 type=type.toLowerCase()
   switch(type){
    case 'gif':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]/n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
     break;
    case 'jpg':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]/n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
     break;
    case 'png':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]/n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
     break;
    case 'bmp':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]/n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
     break;
    case 'jpeg':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[img]'+path+'[/img]/n'}
        else{oEditor.InsertHtml('<img src="'+path+'" alt=""/>')}
     break;
    case 'mp3':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wma]'+path+'[/wma]/n'}
        else{oEditor.InsertHtml('<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"  id="MediaPlayer" width="450" height="70"><param name=""howStatusBar" value="-1"><param name="AutoStart" value="False"><param name="Filename" value="'+path+'"></object>')}
     break;
    case 'wma':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wma]'+path+'[/wma]/n'}
        else{oEditor.InsertHtml('<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"  id="MediaPlayer" width="450" height="70"><param name=""howStatusBar" value="-1"><param name="AutoStart" value="False"><param name="Filename" value="'+path+'"></object>')}
     break;
    case 'rm':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[rm]'+path+'[/rm]/n'}
        else{oEditor.InsertHtml('<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="300"><param name="SRC" value="'+path+'" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="'+path+'" nojava="true" controls="ImageWindow" console="one" width="400" height="300"></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="StatusBar" console="one" width="400" height="24" /></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="ControlPanel" console="one" width="400" height="24" autostart="true" loop="false" /></object>')}
     break;
    case 'rmvb':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[rm]'+path+'[/rm]/n'}
        else{oEditor.InsertHtml('<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="300"><param name="SRC" value="'+path+'" /><param name="CONTROLS" VALUE="ImageWindow" /><param name="CONSOLE" value="one" /><param name="AUTOSTART" value="true" /><embed src="'+path+'" nojava="true" controls="ImageWindow" console="one" width="400" height="300"></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="StatusBar" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="StatusBar" console="one" width="400" height="24" /></object><br/><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="400" height="32" /><param name="CONTROLS" value="ControlPanel" /><param name="AUTOSTART" value="true" /><param name="CONSOLE" value="one" /><embed src="'+path+'" nojava="true" controls="ControlPanel" console="one" width="400" height="24" autostart="true" loop="false" /></object>')}
     break;
    case 'ra':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[ra]'+path+'[/ra]/n'}
        else{oEditor.InsertHtml('<object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" id="RAOCX" width="450" height="60"><param name="_ExtentX" value="6694"><param name="_ExtentY" value="1588"><param name="AUTOSTART" value="true"><param name="SHUFFLE" value="0"><param name="PREFETCH" value="0"><param name="NOLABELS" value="0"><param name="SRC" value="'+path+'"><param name="CONTROLS" value="StatusBar,ControlPanel"><param name="LOOP" value="0"><param name="NUMLOOP" value="0"><param name="CENTER" value="0"><param name="MAINTAINASPECT" value="0"><param name="BACKGROUNDCOLOR" value="#000000"><embed src="'+path+'" width="450" autostart="true" height="60"></embed></object>')}
     break;
    case 'asf':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wmv]'+path+'[/wmv]/n'}
        else{oEditor.InsertHtml('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="" type="application/x-oleobject" standby="Loading..." width="400" height="300"><param name="FileName" VALUE="'+path+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
     break;
    case 'avi':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wmv]'+path+'[/wmv]/n'}
        else{oEditor.InsertHtml('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="" type="application/x-oleobject" standby="Loading..." width="400" height="300"><param name="FileName" VALUE="'+path+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
     break;
    case 'wmv':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[wmv]'+path+'[/wmv]/n'}
        else{oEditor.InsertHtml('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="" type="application/x-oleobject" standby="Loading..." width="400" height="300"><param name="FileName" VALUE="'+path+'" /><param name="ShowStatusBar" value="-1" /><param name="AutoStart" value="true" /><embed type="application/x-mplayer2" pluginspage="" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
     break;
    case 'swf':
        if (EditType=="UBBEditor"){parent.document.forms[0].Message.value+='[swf]'+path+'[/swf]/n'}
        else{oEditor.InsertHtml('<object codebase="" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="300"><param name="movie" value="'+path+'" /><param name="quality" value="high" /><param name="AllowScriptAccess" value="never" /><embed src="'+path+'" quality="high" pluginspage="" type="application/x-shockwave-flash" width="400" height="300" /></object>')}
     break;
    default :
        if (EditType=="UBBEditor"){
        if (memberDown==1)
          {parent.document.forms[0].Message.value+='[mDown='+path+']点击下载此文件[/mDown]/n'}
         else
          {parent.document.forms[0].Message.value+='[down='+path+']点击下载此文件[/down]/n'}
        }
        else{oEditor.InsertHtml('<a href="'+path+'"><img border="0" src="../../images/download.gif" alt="" style="margin:0px 2px -4px 0px"/>点击下载此文件</a>')}
        break;
     }
}
//写入顶部Flash文件
function WriteHeadFlash(Path,Width,Height,Transparent){
  var Temp,T=""
  Temp='<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="FlashH" codebase="" border="0" width="'+Width+'" height="'+Height+'">'
  Temp+='<param name="movie" value="'+Path+'"/>'
  Temp+='<param name="quality" value="High"/>'
  Temp+='<param name="scale" value="ExactFit"/>'
  if (Transparent) {Temp+=' <param name="wmode" value="transparent"/>';T='wmode="transparent"'}
  Temp+='<embed src="'+Path+'" pluginspage="" type="application/x-shockwave-flash" name="FlashH" width="'+Width+'" height="'+Height+'" quality="High"'+T+' scale="ExactFit"/>'
  Temp+='</object>'
  document.getElementById("FlashHead").innerHTML=Temp

 

转载于:https://www.cnblogs.com/xingfuboke/p/4994807.html

你可能感兴趣的文章
“Missing artifact....."的解决办法
查看>>
杨森翔绝句10首
查看>>
线段树(Segment Tree)
查看>>
RESTful API 设计思考
查看>>
docker-compose.yml模板文件
查看>>
51单片机产生1Hz-5kHz可调占空比方波
查看>>
Java抽象类和接口的区别
查看>>
MD5加密以及产生唯一的ID
查看>>
一、CI框架(CodeIgniter)简介
查看>>
html头文件设置常用之<meta>设置缓存
查看>>
docker容器管理及网络管理
查看>>
虚拟机virtualBox
查看>>
【PHP内核剖析】一、PHP基本架构
查看>>
nyoj 309 bobsledding 即河南省第四届大学生程序设计大赛第七题
查看>>
视图引擎浅析
查看>>
9.6日学习笔记
查看>>
[]561. Array Partition I
查看>>
System.getProperty
查看>>
第二阶段冲刺总结01
查看>>
Daily Report 2012.11.06 刘宇翔
查看>>