You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 lines
67 KiB
JavaScript

5 years ago
/*! xhEditor v1.2.1 | (c) 2009, 2013 xheditor.com.
Licence: http://xheditor.com/license/lgpl.txt */
(function(){var e={};window.XHEDITOR=e})(),function(e,t){e.mapLang={},e.setLang=function(i,s){s===t&&(s=i,i=""),""!==i&&(i+=".");var a,n;for(var o in s)n=s[o],a=i+o,"string"==typeof n||n instanceof Array?e.mapLang[a]=n:e.setLang(a,n)},e.getLang=function(i){var s=e.mapLang[i];if(s===t&&(s=i.replace(/{#([^{}]+)}/g,function(t,i){var s=e.mapLang[i];return s?s:i})),"string"==typeof s){var a=arguments;s=s.replace(/{\$(\d+)}/g,function(e,i){var s=a[parseInt(i,10)+1];return s!==t?s:e})}return s}}(XHEDITOR),function(XHEDITOR,$,undefined){var agent=navigator.userAgent.toLowerCase(),bMobile=/mobile/i.test(agent),browser=$.browser,browerVer=parseFloat(browser.version),isIE=browser.msie,isMozilla=browser.mozilla,isWebkit=browser.webkit,isOpera=browser.opera,isChrome=browser.chrome,bAir=agent.indexOf(" adobeair/")>-1,xCount=0,bShowPanel=!1,bClickCancel=!0,bShowModal=!1,bCheckEscInit=!1,_jPanel,_jShadow,_jCntLine,_jPanelButton,jModal,jModalShadow,layerShadow,jOverlay,jHideSelect,onModalRemove,editorRoot,getLang=XHEDITOR.getLang;if($("script[src*=xheditor]").each(function(){var e=this.src;return e.match(/xheditor[^\/]*\.js/i)?(editorRoot=e.replace(/[\?#].*$/,"").replace(/(^|[\/\\])[^\/]*$/,"$1"),!1):undefined}),isIE){try{document.execCommand("BackgroundImageCache",!1,!0)}catch(e){}var jqueryVer=$.fn.jquery;jqueryVer&&jqueryVer.match(/^1\.[67]/)&&($.attrHooks.width=$.attrHooks.height=null)}var specialKeys={27:"esc",9:"tab",32:"space",13:"enter",8:"backspace",145:"scroll",20:"capslock",144:"numlock",19:"pause",45:"insert",36:"home",46:"del",35:"end",33:"pageup",34:"pagedown",37:"left",38:"up",39:"right",40:"down",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12"},arrAlign=[{v:"justifyleft"},{v:"justifycenter"},{v:"justifyright"},{v:"justifyfull"}],arrList=[{v:"insertOrderedList"},{v:"insertUnorderedList"}],htmlPastetext='<div><label for="xhePastetextValue">{#PastetextTip}</label></div><div><textarea id="xhePastetextValue" wrap="soft" spellcheck="false" style="width:300px;height:100px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="{#dialogOk}" /></div>',htmlLink='<div><label for="xheLinkUrl">{#link.url}</label><input type="text" id="xheLinkUrl" value="http://" class="xheText" /></div><div><label for="xheLinkTarget">{#link.target}</label><select id="xheLinkTarget"><option selected="selected" value="">{#default}</option><option value="_blank">{#link.targetBlank}</option><option value="_self">{#link.targetSelf}</option><option value="_parent">{#link.targetParent}</option></select></div><div style="display:none"><label for="xheLinkText">{#link.linkText}</label><input type="text" id="xheLinkText" value="" class="xheText" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="{#dialogOk}" /></div>',htmlAnchor='<div><label for="xheAnchorName">{#anchor.name}</label><input type="text" id="xheAnchorName" value="" class="xheText" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="{#dialogOk}" /></div>',htmlImg='<div><label for="xheImgUrl">{#img.url}</label><input type="text" id="xheImgUrl" value="http://" class="xheText" /></div><div><div><label for="xheImgAlt">{#img.alt}</label><input type="text" id="xheImgAlt" /></div><div><label for="xheImgAlign">{#img.align}</label><select id="xheImgAlign"><option selected="selected" value="">{#default}</option><option value="left">{#img.alignLeft}</option><option value="right">{#img.alignRight}</option><option value="top">{#img.alignTop}</option><option value="middle">{#img.alignMiddle}</option><option value="baseline">{#img.alignBaseline}</option><option value="bottom">{#img.alignBottom}</option></select></div><div><label for="xheImgWidth">{#img.width}</label><input type="text" id="xheImgWidth" style="width:40px;" /> <label for="xheImgHeight">{#img.height}</label><input type="text" id="xheImgHeight" style="width:40px;" /></div><div><label for="xheImgBorder">{#img.border}</label><input type="text" id="xheImgBorder" style="width:40px;" /></div><div><label for="xheI
var o;return s=s.replace(/\s+_xhe_(?:src|href)\s*=\s*("[^"]*"|'[^']*'|[^>\s]+)/i,function(e,t){return o=t.match(/^(["']?)(.*)\1/)[2],""}),o&&urlType&&(o=getLocalUrl(o,urlType,urlBase)),s=s.replace(/\s+([\w\-:]+)\s*=\s*("[^"]*"|'[^']*'|[^>\s]+)/g,function(e,t,i){if(t=t.toLowerCase(),i=i.match(/^(["']?)(.*)\1/)[2].replace(/"/g,"'"),"class"===t){if(i.match(/^["']?(apple|webkit)/i))return"";if(i=i.replace(/\s?xhe-[a-z]+/gi,""),""===i)return""}else{if(t.match(/^((_xhe_|_moz_|_webkit_)|jquery\d+)/i))return"";if(o&&t.match(/^(src|href)$/i))return" "+t+'="'+o+'"';"style"===t&&(i=i.replace(/(^|;)\s*(font-size)\s*:\s*([a-z-]+)\s*(;|$)/i,function(e,t,i,s,a){for(var o,l,r=0;n.length>r;r++)if(o=n[r],s===o.n){l=o.s;break}return t+i+":"+l+a}))}return" "+t+'="'+i+'"'}),"img"!==i||s.match(/\s+alt\s*=\s*("[^"]*"|'[^']*'|[^>\s]+)/i)||(s+=' alt=""'),t+s+a}),e=e.replace(/(<(td|th)(?:\s+[^>]*?)?>)\s*([\s\S]*?)(<br(\s*\/)?>)?\s*<\/\2>/gi,function(e,t,i,s){return t+(s?s:"&nbsp;")+"</"+i+">"}),e=e.replace(/^\s*(?:<(p|div)(?:\s+[^>]*?)?>)?\s*(<span(?:\s+[^>]*?)?>\s*<\/span>|<br(?:\s+[^>]*?)?>|&nbsp;)*\s*(?:<\/\1>)?\s*$/i,"")}return e=e.replace(/(<pre(?:\s+[^>]*?)?>)([\s\S]+?)(<\/pre>)/gi,function(e,t,i,s){return t+i.replace(/<br\s*\/?>/gi,"\r\n")+s})},this.getSource=function(e){var t,i=settings.beforeGetSource;return bSource?(t=$("#sourceCode",_doc).val(),i||(t=_this.formatXHTML(t,!1))):(t=_this.processHTML(_doc.body.innerHTML,"read"),t=_this.cleanHTML(t),t=_this.formatXHTML(t,e),i&&(t=i(t))),_text.value=t,t},this.cleanWord=function(e){function t(e,t,i){return i}var i=settings.cleanPaste;if(i>0&&3>i&&/mso(-|normal)|WordDocument|<table\s+[^>]*?x:str|\s+class\s*=\s*"?xl[67]\d"/i.test(e)){e=e.replace(/<!--[\s\S]*?-->|<!(--)?\[[\s\S]+?\](--)?>|<style(\s+[^>]*?)?>[\s\S]*?<\/style>/gi,""),e=e.replace(/\r?\n/gi,""),isIE?(e=e.replace(/<v:shapetype(\s+[^>]*)?>[\s\S]*<\/v:shapetype>/gi,""),e=e.replace(/<v:shape(\s+[^>]+)?>[\s\S]*?<v:imagedata(\s+[^>]+)?>\s*<\/v:imagedata>[\s\S]*?<\/v:shape>/gi,function(e,t,i){var s;if(s=i.match(/\s+src\s*=\s*("[^"]+"|'[^']+'|[^>\s]+)/i)){s=s[1].match(/^(["']?)(.*)\1/)[2];var a='<img src="'+editorRoot+"xheditor_skin/blank.gif"+'" _xhe_temp="true" class="wordImage"';return s=t.match(/\s+style\s*=\s*("[^"]+"|'[^']+'|[^>\s]+)/i),s&&(s=s[1].match(/^(["']?)(.*)\1/)[2],a+=' style="'+s+'"'),a+=" />"}return""})):e=e.replace(/<img( [^<>]*(v:shapes|msohtmlclip)[^<>]*)\/?>/gi,function(e,t){var i,s='<img src="'+editorRoot+"xheditor_skin/blank.gif"+'" _xhe_temp="true" class="wordImage"';return i=t.match(/ width\s*=\s*"([^"]+)"/i),i&&(s+=' width="'+i[1]+'"'),i=t.match(/ height\s*=\s*"([^"]+)"/i),i&&(s+=' height="'+i[1]+'"'),s+" />"}),e=e.replace(/(<(\/?)([\w\-:]+))((?:\s+[\w\-:]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]+))?)*)\s*(\/?>)/g,function(e,t,s,a,n,o){return a=a.toLowerCase(),a.match(/^(link)$/)&&n.match(/file:\/\//i)||a.match(/:/)||"span"===a&&2===i?"":(s||(n=n.replace(/\s([\w\-:]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^>\s]+))?/gi,function(e,t,s){if(t=t.toLowerCase(),/:/.test(t))return"";if(s=s.match(/^(["']?)(.*)\1/)[2],1===i)switch(a){case"p":if("style"===t)return s=s.replace(/"|&quot;/gi,"'").replace(/\s*([^:]+)\s*:\s*(.*?)(;|$)/gi,function(e,t,i){return/^(text-align)$/i.test(t)?t+":"+i+";":""}).replace(/^\s+|\s+$/g,""),s?" "+t+'="'+s+'"':"";break;case"span":if("style"===t)return s=s.replace(/"|&quot;/gi,"'").replace(/\s*([^:]+)\s*:\s*(.*?)(;|$)/gi,function(e,t,i){return/^(color|background|font-size|font-family)$/i.test(t)?t+":"+i+";":""}).replace(/^\s+|\s+$/g,""),s?" "+t+'="'+s+'"':"";break;case"table":if(t.match(/^(cellspacing|cellpadding|border|width)$/i))return e;break;case"td":if(t.match(/^(rowspan|colspan)$/i))return e;if("style"===t)return s=s.replace(/"|&quot;/gi,"'").replace(/\s*([^:]+)\s*:\s*(.*?)(;|$)/gi,function(e,t,i){return/^(width|height)$/i.test(t)?t+":"+i+";":""}).replace(/^\s+|\s+$/g,""),s?" "+t+'="'+s+'"':"";break;case"a":if(t.match(/^(href)$/i))return e;break;case"font":case"img":return e}else if(2===i)switch(a){case"td":if(t.match(/^(rowspan|colspan)$/i))return e;break;case"img":return e}return""})),t+n+o)});for(var s=
});break;case"fontface":var n=[];$.each(getLang("listFontname"),function(e,t){t.c=t.c?t.c:t.n,n.push({s:'<span style="font-family:'+t.c+'">'+t.n+"</span>",v:t.c,t:t.n})}),_this.showMenu(n,function(e){_this._exec("fontname",e)});break;case"fontsize":var o=[];$.each(settings.listFontsize,function(e,t){o.push({s:'<span style="font-size:'+t.s+';">{#fontsize.'+t.n+"}("+t.s+")</span>",v:e+1,t:"{#fontsize."+t.n+"}"})}),_this.showMenu(o,function(e){_this._exec("fontsize",e)});break;case"fontcolor":_this.showColor(function(e){_this._exec("forecolor",e)});break;case"backcolor":_this.showColor(function(e){isIE?_this._exec("backcolor",e):(setCSS(!0),_this._exec("hilitecolor",e),setCSS(!1))});break;case"align":var l=[];$.each(arrAlign,function(e,t){l.push({s:"{#align."+t.v+"}",v:t.v})}),_this.showMenu(l,function(e){_this._exec(e)});break;case"list":var r=[];$.each(arrList,function(e,t){r.push({s:"{#list."+t.v+"}",v:t.v})}),_this.showMenu(r,function(e){_this._exec(e)});break;case"link":_this.showLink();break;case"anchor":_this.showAnchor();break;case"img":_this.showImg();break;case"flash":_this.showEmbed("Flash",htmlFlash,"application/x-shockwave-flash","clsid:d27cdb6e-ae6d-11cf-96b8-4445535400000",' wmode="opaque" quality="high" menu="false" play="true" loop="true" allowfullscreen="true"',settings.upFlashUrl,settings.upFlashExt);break;case"media":_this.showEmbed("Media",htmlMedia,"application/x-mplayer2","clsid:6bf52a52-394a-11d3-b153-00c04f79faa6",' enablecontextmenu="false" autostart="false"',settings.upMediaUrl,settings.upMediaExt);break;case"hr":_this.pasteHTML("<hr />");break;case"emot":_this.showEmot();break;case"table":_this.showTable();break;case"source":_this.toggleSource();break;case"preview":_this.showPreview();break;case"print":_win.print();break;case"fullscreen":_this.toggleFullscreen();break;case"about":_this.showAbout();break;default:_this._exec(e)}ev=null},this._exec=function(e,t,i){i||_this.focus();var s;return s=t!==undefined?_doc.execCommand(e,!1,t):_doc.execCommand(e,!1,null)}};XHEDITOR.settings={skin:"default",tools:"full",clickCancelDialog:!0,linkTag:!1,internalScript:!1,inlineScript:!1,internalStyle:!0,inlineStyle:!0,showBlocktag:!1,forcePtag:!0,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"wmv,avi,wma,mp3,mid",modalWidth:350,modalHeight:220,modalTitle:!0,defLinkText:"{#link.defText}",layerShadow:3,emotMark:!1,upBtnText:"{#upload.btnText}",cleanPaste:1,hoverExecDelay:100,html5Upload:!0,upMultiple:99,listBlocktag:[{n:"p"},{n:"h1"},{n:"h2"},{n:"h3"},{n:"h4"},{n:"h5"},{n:"h6"},{n:"pre"},{n:"address"}],listColors:["#FFFFFF","#CCCCCC","#C0C0C0","#999999","#666666","#333333","#000000","#FFCCCC","#FF6666","#FF0000","#CC0000","#990000","#660000","#330000","#FFCC99","#FF9966","#FF9900","#FF6600","#CC6600","#993300","#663300","#FFFF99","#FFFF66","#FFCC66","#FFCC33","#CC9933","#996633","#663333","#FFFFCC","#FFFF33","#FFFF00","#FFCC00","#999900","#666600","#333300","#99FF99","#66FF99","#33FF33","#33CC00","#009900","#006600","#003300","#99FFFF","#33FFFF","#66CCCC","#00CCCC","#339999","#336666","#003333","#CCFFFF","#66FFFF","#33CCFF","#3366FF","#3333FF","#000099","#000066","#CCCCFF","#9999FF","#6666CC","#6633FF","#6600CC","#333399","#330099","#FFCCFF","#FF99FF","#CC66CC","#CC33CC","#993399","#663366","#330033"],listFontsize:[{n:"x-small",s:"10px"},{n:"small",s:"12px"},{n:"medium",s:"16px"},{n:"large",s:"18px"},{n:"x-large",s:"24px"},{n:"xx-large",s:"32px"},{n:"-webkit-xxx-large",s:"48px"}]},$.fn.xheditor=function(options){var editTest=document.body.contentEditable?document.body.contentEditable:document.designMode;if(!editTest)return!1;var arrSuccess=[];return this.each(function(){if($.nodeName(this,"TEXTAREA"))if(options===!1)this.xheditor&&(this.xheditor.remove(),this.xheditor=null);else if(this.xheditor)arrSuccess.push(this.xheditor);else{var tOptions=/({.*})/.exec($(this).attr("class"));if(tOptions){try{tOptions=eval("("+tOptions[1]+")")}catch(ex){}options=$.extend({},tOptions,options)}var editor=new Xheditor(this,options);editor.init()?(this.xheditor=editor,arrSuccess.push(editor)):edi