TQEditor.js 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227
  1. /*************************************************
  2. * TQEditor
  3. * Author : TengQiu Li
  4. * E-Mail : litqqs@163.com
  5. * Copyright : TengQiu Li
  6. * Version : 2.3.6
  7. * Site : http://www.e512.net
  8. *************************************************/
  9. (function(window,undefined){
  10. if(window.TQE) return;
  11. var version='2.3.6',//编辑器版本
  12. ua = navigator.userAgent.toLowerCase(),
  13. document=window.document,
  14. isIE =!!window.ActiveXObject, //ie // ua.indexOf('trident')>=0 || ua.indexOf('msie 6')>=0 ;
  15. isIE6 = isIE && !window.XMLHttpRequest,//ie6
  16. ieTest = /msie ([0-9]+)/.exec(ua),
  17. IEVersion = ieTest!=null ? parseInt(ieTest[1]):0, //IE版本号
  18. isWebkit = ua.indexOf('webkit')>=0,//chrome,safari
  19. isOpera = ua.indexOf('presto')>=0, //opera
  20. isGecko = !isWebkit && !isOpera && ua.indexOf('gecko')>=0, //firefox
  21. //相关资源
  22. resStrCreateLink='添加链接',
  23. resStrTargetOptions='<option value="">默认</option><option value="_blank">新窗口</option><option value="_self">当前窗口</option><option value="_parent">父窗口</option><option value="_top">顶层窗口</option>',
  24. resStrInsertLinkUI='网址:<input type="text" id="url" value="" size=45 /><br />标题:<input type="text" id="title" value="" size=45 /><br />打开:<select id="target">'+resStrTargetOptions+'</select>',
  25. resStrInsertImage='插入图片',
  26. resStrInsertImageUI='图片网址:<input type="text" id="url" value="" size=40 /><br />替换文本:<input name="alt" type="text" id="alt" size="20" /><br />尺寸:<input name="width" type="text" id="width" size="4" /> &times; <input name="height" type="text" id="height" size="4" /> px &nbsp;<br />对齐:<select name="align" id="align"><option value="" >默认</option><option value="top">居上</option><option value="textTop">文本上方</option><option value="middle">居中</option><option value="absMiddle">绝对居中</option><option value="baseline">基线</option><option value="bottom">底部</option><option value="absBottom">绝对底部</option><option value="left">左</option><option value="right">右</option></select> &nbsp; &nbsp; 边框:<input name="border" type="text" id="border" size="5" />',
  27. resStrImageContextUI='<form class="ePopForm">网址: <input type="text" id="url" size="50"><br>尺寸: <input type="text" id="width" style="width:30px; overflow:visible;"> &times; <input type="text" id="height" style="width:30px; overflow:visible;">px <a href="javascript:void(0)" id="resetWH" >重设大小</a><label><input name="lock" type="checkbox" id="lock" value="1" checked>锁定比例</label><br>替换文本: <input type="text" id="alt" /> 边框: <input type="text" id="border" style="width:30px; overflow:visible;" /><br>排版: <a href="javascript:void(0)" id="alignDefault">默认</a> | <a href="javascript:void(0)" id="alignLeft">左浮动</a> | <a href="javascript:void(0)" id="alignC">居中</a> | <a href="javascript:void(0)" id="alignRight">右浮动</a> | <a href="javascript:void(0)" id="alignTop">上对齐</a> | <a href="javascript:void(0)" id="alignAbsMiddle">中对齐</a> | <a href="javascript:void(0)" id="alignBottom">下对齐</a><div><hr>链接: <input type="text" id="link" size="40"><select id="target">'+resStrTargetOptions+'</select></div></form>',
  28. resStrInsertFlash='插入动画',
  29. resStrInsertFlashUI='Flash网址:<input type="text" id="url" value="" size=40 /><br />尺寸:<input name="width" type="text" id="width" size="4" value="200" />&times;<input name="height" type="text" id="height" size="4" value="200" /> px',
  30. resStrInsertMusic='插入音频',
  31. resStrInsertMusicUI='音频网址:<input type="text" id="url" value="" size=40 /><br />自动播放:<select id="auto_start" name="auto_start"><option value="0">手动开始</option><option value="1">自动开始</option></select>',
  32. resStrInsertVideo='插入视频',
  33. resStrInsertVideoUI='视频网址:<input type="text" id="url" value="" size=40 /><br />尺寸:<input name="width" type="text" id="width" size="4" value="320"/>&times;<input name="height" type="text" id="height" size="4" value="240" /> px<br />自动播放:<select id="auto_start" name="auto_start"><option value="0">手动开始</option><option value="1">自动开始</option></select><br />视频类型:<select id="video_type" name="video_type"><option value="auto">自动识别</option><option value="flv">FLV</option><option value="rm">RMVB</option><option value="wm">其他视频</option></select>',
  34. resStrInsertRow='插入行',
  35. resStrInsertCol='插入列',
  36. resStrDeleteRow='删除行',
  37. resStrDeleteCol='删除列',
  38. resStrDeleteTable='删除表格',
  39. resStrTableContextUI='<div><a class="eMenuItem" style="width:168px;" ><span id="eMergeCells" class="eButton"></span>合并单元格</a><a style="width:168px;" class="eMenuItem" ><span id="eSplitCells" class="eButton"></span>拆分单元格</a><hr width="166"><div style="padding:1px 1px 1px 3px;">表格排版: <a id="eTableAlignLeft">居左</a> | <a id="eTableAlignCenter">居中</a> | <a id="eTableAlignRight">居右</a></div><table border="0" cellSpacing="2" cellPadding="0"><tbody><tr><td width="65" align="center" valign="top" bgcolor="#FFFFFF" style="border:#999 solid 1px;">内容对齐<br><a id="eCellAlignLT" class="eButton eCellAlign"></a><a id="eCellAlignCT" class="eButton eCellAlign"></a><a id="eCellAlignRT" class="eButton eCellAlign"></a><br><a id="eCellAlignLC" class="eButton eCellAlign"></a><a id="eCellAlignCC" class="eButton eCellAlign"></a><a id="eCellAlignRC" class="eButton eCellAlign"></a><br><a id="eCellAlignLB" class="eButton eCellAlign"></a><a id="eCellAlignCB" class="eButton eCellAlign"></a><a id="eCellAlignRB" class="eButton eCellAlign"></a></td><td width="90" align="center" valign="top">宽度<input id="width" name="width" size="3" type="text"><br>边框<input id="border" name="border" size="3" type="text"><br>间距<input id="cellSpacing" name="cellSpacing" size="3" type="text"><br>填充<input id="cellPadding" name="cellPadding" size="3" type="text"></td></tr></tbody></table></div><div><hr width="166">插入表格</div>',
  40. resStrNoColor='无色',
  41. resStrOK='确定',
  42. resStrCenal='取消',
  43. resStrUpload='上传',
  44. resStrClose='关闭',
  45. resStrVersion='版本',
  46. resStrAuthor='作者',
  47. resStrSite='官网',
  48. resStrMail='邮箱',
  49. resStrPageTitlePre='分页标题: ',
  50. TQE=function(objId,userConfig)
  51. {
  52. var $=this,config=TQE.clone(TQE.config);
  53. $.objId = objId;
  54. if(userConfig){
  55. if(userConfig.height && userConfig.height != "auto" ){
  56. userConfig.height= parseInt(userConfig.height);
  57. if( isNaN(userConfig.height) )userConfig.height='auto';
  58. }
  59. for(var k in userConfig){
  60. config[k] = userConfig[k];
  61. }
  62. }
  63. if(typeof config.toolbar =='string'){
  64. var tm=TQE.toolbarMode[config.toolbar];
  65. if(!tm) tm=TQE.toolbarMode.normal;
  66. config.toolbar=tm.left;
  67. if(!userConfig || undefined===userConfig.toolbarRight)config.toolbarRight=tm.right;
  68. }
  69. $.config = config;
  70. $.hasFocus=false;
  71. $._containerDiv=null;
  72. $._toolbarDiv=null;
  73. $._clientDiv=null;
  74. $._statusDiv=null;
  75. //Methods
  76. $.init=function(){
  77. $.obj = TQE.find($.objId);
  78. if(!$.obj){
  79. if($.config.debug) throw('缺少ID为 '+$.objId+' 表单元素');
  80. return;
  81. }
  82. if($.obj.editor) return;//对象不存在或已执行过
  83. $.obj.editor = $;
  84. if (!$.config.width || $.config.width == "auto") {
  85. if($.obj.style.width){$.config.width = $.obj.style.width; }
  86. else if($.obj.cols){ $.config.width = ($.obj.cols * 8)+'px'; }
  87. else{ $.config.width = '100%'; }
  88. }
  89. if (!$.config.height || $.config.height == "auto") {
  90. if($.obj.style.height){ $.config.height = parseInt($.obj.style.height,10); }
  91. else if($.obj.offsetHeight){ $.config.height = $.obj.offsetHeight }
  92. else if($.obj.rows){ $.config.height = $.obj.rows * 17 }
  93. else{ $.config.height = 200; }
  94. }
  95. //toolbar
  96. var i,j, btn,code ='<div class="" id="'+$.objId+'_EditorToolBar">';
  97. //code +=$._toobarCode($.config.toolbar, $.config.toolbarRight)
  98. code += '</div>'+
  99. //编辑区
  100. '<div id="'+$.objId+'_EditorClient" class="eEditorClient">'+
  101. '<iframe id="'+$.objId+'_Editor" style="height:'+$.config.height+'px;" frameborder=0 ></iframe>'+
  102. '</div>'+
  103. //'</div>'+
  104. '<div class="eStatusBar"><div class="eResizeWH" ></div><div class="eResizeH" ></div></div>';
  105. if (!$.config.debug) {
  106. $.obj.style.display = "none";
  107. }
  108. var e =TQE.CE('DIV','TQEditorContainer_'+$.objId, code );
  109. e.className='eEditor';
  110. e.style.width=$.config.width;
  111. $.obj.parentNode.insertBefore(e, $.obj);
  112. $._containerDiv = e;
  113. $._toolbarDiv = TQE.find($.objId+'_EditorToolBar');
  114. $._clientDiv = TQE.find($.objId+'_EditorClient');
  115. //--
  116. if('function'===typeof $.config.oninit) $.config.oninit.call($);
  117. $._initContent($.obj.value);
  118. $.changeToolbarMode($.config.advToolbarMode,true);
  119. $.obj.focus = function(){this.editor.focus();}
  120. //--
  121. $._statusDiv = e.lastChild;
  122. if(false==$.config.resize)$._statusDiv.style.display='none';
  123. $._statusDiv.onmousedown=function(a){
  124. if($._containerDiv.style.position=='absolute') return;
  125. var x,y,obj,maskDiv,
  126. o=this,
  127. //$=this.context,
  128. p=TQE.pos(this),
  129. scrollTop = TQE._docST(),
  130. scrollLeft = TQE._docSL(),
  131. h = $.config.height,
  132. w=$._containerDiv.offsetWidth-2,
  133. bChangeWidth = this.style.cursor == 'se-resize',
  134. oldTop = TQE.pos($._clientDiv).y;
  135. $._showTableContext(0);
  136. if(isIE){
  137. a=window.event;
  138. obj=a.srcElement;
  139. x=scrollLeft + a.clientX-p.x;
  140. y=scrollTop + a.clientY-p.y;
  141. }else{
  142. obj=a.target;
  143. x=a.pageX-p.x;
  144. y=a.pageY-p.y;
  145. }
  146. bChangeWidth = bChangeWidth || obj===o.firstChild && 'h'!=$.config.resize ;
  147. o.mouseout=o.onmouseleave=null;
  148. //$.setOpacity(o,80);
  149. //if(isWebkit || isIE6){
  150. //maskDiv=TQE.CE('DIV','','',true);
  151. //maskDiv.className='eDragMaskDiv';
  152. //maskDiv.style.cursor= bChangeWidth ? 'se-resize':'s-resize';
  153. //maskDiv.style.height=Math.max(document.documentElement.clientHeight, document.body.scrollHeight)+'px';
  154. //}
  155. var mousemove=function(a){
  156. if(isIE){
  157. a=window.event;
  158. a.pageX=scrollLeft + a.clientX;
  159. a.pageY=scrollTop + a.clientY;
  160. }
  161. var deltaH=oldTop - TQE.pos($._clientDiv).y, ty=Math.max(50-h+p.y-deltaH, a.pageY-y),tx=Math.max(100-w+p.x, a.pageX-x);
  162. if(bChangeWidth){
  163. //o.style.width= tx-p.x + w +'px';
  164. $.setWidth(tx-p.x + w);
  165. }
  166. //o.style.top=ty +'px';
  167. $.setHeight(ty-p.y + h + deltaH );
  168. },
  169. mouseup=function(a){
  170. $.focus();
  171. $._popTableContext();
  172. //$.setOpacity(o,100);
  173. };
  174. maskDiv = TQE._draging(mousemove,mouseup,o);
  175. maskDiv.style.cursor= bChangeWidth ? 'se-resize':'s-resize';
  176. };
  177. };
  178. $._toobarCode=function(leftButtons,rightButtons){
  179. var i,btn,code ='';
  180. //
  181. if(rightButtons.length){
  182. //code +='<ul class="eToolBarGroupRight" >';
  183. code +='<span class="eToolBarGroupRight" >';
  184. for(i=0; i < rightButtons.length; i++){
  185. code += $._btnCode(rightButtons[i], false);
  186. }
  187. //code +='</ul>';
  188. code +='</span>';
  189. }
  190. //工具组
  191. //code +='<ul class="eToolBarGroup" >';
  192. code +='<span class="eToolBarGroup" >';
  193. if($.config.showToolbarGroupHandle){
  194. btn = TQE.toolbarBottons['group'];
  195. code +='<div class="eButton eFirstToolBarGroup" id="eBTNgroup" style="background-position: -'+btn.left+'px 0;width:'+btn.width+'px;" ></div>';
  196. }
  197. for(i=0; i < leftButtons.length; i++){
  198. code += $._btnCode(leftButtons[i], true);
  199. }
  200. //code += '</ul>'+ //工具组完
  201. code += '</span>'+ //工具组完
  202. '<div class="eClear"></div>';
  203. return code;
  204. };
  205. $._btnCode=function(tn, groupFlag){
  206. var submenu='',btn,code,styleCode;
  207. if('||'===tn) tn='group';
  208. else if('|'===tn) tn='separator';
  209. else if('string'!==typeof tn){//子菜单
  210. submenu= 'submenu="'+tn.join(',')+'" ';
  211. tn='submenu';
  212. }
  213. btn = TQE.toolbarBottons[tn];
  214. if(!btn) return '';
  215. styleCode=function(btn){return 'id="eBTN'+tn+'" class="eButton"' + (btn.css ? ' style="'+btn.css+'"':'' ); };
  216. switch(tn){
  217. case 'group':
  218. if(!groupFlag) return '';
  219. //code='</ul><ul class="eToolBarGroup" >';
  220. code='</span><span class="eToolBarGroup" >';
  221. if($.config.showToolbarGroupHandle){
  222. code+= '<div '+styleCode(btn)+' ></div>';
  223. }
  224. return code;
  225. case 'separator':
  226. return '<div '+styleCode(btn)+' ></div>'; // id="eBTN'+tn+'"
  227. case 'br':
  228. //return '<li style="clear:left;"></li>';
  229. return '<br />';
  230. default:
  231. //return'<li name="'+tn+'" title="'+btn.text+'" '+submenu+styleCode(btn)+' >'+btn.text+'</li>';//id="'+$.objId+'_'+tn+'"
  232. return'<a href="javascript:void(0)" name="'+tn+'" title="'+btn.text+'" '+submenu+styleCode(btn)+' >'+btn.text+'</a>';//id="'+$.objId+'_'+tn+'"
  233. }
  234. };
  235. //ie6
  236. $._ieMouseStyle=function(obj,normal,hover,down){
  237. if(!isIE || !isIE6 && document.compatMode == "CSS1Compat") return;
  238. TQE.addListener(obj,'mouseover', function(){this.className=hover;});
  239. TQE.addListener(obj,'mouseup', function(){this.className=hover;});
  240. TQE.addListener(obj,'mousedown', function(){this.className=down;});
  241. TQE.addListener(obj,'mouseout', function(){this.className=normal;});
  242. };
  243. $._keepBookmark=function(){
  244. if(isIE){
  245. var _bookmark,
  246. win = TQE.find($.objId+'_Editor');
  247. TQE.addListener(win,'beforedeactivate',function(){_bookmark=$._getRange();});
  248. TQE.addListener(win,'activate',function(){
  249. if(null==_bookmark) return;
  250. var sel=$._getSelection();
  251. if(sel.addRange) sel.addRange(_bookmark);
  252. else _bookmark.select();
  253. _bookmark=null;
  254. });
  255. }
  256. };
  257. $._toolbarBottonClick=function(){
  258. var e=isIE ? event : arguments[0],
  259. cmd = this.getAttribute('name'),
  260. btn=TQE.toolbarBottons[cmd];
  261. e.cancelBubble = true;
  262. $.focus();
  263. if(btn && btn.click){
  264. btn.click($,this);
  265. }else{
  266. TQE.hidePop();
  267. $.exeCmd(cmd);
  268. }
  269. };
  270. $.__selectOption=function(selectObj,value){
  271. for(var i=selectObj.options.length-1;i>=0;i--){
  272. if(selectObj.options[i].value==value){
  273. selectObj.selectedIndex=i;
  274. return;
  275. }
  276. }
  277. };
  278. $.exeCmd=function(cmd,para){
  279. $.focus();
  280. var cells=$.selectedCells(),
  281. d=$._getDoc(),
  282. sel=$._getSelection(),
  283. i, r, fcs;
  284. if(cells.length){
  285. r= d.createRange ? d.createRange() : d.body.createTextRange();
  286. for(i=0;i<cells.length;i++){
  287. if('backcolor'==cmd || 'hilitecolor'==cmd){
  288. cells[i].style.backgroundColor=para;
  289. continue;
  290. }
  291. if(sel.empty) sel.empty(); //ie6,7,8
  292. else if(sel.removeAllRanges) sel.removeAllRanges();
  293. if(sel.selectAllChildren){
  294. sel.selectAllChildren(cells[i])
  295. }else if(r.moveToElementText){ //ie6,7,8
  296. r.moveToElementText(cells[i]);
  297. r.select();
  298. //}else{
  299. // r.selectNode(cells[i]);
  300. // sel.addRange(r);
  301. }
  302. try{
  303. d.execCommand(cmd,false, para!=null?para:false);
  304. if('bold'==cmd || 'italic'==cmd || 'underline'==cmd ||
  305. 'strikethrough'==cmd || 'subscript'==cmd || 'superscript'==cmd){
  306. if(i==0) fcs = d.queryCommandState(cmd);
  307. else if(fcs != d.queryCommandState(cmd)) d.execCommand(cmd,false, para!=null?para:false);
  308. }
  309. }catch(e){}
  310. }
  311. if(sel.empty) sel.empty(); //ie6,7,8
  312. else if(sel.removeAllRanges) sel.removeAllRanges();
  313. }else{
  314. try{return d.execCommand(cmd,false, para!=null?para:false);}catch(e){}
  315. }
  316. };
  317. $.focus=function(){
  318. if($.hasFocus) return ;
  319. if('visual'==$.currentMode()){
  320. var cells=$.selectedCells(),r,sel;
  321. if(cells.length<1){
  322. $._editorObj().contentWindow.focus();
  323. var r=$._getRange(), sel = $._getSelection();
  324. if(isWebkit && sel.rangeCount<1){
  325. r.selectNodeContents($._getDoc().body);
  326. r.collapse(true);
  327. sel.removeAllRanges();
  328. sel.addRange(r);
  329. }
  330. }else{
  331. var r=$._getRange();
  332. if(r.select){ //ie6,7,8
  333. r.collapse(false);
  334. r.select();
  335. }else{
  336. r.selectNodeContents(cells[0]);
  337. r.collapse(false);
  338. sel = $._getSelection();
  339. sel.removeAllRanges();
  340. sel.addRange(r);
  341. }
  342. }
  343. }else{
  344. $._editorObj().focus();
  345. }
  346. $.hasFocus=true;
  347. };
  348. $.focusNode=function(){
  349. if('visual'!==$.currentMode() || !$.hasFocus ) return null;
  350. var r,node = $._getSelection().focusNode;
  351. if(!node){//ie6,7,8
  352. r = $._getRange();
  353. return (r.length)? r.item(0).parentNode : r.parentElement? r.parentElement():null;
  354. }
  355. return node;
  356. };
  357. $._showColorSelectUI=function(sender,cmd){
  358. var o=TQE.find($.objId+'ColorSelect'+cmd);
  359. if(null==o){
  360. o = TQE.CE('DIV',$.objId+'ColorSelect'+cmd, TQE._colorPickerUI() ,true);
  361. o.className='ePopPanel';
  362. TQE._noSel(o);//,'TABLE,TR,TD,DIV');
  363. TQE.listenTags(o,'TD','click',function(){TQE.hidePop();$.exeCmd(cmd, this.bgColor);});
  364. o.lastChild.lastChild.onclick=function(){TQE.hidePop();$.exeCmd(cmd, '');};
  365. TQE.listenTags(o,'TD','mouseover',function(){
  366. var self=this,
  367. iid = window.setInterval(function(){self.style.backgroundColor=(self.style.backgroundColor!='')?'':'#FFFFFF'},500),
  368. p=this.parentNode.parentNode.parentNode.parentNode.lastChild;
  369. p.firstChild.style.backgroundColor=this.bgColor;
  370. p.firstChild.nextSibling.innerHTML=this.bgColor;
  371. this.style.backgroundColor='#FFFFFF';
  372. this.onmouseout=function(){window.clearInterval(iid);this.style.backgroundColor='';}
  373. });
  374. }
  375. TQE.pop(o,sender);
  376. };
  377. $._popAsMenu=function(sender, btns){
  378. var cmd=sender.getAttribute('name'),
  379. o=TQE.find($.objId+'PopMenu'+cmd),
  380. s='',
  381. es,i,tn,btn;
  382. if(null==o){
  383. o = TQE.CE('DIV',$.objId+'PopMenu'+cmd, '' ,true);
  384. o.className='ePopPanel';
  385. }
  386. for(i=0; i < btns.length; i++){
  387. tn = btns[i];
  388. if('separator'==tn || '|'==tn){
  389. s +='<hr style="width:120px; clear:both;" />';
  390. continue;
  391. }
  392. btn = TQE.toolbarBottons[tn];
  393. if(btn){
  394. s +='<div name="'+tn+'" class="eMenuItem" ><span class="eButton" id="eBTN'+tn+'" ></span>'+btn.text+'</div>';
  395. }
  396. }
  397. o.innerHTML=s;
  398. TQE._noSel(o);
  399. if(isOpera)TQE._noSel(o,'DIV');
  400. TQE.listenTags(o,'DIV','click',$._toolbarBottonClick);
  401. if(isIE6){
  402. es = TQE._tags(o,'DIV');
  403. for(i=es.length-1;i>=0;i--){
  404. $._ieMouseStyle(es[i],'eMenuItem','eMenuItemUp','eMenuItem');
  405. }
  406. }
  407. TQE.pop(o,sender);
  408. };
  409. $._popFormUI=function(id, caption, htm, cbOK, intInputNames, uploadUrl, uploadFileTypes, uploadFileSize, uploadType){
  410. var s='<form class="ePopForm">';
  411. if(uploadUrl){
  412. s+='<div class="eTabBar"><a href="javascript:void(0)" class="active" HIDEFOCUS="true">'+caption+'</a><a href="javascript:void(0)" HIDEFOCUS="true">'+resStrUpload+'</a></div>';
  413. s+='<div>';
  414. }
  415. s += htm;
  416. s+='<div class="eBar"><button id="OK" name="OK" type="submit" class="eBtn" HIDEFOCUS="true"/>'+resStrOK+'</button> &nbsp; <button id="Cancel" name="Cancel" type="button" class="eBtn" HIDEFOCUS="true">'+resStrCenal+'</button></div>';
  417. if(uploadUrl){
  418. s+='</div><div style="display:none">';
  419. var url=uploadUrl;
  420. if(uploadUrl.substr(0,1)=='#'){//自定上传界面
  421. url=uploadUrl.substring(1);
  422. }else{
  423. //修正相对网址
  424. if(!('http://'==uploadUrl.substr(0,7).toLowerCase() || '/'==uploadUrl.substr(0,1) || 'https://'==uploadUrl.substr(0,6).toLowerCase())){
  425. if('?'==uploadUrl.substr(0,1)){
  426. uploadUrl = location.pathname+uploadUrl;
  427. }else{
  428. var a=location.pathname.split('/');
  429. a[a.length-1]= uploadUrl;
  430. uploadUrl = a.join('/');
  431. }
  432. }
  433. url=TQE.url+'upload.htm?url='+encodeURIComponent(uploadUrl)+'&field_name='+$.config.uploadFieldName+'&exts='+encodeURIComponent(uploadFileTypes)+'&max_size='+encodeURIComponent(uploadFileSize)+'&debug='+$.config.debug+'&upload_type='+uploadType;
  434. }
  435. s+='<iframe src="'+url+'" frameborder=0 width=358 height=45 ALLOWTRANSPARENCY=true marginwidth=0 marginheight=0 ></iframe>';
  436. s+='</div>';
  437. }
  438. s +='</form>';
  439. var o= TQE.CE('DIV',id, s ,true);
  440. o.className='ePopPanel';
  441. if(uploadUrl){
  442. var tabClick=function(){
  443. this.className='active';
  444. var pn= this.parentNode.nextSibling;
  445. if(this.nextSibling){
  446. this.nextSibling.className='';
  447. pn.style.display='';
  448. pn.nextSibling.style.display='none';
  449. pn.parentNode.getElementsByTagName('INPUT')[0].focus();
  450. }else if(this.previousSibling){
  451. this.previousSibling.className='';
  452. pn.style.display='none';
  453. pn.nextSibling.style.display='';
  454. }
  455. },
  456. tabbar = o.firstChild.firstChild;
  457. tabbar.firstChild.onclick=tabClick;
  458. tabbar.lastChild.onclick=tabClick;
  459. }
  460. var f= TQE._tags(o,'FORM')[0],es = f.elements;
  461. f.srcEditor=$;
  462. es['Cancel'].onclick= TQE.hidePop;
  463. es['OK'].onclick=cbOK;
  464. f.onsubmit=function(){
  465. this.elements['OK'].click();
  466. return false;
  467. }
  468. if(intInputNames) for(i=intInputNames.length-1;i>=0;i--) $._intEdit(es[intInputNames[i]]);
  469. TQE._noSel(o);
  470. if(isOpera)TQE._noSel(o,'FORM,DIV');
  471. return o;
  472. };
  473. $.insertMusic=function(url,auto_start){
  474. var s = $.config.tplMusic.replace(/\{\$url\}/g,url).replace(/\{\$auto_start\}/g,auto_start);
  475. $.insertHtml(s);
  476. };
  477. $.insertFlash=function(url,width,height){
  478. var s = $.config.tplFlash.replace(/\{\$url\}/g,url);
  479. s = s.replace(/\{\$width\}/g,width);
  480. s = s.replace(/\{\$height\}/g,height);
  481. $.insertHtml(s);
  482. };
  483. $.insertVideo=function(url,auto_start,width,height,video_type){
  484. var tpl='',ext;
  485. switch(video_type){
  486. case 'rm':tpl = $.config.tplRm;break;
  487. case 'flv':tpl = $.config.tplFlv;break;
  488. case 'wm':tpl = $.config.tplVideo;break;
  489. default:
  490. ext = url.substr(url.lastIndexOf('.')).toLowerCase();
  491. if('.flv'==ext){
  492. tpl = $.config.tplFlv;
  493. }else if('.rm'==ext || '.rmvb'==ext){
  494. tpl = $.config.tplRm;
  495. }else{
  496. tpl = $.config.tplVideo;
  497. }
  498. break;
  499. }
  500. tpl = tpl.replace(/\{\$url\}/g,url).replace(/\{\$auto_start\}/g,auto_start).replace(/\{\$width\}/g,width).replace(/\{\$height\}/g,height);
  501. $.insertHtml(tpl);
  502. };
  503. //可视模式时有效
  504. //position 可选值[before|after|replace|-1|1|0]
  505. $.insertHtml=function(htm, position){//
  506. $.focus();
  507. if('code'==$.currentMode()){
  508. var editor=$._editorObj();
  509. if(document.selection){//ie
  510. var r = document.selection.createRange();
  511. if('before'==position || -1==position) r.text = htm+r.text;
  512. else if('after'==position || 1==position) r.text+=htm;
  513. else r.text=htm;
  514. r.select();
  515. }else if(editor.selectionStart || editor.selectionStart=='0'){
  516. var startPos = editor.selectionStart,
  517. endPos = editor.selectionEnd,
  518. scrollTop = editor.scrollTop,
  519. str=editor.value;
  520. if('before'==position || -1==position) htm = str.substring(startPos,endPos)+htm;
  521. else if('after'==position || 1==position) htm += str.substring(startPos,endPos);
  522. editor.value=str.substr(0,startPos)+htm+str.substr(endPos, str.length);
  523. editor.focus();
  524. editor.selectionStart=editor.selectionEnd= startPos+htm.length;
  525. editor.scrollTop=scrollTop;
  526. }else{
  527. editor.value+=htm;
  528. editor.focus();
  529. }
  530. $.save();
  531. return;
  532. }
  533. //$.unselectAllCells();
  534. if(isGecko){
  535. htm = htm.replace(/<td([^>]*)>\s*<\/td/ig, '<td$1 ><br></td');
  536. }
  537. var r = $._getRange();
  538. if(r.length){//ie
  539. var d=$._getDoc(),
  540. e=r.item(0),
  541. tr=d.body.createTextRange();
  542. tr.moveToElementText(e);
  543. if('before'==position || -1==position){
  544. tr.collapse();
  545. }else if('after'==position || 1==position){
  546. tr.collapse(false);
  547. }else{
  548. r.execCommand('Delete');
  549. }
  550. tr.pasteHTML(htm);
  551. tr.select();//重设光标
  552. }else if(r.insertNode){//ie9,firefox,chrome,opera
  553. var cf,n,sel;
  554. if(r.createContextualFragment){//IE9 未实现此方法
  555. cf=r.createContextualFragment(htm);
  556. }else{
  557. cf =$._getDoc().createDocumentFragment();
  558. cf.appendChild(TQE.CE('div'));
  559. cf.firstChild.outerHTML=htm;
  560. }
  561. if('before'==position || -1==position){
  562. n= cf.lastChild;
  563. r.insertNode(cf);
  564. r.setEndAfter(n);
  565. }else if('after'==position || 1==position){
  566. r.collapse(false);
  567. r.insertNode(cf);
  568. }else{
  569. r.deleteContents();
  570. r.insertNode(cf);
  571. }
  572. r.collapse(false);
  573. sel = $._getSelection();
  574. sel.removeAllRanges();
  575. sel.addRange(r);
  576. }else{ //ie6,7,8
  577. if('before'==position || -1==position){
  578. r.collapse(true);
  579. }else if('after'==position || 1==position){
  580. r.collapse(false);
  581. }
  582. r.pasteHTML(htm);
  583. r.collapse(false);
  584. r.select();
  585. }
  586. $.save();
  587. };
  588. //最后的地方加入网页代码
  589. $.appendHtml=function(html){
  590. $.unselectAllCells();
  591. $.setContent($.content()+html);
  592. //if('code'==$.currentMode()) $._editorObj().value += html;
  593. //else $._getDoc().body.innerHTML += html;
  594. //$.save();
  595. //return $;
  596. };
  597. $._editorObj= function(){
  598. return TQE.find($.objId+'_Editor');
  599. };
  600. $.currentMode=function(){//取得当前的编辑模式, code 代码 , visual 可视化
  601. return ($._editorObj().tagName.toUpperCase()==='IFRAME')?'visual':'code';
  602. };
  603. $._getDoc=function(){
  604. var iframe =$._editorObj();
  605. return iframe.contentDocument || iframe.contentWindow.document;
  606. };
  607. $._getSelection=function(){
  608. var win =$._editorObj().contentWindow;
  609. return (win.getSelection) ? win.getSelection() : $._getDoc().selection;
  610. };
  611. $._getRange=function(){
  612. var selection=$._getSelection(), d=$._getDoc(),r;
  613. try{//标准dom
  614. r = selection.rangeCount > 0 ? selection.getRangeAt(0) : (selection.createRange ? selection.createRange() : d.createRange());
  615. }catch (e){}
  616. if(!r) r = isIE ? d.body.createTextRange() : d.createRange();
  617. return r;
  618. };
  619. $.insertImage=function(image_url,width,height,border,alt,align){
  620. if(''==image_url) return;
  621. var s='<img src="'+image_url+'" ';
  622. if(width!==undefined && ''!=width && !isNaN(parseInt(width)) && parseInt(width)>0 ) s += ' width='+parseInt(width);
  623. if(height!==undefined && ''!=height && !isNaN(parseInt(height)) && parseInt(height)>0 ) s +=' height='+parseInt(height);
  624. if(border!==undefined && ''!=border && !isNaN(parseInt(border))) s +=' border='+parseInt(border);
  625. if(alt!==undefined && ''!=alt) s +=' alt="'+alt+'"';
  626. if(align!==undefined && ''!=align) s +=' align="'+align+'"';
  627. s +=' />';
  628. $.insertHtml(s);
  629. return;
  630. };
  631. $._enableButton=function(btn,enable){
  632. if(btn.disabled===undefined)btn.disabled=false;
  633. if(btn.disabled!=enable) return;
  634. if(enable){
  635. btn.disabled=false;
  636. $.setOpacity(btn,100);
  637. TQE.addListener(btn,'click',$._toolbarBottonClick);
  638. }else{
  639. btn.disabled=true;
  640. $.setOpacity(btn,30);
  641. TQE.delListener(btn,'click',$._toolbarBottonClick);
  642. }
  643. };
  644. $._updateToolbar=function(enable, buttons, exceptFlag){
  645. var tb=$._toolbarDiv,
  646. btn=$._button('mode'),
  647. //btns = TQE._tags(tb,'LI'),
  648. btns = TQE._tags(tb,'A'),
  649. i;
  650. if(btn) btn.id = 'visual'===$.currentMode()?'eBTNmode':'eBTNmode-reset';
  651. for(i=btns.length-1;i>=0;i--){
  652. if($.inArray(btns[i].getAttribute('name'), buttons) ^ exceptFlag ) {
  653. $._enableButton(btns[i],enable);
  654. }
  655. }
  656. };
  657. //设置光标插入点
  658. //$.setCaret=function(node, position){
  659. // var d=$._getDoc(), sel = $._getSelection();
  660. // if(isIE){
  661. // tr=d.body.createTextRange();
  662. // tr.moveToElementText(node)
  663. // tr.collapse(true);
  664. // tr.select();
  665. // }else{
  666. // tr = d.createRange();
  667. // tr.selectNode(node);
  668. // tr.collapse(true);
  669. // sel.removeAllRanges();
  670. // sel.addRange(tr);
  671. // }
  672. //};
  673. $._hook=function(){
  674. //if('visual'!=$.currentMode()) return; //!isIE || !$.config.enter2br ||
  675. var doc=$._getDoc();
  676. doc.onkeydown = function(e){
  677. TQE._hideContext();
  678. if(isIE) e = $._realEvent(e);
  679. var key = e.keyCode || e.which;
  680. if(e.ctrlKey &&(13==key || 10==key || 83==key)) $.save();//按 Ctrl+(Enter|s) 保存数据至表单
  681. var r=$._call('keydown',e);
  682. if(undefined!==r && false==r) return false;//用户已处理
  683. if((8==key || 46==key) && $.selectedCells().length) $.exeCmd('delete'); //清除选中单元格内容
  684. if(key==13){
  685. var o = $.focusNode(), p,br,tr,d;
  686. if(!o) return;
  687. if(o.nodeName==='#text') o = o.parentNode;
  688. if(o.className == 'splitPage'){//分页标题
  689. p=o.parentNode;
  690. if(o.nextSibling && o.nextSibling.nodeName==='BR'){
  691. br = o.nextSibling;
  692. }else{
  693. br = document.createElement('BR');
  694. if(p.lastChild == o){
  695. p.appendChild(br);
  696. }else{
  697. p.insertBefore(br,o.nextSibling);
  698. }
  699. }
  700. //重设光标
  701. d=$._getDoc();
  702. if(isIE){
  703. tr=d.body.createTextRange();
  704. tr.moveToElementText(br)
  705. tr.collapse(true);
  706. tr.select();
  707. }else{
  708. tr = d.createRange();
  709. tr.selectNode(br);
  710. tr.collapse(true);
  711. var sel = $._getSelection();
  712. sel.removeAllRanges();
  713. sel.addRange(tr);
  714. }
  715. return false;
  716. }
  717. //--
  718. //if(e.shiftKey){e.shiftKey=false;return true;}
  719. if($.config.enter2br){
  720. if(o.tagName != 'LI'){
  721. $.insertHtml('<br />');
  722. return false;
  723. }
  724. }else if(!isIE && !e.shiftKey){//非IE, 回车默认是br的,加以修正
  725. var r=$._getRange(), n, nn;
  726. for(n=r.startContainer; n; n=n.parentNode){
  727. nn=n.nodeName;
  728. if(nn=='LI' || nn=='P'|| 'H1'==nn|| 'H2'==nn|| 'H3'==nn|| 'H4'==nn|| 'H5'==nn|| 'H6'==nn|| 'DIV'==nn) return true;
  729. }
  730. $.exeCmd('FormatBlock','p');
  731. }
  732. }
  733. };
  734. doc.onkeyup =function(e){
  735. e = $._realEvent(e);
  736. var key = e.keyCode || e.which,
  737. node = this.body.firstChild;
  738. if((8===key || 46===key) && node&& node === doc.body.lastChild ){//delete | backspace
  739. var nn=node.nodeName,
  740. ns=node.innerHTML,
  741. reg=/^<(strong|em|b|i|u|font)[^>]*><\/\1>|&nbsp;$/i;
  742. if(nn==='P' || nn==='H1'|| nn==='H2'|| nn==='H3'|| nn==='H4'|| nn==='H5'|| nn==='H6' || nn==='BR'){
  743. if(''===ns || reg.test(ns))doc.body.innerHTML='';
  744. }
  745. }
  746. $._call('keyup',e);
  747. };
  748. doc.ondragstart=function(e){TQE._hideContext();$._showTableContext(0);};
  749. doc.onclick=function(e){
  750. var node,r,sel;
  751. TQE._hideContext();
  752. //$.focus();
  753. //$._popTableContext();
  754. if(!isIE){
  755. node=e.target;
  756. if('IMG'===node.nodeName){
  757. r = $._getDoc().createRange();
  758. sel = $._getSelection();
  759. r.selectNode(e.target);
  760. sel.removeAllRanges();
  761. sel.addRange(r);
  762. $._popImagePanel(node);
  763. }
  764. }else{
  765. e=$._realEvent(e);
  766. node= e.srcElement;
  767. if('IMG'===node.nodeName){
  768. $._popImagePanel(node);
  769. }
  770. }
  771. };
  772. if(isIE){
  773. doc.onmousedown=doc.onclick;
  774. doc.onclick=null;
  775. }
  776. //if($.config.autoClean) doc.body.onpaste=function(){setTimeout($.cleanWord,200);};
  777. doc.body.onpaste=function(e){
  778. if(isIE) e = $._realEvent(e);
  779. var r=$._call('paste',e);
  780. if($.config.autoClean) setTimeout($.cleanWord,200);
  781. };
  782. TQE.addListener(doc,'mouseup',TQE.hidePop);
  783. TQE.addListener(doc,'scroll',$._popTableContext);
  784. //if(isIE6 || isIE && (document.documentMode==7 || document.compatMode != "CSS1Compat"))
  785. TQE.addListener(doc.body,'scroll',$._popTableContext); //IE6或兼容视图
  786. TQE.addListener(doc,'keyup', $._popTableContext);
  787. TQE.addListener(doc,'mouseup',$._popTableContext);
  788. TQE.addListener(doc,'mousedown',$._startSelectTd);
  789. TQE.addListener(doc,'keypress',$.unselectAllCells);
  790. //TQE.addListener(doc,'blur',$.unselectAllCells);
  791. if(isIE6){
  792. TQE.addListener(doc,'mouseup',$.focus);
  793. TQE.addListener(doc,'mousedown',$.focus);
  794. }
  795. };
  796. $._popImagePanel=function(img){
  797. if(!$.config.autoPopImagePanel) return;
  798. var o=TQE.find('__tqImagePanel');
  799. if(null==o){
  800. //var s='<form class="ePopForm">网址: <input type="text" id="url" size="50"><br>尺寸: <input type="text" id="width" style="width:30px; overflow:visible;"> &times; <input type="text" id="height" style="width:30px; overflow:visible;">px <a href="javascript:void(0)" id="resetWH" >重设大小</a><label><input name="lock" type="checkbox" id="lock" value="1" checked>锁定比例</label><br>替换文本: <input type="text" id="alt" /> 边框: <input type="text" id="border" style="width:30px; overflow:visible;" /><br>排版: <a href="javascript:void(0)" id="alignDefault">默认</a> | <a href="javascript:void(0)" id="alignLeft">左浮动</a> | <a href="javascript:void(0)" id="alignC">居中</a> | <a href="javascript:void(0)" id="alignRight">右浮动</a> | <a href="javascript:void(0)" id="alignTop">上对齐</a> | <a href="javascript:void(0)" id="alignAbsMiddle">中对齐</a> | <a href="javascript:void(0)" id="alignBottom">下对齐</a><div>链接: <input type="text" id="link" size="40"><select id="target"><option value="" >默认</option><option value="_blank">新窗口</option><option value="_self">当前窗口</option><option value="_parent">父窗口</option><option value="_top">顶层窗口</option></select></div></form>';
  801. o= TQE.CE('DIV','__tqImagePanel', resStrImageContextUI ,true);
  802. o.className='ePopPanel';
  803. var f= TQE._tags(o,'FORM')[0],
  804. es = f.elements;
  805. $._intEdit(es['width']);
  806. $._intEdit(es['height']);
  807. $._intEdit(es['border']);
  808. o.urlField=es['url'];
  809. o.widthField=es['width'];
  810. o.heightField=es['height'];
  811. o.lockField=es['lock'];
  812. o.borderField=es['border'];
  813. o.altField=es['alt'];
  814. //link attri
  815. o.linkField=es['link'];
  816. o.targetField=es['target'];
  817. o.linkField.onchange=function(){
  818. var o=this.parentNode.parentNode.parentNode, img=o.target, a=img.parentNode;
  819. if(a.nodeName!=='A') return;
  820. a.setAttribute('href', this.value);
  821. };
  822. o.targetField.onchange=function(){
  823. var o=this.parentNode.parentNode.parentNode, img=o.target, a=img.parentNode;
  824. if(a.nodeName!=='A') return ;
  825. a.setAttribute('target', this.options[this.selectedIndex].value);
  826. };
  827. o.urlField.onchange=function(){
  828. this.parentNode.parentNode.target.src=this.value;;
  829. };
  830. o.urlField.onfocus=function(){this.select();};
  831. var setwh=function(){
  832. var o=this.parentNode.parentNode, img=o.target, w=h=Math.max(1,this.value);
  833. if(o.lockField.checked){
  834. if(this.id=='width') h=o.heightField.value=Math.round(w/ o.rate);
  835. else w=o.widthField.value=Math.round(h * o.rate);
  836. }else{
  837. if(this.id=='width') h=o.heightField.value;
  838. else w=o.widthField.value;
  839. }
  840. img.width=w;
  841. img.height=h;
  842. img.style.width='';
  843. img.style.height='';
  844. };
  845. o.widthField.onchange=o.widthField.onblur=o.heightField.onchange=o.heightField.onblur=setwh;
  846. o.borderField.onchange=function(){
  847. var img= this.parentNode.parentNode.target;
  848. if(''===this.value) img.removeAttribute('border'); else img.border=this.value;
  849. };
  850. o.altField.onchange=function(){
  851. var img= this.parentNode.parentNode.target;
  852. if(''===this.value) img.removeAttribute('alt'); else img.alt=this.value;
  853. };
  854. o.lockField.onclick=function(){
  855. if(this.checked){
  856. var o=this.parentNode.parentNode.parentNode;
  857. o.rate=o.widthField.value/o.heightField.value;
  858. }
  859. };
  860. var aClick=function(e){
  861. var op=this.parentNode.parentNode,
  862. o=op.target,
  863. id=this.id;
  864. if('resetWH'==id){
  865. o.removeAttribute('width');
  866. o.removeAttribute('height');
  867. o.style.width='';
  868. o.style.height='';
  869. op.widthField.value=o.width;
  870. op.heightField.value=o.height;
  871. op.rate=o.width/o.height;
  872. }else{ // if('align'==id.substring(0,5)){
  873. o.align='';
  874. o.style.display='';
  875. o.style.margin='';
  876. $.exeCmd('justifynone');
  877. if('alignC'==id){
  878. //o.style.display='block';
  879. //o.style.margin='5px auto';
  880. $.exeCmd('justifycenter');
  881. }else if('alignDefault'!=id){
  882. o.align=id.substring(5,20).toLowerCase();;
  883. }
  884. }
  885. return false;
  886. };
  887. var os = TQE._tags(o,'A'),i;
  888. for(i=os.length-1;i>=0;i--){
  889. os[i].onclick=aClick;
  890. }
  891. TQE._noSel(o);
  892. }
  893. if(img.parentNode && img.parentNode.nodeName==='A'){
  894. o.lastChild.lastChild.style.display='';
  895. o.linkField.value=img.parentNode.getAttribute('href');
  896. $.__selectOption(o.targetField, img.parentNode.getAttribute('target'));
  897. }else{
  898. o.lastChild.lastChild.style.display='none';
  899. o.linkField.value='';
  900. o.targetField.selectedIndex=0;
  901. }
  902. o.target=img;
  903. o.urlField.value=img.getAttribute('src');
  904. o.widthField.value=img.width;
  905. o.heightField.value=img.height;
  906. o.borderField.value=img.border;
  907. o.altField.value=img.alt;
  908. o.rate= (img.width>0 && img.height>0) ? img.width / img.height:1;
  909. $._popContext(o, img);
  910. };
  911. $._popContext=function(o,relateObj){
  912. if(TQE.activeContext != o )TQE._hideContext();
  913. var x,y,my
  914. p=TQE.pos($._editorObj()),
  915. p2=relateObj.getBoundingClientRect(),
  916. d=TQE._doc();
  917. o.style.display="block";
  918. x = Math.min( p.x+ p2.left , TQE._docSL() + d.clientWidth-o.offsetWidth-5);
  919. y = Math.min( p.y+p.height, 10+p.y+ p2.bottom);
  920. my = TQE._docST() + d.clientHeight - o.offsetHeight-10;
  921. if(y > my){
  922. y = Math.max(p.y-o.offsetHeight, p.y+p2.top-o.offsetHeight-10);
  923. //y=p2.top+p.y-o.offsetHeight-10;
  924. //if(y<TQE._docST())y=10+Math.max(p.y, TQE._docST());// isIE? window.event.clientY :
  925. //if(y<p.y-o.offsetHeight)y= p.y-o.offsetHeight;
  926. }
  927. o.style.left= x+'px';
  928. o.style.top= y+'px';
  929. TQE.activeContext=o;
  930. TQE.drag(o);
  931. };
  932. $._showTableContext=function(b){
  933. var i,btn,
  934. ids=['TQEAddRowBefore','TQEAddRowAfter','TQEAddColBefore','TQEAddColAfter','TQEDeleteRow','TQEDeleteColumn','TQEDeleteTable'];
  935. for(i=ids.length;i>=0;i--){
  936. btn=TQE.find(ids[i])
  937. if(btn){
  938. btn.style.display = b ? '':'none';
  939. }
  940. }
  941. };
  942. $._popTableContext=function(){
  943. if(!$.config.autoPopTablePanel) return;
  944. var table,td=$.focusNode();
  945. while(td && td.nodeName !=='TD'){
  946. td = td.parentNode;
  947. }
  948. if(!td){
  949. return $._showTableContext(0);
  950. }
  951. table=td.parentNode.parentNode.parentNode;
  952. var editorPos=TQE.pos($._editorObj()),
  953. tablePos=table.getBoundingClientRect(),
  954. tdPos=td.getBoundingClientRect(),
  955. btnTQEAddRowBefore=TQE.find('TQEAddRowBefore'),
  956. btnTQEAddRowAfter=TQE.find('TQEAddRowAfter'),
  957. btnTQEAddColBefore=TQE.find('TQEAddColBefore'),
  958. btnTQEAddColAfter=TQE.find('TQEAddColAfter'),
  959. btnTQEDeleteRow=TQE.find('TQEDeleteRow'),
  960. btnTQEDeleteColumn=TQE.find('TQEDeleteColumn'),
  961. btnTQEDeleteTable=TQE.find('TQEDeleteTable'),
  962. d=$._getDoc().documentElement,
  963. p1,p2;
  964. //单元格不在可见范围内
  965. if(tdPos.top+td.offsetHeight<0 || tdPos.left+td.offsetWidth<0 || tdPos.top>=d.clientHeight || tdPos.left>=d.clientWidth){
  966. return $._showTableContext(0);
  967. }
  968. if(!btnTQEAddRowBefore){
  969. btnTQEDeleteTable=TQE.CE('A','TQEDeleteTable','',true);
  970. btnTQEDeleteTable.title=resStrDeleteTable;
  971. btnTQEAddRowBefore=TQE.CE('A','TQEAddRowBefore','',true);
  972. btnTQEAddRowAfter=TQE.CE('A','TQEAddRowAfter','',true);
  973. btnTQEAddRowAfter.className=btnTQEAddRowBefore.className='eButtonAddRow';
  974. btnTQEAddRowBefore.title=btnTQEAddRowAfter.title=resStrInsertRow;
  975. btnTQEAddColBefore=TQE.CE('A','TQEAddColBefore','',true);
  976. btnTQEAddColAfter=TQE.CE('A','TQEAddColAfter','',true);
  977. btnTQEAddColAfter.className=btnTQEAddColBefore.className='eButtonAddCol';
  978. btnTQEAddColBefore.title=btnTQEAddColAfter.title=resStrInsertCol;
  979. btnTQEDeleteRow=TQE.CE('A','TQEDeleteRow','',true);
  980. btnTQEDeleteColumn=TQE.CE('A','TQEDeleteColumn','',true);
  981. btnTQEDeleteColumn.className=btnTQEDeleteRow.className=btnTQEDeleteTable.className='eButtonDeleteRC';
  982. btnTQEDeleteRow.title=resStrDeleteRow;
  983. btnTQEDeleteColumn.title=resStrDeleteCol;
  984. TQE._noSel(btnTQEAddRowBefore);
  985. TQE._noSel(btnTQEAddRowAfter);
  986. TQE._noSel(btnTQEAddColBefore);
  987. TQE._noSel(btnTQEAddColAfter);
  988. TQE._noSel(btnTQEDeleteRow);
  989. TQE._noSel(btnTQEDeleteColumn);
  990. TQE._noSel(btnTQEDeleteTable);
  991. btnTQEAddRowBefore.onclick=btnTQEAddRowAfter.onclick=btnTQEAddColBefore.onclick=btnTQEAddColAfter.onclick=btnTQEDeleteRow.onclick=btnTQEDeleteColumn.onclick=btnTQEDeleteTable.onclick=function(){
  992. if(!this.cell) return;
  993. var td=this.cell,
  994. table=td.parentNode.parentNode.parentNode,
  995. $=this.editor;
  996. $.unselectAllCells();
  997. switch(this.id){
  998. case 'TQEAddRowBefore':
  999. TQE.insertRow(td,1);
  1000. break;
  1001. case 'TQEAddRowAfter':
  1002. TQE.insertRow(td,0);
  1003. break;
  1004. case 'TQEAddColBefore':
  1005. TQE.insertCol(td,1);
  1006. break;
  1007. case 'TQEAddColAfter':
  1008. TQE.insertCol(td,0);
  1009. break;
  1010. case 'TQEDeleteRow':
  1011. TQE.deleteRow(td);
  1012. break;
  1013. case 'TQEDeleteColumn':
  1014. TQE.deleteCol(td);
  1015. break;
  1016. case 'TQEDeleteTable':
  1017. table.parentNode.removeChild(table);
  1018. break;
  1019. }
  1020. $.focus();
  1021. $._popTableContext();
  1022. };
  1023. }else{
  1024. $._showTableContext(1);
  1025. }
  1026. btnTQEAddRowBefore.cell=btnTQEAddRowAfter.cell=btnTQEAddColBefore.cell=btnTQEAddColAfter.cell=btnTQEDeleteRow.cell=btnTQEDeleteColumn.cell=btnTQEDeleteTable.cell=td;
  1027. btnTQEAddRowBefore.editor=btnTQEAddRowAfter.editor=btnTQEAddColBefore.editor=btnTQEAddColAfter.editor=btnTQEDeleteRow.editor=btnTQEDeleteColumn.editor=btnTQEDeleteTable.editor=$;
  1028. btnTQEAddRowAfter.style.left = btnTQEAddRowBefore.style.left= btnTQEDeleteRow.style.left = (Math.min(editorPos.x+$._getDoc().body.offsetWidth-12,editorPos.x+tablePos.left+table.offsetWidth))+'px';
  1029. btnTQEAddRowBefore.style.top=(editorPos.y+tdPos.top-5)+'px';
  1030. btnTQEAddRowAfter.style.top=(editorPos.y+tdPos.top+td.offsetHeight-4)+'px';
  1031. btnTQEDeleteRow.style.top=(editorPos.y+tdPos.top+ (td.offsetHeight >>> 1) -6)+'px';
  1032. btnTQEAddColAfter.style.top = btnTQEAddColBefore.style.top= btnTQEDeleteColumn.style.top = (editorPos.y + Math.max(0,tablePos.top-12))+'px';
  1033. btnTQEAddColBefore.style.left=(editorPos.x+tdPos.left-5)+'px';
  1034. btnTQEAddColAfter.style.left=(editorPos.x+tdPos.left+td.offsetWidth-5)+'px';
  1035. btnTQEDeleteColumn.style.left=(editorPos.x+tdPos.left+(td.offsetWidth>>1)-6)+'px';
  1036. p1=TQE.pos(btnTQEAddRowBefore);
  1037. p2=TQE.pos(btnTQEAddColAfter);
  1038. btnTQEDeleteTable.style.top= Math.min(p2.y,p1.y-13) + 'px';
  1039. btnTQEDeleteTable.style.left= Math.max(p2.x+10, p1.x) + 'px';
  1040. };
  1041. $.activeTable=null;
  1042. $.unselectAllCells=function(){
  1043. if(!$.activeTable) return;
  1044. try{
  1045. var table=$.activeTable,i,j;
  1046. for( i=table.rows.length-1; i>=0;i--){
  1047. for(j=table.rows[i].cells.length-1;j>=0;j--){
  1048. td=table.rows[i].cells[j];
  1049. p=TQE.pos(td);
  1050. $._selectCell(td, false );
  1051. }
  1052. }
  1053. }catch(e){}
  1054. $.activeTable=null;
  1055. };
  1056. $.selectedCells=function(){
  1057. if(!$.activeTable) return [];
  1058. try{
  1059. var table=$.activeTable,i,j,result=[];
  1060. for( i=table.rows.length-1; i>=0;i--){
  1061. for(j=table.rows[i].cells.length-1;j>=0;j--){
  1062. if(table.rows[i].cells[j].isSelected) result.push(table.rows[i].cells[j]);
  1063. }
  1064. }
  1065. }catch(e){}
  1066. return result;
  1067. };
  1068. $._selectCell=function(cell,b){
  1069. if(cell.isSelected==b) return;
  1070. cell.className=b?'selectedTD':'';
  1071. //if(b){
  1072. // var rang=document.createRange(), sel=$._getSelection();
  1073. // rang.selectNode(cell);
  1074. // sel.addRange(rang);
  1075. //}
  1076. cell.isSelected=b;
  1077. };
  1078. $._pos=function(e){
  1079. var x=0,y=0,
  1080. box = e.getBoundingClientRect(),
  1081. d=$._getDoc(),
  1082. dWin= $._editorObj().contentWindow,
  1083. dRoot= d.compatMode != "CSS1Compat" ? d.body : d.documentElement;
  1084. x = box.left - dRoot.clientLeft + (dWin.scrollX ? dWin.scrollX : dRoot.scrollLeft);
  1085. y = box.top - dRoot.clientTop + (dWin.scrollY ? dWin.scrollY : dRoot.scrollTop);
  1086. return {'x' : x, 'y' : y, left:x, top:y, width:e.offsetWidth, height:e.offsetHeight};
  1087. };
  1088. $._startSelectTd=function(e){
  1089. var x,y,oldX,oldY,
  1090. table,
  1091. d,dt,dl,
  1092. tdP,td,
  1093. startSelectCell=false,
  1094. doc = $._getDoc(),
  1095. docWin=doc.parentWindow,
  1096. dRoot= doc.compatMode != "CSS1Compat" ? doc.body : doc.documentElement,
  1097. docMM=doc.onmousemove,
  1098. docMU=doc.onmouseup,
  1099. docDS=doc.ondragstart,
  1100. rootMU=document.onmouseup;
  1101. e =$._realEvent(e);
  1102. if(e.ctrlKey || e.altKey || e.button!= isIE ? 1:0) return;
  1103. $.unselectAllCells();
  1104. td =(isIE)? e.srcElement:e.target;
  1105. while(td && td.nodeName!='BODY' && td.nodeName!='TD' ){
  1106. td=td.parentNode;
  1107. }
  1108. if(!td || td.nodeName!=='TD') return;
  1109. table=td.parentNode.parentNode.parentNode;
  1110. if(table.nodeName!=='TABLE') return;
  1111. tdP=$._pos(td);
  1112. //d = (doc.compatMode != "CSS1Compat") ? doc.body : doc.documentElement;
  1113. //dl=0;// (isIE || isOpera)? d.scrollLeft : docWin.scrollX;
  1114. //dt=0;// (isIE || isOpera)? d.scrollTop : docWin.scrollY;
  1115. oldX=isIE ? e.clientX + (docWin.scrollX ? docWin.scrollX : dRoot.scrollLeft) : e.pageX;
  1116. oldY=isIE ? e.clientY + (docWin.scrollY ? docWin.scrollY : dRoot.scrollTop) : e.pageY;
  1117. doc.onmousemove=function(docEvent){
  1118. var x,y,dl,dt,i,j,x1,x2,y1,y2,p,cell,sel;
  1119. //dl= (isIE || isOpera)? d.scrollLeft : docWin.scrollX;
  1120. //dt= (isIE || isOpera)? d.scrollTop : docWin.scrollY;
  1121. if(isIE){
  1122. docEvent=this.parentWindow.event;
  1123. x=docEvent.clientX + (docWin.scrollX ? docWin.scrollX : dRoot.scrollLeft);
  1124. y=docEvent.clientY + (docWin.scrollY ? docWin.scrollY : dRoot.scrollTop);
  1125. }else{
  1126. x=docEvent.pageX;
  1127. y=docEvent.pageY;
  1128. }
  1129. if(!startSelectCell && (x<tdP.x || x>tdP.x+tdP.width || y<tdP.y || y>tdP.y+tdP.height)){
  1130. startSelectCell=true;
  1131. $.activeTable=table;
  1132. }
  1133. if(! startSelectCell) return;
  1134. sel= $._getSelection()
  1135. if(sel.empty) sel.empty(); //ie6,7,8
  1136. else if(sel.removeAllRanges) sel.removeAllRanges();
  1137. x1=Math.min(oldX,x);
  1138. x2=Math.max(oldX,x);
  1139. y1=Math.min(oldY,y);
  1140. y2=Math.max(oldY,y);
  1141. for(i=table.rows.length-1; i>=0;i--){
  1142. for(j=table.rows[i].cells.length-1;j>=0;j--){
  1143. cell=table.rows[i].cells[j];
  1144. p=$._pos(cell);
  1145. $._selectCell(cell, p.x<=x2 && p.y<=y2 && p.x+p.width>=x1 && p.y+p.height>y1 );
  1146. }
  1147. }
  1148. };
  1149. doc.ondragstart=doc.onmouseup=document.onmouseup=function(){
  1150. doc.onmousemove=docMM;
  1151. doc.ondragstart=docDS,
  1152. document.onmouseup=rootMU;
  1153. startSelectCell=false;
  1154. //return;
  1155. //var i,cells = $.selectedCells(),
  1156. // rang,
  1157. // sel=$._getSelection();
  1158. //if(startSelectCell){
  1159. // if(sel.removeAllRanges) sel.removeAllRanges();
  1160. // else if(sel.clear) sel.clear(); //ie6,7,8
  1161. //}
  1162. //for(i=cells.length-1;i>=0;i--){
  1163. // rang=document.createRange();
  1164. // rang.selectNode(cells[i]);
  1165. // sel.addRange(rang);
  1166. //}
  1167. //sel.selectAllChildren();
  1168. };
  1169. };
  1170. //判断是否可以合并选中的单元格
  1171. $.canMergeSelectedCells=function(){
  1172. if(!$.activeTable) return false;
  1173. var table=$.activeTable, i,j, l,t,r,b, p,cell,count=0,cells = $.selectedCells();
  1174. if(cells.length<2) return false;
  1175. TQE.updateCellsStatus(table);
  1176. l=cells[0].colStart;
  1177. r=cells[0].colEnd;
  1178. t=cells[0].rowStart;
  1179. b=cells[0].rowEnd;
  1180. for(i=cells.length-1;i>0;i--){
  1181. l=Math.min(l,cells[i].colStart);
  1182. t=Math.min(t,cells[i].rowStart);
  1183. r=Math.max(r,cells[i].colEnd);
  1184. b=Math.max(b,cells[i].rowEnd);
  1185. }
  1186. for(i=Math.min(b,table.rows.length-1); i>=0;i--){
  1187. for(j=table.rows[i].cells.length-1;j>=0;j--){
  1188. cell=table.rows[i].cells[j];
  1189. if(!cell.isSelected && cell.colStart<=r && cell.colEnd>=l && cell.rowStart<=b && cell.rowEnd>=t){
  1190. return false;
  1191. }
  1192. }
  1193. }
  1194. return true;
  1195. };
  1196. //合并选中的单元格
  1197. $.mergeSelectedCells=function(){
  1198. if(! $.canMergeSelectedCells() ) return false;
  1199. var table=$.activeTable,i,j,l,t,p, s='', firstCell=null, rowSpan=1,colSpan=1,cell;
  1200. for( i=0; i<table.rows.length;i++){
  1201. for(j=0;j<table.rows[i].cells.length;j++){
  1202. if(table.rows[i].cells[j].isSelected){
  1203. cell=table.rows[i].cells[j];
  1204. s += cell.innerHTML;
  1205. p=TQE.pos(cell);
  1206. if(firstCell===null){
  1207. firstCell=cell;
  1208. l=p.x;
  1209. t=p.y;
  1210. rowSpan=firstCell.rowSpan;
  1211. colSpan=firstCell.colSpan;
  1212. }else{
  1213. if(p.y===t) colSpan+= cell.colSpan;
  1214. else if(p.x===l) rowSpan+=cell.rowSpan;
  1215. cell.innerHTML='';
  1216. //cell.parentNode.removeChild(cell);
  1217. }
  1218. }
  1219. }
  1220. }
  1221. firstCell.innerHTML=s.replace(/(&nbsp;|<br\s*\/?>)+$/,'$1');
  1222. firstCell.rowSpan=rowSpan;
  1223. firstCell.colSpan=colSpan;
  1224. for(i=table.rows.length-1; i>=0;i--){
  1225. p=table.rows[i];
  1226. for(j=p.cells.length-1;j>=0;j--){
  1227. if(p.cells[j].isSelected){
  1228. cell= p.cells[j];
  1229. if(cell!=firstCell){
  1230. p.removeChild(cell);
  1231. }
  1232. }
  1233. }
  1234. if(p.cells.length<1)table.deleteRow(i);
  1235. }
  1236. TQE.updateCellsStatus(table);
  1237. };
  1238. $.splitCell=function(cell){
  1239. if(!cell || cell.rowSpan<2 && cell.colSpan<2) return true;
  1240. var table=cell.parentNode.parentNode.parentNode, i,j,k, row, td;
  1241. TQE.updateCellsStatus(table);
  1242. for(i=cell.rowStart;i<=cell.rowEnd;i++){
  1243. row=table.rows[i];
  1244. for(j=0;j<row.cells.length;j++){
  1245. if(row.cells[j].colStart>cell.colEnd){
  1246. break;
  1247. }
  1248. }
  1249. k = cell.colSpan;
  1250. if(i==cell.rowStart) k--;
  1251. while( 0 < k-- ){
  1252. td=row.insertCell(j);
  1253. $._selectCell(td,cell.isSelected);
  1254. td.style.backgroundColor=cell.style.backgroundColor;
  1255. }
  1256. }
  1257. cell.rowSpan=1;
  1258. cell.colSpan=1;
  1259. };
  1260. $._changed=function(){
  1261. $._autoSave(1);
  1262. $._showTableContext(false);
  1263. var o;
  1264. if('visual'===$.currentMode()){
  1265. $._keepBookmark();
  1266. $._hook();
  1267. //if($.config.autoClean) doc.body.onpaste=function(){setTimeout($.cleanWord,200);};
  1268. o=$._editorObj().contentWindow;
  1269. TQE.addListener(o,'resize',$._popTableContext);
  1270. if(isIE6){
  1271. o=o.document.body;//晕,ie6里iframe 不能触发 onfocus 与 onblur 事件
  1272. }
  1273. }else{
  1274. o= $._editorObj();
  1275. TQE.addListener(o,'mouseup',TQE.hidePop);
  1276. o.onkeydown=function(e){return $._call('keydown',e);}
  1277. o.onkeyup=function(e){return $._call('keyup',e);}
  1278. }
  1279. //绑定事件
  1280. o.onfocus=function(e){
  1281. $.hasFocus=true;
  1282. if($.obj.onfocus) $.obj.onfocus();
  1283. $._call('focus',e);
  1284. };
  1285. o.onblur=function(e){
  1286. $.hasFocus=false;
  1287. if($.obj.onblur) $.obj.onblur();
  1288. $._call('blur',e);
  1289. };
  1290. };
  1291. $._realEvent=function(e){
  1292. if(isIE) e = 'code'===$.currentMode() ? window.event : $._editorObj().contentWindow.event;
  1293. return e;
  1294. };
  1295. $._call=function(eventName,e){
  1296. var handler = $.config['on'+eventName];
  1297. if('function'===typeof handler) return handler.call($,$._realEvent(e));
  1298. };
  1299. //mode 可选值[code|visual]
  1300. $.changeMode=function(mode){//更改编辑方式,空值时自动转另一种方式
  1301. var old=$.currentMode();
  1302. if(old===mode) return;
  1303. if(!mode){
  1304. mode = ('code'!=old) ? 'code' : 'visual';
  1305. }
  1306. if(mode==old) return;
  1307. $.hasFocus=false;
  1308. var eo=$._editorObj(), h=eo.offsetHeight, editorHtm, visualMode='visual'===mode;
  1309. if('code'===mode){
  1310. $.unselectAllCells();
  1311. h-=4;
  1312. editorHtm='<table width=100% border=0 cellpadding=0 cellspacing=0><tr><td width=2 style="padding:0"></td><td style="padding:0"><textarea id="'+$.objId+'_Editor" wrap="hard" style="height:'+h+'px"></textarea></td></tr></table>';
  1313. }
  1314. else if(visualMode){
  1315. editorHtm='<IFRAME id="'+$.objId+'_Editor" frameborder=0 marginheight=0 marginwidth=0 style="height:'+h+'px" ></IFRAME>';
  1316. }else{
  1317. return;
  1318. }
  1319. $._autoSave(0);
  1320. TQE._hideContext();
  1321. var code = $.content();
  1322. document.body.appendChild($._clientDiv); //专用来修改IE6,7,8里编辑器直接父节点是P的bug。 即 <p><textarea id="forEditor"></textarea>
  1323. $._clientDiv.innerHTML=editorHtm;
  1324. $._containerDiv.insertBefore($._clientDiv,$._containerDiv.lastChild);
  1325. //$._clientDiv.insertAdjacentHTML('beforeEnd',editorHtm)
  1326. $._initContent(code);
  1327. //$._setHeight(visualMode? h: h-4);
  1328. //var btn=$._button('mode');
  1329. //if(btn) btn.id = visualMode?'eBTNmode':'eBTNmode-reset';
  1330. $._updateToolbar(visualMode,['toolbarmode','mode','fullscreen','help'], true);
  1331. };
  1332. //自动排版
  1333. $.typeset=function(){
  1334. if('visual'!=$.currentMode()) return;
  1335. $._showTableContext(0);
  1336. var d = $._getDoc(),e,es,s,div,ep,fw;
  1337. //删除不必要的空格,将DIV转为P
  1338. s=d.body.innerHTML;
  1339. s=s.replace(/&nbsp;/gi,' ').replace(/>\s+</gm,'> <').replace(/ +/gi,' ').replace(/<div/gi,'<p').replace(/<\/div/gi,'</p');
  1340. d.body.innerHTML=s;
  1341. //删除CENTER
  1342. es=TQE._tags(d,'CENTER');
  1343. for(i=es.length-1;i>=0;i--){
  1344. TQE.removeNode(es[i],false);
  1345. }
  1346. //删除不必要的SPAN
  1347. es=TQE._tags(d,'SPAN');
  1348. for(i=es.length-1;i>=0;i--){
  1349. e=es[i];
  1350. fw= e.style.fontWeight,c=e.style.color;
  1351. if(''===e.innerHTML.replace(/<[a-z\/][^>]*>/gi,'') || ( fw=='' && c=='')){
  1352. TQE.removeNode(e,false);
  1353. continue;
  1354. }
  1355. e.removeAttribute('style');
  1356. e.className=''
  1357. e.removeAttribute('class');
  1358. e.style.fontWeight=fw;
  1359. e.style.color=c;
  1360. }
  1361. //清理分页符
  1362. es=TQE._tags(d,'H3');
  1363. for(i=es.length-1;i>=0;i--){
  1364. if(es[i].className === 'splitPage') es[i].innerHTML=es[i].innerHTML.replace(/<\/?[a-zA-z][^>]*>/g,'');
  1365. }
  1366. //清理段落
  1367. es=TQE._tags(d,'P');
  1368. var emtpyReg=/^(&nbsp;| ){3,}/
  1369. for(i=es.length-1;i>=0;i--){
  1370. e=es[i];
  1371. if(''==e.innerHTML.replace(/<[a-z\/][^>]*>/gi,'').replace( /( |\n|\r|\t|&nbsp;)/gi, '')){//删除空白的段落
  1372. TQE.removeNode(e,false);
  1373. continue;
  1374. }
  1375. e.removeAttribute('style');
  1376. e.className=''
  1377. e.removeAttribute('class');
  1378. if(emtpyReg.test(e.innerHTML)){
  1379. e.align='center';
  1380. }else{
  1381. e.removeAttribute('align');
  1382. e.style.textIndent=$.config.typesetIndentParagraph ? '2em':'';
  1383. }
  1384. }
  1385. //清理链接
  1386. es=TQE._tags(d,'A');
  1387. for(i=es.length-1;i>=0;i--){
  1388. e=es[i];
  1389. if(''==e.innerHTML.replace(/<[a-z\/][^>]*>/gi,'').replace( /( |\n|\r|\t|&nbsp;)/gi, '')){//删除空白的链接
  1390. TQE.removeNode(e,false);
  1391. continue;
  1392. }
  1393. e.removeAttribute('style');
  1394. e.className=''
  1395. e.removeAttribute('class');
  1396. }
  1397. var isEmptyNode=function(node){
  1398. var nn=node.nodeName, emptyReg=/^( |\n|\r|\t|&nbsp;)*$/gi;
  1399. if(nn==='#text') return emptyReg.test(node.nodeValue)
  1400. return 'BR'===nn || 'IMG'!==nn && ''==node.innerHTML.replace(/<[a-z\/][^>]*>/gi,'').replace(/(\s|&nbsp;)/gmi,'');
  1401. },
  1402. //排版图片下方的文字
  1403. centerImageText=function(node){
  1404. var ne,s;
  1405. while(node && node.tagName!='BODY'){
  1406. ne = node;
  1407. while(ne = ne.nextSibling){
  1408. if(isEmptyNode(ne)) continue;
  1409. if(ne.nodeName==='#text'){
  1410. div = TQE.CE('CENTER','',ne.nodeValue);
  1411. //div.style.textAlign='center';
  1412. node.parentNode.insertBefore(div,ne);
  1413. TQE.removeNode(ne,true);
  1414. return ;
  1415. }else{
  1416. if(ne.tagName=='CENTER') return;
  1417. if(ne.tagName=='P') ne.align='center';
  1418. else ne.style.textAlign='center';
  1419. return ;
  1420. }
  1421. }
  1422. node=node.parentNode;
  1423. }
  1424. };
  1425. //排版图片
  1426. es=TQE._tags(d,'IMG');
  1427. for(i=es.length-1;i>=0;i--){
  1428. e=es[i];
  1429. if(e.getAttribute('emot')) continue;//表情
  1430. if($.config.typesetImageTextCenter)centerImageText(e);
  1431. e.removeAttribute('style');
  1432. e.border= $.config.typesetImageBorder ? '1':'0';
  1433. e.style.margin='5px';
  1434. //e.style.margin='5px auto';
  1435. //e.style.display='block';
  1436. ep=e.parentNode;
  1437. if(ep.tagName=='A' && ep.firstChild==ep.lastChild){
  1438. e=ep;
  1439. ep=ep.parentNode;
  1440. }
  1441. if(ep.tagName=='P' && ep.align=='center' || ep.tagName=='CENTER' || ep.style.textAlign=='center') continue;
  1442. div = TQE.CE('CENTER');
  1443. ep.insertBefore(div, e);
  1444. div.appendChild(e);
  1445. }
  1446. //排版视频,flash等
  1447. es=TQE._tags(d,'OBJECT');
  1448. for(i=es.length-1;i>=0;i--){
  1449. e=es[i];
  1450. if($.config.typesetImageTextCenter)centerImageText(e);
  1451. ep=e.parentNode;
  1452. if(ep.tagName=='P' && ep.align=='center' || ep.tagName=='CENTER' || ep.style.textAlign=='center') continue;
  1453. div = TQE.CE('CENTER');
  1454. ep.insertBefore(div, e);
  1455. div.appendChild(e);
  1456. }
  1457. //排版视频,flash等
  1458. es=TQE._tags(d,'EMBED');
  1459. for(i=es.length-1;i>=0;i--){
  1460. e=es[i];
  1461. if('OBJECT'===e.parentNode.tagName) continue;
  1462. if($.config.typesetImageTextCenter) centerImageText(e);
  1463. ep=e.parentNode;
  1464. if(ep.tagName=='P' && ep.align=='center' || ep.tagName=='CENTER' || ep.style.textAlign=='center') continue;
  1465. div = TQE.CE('CENTER');
  1466. ep.insertBefore(div, e);
  1467. div.appendChild(e);
  1468. }
  1469. $.cleanWord(true);
  1470. };
  1471. //force 布尔值
  1472. $.cleanWord=function(force){
  1473. if('visual'!=$.currentMode()) return;
  1474. var d = $._getDoc(),s;
  1475. if(!force){
  1476. s= d.body.innerHTML;
  1477. if(s.indexOf('mso') <0 && s.search(/[a-z]+:[a-z0-9]+="[^\"]*"/ig)<0) return;
  1478. }
  1479. var cleanTag=function(tags, removeOnEmptyStyle){
  1480. for(var e,es,s,j,i=tags.length-1; i>=0; i--){
  1481. es=TQE._tags(d,tags[i]);
  1482. for(j=es.length-1;j>=0;j--){
  1483. e=es[j];
  1484. e.removeAttribute('lang');
  1485. s = e.getAttribute('style');
  1486. if(null==s && removeOnEmptyStyle){
  1487. TQE.removeNode(e,false);
  1488. continue;
  1489. }
  1490. if(typeof s =='string' && s.indexOf('mso-')>=0){
  1491. s+=';';
  1492. s=s.replace(/mso\-[^;]+?;/gi,'').replace(/FONT\-FAMILY[^;]+?;/gi,'').replace(/\s+/g,' ').replace(/MARGIN\: 0cm 0cm 0pt;/gi,'').replace(/tab\-stops\:[^;]+?;/gi,'');
  1493. if(''==s || ' '==s){
  1494. if(removeOnEmptyStyle){
  1495. TQE.removeNode(e,false);
  1496. continue;
  1497. }
  1498. e.removeAttribute('style');
  1499. }else{
  1500. e.setAttribute('style',s);
  1501. }
  1502. }
  1503. s = e.getAttribute('class');
  1504. if(null!=s){
  1505. s=s.replace(/mso[a-z\-]+\s*/gi,'').replace(/^xl[0-9]+$/i,'');
  1506. if(''==s){
  1507. e.removeAttribute('class');
  1508. }else{
  1509. e.setAttribute('class',s);
  1510. }
  1511. }
  1512. }
  1513. }
  1514. },
  1515. removeEmtpyTags=function(tags){
  1516. for(var e,es,s,j,i=tags.length-1; i>=0; i--){
  1517. es=TQE._tags(d,tags[i]);
  1518. for(j=es.length-1;j>=0;j--){
  1519. e=es[j];
  1520. if(e.innerHTML=='')TQE.removeNode(e,false);
  1521. }
  1522. }
  1523. };
  1524. cleanTag(['SPAN'],true);
  1525. cleanTag(['P','B','I','U','TD','TR','TABLE','DIV','COL','FONT'],false);
  1526. //.replace(/<([a-z][a-z0-9]*)[^>]*>\s*<\/\1>/gi,'') ,'FONT'
  1527. d.body.innerHTML=d.body.innerHTML.replace(/<o:[a-z0-9_]+[^>]*>/gi,'').replace(/<\/o:[a-z0-9_]+>/gi,'').replace(/<\?xml.+?\/>/gi,'').replace(/(<[a-z]+[^>]+>)/ig,function(m,p1){if(p1.indexOf(':')>0){ p1=p1.replace(/[a-z]+:[a-z0-9]+="[^\"]*"/ig,''); }return p1; });
  1528. cleanTag(['SPAN'],true);
  1529. removeEmtpyTags(['SPAN','FONT','B','U','I','STRONG','EM']);
  1530. $.save();
  1531. };
  1532. // 设置编辑器宽度,值大于1时,单位像, 小于1时是 百分比, 如 0.5表示50%
  1533. // 参数必须是0-1之间的小数或大于1的整数
  1534. $.setWidth=function(value){
  1535. if(value>1){
  1536. $.config.width=value+'px';
  1537. }else{
  1538. $.config.width=(value*100)+'%';
  1539. }
  1540. $._containerDiv.style.width= $.config.width;
  1541. };
  1542. //设置编辑器高度,单位像素
  1543. $.setHeight=function(value){
  1544. if(value<9) value=9;
  1545. $.config.height=value;
  1546. $._setHeight(value);
  1547. };
  1548. $._setHeight=function(value){
  1549. if(value<2)value=2;
  1550. $._editorObj().style.height= value+'px';
  1551. if('visual'==$.currentMode()){
  1552. value-=6;
  1553. if(value<2) value=2;
  1554. $._getDoc().body.style.minHeight=value+'px';
  1555. if(isIE6)$._getDoc().body.style.height=value+'px';
  1556. }
  1557. };
  1558. $._fixFull=function(){
  1559. var d=TQE._doc(),e=$._containerDiv, h;
  1560. e.style.zIndex='10000';
  1561. e.style.width=(d.clientWidth-2) + 'px';
  1562. e.style.top = TQE._docST()+'px';
  1563. e.style.left = TQE._docSL()+'px';
  1564. h = d.clientHeight-$._toolbarDiv.offsetHeight
  1565. $._setHeight(h- ('visual'==$.currentMode()?2:6));
  1566. //e.scrollIntoView();
  1567. //return;
  1568. //e=$._editorObj();
  1569. //if('visual'==$.currentMode()){
  1570. // $.setHeight(h-2);
  1571. // e.style.height= h-2 + 'px';
  1572. // d = $._getDoc();
  1573. // if(d.body){
  1574. // h-=6;
  1575. // if(h<2)h=2;
  1576. // d.body.style.minHeight=h+'px';
  1577. // if(isIE6)d.body.style.height=h+'px';
  1578. // }
  1579. // //e.style.width='';
  1580. //}else{
  1581. // //e.style.width=(d.clientWidth-6)+'px';
  1582. // e.style.height= h-7 + 'px';
  1583. //}
  1584. };
  1585. $._button=function(name){
  1586. //var btns = TQE._tags($._toolbarDiv,'LI'),i;
  1587. var btns = TQE._tags($._toolbarDiv,'A'),i;
  1588. for(i=btns.length-1;i>=0;i--){
  1589. if(name==btns[i].getAttribute('name') ) {//
  1590. return btns[i];
  1591. }
  1592. }
  1593. return null;
  1594. };
  1595. $.changeToolbarMode=function(advMode,force){
  1596. var e=$._toolbarDiv,btns,i,hOld=e.offsetHeight;
  1597. if(advMode===undefined || null===advMode){
  1598. advMode = (e.className=='eToolBar')?true:false;
  1599. }else if(force===undefined || !force){
  1600. if(advMode == (e.className!='eToolBar')) return;
  1601. }
  1602. if(advMode){
  1603. e.className='eToolBar eLargeIcons';
  1604. document.body.appendChild(e); //专用来修改IE6,7,8里编辑器直接父节点是P的bug。 即 <p><textarea id="forEditor"></textarea>
  1605. e.innerHTML=$._toobarCode($.config.advToolbar, $.config.advToolbarRight);
  1606. }else{ //toolbar common mode
  1607. e.className='eToolBar';
  1608. document.body.appendChild(e); //专用来修改IE6,7,8里编辑器直接父节点是P的bug。 即 <p><textarea id="forEditor"></textarea>
  1609. e.innerHTML=$._toobarCode($.config.toolbar, $.config.toolbarRight);
  1610. }
  1611. $._containerDiv.insertBefore(e,$._containerDiv.firstChild);//专用来修改IE6,7,8里编辑器直接父节点是P的bug。 即 <p><textarea id="forEditor"></textarea>
  1612. //if(isIE6 || isIE && (document.documentMode==7 || document.compatMode != "CSS1Compat")){//IE6或兼容视图或怪异模式
  1613. if( isIE && IEVersion<9){//ie6,7,8
  1614. //var groups = TQE._tags(e,'UL'),w;
  1615. var groups = TQE._tags(e,'SPAN'),w=0,j=0;
  1616. for(i=groups.length-1;i>=0;i--){
  1617. groups[i].style.width=groups[i].offsetWidth+2+'px';
  1618. //if(isIE6) break;
  1619. btns = TQE._tags(groups[i],'A');
  1620. w=0;
  1621. for(j=btns.length-1;j>=0;j--){
  1622. if(btns[j].offsetLeft+btns[j].offsetWidth > w) w= btns[j].offsetLeft+btns[j].offsetWidth;
  1623. }
  1624. w-=groups[i].offsetLeft-2;
  1625. if(w>0)groups[i].style.width=w+'px';
  1626. /*continue;
  1627. w=3;
  1628. btns=groups[i].childNodes;
  1629. for(j=btns.length-1;j>=0;j--){w += btns[j].offsetWidth;}
  1630. groups[i].style.minWidth=w+'px';
  1631. */
  1632. }
  1633. }
  1634. if(hOld){
  1635. $.setHeight($.config.height+hOld-e.offsetHeight);
  1636. if($._containerDiv.style.position=='absolute')$._fixFull();
  1637. }
  1638. TQE._noSel(e);
  1639. if($.config.showToolbarGroupHandle){
  1640. var w = e.getElementsByTagName('DIV')[0].offsetWidth;
  1641. e.style.marginLeft="-"+w+"px";
  1642. }
  1643. //btns = TQE._tags(e,'LI');
  1644. btns = TQE._tags(e,'A');
  1645. for(i=btns.length-1;i>=0;i--){
  1646. //$._ieMouseStyle(btns[i],'eButton','eButtonUp','eButtonDown'); //ie6
  1647. TQE.addListener(btns[i],'click', $._toolbarBottonClick);
  1648. TQE.addListener(btns[i],'mouseout', function(){
  1649. var o=TQE.activePop;
  1650. this.className= (o && o.relateObj==this)? 'eButtonDropDown':'eButton';
  1651. });
  1652. }
  1653. $._updateToolbar('visual'===$.currentMode(),['toolbarmode','mode','fullscreen','help'], true);
  1654. };
  1655. $.fullScreen=function(b){
  1656. var e=$._containerDiv,isVisualMode = 'visual'===$.currentMode(),o,btn;
  1657. if(b===undefined || null===b){
  1658. b = (e.style.position!='absolute');
  1659. }else{
  1660. if(b == (e.style.position=='absolute'))return;
  1661. }
  1662. //移动IFrame会导致内容丢失, 所以要转为代码模式
  1663. if(isVisualMode){
  1664. $.changeMode('code');
  1665. }
  1666. if(b){
  1667. //$.tl=[TQE._docST(),TQE._docSL()];
  1668. document.body.parentNode.style.overflow = 'hidden';
  1669. //e.parentNode.removeChild(e);
  1670. document.body.appendChild(e);
  1671. if(isVisualMode){
  1672. if(isGecko){//算是Firefox的bug吗?
  1673. window.setTimeout(function(){$.changeMode('visual');},1);
  1674. }else{
  1675. $.changeMode('visual');
  1676. }
  1677. }
  1678. e.style.position='absolute';
  1679. e.style.top = '0px';
  1680. $._fixFull();
  1681. TQE.addListener(window,'resize',$._fixFull);
  1682. }else{
  1683. //TQE._docST($.tl[0]);
  1684. //TQE._docSL($.tl[1]);
  1685. document.body.parentNode.style.overflow = 'auto';
  1686. TQE.delListener(window,'resize',$._fixFull);
  1687. e.style.position='';
  1688. e.style.width=$.config.width;
  1689. o=$._editorObj();
  1690. o.style.height=$.config.height+'px';
  1691. //e.parentNode.removeChild(e);
  1692. $.obj.parentNode.insertBefore(e,$.obj);
  1693. if(isVisualMode){
  1694. $.changeMode('visual');
  1695. }
  1696. e.scrollIntoView(false);
  1697. }
  1698. //更新全屏按钮图标
  1699. btn=$._button('fullscreen');
  1700. if(btn){
  1701. btn.id = b ? 'eBTNfullscreen-reset' : 'eBTNfullscreen';
  1702. }
  1703. };
  1704. $.setContent=function(code){
  1705. //code = ('code'==$.currentMode())? changeAsUbb(code): changeAsHtml(code);
  1706. if('code'===$.currentMode()){
  1707. $._editorObj().value=code;
  1708. }else{
  1709. if('function'===typeof $.config.onsetcontent) code=$.config.onsetcontent.call($,code);
  1710. $._getDoc().body.innerHTML=code;
  1711. }
  1712. $.save();
  1713. };
  1714. $._initContent=function(code){
  1715. if('code'!==$.currentMode()){
  1716. if((isGecko || isOpera) && '<br>'==code.substring(0,4)){
  1717. code=code.substr(4); // 怪怪的Firefox
  1718. }
  1719. if(isGecko) code = code.replace(/<td([^>]*)>\s*<\/td/ig, '<td$1 ><br></td');
  1720. var s= isIE6 ?'':'<!DOCTYPE html>',
  1721. d = $._getDoc(),
  1722. h;
  1723. s+='<html><head><style>\nbody{border:none;height:100%;margin:0;padding:2px;overflow:auto;';//
  1724. if($.config.bgColor || $.config.textColor){
  1725. if($.config.bgColor) s+='background-color:'+$.config.bgColor+';';
  1726. if($.config.textColor) s+='color:'+$.config.textColor+';';
  1727. }
  1728. s +='}\nimg{cursor:default;}\n.selectedTD{background:#3399ff !important;}\n.splitPage{display:block;width:98%;!important;border-top:#999 1px solid;border-bottom:#999 1px solid;background:#FFFFFF; color:#000000;font-weight:bold;text-align:center;margin:30px auto 5;padding-top:30px;clear:both;}\n.splitPage:before{content:"'+resStrPageTitlePre+'";}';
  1729. if ($.config.cssCode) {
  1730. s += $.config.cssCode
  1731. }
  1732. s +='</style>\n';
  1733. if($.config.baseHref!=''){
  1734. s +='<base href="'+$.config.baseHref+'" />';
  1735. }
  1736. if ($.config.css) {
  1737. s += '<link href="' +$.config.css+ '" rel="stylesheet" type="text/css">\n';
  1738. }
  1739. s+='</head><body contenteditable="true" ></body></html>';// '+ code+'
  1740. d.open();
  1741. d.write(s);
  1742. d.close();
  1743. h=Math.max(20,$._editorObj().offsetHeight-6);
  1744. if(d.body){
  1745. d.body.style.minHeight=h+'px';
  1746. if(isIE6)d.body.style.height=h+'px';
  1747. }
  1748. }
  1749. $.setContent(code);
  1750. $._changed();
  1751. };
  1752. $.setOpacity=function(e, opacity) {
  1753. if (isIE) {// && IEVersion<9
  1754. e.style.filter = (opacity == 100) ? '' : 'gray() alpha(opacity=' + opacity + ')';
  1755. } else {
  1756. e.style.opacity = (opacity == 100) ? '' : opacity/100;
  1757. }
  1758. };
  1759. $.inArray=function(e,arr){
  1760. for(var i=arr.length-1;i>=0;i--) if(e==arr[i]) return true;
  1761. return false;
  1762. };
  1763. $.content=function(){
  1764. var m=$.currentMode(), cells,i,code;
  1765. if('visual'===m){
  1766. cells = $.selectedCells();
  1767. for(i=cells.length-1;i>=0;i--){
  1768. cells[i].className='';
  1769. }
  1770. code= $._getDoc().body.innerHTML;
  1771. for(i=cells.length-1;i>=0;i--){
  1772. cells[i].className='selectedTD';
  1773. }
  1774. if((isGecko || isOpera) && '<br>'==code.substring(0,4)) code=code.substr(4);//怪怪的Firefox
  1775. if(''==code.replace(/<\/?(div|p|font|b|s|u|i|strong|em|strike)(?![a-z0-9])[^>]*>|&nbsp;|\s/ig , '')) code= '';
  1776. if('function'===typeof $.config.ongetcontent) code=$.config.ongetcontent.call($,code);
  1777. else code=TQE.formatHTML(code);
  1778. }else{
  1779. code= $._editorObj().value;
  1780. }
  1781. return code;
  1782. };
  1783. $._autoSave=function(b){
  1784. var e = $._editorObj(), func = b? TQE.addListener : TQE.delListener;
  1785. if (isIE ){
  1786. func(e,'beforedeactivate',$.save);
  1787. }else if('code'==$.currentMode()){
  1788. func(e,'blur',$.save);
  1789. }else{
  1790. func(e.contentWindow,'blur',$.save);
  1791. }
  1792. };
  1793. $.save=function(){
  1794. $.obj.value=$.content();
  1795. };
  1796. $._intEdit=function(obj){
  1797. if(obj.isIniEdit)return;
  1798. obj.isIniEdit=true;
  1799. obj.style.imeMode='disabled';
  1800. obj.onkeypress=function(){
  1801. if(45==event.keyCode){
  1802. this.value = ('-'==this.value.charAt(0))? this.value.substr(1) : '-'+this.value;
  1803. return false;
  1804. }
  1805. return event.keyCode>=48&&event.keyCode<=57;
  1806. };
  1807. obj.onpaste=function(){return !clipboardData.getData('text').match(/\D/);};
  1808. obj.ondragenter=function(){return ! /\D/.test(event.dataTransfer.getData('text'));};
  1809. obj.oldBlur=obj.onblur;
  1810. obj.onblur=function(){
  1811. if(''==this.value) return;
  1812. this.value=parseInt(this.value,10);
  1813. var max = this.getAttribute('max'),
  1814. min = this.getAttribute('min');
  1815. if(max!==undefined && parseInt(this.value,10)>parseInt(max,10))this.value=parseInt(max,10);
  1816. if(min!=undefined && parseInt(this.value,10)<parseInt(min,10))this.value=parseInt(min,10);
  1817. if(this.oldBlur)this.oldBlur();
  1818. };
  1819. };
  1820. //------------执行初始化
  1821. if(isIE6 || isIE && (document.documentMode==7 || document.compatMode != "CSS1Compat")){//IE6或兼容视图或怪异模式
  1822. var _topTableNode=function(node){
  1823. var reault=null;
  1824. while(node){
  1825. if(node.tagName=='TABLE'){
  1826. reault=node;
  1827. }
  1828. node = node.parentNode;
  1829. }
  1830. return reault;
  1831. },
  1832. t = _topTableNode(document.scripts(document.scripts.length-1));
  1833. if(t && _topTableNode(TQE.find(objId))===t ){
  1834. window.setTimeout($.init,20);
  1835. }else{
  1836. $.init();
  1837. }
  1838. }else{
  1839. $.init();
  1840. }
  1841. };
  1842. TQE.url='./';//编辑器相关资源网址
  1843. TQE.version = version; //编辑器版本
  1844. //-- init TQE resources
  1845. if(TQE.url==='./'){
  1846. var scripts = document.scripts || document.getElementsByTagName('SCRIPT'), //firefox
  1847. tqJSUrl = scripts[scripts.length-1].getAttribute('src'),
  1848. skinFind= /[\?&]skin=([a-z0-9_A-Z]+)/.exec(tqJSUrl),
  1849. l=window.location,
  1850. urlHost=l.protocol+'//'+l.host + (l.port?':'+l.port:'')+'/',
  1851. skinUrl='';
  1852. tqJSUrl=tqJSUrl.split('?')[0];
  1853. TQE.url = tqJSUrl.substring(0,tqJSUrl.lastIndexOf('/'));
  1854. if(''==TQE.url) TQE.url='./';
  1855. else TQE.url +='/';
  1856. if(TQE.url.indexOf(urlHost)===0) TQE.url=TQE.url.substring(urlHost.length-1, TQE.url.length);
  1857. document.write('<link href="'+TQE.url+(skinFind ? 'skin/'+skinFind[1]+'/':'')+'TQEditor.css" id="TQEditorSkinCSS" rel="stylesheet" type="text/css" onload="TQE.checkSkin(this)" />');
  1858. if(isIE && document.compatMode != "CSS1Compat"){
  1859. document.write('<link href="'+TQE.url+'QuirksMode.css" id="TQEditorQuirksMode" rel="stylesheet" type="text/css" onload="TQE.checkSkin(this)" />');
  1860. }
  1861. }
  1862. //配置
  1863. TQE.config={
  1864. "paragraphs" : [
  1865. ["正文", "p"],
  1866. ["标题1", "h1"],
  1867. ["标题2", "h2"],
  1868. ["标题3", "h3"],
  1869. ["标题4", "h4"],
  1870. ["标题5", "h5"],
  1871. ["标题6", "h6"],
  1872. ["预定义", "pre"]
  1873. ],
  1874. "fontnames" : [
  1875. ["宋体", "宋体"],
  1876. ["新宋体", "新宋体"],
  1877. ["仿宋_GB2312", "仿宋_GB2312"],
  1878. ["黑体", "黑体"],
  1879. ["微软雅黑", "微软雅黑"],
  1880. ["楷体_GB2312", "楷体_GB2312"],
  1881. ["Arial", "arial, helvetica, sans-serif"],
  1882. ["Courier New", "courier new, courier, mono"],
  1883. ["Georgia", "Georgia, Times New Roman, Times, Serif"],
  1884. ["Tahoma", "Tahoma, Arial, Helvetica, sans-serif"],
  1885. ["Times New Roman", "times new roman, times, serif"]
  1886. ],
  1887. "fontsizes": [
  1888. //[text,preview, value]
  1889. ["特小","xx-small", 1],
  1890. ["较小","x-small", 2],
  1891. ["小", "small", 3],
  1892. ["中", "medium", 4],
  1893. ["大", "large", 5],
  1894. ["较大","x-large", 6],
  1895. ["特大","xx-large", 7]
  1896. ],
  1897. "toolbar":'default',
  1898. "toolbarRight":[],
  1899. "advToolbar":['paragraph','fontname','fontsize','br','bold','italic','underline','strikethrough','forecolor','backcolor','removeformat','typeset',
  1900. '||','justifyleft','justifycenter','justifyright','justifynone',['superscript','subscript'],'br','orderedlist','unorderedlist','indent','outdent',
  1901. '||','inserthorizontalrule','splitpage','cleanword','br','createlink','unlink','inserttable',
  1902. '||','insertface','insertimage','insertmusic','insertflash','insertvideo'],
  1903. "advToolbarRight":['toolbarmode','br','fullscreen','mode','help'],
  1904. "advToolbarMode":false,
  1905. 'showToolbarGroupHandle':true, //显示工具组最前的图
  1906. //模板
  1907. //插入媒体***时的模板代码,
  1908. //flash 宏 {$url} {$width} {$height}
  1909. 'tplFlash':'<embed src="{$url}" width="{$width}" height="{$height}" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always"></embed>',
  1910. //flv视频 宏 {$url} {$width} {$height} {$auto_start}
  1911. 'tplFlv':'<embed src="'+TQE.url+'flvPlayer.swf" flashvars="vcastr_file={$url}&IsAutoPlay={$auto_start}" width="{$width}" height="{$height}" quality="high" bgcolor="#0E0E0E" name="play" align="middle" allowscriptaccess="sameDomain" allowfullscreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="opaque" />',
  1912. //rm视频 宏 {$url} {$width} {$height} {$auto_start}
  1913. 'tplRm':'<embed src="{$url}" width={$width} height={$height} autostart="{$auto_start}"type="audio/x-pn-realaudio-plugin" console="Clip1" controls="ImageWindow" ></embed>',
  1914. //windows的媒体文件 宏 {$url} {$width} {$height} {$auto_start}
  1915. 'tplVideo':'<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-ms-wmp" width="{$width}" height="{$height}"><PARAM NAME="URL" VALUE="{$url}" /><PARAM NAME="autoStart" VALUE="{$auto_start}" /><PARAM NAME="invokeURLs" VALUE="false"><PARAM NAME="playCount" VALUE="100"><PARAM NAME="Volume" VALUE="100"><PARAM NAME="defaultFrame" VALUE="datawindow"></object>',
  1916. //音乐播放 宏 {$url} {$auto_start}
  1917. 'tplMusic':'<object id="tqeMP" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-ms-wmp" width="230" height="64"><PARAM NAME="URL" VALUE="{$url}" /><PARAM NAME="autoStart" VALUE="{$auto_start}" /><PARAM NAME="invokeURLs" VALUE="false"><PARAM NAME="playCount" VALUE="100"><PARAM NAME="Volume" VALUE="100"><PARAM NAME="defaultFrame" VALUE="datawindow"></object>',
  1918. //分页符代码
  1919. 'tplSplitPage':'<h3 class="splitPage" name="split_page"></h3>',
  1920. 'uploadFieldName':'file',//接收上传时的上传表单名
  1921. 'imageUploadUrl':'',//接收上传图片网址, 留空表示不允许上传, 以#开头, 表示点击上传按扭后的界面网址
  1922. 'imageFileTypes':'*.jpg;*.gif;*.png;*.jpeg',//允许上传的图片后缀
  1923. 'imageFileSize':'2MB',//允许上传文件大小
  1924. 'directInsertUploadImage':false,//直接将上传的图片插入编辑器中
  1925. 'linkUploadUrl':'',//接收上传网址, 留空表示不允许上传, 以#开头, 表示点击上传按扭后的界面网址
  1926. 'linkFileTypes':'*.*',//允许上传的后缀
  1927. 'linkFileSize':'2MB',//允许上传文件大小
  1928. 'flashUploadUrl':'',//接收上传Flash网址, 留空表示不允许上传, 以#开头, 表示点击上传按扭后的界面网址
  1929. 'flashFileTypes':'*.swf',//允许上传的图片后缀
  1930. 'flashFileSize':'2MB',//允许上传文件大小
  1931. 'musicUploadUrl':'',//接收上传音频文件网址, 留空表示不允许上传, 以#开头, 表示点击上传按扭后的界面网址
  1932. 'musicFileTypes':'*.mp3;*.wma',//允许上传音频文件后缀
  1933. 'musicFileSize':'2MB',//允许上传文件大小
  1934. 'videoUploadUrl':'',//接收上传视频文件网址, 留空表示不允许上传, 以#开头, 表示点击上传按扭后的界面网址
  1935. 'videoFileTypes':'*.flv;.mp4;*.mkv;*.wmv;*.asf;*.avi;*.rmvb;*.rm',//允许上传的文件后缀
  1936. 'videoFileSize':'2MB',//允许上传文件大小
  1937. 'enter2br':false,
  1938. //'formatHTML':true,//对HTML源码进行美化(换行与缩进)
  1939. //'height_delta':20,
  1940. 'width':'auto',
  1941. 'height':'auto',
  1942. 'autoClean':true,//在执行粘贴时,自动清理word相关的垃圾代码
  1943. 'faceCount':55,//表情数量, 在face目录中
  1944. 'css':'',//设计辅助的相关样式网址
  1945. 'cssCode':'',//直接指定设计辅助的相关样式代码
  1946. 'bgColor':'', //可视化编辑时, 编辑器背景色
  1947. 'textColor':'', //可视化编辑时, 文字色
  1948. 'autoPopImagePanel':true, //自动弹出图片面板
  1949. 'autoPopTablePanel':true, //自动弹出表格操作面板(插入行/列,删行/列/表格)
  1950. 'typesetImageTextCenter':true,//自动排版图片下方的文字居中
  1951. 'typesetIndentParagraph':false,//自动排版段落首行缩进2字
  1952. 'typesetImageBorder':true,//自动排版图片添边框
  1953. 'baseHref':'',//设置相对网址的基网址
  1954. 'resize':false,//允许修改编辑器尺寸
  1955. 'onfocus':null,//获取焦点时的回调, function(event){}
  1956. 'onblur':null,//失去焦点时的回调, function(event){}
  1957. 'onkeydown':null,//当用户按下键盘按键时触发, function(event){}
  1958. 'onkeyup':null,//当用户释放键盘按键时触发, function(event){}
  1959. 'onpaste':null,//当粘贴时触发, function(event){}
  1960. 'oninit':null,//设置执行初始化时的回调函数, function(){}
  1961. 'ongetcontent':null,//取代码时的事件回调函数, function(code){}
  1962. 'onsetcontent':null,//设置代码时的事件回调函数, function(code){}
  1963. //'onuploaded':null,//上传成功后的回调函数
  1964. 'debug':false
  1965. };
  1966. TQE.find=function(id){return document.getElementById(id);};
  1967. TQE.CE=function(tag,id, htm, append){
  1968. var o=document.createElement(tag);
  1969. if(id)o.id=id;
  1970. if(htm)o.innerHTML=htm;
  1971. if(append) document.body.appendChild(o);
  1972. return o;
  1973. };
  1974. TQE.loadSkin=function(skin){
  1975. var e = TQE.find('TQEditorSkinCSS');
  1976. e.href= TQE.url+(skin &&'default'!=skin ? 'skin/'+skin+'/':'')+'TQEditor.css';
  1977. };
  1978. TQE.checkSkin=function(linkObj){
  1979. var i,objs=document.styleSheets,rules;
  1980. for(i=objs.length-1;i>=0;i--){
  1981. if(objs[i].href==linkObj.href){
  1982. rules = objs[i].cssRules || objs[i].rules;
  1983. if(rules.length<1) linkObj.href= TQE.url+'TQEditor.css';
  1984. break;
  1985. }
  1986. }
  1987. };
  1988. TQE._doc=function(){return (document.compatMode != "CSS1Compat") ? document.body : document.documentElement;};
  1989. TQE._docST=function(){
  1990. return window.scrollY ? window.scrollY : TQE._doc().scrollTop ;
  1991. };
  1992. TQE._docSL=function(){
  1993. return window.scrollX ? window.scrollX : TQE._doc().scrollLeft ;
  1994. };
  1995. TQE.pos=function(e){
  1996. var x = 0, y = 0;
  1997. //if (e.getBoundingClientRect) {
  1998. var box = e.getBoundingClientRect(),
  1999. d=TQE._doc();
  2000. x = box.left + TQE._docSL() - d.clientLeft;
  2001. y = box.top + TQE._docST() - d.clientTop;
  2002. //} else {
  2003. // x = e.offsetLeft;
  2004. // y = e.offsetTop;
  2005. // var parent = e.offsetParent;
  2006. // while (parent) {
  2007. // x += parent.offsetLeft;
  2008. // y += parent.offsetTop;
  2009. // parent = parent.offsetParent;
  2010. // }
  2011. //}
  2012. return {'x' : x, 'y' : y, left:x, top:y, width:e.offsetWidth, height:e.offsetHeight};
  2013. };
  2014. TQE._hideContext=function(){
  2015. if(TQE.activeContext){
  2016. TQE.activeContext.style.display="none";
  2017. TQE.activeContext=null;
  2018. }
  2019. };
  2020. TQE.pop=function(obj,relateObj){
  2021. if(TQE.activePop==obj){
  2022. TQE.hidePop();
  2023. return false;
  2024. }
  2025. TQE._hideContext();
  2026. TQE.hidePop();
  2027. TQE.activePop=obj;
  2028. obj.relateObj=relateObj;
  2029. relateObj.className='eButtonDropDown';
  2030. obj.style.display='block';
  2031. var p=TQE.pos(relateObj),
  2032. l=p.x,
  2033. t= 1+relateObj.clientHeight +p.y,
  2034. dl = TQE._docSL(),
  2035. w = TQE._doc().clientWidth;
  2036. if(l+obj.offsetWidth>dl+w)l-=obj.offsetWidth-relateObj.offsetWidth;
  2037. obj.style.left= l + 'px';
  2038. obj.style.top = t+ 'px';
  2039. return true;
  2040. };
  2041. TQE.hidePop=function(){
  2042. if(!TQE.activePop) return;
  2043. var o=TQE.activePop;
  2044. TQE.activePop=null;
  2045. o.style.display='none';
  2046. if(o.relateObj && o.relateObj.className=='eButtonDropDown') o.relateObj.className='eButton';
  2047. o=TQE.find('ColorPicker');
  2048. if(o)o.style.display='none';
  2049. };
  2050. TQE.delListener=function(e,eventName,func){
  2051. if(e.removeEventListener) {
  2052. e.removeEventListener(eventName, func, false );
  2053. }else{
  2054. e.detachEvent('on'+eventName, e['e'+eventName+func]);
  2055. }
  2056. };
  2057. TQE.addListener=function(e,eventName,func){
  2058. if(e.addEventListener) {
  2059. e.addEventListener( eventName, func, false );
  2060. }else{
  2061. e['fn'+func]=func;
  2062. e['e'+eventName+func]=function(et){e['fn'+func](et)};
  2063. e.attachEvent('on'+eventName, e['e'+eventName+func]);//
  2064. }
  2065. };
  2066. TQE._tags=function(domNode, tagName){
  2067. return domNode.getElementsByTagName(tagName);
  2068. };
  2069. TQE.listenTags=function(node,tag,eventname,func){
  2070. var ds = TQE._tags(node,tag),i;
  2071. for(i=ds.length-1;i>=0;i--){
  2072. TQE.addListener(ds[i],eventname,func);
  2073. }
  2074. };
  2075. TQE._noSel=function(o, tagsName){
  2076. var noSel=function(){
  2077. if(isIE){
  2078. var tn=event.srcElement.tagName;
  2079. return 'INPUT'==tn || 'TEXTAREA'==tn;
  2080. }
  2081. return false;
  2082. };
  2083. if(tagsName){
  2084. var a=tagsName.split(','),nodes,i,j;
  2085. for(j=a.length-1;j>=0;j--){
  2086. nodes = TQE._tags(o,a[j]);
  2087. for(i=nodes.length-1; i>=0;i--){
  2088. nodes[i].unselectable='on';
  2089. nodes[i].onselectstart = noSel
  2090. }
  2091. }
  2092. }else{
  2093. o.unselectable='on';
  2094. o.onselectstart = noSel;
  2095. }
  2096. };
  2097. TQE._colorPickerUI=function(){
  2098. var ColorHex=['00','33','66','99','CC','FF'],
  2099. SpColorHex=['FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF'],
  2100. w=191,//1+19*10
  2101. colorTable='<table width="'+w+'" cellpadding=0 ',i,j,k,
  2102. colorTD=function(color){ return '<td bgcolor="#'+color+'" style="width:10px;height:10px;border:1px inset #999; overflow:hidden;padding:0;margin:0;"></td>';};
  2103. colorTable += isIE ? 'cellspacing=1 border=0 bgcolor="#000000;">':'cellspacing=0 border=1 style="border-collapse:collapse;" >';
  2104. for (i=0;i<2;i++){
  2105. for (j=0;j<6;j++){
  2106. colorTable += '<tr height=10>';
  2107. //colorTable += '<td bgcolor="#000" name="'+name+'" ></td>';
  2108. if (i>0) colorTable += colorTD(SpColorHex[j]);
  2109. else colorTable += colorTD(ColorHex[j]+ColorHex[j]+ColorHex[j]);
  2110. //colorTable += '<td bgcolor="#000"></td>';
  2111. for (k=0;k<3;k++){
  2112. for (l=0;l<6;l++){
  2113. //立方色
  2114. colorTable += colorTD(ColorHex[k+i*3]+ColorHex[l]+ColorHex[j]);
  2115. //连续色
  2116. //var c1 = 4+i-k*2;
  2117. //var c2 = i*j + (1-i)*(5-j);// i?j:5-j
  2118. //var c3 = k!=1? 5-l:l; //k!=1? 5-l:l;
  2119. //colorTable += '<td bgcolor="#'+ColorHex[c1]+ColorHex[c2]+ColorHex[c3]+'"></td>';
  2120. }
  2121. }
  2122. colorTable += '</tr>';
  2123. }
  2124. }
  2125. colorTable +='</table>'+
  2126. '<div style="padding:2px 2px 1px 2px;line-height:25px;"><div style="height:25px;width:60px;display:block;float:left; margin-right:5px;" name=colorPreview></div><span name="colorValue" style="width:50px; display:inline-block;"></span><input type="button" value="'+resStrNoColor+'" /></div>';
  2127. return colorTable;
  2128. };
  2129. TQE.pickColor=function(callbackFunc,x,y){
  2130. var o=TQE.find('ColorPicker');
  2131. if(null==o){
  2132. o = TQE.CE('DIV','ColorPicker', TQE._colorPickerUI() ,true);
  2133. o.className='ePopPanel';
  2134. o.style.zIndex=99999999;
  2135. o.onmouseover=function(){this.active=true;};
  2136. o.onmouseout=function(){this.active=false;};
  2137. TQE._noSel(o);//,'TABLE,TR,TD,DIV');
  2138. TQE.listenTags(o,'TD','mouseover',function(){
  2139. var self=this,
  2140. p=this.parentNode.parentNode.parentNode.parentNode.lastChild,
  2141. iid = window.setInterval(function(){self.style.backgroundColor=(self.style.backgroundColor!='')?'':'#FFFFFF'},500);
  2142. p.firstChild.style.backgroundColor=this.bgColor;
  2143. p.firstChild.nextSibling.innerHTML=this.bgColor;
  2144. self.style.backgroundColor='#FFFFFF';
  2145. self.onmouseout=function(){window.clearInterval(iid);this.style.backgroundColor='';}
  2146. });
  2147. o.lastChild.lastChild.onclick=function(){this.parentNode.parentNode.style.display='none';};
  2148. TQE.listenTags(o,'TD','mouseup',function(){this.parentNode.parentNode.parentNode.parentNode.style.display='none';});
  2149. TQE.addListener(document,'mousedown',function(){var o=TQE.find('ColorPicker');if(!o.active)o.style.display='none';});
  2150. }
  2151. var ds = TQE._tags(o,'TD');
  2152. for(var i=ds.length-1;i>=0;i--){
  2153. ds[i].onmousedown=function(e){callbackFunc(this.bgColor); e = e || event; e.cancelBubble=true; }
  2154. }
  2155. o.lastChild.lastChild.onclick=function(e){callbackFunc(''); e = e || event; e.cancelBubble=true;};
  2156. o.style.left=x+'px';
  2157. o.style.top=y+'px';
  2158. o.style.display='block';
  2159. };
  2160. TQE.drag=function(o){
  2161. o.style.position='absolute';
  2162. o.style.userSelect='none';
  2163. o.style.mozUserSelect='none';
  2164. o.style.webkitUserSelect='none';
  2165. o.dragging=false;
  2166. o.onmousedown=function(a){
  2167. var x,y,obj,n,
  2168. p=TQE.pos(this),
  2169. scrollLeft = TQE._docSL(),
  2170. scrollTop =TQE._docST();
  2171. if(isIE){
  2172. a=window.event;
  2173. //if(a.button!=0) return;
  2174. obj=a.srcElement;
  2175. x=scrollLeft + a.clientX-p.x;
  2176. y=scrollTop + a.clientY-p.y;
  2177. }else{
  2178. //if(a.button!=0) return;
  2179. obj=a.target;
  2180. x=a.pageX-p.x;
  2181. y=a.pageY-p.y;
  2182. }
  2183. if(o.dragging)return ;
  2184. n=obj.tagName;
  2185. if(obj!=this && ( n=='INPUT' || n=='TEXTAREA'|| n=='BUTTON'|| n=='SELECT')) return;
  2186. o.dragging=true;
  2187. var mousemove=function(a){
  2188. if(isIE){
  2189. a=window.event;
  2190. a.pageX=scrollLeft + a.clientX;
  2191. a.pageY=scrollTop + a.clientY;
  2192. }
  2193. var tx=a.pageX-x, ty=a.pageY-y;
  2194. o.style.left=tx +'px';
  2195. o.style.top=ty +'px';
  2196. o.style.cursor='move';
  2197. },
  2198. mouseup=function(){
  2199. o.style.cursor='';
  2200. o.dragging=false;
  2201. };
  2202. TQE._draging(mousemove,mouseup,o);
  2203. };
  2204. };
  2205. TQE._draging=function(mousemove,mouseup,o){
  2206. if(TQE._draging.running) return;
  2207. if(o.setCapture)
  2208. o.setCapture();
  2209. else if(window.captureEvents)
  2210. window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
  2211. TQE._draging.running=true;
  2212. TQE._draging.mm=document.onmousemove;
  2213. TQE._draging.mu=document.onmouseup;
  2214. var maskDiv=TQE.CE('DIV','','',true);//ie6,webkit
  2215. maskDiv.className='eDragMaskDiv';
  2216. maskDiv.style.height=Math.max(document.documentElement.clientHeight, document.body.scrollHeight)+'px';
  2217. document.onmousemove=mousemove;
  2218. document.onmouseup=function(a){
  2219. if(maskDiv) document.body.removeChild(maskDiv);
  2220. maskDiv=null;
  2221. document.onmousemove=TQE._draging.mm;
  2222. document.onmouseup=TQE._draging.mu;
  2223. if(o.releaseCapture)
  2224. o.releaseCapture();
  2225. else if(window.releaseEvents)
  2226. window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
  2227. TQE._draging.running=false;
  2228. mouseup(a);
  2229. }
  2230. return maskDiv;
  2231. };
  2232. TQE._draging.running=null;
  2233. //TQE._draging.mm=null;
  2234. //TQE._draging.mu=null;
  2235. TQE.clone=function(srcObj){
  2236. if(typeof(srcObj) != 'object') return srcObj;
  2237. if(srcObj == null) return srcObj;
  2238. var i, newObj = '[object Array]'==Object.prototype.toString.call(srcObj)? [] : {};
  2239. for(i in srcObj) newObj[i] = TQE.clone(srcObj[i]);
  2240. return newObj;
  2241. };
  2242. TQE.removeNode=function(node, delChild){
  2243. if(node.removeNode) return node.removeNode(delChild); //ie
  2244. if(delChild) return node.parentNode.removeChild(node);
  2245. while(node.firstChild) node.parentNode.insertBefore(node.firstChild,node);
  2246. node.parentNode.removeChild(node);
  2247. };
  2248. //table functions
  2249. TQE.updateCellsStatus=function(table){
  2250. var rows=table.rows,cells,cells2,td,td2, i,j,k,l;
  2251. for(i=0;i<rows.length;i++){
  2252. k=0;
  2253. for(j=0;j<rows[i].cells.length;j++){
  2254. td= rows[i].cells[j];
  2255. td.colStart=k;
  2256. k += td.colSpan;
  2257. td.colEnd= k-1;
  2258. td.rowStart=i;
  2259. td.rowEnd= i+td.rowSpan-1;
  2260. }
  2261. }
  2262. //fix colIndex
  2263. for(i=0;i<rows.length;i++){
  2264. cells= rows[i].cells;
  2265. for(j=0;j<cells.length;j++){
  2266. if(cells[j].rowSpan<2) continue;
  2267. for(k=1;k<cells[j].rowSpan; k++){
  2268. if(!rows[i+k]) break;
  2269. cells2= rows[i+k].cells;
  2270. td= cells[j];
  2271. for(l=0;l<cells2.length;l++){
  2272. td2= cells2[l];
  2273. if(td2.colStart >= td.colStart){
  2274. td2.colStart += td.colSpan;
  2275. td2.colEnd += td.colSpan;
  2276. }
  2277. }
  2278. }
  2279. }
  2280. }
  2281. //fix rowIndex
  2282. for(i=rows.length-1;i>=0;i--){
  2283. cells= rows[i].cells;
  2284. var minrs=cells[0].rowSpan;
  2285. for(j=cells.length-1;j>0;j--){
  2286. minrs = Math.min(minrs,cells[j].rowSpan);
  2287. if(minrs<2)break;
  2288. }
  2289. if(--minrs > 0){
  2290. for(j=cells.length-1;j>=0;j--){
  2291. cells[j].rowSpan-=minrs;
  2292. cells[j].rowEnd -=minrs;
  2293. }
  2294. for(k=i-1;k>=0;k--){
  2295. for(l=rows[k].cells.length-1;l>=0;l--){
  2296. if(rows[k].cells[l].rowEnd>cells[0].rowStart){
  2297. rows[k].cells[l].rowSpan-=minrs;
  2298. rows[k].cells[l].rowEnd-=minrs;
  2299. }
  2300. }
  2301. }
  2302. }
  2303. }
  2304. };
  2305. TQE.insertCol=function(cell, bBegin){
  2306. var table=cell.parentNode.parentNode.parentNode,cells,td,td2, i=0,j, colIndex, cc, row, rowCount=table.rows.length;
  2307. TQE.updateCellsStatus(table);
  2308. colIndex= bBegin?cell.colStart : cell.colEnd+1;
  2309. //for(i=table.rows.length-1;i>=0;i--){
  2310. while(i<rowCount){
  2311. row= table.rows[i];
  2312. i++;
  2313. cells= row.cells;
  2314. td=null;
  2315. for(j=Math.min(colIndex, cells.length-1);j>=0;j--){
  2316. cc=cells[j];
  2317. if(cc.colStart<=colIndex){
  2318. if(cc.colStart<colIndex && cc.colEnd>=colIndex){
  2319. cc.colSpan++;
  2320. cc.colEnd++;
  2321. i+=cc.rowSpan-1;
  2322. }else{
  2323. td=row.insertCell(cc.colStart!=colIndex && (cc.colEnd==colIndex-1 || j==cells.length-1) ? j+1 : j);
  2324. }
  2325. //if(cc.colStart==colIndex){
  2326. // td=row.insertCell(j);
  2327. //}else if(cc.colEnd==colIndex-1){
  2328. // td=row.insertCell(j+1);
  2329. //}else if(cc.colSpan>1 && cc.colEnd>=colIndex){
  2330. // cc.colSpan++;
  2331. //}else if(j==cells.length-1 && cc.colEnd<colIndex){
  2332. // td=row.insertCell(j+1);
  2333. //}
  2334. if(td){
  2335. if(bBegin){
  2336. td2=td.nextSibling;
  2337. if(td2 && td2.rowSpan<2 && td2.colStart==colIndex){
  2338. td.style.backgroundColor = td2.style.backgroundColor;
  2339. }
  2340. }else{
  2341. td2 = td.previousSibling;
  2342. if(td2 && td2.rowSpan<2 && td2.colEnd==colIndex-1){
  2343. td.style.backgroundColor = td2.style.backgroundColor;
  2344. }
  2345. }
  2346. }
  2347. break;
  2348. }
  2349. }
  2350. }
  2351. };
  2352. TQE.insertRow=function(cell, bBegin){
  2353. var table=cell.parentNode.parentNode.parentNode,cells, row, cells2, i,j,k=0, rowIndex;
  2354. TQE.updateCellsStatus(table);
  2355. rowIndex= bBegin?cell.rowStart : cell.rowEnd+1;
  2356. for(i=Math.min(table.rows.length-1, rowIndex-1);i>=0;i--){
  2357. cells= table.rows[i].cells;
  2358. for(j=cells.length-1;j>=0;j--){
  2359. if(cells[j].rowEnd>=rowIndex){
  2360. cells[j].rowSpan++;
  2361. k+=cells[j].colSpan;
  2362. }
  2363. }
  2364. }
  2365. cells= table.rows[0].cells;
  2366. for(j=cells.length-1;j>=0;j--){
  2367. k -= cells[j].colSpan;
  2368. }
  2369. row = table.insertRow(rowIndex);
  2370. while(k++ <0){
  2371. row.insertCell(0).innerHTML='&nbsp;';
  2372. }
  2373. TQE.updateCellsStatus(table);
  2374. cells = row.cells;
  2375. cells2 = table.rows[ bBegin ? rowIndex+1 : rowIndex-1].cells;
  2376. j=cells2.length-1;
  2377. for(i=cells.length-1;i>=0;i--){
  2378. while(j>=0 && cells2[j].colStart > cells[i].colStart ) j--;
  2379. if(j>=0 && cells2[j].colStart == cells[i].colStart && cells2[j].colEnd == cells[i].colEnd ){
  2380. cells[i].style.backgroundColor = cells2[j].style.backgroundColor;
  2381. }
  2382. }
  2383. };
  2384. TQE.deleteCol=function(cell){
  2385. var table=cell.parentNode.parentNode.parentNode,rows=table.rows,td, i,j, start,end;
  2386. TQE.updateCellsStatus(table);
  2387. start=cell.colStart;
  2388. end=cell.colEnd;
  2389. for(i=rows.length-1;i>=0;i--){
  2390. for(j=Math.min(end,rows[i].cells.length-1);j>=0;j--){
  2391. td=rows[i].cells[j];
  2392. if(td.colEnd>=start && td.colStart<=end){
  2393. if(td.colStart>=start && td.colEnd<=end) rows[i].removeChild(td);
  2394. else if(td.colStart<start && td.colEnd>end) td.colSpan -= 1+end-start;
  2395. else if(td.colStart<start && td.colEnd>=start) td.colSpan -= td.colEnd-start+1;
  2396. else if(td.colStart<=end && td.colEnd>end){ td.colSpan -= 1+end-td.colStart; td.innerHTML='';}
  2397. }
  2398. }
  2399. if(rows[i].cells.length<1) rows[i].parentNode.removeChild(rows[i]);
  2400. }
  2401. if(rows.length<1) table.parentNode.removeChild(table);
  2402. };
  2403. TQE.deleteRow=function(cell){
  2404. var table=cell.parentNode.parentNode.parentNode,rows=table.rows,nextRow,td,td2, i,j,k, start,end;
  2405. TQE.updateCellsStatus(table);
  2406. start=cell.rowStart;
  2407. end=cell.rowEnd;
  2408. delRowCount=cell.rowSpan;
  2409. nextRow=rows[end+1];
  2410. for(i=Math.min(end,rows.length-1);i>=0;i--){
  2411. for(j=rows[i].cells.length-1;j>=0;j--){
  2412. td=rows[i].cells[j];
  2413. if(td.rowEnd>=start && td.rowStart<=end) {
  2414. if(td.rowStart>=start && td.rowEnd<=end) rows[i].removeChild(td);
  2415. else if(td.rowStart<start && td.rowEnd>end) td.rowSpan -= delRowCount;
  2416. else if(td.rowStart<start && td.rowEnd>=start) td.rowSpan -= td.rowEnd-start+1;
  2417. else if(td.rowStart<=end && td.rowEnd>end){
  2418. if(nextRow){
  2419. for(k=0;k<nextRow.cells.length;k++){
  2420. if(nextRow.cells[k].colStart>td.colEnd){
  2421. break;
  2422. }
  2423. }
  2424. td2=nextRow.insertCell(k);
  2425. td2.rowSpan= td.rowSpan-delRowCount;
  2426. td2.colSpan=td.colSpan;
  2427. td2.colStart=td.colStart;
  2428. td2.colEnd=td.colEnd;
  2429. td2.style.backgroundColor=td.style.backgroundColor;
  2430. }
  2431. rows[i].removeChild(td);
  2432. }
  2433. }
  2434. }
  2435. if(rows[i].cells.length<1) rows[i].parentNode.removeChild(rows[i]);
  2436. }
  2437. if(rows.length<1) table.parentNode.removeChild(table);
  2438. };
  2439. TQE.formatHTML=function(htmStr){
  2440. return htmStr.replace(/\s*<(p|table|tr|hr|div|object|ol|li|ul|h[1-6])(?![a-z])/ig,'\n<$1')
  2441. .replace(/<\/(p|table|div|object|ol|ul|h[1-6])>\s*/ig,'</$1>\n')
  2442. .replace(/(<(?:br|hr)(?![a-z0-9])[^>]*>)\s*/ig,'$1\n')
  2443. .replace(/^\s*/,'').replace(/\s*$/,'')
  2444. };
  2445. //常用工具栏模式
  2446. TQE.toolbarMode={
  2447. admin:{left:['paragraph','fontsize','|','bold','italic','underline','forecolor','backcolor','removeformat','|','justifyleft','justifycenter','orderedlist','unorderedlist',['justifyright','|','indent','outdent','|','superscript','subscript'],
  2448. '||','createlink','insertimage','inserttable',['splitpage','inserthorizontalrule'],'|','insertmusic','insertflash','insertvideo',
  2449. '||','cleanword','typeset'],
  2450. right:['toolbarmode','fullscreen','|','help']},
  2451. bbs:{left:['fontsize','|','bold','italic','underline','forecolor','backcolor','removeformat','|','justifyleft','justifycenter','justifyright',
  2452. '||','createlink','insertimage','|','insertface','insertmusic','insertflash','insertvideo','|','typeset'],
  2453. right:['toolbarmode','fullscreen','|','help']},
  2454. user:{left:['fontsize','|','bold','italic','underline','forecolor','backcolor','removeformat','|','justifyleft','justifycenter','orderedlist',['justifyright','unorderedlist','|','indent','outdent','|','inserthorizontalrule'],
  2455. '||','createlink','insertimage','insertvideo','|','typeset'],
  2456. right:['toolbarmode','fullscreen','|','help']},
  2457. mini:{left:['fontsize','|','bold','italic','underline','forecolor','backcolor','removeformat','|','align','|','createlink','insertimage'],
  2458. right:['fullscreen']},
  2459. message:{left:['insertface','|','bold','italic','underline','forecolor','removeformat'],
  2460. right:['help']},
  2461. full:{left:['paragraph','fontname','fontsize','|','bold','italic','underline','strikethrough','forecolor','backcolor','removeformat',
  2462. '||','align','list','iodent',['superscript','subscript'],
  2463. '||','createlink','unlink','insertimage','inserttable','inserthorizontalrule','splitpage','insertface','|','insertmusic','insertflash','insertvideo',
  2464. '||','cleanword','typeset'],
  2465. right:['toolbarmode','fullscreen','mode']},
  2466. normal:{left:['paragraph','fontsize','|','bold','italic','underline','forecolor','backcolor','removeformat',
  2467. '||','justifyleft','justifycenter','orderedlist','unorderedlist',
  2468. '||','createlink','insertimage','inserttable','|','insertvideo','|','typeset'],
  2469. right:['toolbarmode','fullscreen']}
  2470. };
  2471. //可用的按钮
  2472. TQE.toolbarBottons={
  2473. paragraph:{
  2474. text:'段落',
  2475. click:function($,sender){
  2476. var o=TQE.find($.objId+'Paragraph'),i;
  2477. if(null==o){
  2478. var s='',fs=$.config.paragraphs;
  2479. for(i=0;i < fs.length; i++){
  2480. s +='<div name="FormatBlock" class="eMenuItem" unselectable=on onselectstart="return false" paraValue="'+fs[i][1]+'">'+fs[i][0]+'</div>';
  2481. }
  2482. o = TQE.CE('DIV',$.objId+'Paragraph',s,true);
  2483. o.className='ePopPanel';
  2484. TQE._noSel(o);//,'DIV'
  2485. TQE.listenTags(o,'DIV','click',function(){
  2486. TQE.hidePop();
  2487. var pv=this.getAttribute('paraValue');
  2488. if(isIE)pv ='<'+pv+'>';
  2489. $.exeCmd('FormatBlock', pv);
  2490. });
  2491. if(isIE6){
  2492. var es = TQE._tags(o,'DIV');
  2493. for(i=es.length-1;i>=0;i--){
  2494. $._ieMouseStyle(es[i],'eMenuItem','eMenuItemUp','eMenuItem');
  2495. }
  2496. }
  2497. }
  2498. TQE.pop(o,sender);
  2499. }
  2500. },
  2501. fontsize:{
  2502. text:'文字大小',
  2503. click:function($,sender){
  2504. var o=TQE.find($.objId+'FontSize');
  2505. if(null==o){
  2506. var s='',i,es,
  2507. fs=$.config.fontsizes;
  2508. for(i=0;i < fs.length; i++){
  2509. s +='<div name="FontSize" class="eMenuItem" unselectable=on onselectstart="return false" paraValue="'+fs[i][2]+'" style="font-size:'+fs[i][1]+';" >'+fs[i][0]+'</div>';
  2510. }
  2511. o = TQE.CE('DIV',$.objId+'FontSize',s,true);
  2512. o.className='ePopPanel';
  2513. TQE._noSel(o);//,'DIV'
  2514. TQE.listenTags(o,'DIV','click',function(){TQE.hidePop();$.exeCmd('FontSize', this.getAttribute('paraValue'))});
  2515. if(isIE6){
  2516. es = TQE._tags(o,'DIV');
  2517. for(i=es.length-1;i>=0;i--){
  2518. $._ieMouseStyle(es[i],'eMenuItem','eMenuItemUp','eMenuItem');
  2519. }
  2520. }
  2521. }
  2522. TQE.pop(o,sender);
  2523. }
  2524. },
  2525. fontname:{
  2526. text:'字体',
  2527. click:function($,sender){
  2528. var o=TQE.find($.objId+'FontName');
  2529. if(null==o){
  2530. var es,i,s='',fs=$.config.fontnames;
  2531. for(i=0;i < fs.length; i++){
  2532. s +='<div name="FontName" class="eMenuItem" unselectable=on onselectstart="return false" paraValue="'+fs[i][1]+'" style="font-family:'+fs[i][1]+';" >'+fs[i][0]+'</div>';
  2533. }
  2534. o = TQE.CE('DIV',$.objId+'FontName',s,true);
  2535. o.className='ePopPanel';
  2536. TQE._noSel(o);//,'DIV'
  2537. TQE.listenTags(o,'DIV','click',function(){TQE.hidePop();$.exeCmd('FontName', this.getAttribute('paraValue'))});
  2538. if(isIE6){
  2539. es = TQE._tags(o,'DIV');
  2540. for(i=es.length-1;i>=0;i--){
  2541. $._ieMouseStyle(es[i],'eMenuItem','eMenuItemUp','eMenuItem');
  2542. }
  2543. }
  2544. }
  2545. TQE.pop(o,sender);
  2546. }
  2547. },
  2548. forecolor:{
  2549. text:'文本颜色',
  2550. click:function($,sender){
  2551. $._showColorSelectUI(sender,'forecolor');
  2552. }
  2553. },
  2554. backcolor:{
  2555. text:'背景色',
  2556. click:function($,sender){
  2557. $._showColorSelectUI(sender, isIE ? 'backcolor':'hilitecolor');
  2558. }
  2559. },
  2560. bold:{
  2561. text:'粗体',
  2562. click:null
  2563. },
  2564. italic:{
  2565. text:'斜体',
  2566. click:null
  2567. },
  2568. underline:{
  2569. text:'下划线',
  2570. click:null
  2571. },
  2572. strikethrough:{
  2573. text:'删除线',
  2574. click:null
  2575. },
  2576. removeformat:{
  2577. text:'消除格式',
  2578. click:function($,sender){
  2579. TQE.hidePop();
  2580. $.exeCmd('removeformat');
  2581. if(isGecko || isOpera) return;//ff,opera本身已完美的清理格式, 其他的浏览器还要加代码处理word的代码
  2582. var rang=$._getRange(),
  2583. clear=function(s){return s.replace(/<\/?span[^>]*>/ig,'').replace(/<p [^>]*>/ig,'<p>').replace(/<div [^>]*>/ig,'<div>');},
  2584. htm='',
  2585. str=rang.htmlText,
  2586. nodes,
  2587. i;
  2588. if(str){//ie6,7,8
  2589. $.insertHtml(clear(str));
  2590. }else{//ie9,chrome
  2591. nodes=rang.cloneContents().childNodes;
  2592. for(i=0;i<nodes.length;i++){
  2593. if('#comment'!=nodes[i].nodeName){
  2594. str = nodes[i].outerHTML || nodes[i].nodeValue ;
  2595. if(str) htm += str;
  2596. }
  2597. }
  2598. $.insertHtml(clear(htm));
  2599. }
  2600. }
  2601. },
  2602. submenu:{
  2603. text:'',
  2604. click:function($,sender){
  2605. $._popAsMenu(sender,sender.getAttribute('submenu').split(','));
  2606. }
  2607. },
  2608. //使用submenu来替代此功能
  2609. //moreformat:{
  2610. // text:'',
  2611. // click:function($,sender){
  2612. // $._popAsMenu(sender,['orderedlist','unorderedlist','|','indent','outdent','|','superscript','subscript']);
  2613. // }
  2614. //},
  2615. subscript:{
  2616. text:'下标',
  2617. click:null
  2618. },
  2619. superscript:{
  2620. text:'上标',
  2621. click:null
  2622. },
  2623. align:{
  2624. text:'对齐',
  2625. click:function($,sender){
  2626. $._popAsMenu(sender,['justifyleft','justifycenter','justifyright']);
  2627. }
  2628. },
  2629. justifyleft:{
  2630. text:'左对齐',
  2631. click:null
  2632. },
  2633. justifycenter:{
  2634. text:'居中对齐',
  2635. click:null
  2636. },
  2637. justifyright:{
  2638. text:'右对齐',
  2639. click:null
  2640. },
  2641. justifyfull:{
  2642. text:'两端对齐',
  2643. click:null
  2644. },
  2645. justifynone:{
  2646. text:'取消对齐',
  2647. click:null
  2648. },
  2649. list:{
  2650. text:'列表',
  2651. click:function($,sender){
  2652. $._popAsMenu(sender,['orderedlist','unorderedlist']);
  2653. }
  2654. },
  2655. unorderedlist:{
  2656. text:'项目列表',
  2657. click:function($,sender){
  2658. TQE.hidePop();
  2659. $.exeCmd('InsertUnorderedList');
  2660. }
  2661. },
  2662. orderedlist:{
  2663. text:'数目列表',
  2664. click:function($,sender){
  2665. TQE.hidePop();
  2666. $.exeCmd('InsertOrderedList');
  2667. }
  2668. },
  2669. iodent:{
  2670. text:'缩进方向',
  2671. click:function($,sender){
  2672. $._popAsMenu(sender,['indent','outdent'])
  2673. }
  2674. },
  2675. outdent:{
  2676. text:'减少缩进',
  2677. click:null
  2678. },
  2679. indent:{
  2680. text:'增加缩进',
  2681. click:null
  2682. },
  2683. inserthorizontalrule:{
  2684. text:'插入水平线',
  2685. click:null
  2686. },
  2687. createlink:{
  2688. text:'添加链接',
  2689. click:function($,sender){
  2690. var o=TQE.find($.objId+'CreateLink');
  2691. if(null==o){
  2692. //var s='网址:<input type="text" id="url" value="" size=45 /><br />打开:<select id="target"><option value="" >默认</option><option value="_blank">新窗口</option><option value="_self">当前窗口</option><option value="_parent">父窗口</option><option value="_top">顶层窗口</option></select>';
  2693. var okClick= function(){
  2694. TQE.hidePop();
  2695. var es=this.form.elements,
  2696. href=es['url'].value,
  2697. target=es['target'].value,
  2698. title=es['title'].value,
  2699. titleTxt='';
  2700. if('http://'==href || ''==href){
  2701. $.exeCmd('Unlink');
  2702. return false;
  2703. }
  2704. var r= $._getRange();
  2705. if(isWebkit && r.collapsed || !$.exeCmd('CreateLink', href)){
  2706. if(target!=='') target = ' target="'+target+'" ';
  2707. if(title!=='') titleTxt = ' title="'+title+'" ';
  2708. $.insertHtml('<a href="'+href+'" '+titleTxt+target+'>'+(title?title:href)+'</a>');
  2709. return false;
  2710. }
  2711. var n=$.focusNode();
  2712. do{
  2713. if(n.tagName=='A'){
  2714. if(''==target) n.removeAttribute('target') ;
  2715. else n.setAttribute('target',target);
  2716. if(''==title) n.removeAttribute('title');
  2717. else n.setAttribute('title',title);
  2718. break;
  2719. }
  2720. }while(n = n.parentNode);
  2721. return false;
  2722. };
  2723. o = $._popFormUI($.objId+'CreateLink',resStrCreateLink, resStrInsertLinkUI, okClick,null, $.config.linkUploadUrl,$.config.linkFileTypes,$.config.linkFileSize,'link');
  2724. TQE.drag(o);
  2725. }
  2726. if(!TQE.pop(o,sender)) return;
  2727. var f = TQE._tags(o,'FORM')[0],
  2728. es = f.elements,
  2729. n = $.focusNode();
  2730. f.reset();
  2731. do{
  2732. if(n.tagName=='A'){
  2733. es['url'].value=n.getAttribute('href');
  2734. es['title'].value=n.getAttribute('title');
  2735. $.__selectOption(es['target'],n.getAttribute('target'));
  2736. break;
  2737. }
  2738. }while(n = n.parentNode);
  2739. es['url'].focus();
  2740. }
  2741. },
  2742. unlink:{
  2743. text:'删除链接',
  2744. click:null
  2745. },
  2746. inserttable:{
  2747. text:'插入表格',
  2748. click:function($,sender){
  2749. var o=TQE.find($.objId+'InsertTable');
  2750. if(null==o){
  2751. var s=resStrTableContextUI + '<div><table border=1 cellspacing=0 cellpadding=0 bgcolor="#FFFFFF" bordercolor="#CCCCCC" class="eTableInserUI"><tbody>',i=0,j=0;
  2752. for(i=0;i<5;i++){
  2753. s+='<tr>';
  2754. for(j=0;j<8;j++){
  2755. s+='<td width="20" height="20" ></td>';
  2756. }
  2757. s+='</tr>';
  2758. }
  2759. s+='</tbody></table><div style="padding:2px 5px;">1 &times 1</div></div>';
  2760. o = TQE.CE('DIV',$.objId+'InsertTable', s ,true);
  2761. o.className='ePopPanel';
  2762. TQE._noSel(o);//,'TABLE,TR,TD,DIV');
  2763. TQE.listenTags(o.lastChild,'TD','click',function(){
  2764. TQE.hidePop();
  2765. var i,j,s='<table style="border-collapse:collapse;" width=96% align=center border=1 cellspace=0 cellpadding=3 ><tbody>';
  2766. for(i=this.parentNode.rowIndex;i>=0;i--){
  2767. s+='<tr>';
  2768. for(j=this.cellIndex;j>=0;j--){
  2769. s+= isIE ? '<td valign="top"></td>':'<td valign="top"><br></td>';
  2770. }
  2771. s+='</tr>';
  2772. }
  2773. s+='</tbody></table>';
  2774. //s = '<p>'+s+'</p>';
  2775. //$.exeCmd('InsertParagraph');
  2776. //$.exeCmd('FormatBlock','p');
  2777. $.insertHtml(s);
  2778. }
  2779. );
  2780. TQE.listenTags(o.lastChild,'TD','mouseover',function(){
  2781. var i,j,ci=this.cellIndex, row=this.parentNode,ri=row.rowIndex,table=row.parentNode.parentNode, rc=table.rows.length,cc=row.cells.length;
  2782. for(i=0;i<rc;i++){
  2783. row=table.rows[i];
  2784. for(j=0;j<cc;j++)
  2785. row.cells[j].bgColor= (i<=ri && j<=ci)?'#3399ff':'';
  2786. }
  2787. table.parentNode.lastChild.innerHTML= (ri+1) +' &times; '+(ci+1);
  2788. });
  2789. }
  2790. var table, td,
  2791. selectedCells=$.selectedCells(),
  2792. propertyPanel=o.firstChild,
  2793. miMerge=propertyPanel.firstChild,
  2794. miSplit=miMerge.nextSibling,
  2795. insertPanel=o.lastChild,
  2796. row=o.lastChild.firstChild.firstChild.firstChild,
  2797. cc=row.cells.length,
  2798. showObj=function(obj,b){obj.style.display=b?'':'none';};
  2799. while(row){
  2800. for(var i=0;i<cc;i++) row.cells[i].bgColor='';
  2801. row=row.nextSibling;
  2802. }
  2803. insertPanel.lastChild.innerHTML='1 &times; 1';
  2804. //--
  2805. if(selectedCells.length){//选中格
  2806. showObj(insertPanel, 0);
  2807. td=selectedCells[0];
  2808. }else{
  2809. showObj(insertPanel, 1);
  2810. td=$.focusNode();
  2811. while(td && td.nodeName !=='TD'){
  2812. td = td.parentNode
  2813. }
  2814. }
  2815. if(td){
  2816. table=td.parentNode.parentNode.parentNode;
  2817. showObj(propertyPanel, 1);
  2818. showObj(miMerge, $.canMergeSelectedCells());
  2819. showObj(miSplit, selectedCells.length<2 && (td.rowSpan>1 || td.colSpan>1));
  2820. showObj(miSplit.nextSibling, miMerge.style.display!='none' || miSplit.style.display!='none');
  2821. }else{
  2822. showObj(propertyPanel, 0);
  2823. }
  2824. showObj(insertPanel.previousSibling, propertyPanel.style.display!='none' && insertPanel.style.display!='none');
  2825. var objs=o.firstChild.getElementsByTagName('A'),
  2826. alignTD=function(align,vAlign){
  2827. if(selectedCells.length>0){
  2828. for(var i=selectedCells.length-1;i>=0;i--){
  2829. selectedCells[i].align=align;
  2830. selectedCells[i].vAlign=vAlign;
  2831. }
  2832. }else if(td){
  2833. td.align=align;
  2834. td.vAlign=vAlign;
  2835. }
  2836. };
  2837. for(i=objs.length-1;i>=0;i--){
  2838. objs[i].href='#';
  2839. objs[i].onclick=function(){
  2840. switch(this.id){
  2841. case 'eTableAlignDefault':table.align=''; break;
  2842. case 'eTableAlignLeft':table.align='left'; break;
  2843. case 'eTableAlignCenter':table.align='center'; break;
  2844. case 'eTableAlignRight':table.align='right'; break;
  2845. case 'eCellAlignLT':alignTD('left','top');break;
  2846. case 'eCellAlignCT':alignTD('center','top');break;
  2847. case 'eCellAlignRT':alignTD('right','top');break;
  2848. case 'eCellAlignLC':alignTD('left','middle');break;
  2849. case 'eCellAlignCC':alignTD('center','middle');break;
  2850. case 'eCellAlignRC':alignTD('right','middle');break;
  2851. case 'eCellAlignLB':alignTD('left','bottom');break;
  2852. case 'eCellAlignCB':alignTD('center','bottom');break;
  2853. case 'eCellAlignRB':alignTD('right','bottom');break;
  2854. }
  2855. $.focus();
  2856. return false;
  2857. };
  2858. }
  2859. objs=o.firstChild.getElementsByTagName('INPUT');
  2860. for(i=objs.length-1;i>=0;i--){
  2861. if(table) objs[i].value= undefined==table[objs[i].id] ? '' : table[objs[i].id];
  2862. objs[i].onblur=function(){
  2863. if(''==this.value ) table.removeAttribute(this.id);
  2864. else table[this.id]=this.value;
  2865. table.style.borderCollapse = table.cellSpacing<1 && table.border==1 ? 'collapse':'';
  2866. };
  2867. }
  2868. miMerge.onclick=function(){TQE.hidePop();$.mergeSelectedCells();$.focus(); return false;}
  2869. miSplit.onclick=function(){TQE.hidePop();$.splitCell(td);$.focus();return false;}
  2870. //--
  2871. if(!TQE.pop(o,sender)) return;
  2872. }
  2873. },
  2874. insertimage:{
  2875. text:'插入图片',
  2876. click:function($,sender){
  2877. var o=TQE.find($.objId+'InsertImage');
  2878. if(null==o){
  2879. //var s='图片网址:<input type="text" id="url" value="" size=40 /><br />替换文本:<input name="alt" type="text" id="alt" size="20" /><br />尺寸:<input name="width" type="text" id="width" size="4" /> &times; <input name="height" type="text" id="height" size="4" /> px &nbsp;<br />对齐:<select name="align" id="align"><option value="" >默认</option><option value="top">居上</option><option value="textTop">文本上方</option><option value="middle">居中</option><option value="absMiddle">绝对居中</option><option value="baseline">基线</option><option value="bottom">底部</option><option value="absBottom">绝对底部</option><option value="left">左</option><option value="right">右</option></select> &nbsp; &nbsp; 边框:<input name="border" type="text" id="border" size="5" />';
  2880. var okClick=function(){
  2881. TQE.hidePop();
  2882. var es=this.form.elements;
  2883. $.insertImage(es['url'].value,es['width'].value,es['height'].value,es['border'].value, es['alt'].value,es['align'].value);
  2884. return false;
  2885. };
  2886. o = $._popFormUI($.objId+'InsertImage',resStrInsertImage, resStrInsertImageUI, okClick ,['width','height','border'], $.config.imageUploadUrl,$.config.imageFileTypes, $.config.imageFileSize, 'image');
  2887. TQE.drag(o);
  2888. }
  2889. if(!TQE.pop(o,sender)) return;
  2890. var f = TQE._tags(o,'FORM')[0],
  2891. es = f.elements,
  2892. r=$._getRange(),
  2893. n=r.commonAncestorContainer;
  2894. f.reset();
  2895. if(n){ //标准dom
  2896. if(!r.collapsed && r.startContainer == r.endContainer && r.startOffset - r.endOffset < 2 && r.startContainer.hasChildNodes()){
  2897. n=r.startContainer.childNodes[r.startOffset];
  2898. }
  2899. if(n.tagName!='IMG' && IEVersion>=9 && ''===r.toString()){
  2900. if(undefined===r.startContainer.length && r.startContainer.firstChild===r.endContainer.previousSibling)n=r.startContainer.firstChild;
  2901. else if(r.endContainer.lastChild===r.startContainer.nextSibling)n=r.endContainer.lastChild;
  2902. else if(r.startContainer.length == r.startOffset && r.endOffset==0 && r.startContainer.nextSibling==r.endContainer.previousSibling){
  2903. n=r.startContainer.nextSibling;
  2904. }
  2905. }
  2906. if(!n || n.tagName!='IMG') n=null;
  2907. }else if(r.length && r.item(0).tagName=='IMG'){ //isIE, ie6,7,8
  2908. n=r.item(0);
  2909. }
  2910. if(n && 'IMG'==n.nodeName){
  2911. es['url'].value=n.getAttribute('src');
  2912. es['width'].value=n.width;
  2913. es['height'].value=n.height;
  2914. es['border'].value=n.border;
  2915. es['alt'].value=n.alt;
  2916. $.__selectOption(es['align'],n.align);
  2917. }
  2918. es['url'].focus();
  2919. }
  2920. },
  2921. insertface:{
  2922. text:'表情',
  2923. click:function($,sender){
  2924. var o=TQE.find($.objId+'InsertFace');
  2925. if(null==o){
  2926. var i,es,s='<div class="eFace">';
  2927. for( i=1;i<=$.config.faceCount;i++){
  2928. s+='<img src="'+TQE.url+'face/'+i+'.gif" emot="'+i+'" />';
  2929. }
  2930. s+='</div>';
  2931. o = TQE.CE('DIV',$.objId+'InsertFace', s ,true);
  2932. o.className='ePopPanel';
  2933. TQE._noSel(o);//,'IMG,DIV');
  2934. TQE.listenTags(o,'IMG','click',function(){TQE.hidePop();$.insertHtml('<img align=absMiddle src="'+this.getAttribute('src')+'" emot="'+this.getAttribute('emot')+'" />');});
  2935. if(isIE6){
  2936. es = TQE._tags(o,'IMG');
  2937. for(i=es.length-1;i>=0;i--){
  2938. $._ieMouseStyle(es[i],'','imgHover','');
  2939. }
  2940. }
  2941. }
  2942. TQE.pop(o,sender);
  2943. }
  2944. },
  2945. insertflash:{
  2946. text:'插入Flash',
  2947. click:function($,sender){
  2948. var o=TQE.find($.objId+'InsertFlash'),form;
  2949. if(null==o){
  2950. //var s='Flash网址:<input type="text" id="url" value="" size=40 /><br />尺寸:<input name="width" type="text" id="width" size="4" value="200" />&times;<input name="height" type="text" id="height" size="4" value="200" /> px';
  2951. var okClick= function(){
  2952. TQE.hidePop();
  2953. var es=this.form.elements;
  2954. $.insertFlash(es['url'].value,es['width'].value,es['height'].value);
  2955. return false;
  2956. };
  2957. o = $._popFormUI($.objId+'InsertFlash',resStrInsertFlash, resStrInsertFlashUI, okClick,['width','height'], $.config.flashUploadUrl,$.config.flashFileTypes,$.config.flashFileSize, 'flash');
  2958. TQE.drag(o);
  2959. }
  2960. if(!TQE.pop(o,sender)) return;
  2961. form=TQE._tags(o,'FORM')[0];
  2962. form.reset();
  2963. form.elements['url'].focus();
  2964. }
  2965. },
  2966. insertmusic:{
  2967. text:'插入音频',
  2968. click:function($,sender){
  2969. var o=TQE.find($.objId+'InsertMusic'),form;
  2970. if(null==o){
  2971. //var s='音频网址:<input type="text" id="url" value="" size=40 /><br />自动播放:<select id="auto_start" name="auto_start"><option value="0">手动开始</option><option value="1">自动开始</option></select>';
  2972. var okClick= function(){
  2973. TQE.hidePop();
  2974. var es=this.form.elements;
  2975. $.insertMusic(es['url'].value,es['auto_start'].value);
  2976. return false;
  2977. };
  2978. o = $._popFormUI($.objId+'InsertMusic',resStrInsertMusic, resStrInsertMusicUI, okClick,null, $.config.musicUploadUrl,$.config.musicFileTypes,$.config.musicFileSize, 'music');
  2979. TQE.drag(o);
  2980. }
  2981. if(!TQE.pop(o,sender)) return ;
  2982. form=TQE._tags(o,'FORM')[0];
  2983. form.reset();
  2984. form.elements['url'].focus();
  2985. }
  2986. },
  2987. insertvideo:{
  2988. text:'插入视频',
  2989. click:function($,sender){
  2990. var o=TQE.find($.objId+'InsertVideo'),form;
  2991. if(null==o){
  2992. //var s='视频网址:<input type="text" id="url" value="" size=40 /><br />尺寸:<input name="width" type="text" id="width" size="4" value="320"/>&times;<input name="height" type="text" id="height" size="4" value="240" /> px<br />自动播放:<select id="auto_start" name="auto_start"><option value="0">手动开始</option><option value="1">自动开始</option></select><br />视频类型:<select id="video_type" name="video_type"><option value="auto">自动识别</option><option value="flv">FLV</option><option value="rm">RMVB</option><option value="wm">其他视频</option></select>';
  2993. var okClick= function(){
  2994. TQE.hidePop();
  2995. var es=this.form.elements;
  2996. $.insertVideo(es['url'].value,es['auto_start'].value,es['width'].value,es['height'].value,es['video_type'].value);
  2997. return false;
  2998. };
  2999. o = $._popFormUI($.objId+'InsertVideo',resStrInsertVideo, resStrInsertVideoUI, okClick,['width','height'], $.config.videoUploadUrl,$.config.videoFileTypes,$.config.videoFileSize, 'video');
  3000. TQE.drag(o);
  3001. }
  3002. if(!TQE.pop(o,sender)) return;
  3003. form=TQE._tags(o,'FORM')[0];
  3004. form.reset();
  3005. form.elements['url'].focus();
  3006. }
  3007. },
  3008. cleanword:{
  3009. text:'清理Word代码',
  3010. click:function($,sender){
  3011. TQE.hidePop();
  3012. $.cleanWord(true);
  3013. }
  3014. },
  3015. typeset:{
  3016. text:'自动排版',
  3017. click:function($,sender){
  3018. TQE.hidePop();
  3019. $.typeset();
  3020. /*return;
  3021. var o=TQE.find($.objId+'Typeset'),form;
  3022. if(null==o){
  3023. var resStrTypeset='自动排版', resStrTypesetUI='图片/视频/Flash <label><input type="radio" name="align" id="alignLeft" value="left" checked onClick="this.form.elements[\'centerCaption\'].disabled=true;">左对齐</label> <label><input type="radio" name="align" id="alignCenter" value="center" onClick="this.form.elements[\'centerCaption\'].disabled=false;">居中</label><label><input name="centerCaption" type="checkbox" disabled id="centerCaption" value="1" checked >同时居中下方文本</label><br>首行缩进 <select name="textIndent" id="textIndent"><option value="-" selected>不修改</option><option value="style">使用样式缩进</option><option value="text">使用中文空格缩进</option><option value="none">清除缩进</option></select>';
  3024. var okClick= function(){
  3025. TQE.hidePop();
  3026. var es=this.form.elements;
  3027. $.typeset();
  3028. //$.insertVideo(es['url'].value,es['auto_start'].value,es['width'].value,es['height'].value,es['video_type'].value);
  3029. return false;
  3030. };
  3031. o = $._popFormUI($.objId+'Typeset',resStrTypeset, resStrTypesetUI, okClick);
  3032. TQE.drag(o);
  3033. }
  3034. if(!TQE.pop(o,sender)) return;
  3035. form=TQE._tags(o,'FORM')[0];
  3036. form.reset();
  3037. form.elements['url'].focus();
  3038. */
  3039. }
  3040. },
  3041. mode:{
  3042. text:'查看源码',
  3043. click:function($,sender){
  3044. TQE.hidePop();
  3045. $.changeMode();
  3046. }
  3047. },
  3048. splitpage:{
  3049. text:'插入分页符',
  3050. click:function($,sender){
  3051. TQE.hidePop();
  3052. //$.insertHtml($.config.tplSplitPage,'after');
  3053. $.insertHtml($.config.tplSplitPage);
  3054. }
  3055. },
  3056. group:{
  3057. text:'',
  3058. click:null
  3059. },
  3060. br:{
  3061. text:'',
  3062. click:null
  3063. },
  3064. separator:{
  3065. text:'',
  3066. click:null
  3067. },
  3068. fullscreen:{
  3069. text:'全屏',
  3070. click:function($,sender){
  3071. TQE.hidePop();
  3072. $.fullScreen();
  3073. }
  3074. },
  3075. toolbarmode:{
  3076. text:'工具栏模式',
  3077. click:function($,sender){
  3078. TQE.hidePop();
  3079. $.changeToolbarMode();
  3080. }
  3081. },
  3082. help:{
  3083. text:'帮助',
  3084. click:function($,sender){
  3085. var o=TQE.find($.objId+'TQHelpPanel');
  3086. if(null==o){
  3087. o = TQE.CE('DIV',$.objId+'TQHelpPanel', '<form class="ePopForm" style="line-height:20px;">TQEditor<br/>'+resStrVersion+': '+version+'<br/>'+resStrSite+': <a href="http://www.huimv.com" target="_blank">www.huimv.com</a><br />'+resStrMail+': <a href="mailto:huimvtech@163.com">huimvtech@163.com</a><br /></form>' ,true);
  3088. o.className='ePopPanel';
  3089. }
  3090. TQE.pop(o,sender);
  3091. }
  3092. }
  3093. };
  3094. //运行时对象容器
  3095. //TQE.rto={};
  3096. //explode names;
  3097. window.tqEditor=window.tqeditor=window.TQEditor=window.TQE=TQE;
  3098. window.isIE=isIE;
  3099. window.isIE6=isIE6;
  3100. window.IEVersion=IEVersion;
  3101. window.isWebkit=isWebkit;
  3102. window.isOpera=isOpera;
  3103. window.isGecko=isGecko;
  3104. })(window);