PBlog2 公用JS代码
//pblog2 公用js代码
//author:puterjam
//查找网页内宽度太大的图片进行缩放以及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].onclick=function(e){window.open(this.src)}
}
}
}
}
//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="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" 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="http://www.macromedia.com/go/getflashplayer" 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="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,0,02,902" 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="http://www.microsoft.com/windows/mediaplayer/" 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="http://www.apple.com/quicktime/" />';
}
document.getelementbyid(strid).innerhtml = tmpstr;
}
document.getelementbyid(strid+"_href").blur()
}
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
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+='
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+='
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+='
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+='
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+='
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+='
else{oeditor.inserthtml('<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,0,02,902" 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="http://www.microsoft.com/windows/mediaplayer/" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
break;
case 'avi':
if (edittype=="ubbeditor"){parent.document.forms[0].message.value+='
else{oeditor.inserthtml('<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,0,02,902" 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="http://www.microsoft.com/windows/mediaplayer/" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
break;
case 'wmv':
if (edittype=="ubbeditor"){parent.document.forms[0].message.value+='
else{oeditor.inserthtml('<object classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,0,02,902" 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="http://www.microsoft.com/windows/mediaplayer/" src="'+path+'" autostart="true" width="400" height="300" /></object>')}
break;
case 'swf':
if (edittype=="ubbeditor"){parent.document.forms[0].message.value+='
else{oeditor.inserthtml('<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" 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="http://www.macromedia.com/go/getflashplayer" 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+=' \n'}
}
else{oeditor.inserthtml('<a href="'+path+'"><img border="0" src="../..http://images.10qianwan.com/10qianwan/20171212/b_1_201712122041551151.jpg" 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="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" 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="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="flashh" width="'+width+'" height="'+height+'" quality="high"'+t+' scale="exactfit"/>'
temp+='</object>'
document.getelementbyid("flashhead").innerhtml=temp
}
上一篇: 正则表达式的语法
下一篇: Vue-CLI与Vuex使用方法实例分析