editor3.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /*
  2. *☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
  3. *★ ★
  4. *☆ eWebEditor - eWebSoft在线文本编辑器飞鱼修改版 ☆
  5. *★ ★
  6. *☆ 版权所有: eWebSoft.com ☆
  7. *★ ★
  8. *☆ 程序制作: eWeb开发团队 ☆
  9. *★ email:webmaster@webasp.net ★
  10. *☆ QQ:589808 ☆
  11. *★ ★
  12. *☆ 相关网址: [原版地址]http://www.eWebSoft.com/Product/eWebEditor/ ☆
  13. *★ [支持论坛]http://bbs.eWebSoft.com/ ★
  14. *☆ ☆
  15. *★ 主页地址: http://www.fiyu.net/ 飞鱼论坛 ★
  16. *☆ 有什么问题欢迎到飞鱼论坛提出! ☆
  17. *★ ★
  18. *★ ★
  19. *☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
  20. */
  21. // 当前模式
  22. var sCurrMode = null;
  23. var bEditMode = null;
  24. // 连接对象
  25. var oLinkField = null;
  26. var sBaseUrl = document.location.protocol + '//' + document.location.host ;
  27. // 浏览器版本检测
  28. var BrowserInfo = new Object() ;
  29. BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;
  30. BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1] ;
  31. BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 && BrowserInfo.MinorVer >= 5 ) ;
  32. var yToolbars = new Array(); // 工具栏数组
  33. // 当文档完全调入时,进行初始化
  34. var bInitialized = false;
  35. document.onreadystatechange =function(){
  36. if (document.readyState!="complete") return;
  37. if (bInitialized) return;
  38. bInitialized = true;
  39. var i, s, curr;
  40. // 初始每个工具栏
  41. for (i=0; i<document.body.all.length;i++){
  42. curr=document.body.all[i];
  43. if (curr.className == "yToolbar"){
  44. InitTB(curr);
  45. yToolbars[yToolbars.length] = curr;
  46. }
  47. }
  48. oLinkField = parent.document.getElementsByName(sLinkFieldName)[0];
  49. if (ContentFlag.value=="0") {
  50. ContentEdit.value = oLinkField.value;
  51. ContentLoad.value = oLinkField.value;
  52. ContentFlag.value = "1";
  53. }
  54. setMode(config.InitMode);
  55. setLinkedField() ;
  56. eWebEditor.document.body.onpaste = onPaste ;
  57. eWebEditor.focus();
  58. }
  59. // 初始化一个工具栏上的按钮
  60. function InitBtn(btn) {
  61. btn.onmouseover = BtnMouseOver;
  62. btn.onmouseout = BtnMouseOut;
  63. btn.onmousedown = BtnMouseDown;
  64. btn.onmouseup = BtnMouseUp;
  65. btn.ondragstart = YCancelEvent;
  66. btn.onselectstart = YCancelEvent;
  67. btn.onselect = YCancelEvent;
  68. btn.YUSERONCLICK = btn.onclick;
  69. btn.onclick = YCancelEvent;
  70. btn.YINITIALIZED = true;
  71. return true;
  72. }
  73. //Initialize a toolbar.
  74. function InitTB(y) {
  75. // Set initial size of toolbar to that of the handle
  76. y.TBWidth = 0;
  77. // Populate the toolbar with its contents
  78. if (! PopulateTB(y)) return false;
  79. // Set the toolbar width and put in the handle
  80. y.style.posWidth = y.TBWidth;
  81. return true;
  82. }
  83. // Hander that simply cancels an event
  84. function YCancelEvent() {
  85. event.returnValue=false;
  86. event.cancelBubble=true;
  87. return false;
  88. }
  89. // Toolbar button onmouseover handler
  90. function BtnMouseOver() {
  91. if (event.srcElement.tagName != "IMG") return false;
  92. var image = event.srcElement;
  93. var element = image.parentElement;
  94. // Change button look based on current state of image.
  95. if (image.className == "Ico") element.className = "BtnMouseOverUp";
  96. else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";
  97. event.cancelBubble = true;
  98. }
  99. // Toolbar button onmouseout handler
  100. function BtnMouseOut() {
  101. if (event.srcElement.tagName != "IMG") {
  102. event.cancelBubble = true;
  103. return false;
  104. }
  105. var image = event.srcElement;
  106. var element = image.parentElement;
  107. yRaisedElement = null;
  108. element.className = "Btn";
  109. image.className = "Ico";
  110. event.cancelBubble = true;
  111. }
  112. // Toolbar button onmousedown handler
  113. function BtnMouseDown() {
  114. if (event.srcElement.tagName != "IMG") {
  115. event.cancelBubble = true;
  116. event.returnValue=false;
  117. return false;
  118. }
  119. var image = event.srcElement;
  120. var element = image.parentElement;
  121. element.className = "BtnMouseOverDown";
  122. image.className = "IcoDown";
  123. event.cancelBubble = true;
  124. event.returnValue=false;
  125. return false;
  126. }
  127. // Toolbar button onmouseup handler
  128. function BtnMouseUp() {
  129. if (event.srcElement.tagName != "IMG") {
  130. event.cancelBubble = true;
  131. return false;
  132. }
  133. var image = event.srcElement;
  134. var element = image.parentElement;
  135. if (navigator.appVersion.match(/MSIE (7|8)\./i)!=null){
  136. if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "onclick(event)");
  137. }else{
  138. if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");
  139. }
  140. element.className = "BtnMouseOverUp";
  141. image.className = "Ico";
  142. event.cancelBubble = true;
  143. return false;
  144. }
  145. // Populate a toolbar with the elements within it
  146. function PopulateTB(y) {
  147. var i, elements, element;
  148. // Iterate through all the top-level elements in the toolbar
  149. elements = y.children;
  150. for (i=0; i<elements.length; i++) {
  151. element = elements[i];
  152. if (element.tagName == "SCRIPT" || element.tagName == "!") continue;
  153. switch (element.className) {
  154. case "Btn":
  155. if (element.YINITIALIZED == null) {
  156. if (! InitBtn(element)) {
  157. alert("Problem initializing:" + element.id);
  158. return false;
  159. }
  160. }
  161. element.style.posLeft = y.TBWidth;
  162. y.TBWidth += element.offsetWidth + 1;
  163. break;
  164. case "TBGen":
  165. element.style.posLeft = y.TBWidth;
  166. y.TBWidth += element.offsetWidth + 1;
  167. break;
  168. case "TBSep":
  169. element.style.posLeft = y.TBWidth + 2;
  170. y.TBWidth += 5;
  171. break;
  172. case "TBHandle":
  173. element.style.posLeft = 2;
  174. y.TBWidth += element.offsetWidth + 7;
  175. break;
  176. default:
  177. alert("Invalid class: " + element.className + " on Element: " + element.id + " <" + element.tagName + ">");
  178. return false;
  179. }
  180. }
  181. y.TBWidth += 1;
  182. return true;
  183. }
  184. // 设置所属表单的提交或reset事件
  185. function setLinkedField() {
  186. if (! oLinkField) return ;
  187. var oForm = oLinkField.form ;
  188. if (!oForm) return ;
  189. // 附加submit事件
  190. oForm.attachEvent("onsubmit", AttachSubmit) ;
  191. if (! oForm.submitEditor) oForm.submitEditor = new Array() ;
  192. oForm.submitEditor[oForm.submitEditor.length] = AttachSubmit ;
  193. if (! oForm.originalSubmit) {
  194. oForm.originalSubmit = oForm.submit ;
  195. oForm.submit = function() {
  196. if (this.submitEditor) {
  197. for (var i = 0 ; i < this.submitEditor.length ; i++) {
  198. this.submitEditor[i]() ;
  199. }
  200. }
  201. this.originalSubmit() ;
  202. }
  203. }
  204. // 附加reset事件
  205. oForm.attachEvent("onreset", AttachReset) ;
  206. if (! oForm.resetEditor) oForm.resetEditor = new Array() ;
  207. oForm.resetEditor[oForm.resetEditor.length] = AttachReset ;
  208. if (! oForm.originalReset) {
  209. oForm.originalReset = oForm.reset ;
  210. oForm.reset = function() {
  211. if (this.resetEditor) {
  212. for (var i = 0 ; i < this.resetEditor.length ; i++) {
  213. this.resetEditor[i]() ;
  214. }
  215. }
  216. this.originalReset() ;
  217. }
  218. }
  219. }
  220. // 附加submit提交事件,大表单数据提交,远程文件获取,保存eWebEditor中的内容
  221. var bDoneAutoRemote = false;
  222. function AttachSubmit() {
  223. var oForm = oLinkField.form ;
  224. if (!oForm) return;
  225. if ((config.AutoRemote=="1")&&(!bDoneAutoRemote)){
  226. parent.event.returnValue = false;
  227. bDoneAutoRemote = true;
  228. remoteUpload();
  229. } else {
  230. var html = getHTML();
  231. ContentEdit.value = html;
  232. if (sCurrMode=="TEXT"){
  233. html = HTMLEncode(html);
  234. }
  235. splitTextField(oLinkField, html);
  236. }
  237. }
  238. // 提交表单
  239. function doSubmit(){
  240. var oForm = oLinkField.form ;
  241. if (!oForm) return ;
  242. oForm.submit();
  243. }
  244. // 附加Reset事件
  245. function AttachReset() {
  246. if (!bEditMode) setMode('EDIT');
  247. if(bEditMode){
  248. eWebEditor.document.body.innerHTML = ContentLoad.value;
  249. }else{
  250. eWebEditor.document.body.innerText = ContentLoad.value;
  251. }
  252. }
  253. // 粘贴时自动检测是否来源于Word格式
  254. function onPaste() {
  255. if (config.AutoDetectPasteFromWord && BrowserInfo.IsIE55OrMore) {
  256. var sHTML = GetClipboardHTML() ;
  257. var re = /<\w[^>]* class="?MsoNormal"?/gi ;
  258. if ( re.test( sHTML ) )
  259. {
  260. if ( confirm( "你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?" ) )
  261. {
  262. cleanAndPaste( sHTML ) ;
  263. return false ;
  264. }
  265. }
  266. }
  267. else
  268. return true ;
  269. }
  270. function GetClipboardHTML() {
  271. var oDiv = document.getElementById("eWebEditor_Temp_HTML")
  272. oDiv.innerHTML = "" ;
  273. var oTextRange = document.body.createTextRange() ;
  274. oTextRange.moveToElementText(oDiv) ;
  275. oTextRange.execCommand("Paste") ;
  276. var sData = oDiv.innerHTML ;
  277. oDiv.innerHTML = "" ;
  278. return sData ;
  279. }
  280. function cleanAndPaste( html ) {
  281. // Remove all SPAN tags
  282. html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
  283. // Remove Class attributes
  284. html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  285. // Remove Style attributes
  286. html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
  287. // Remove Lang attributes
  288. html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  289. // Remove XML elements and declarations
  290. html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
  291. // Remove Tags with XML namespace declarations: <o:p></o:p>
  292. html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
  293. // Replace the &nbsp;
  294. html = html.replace(/&nbsp;/, " " );
  295. // Transform <P> to <DIV>
  296. var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
  297. html = html.replace( re, "<div$2</div>" ) ;
  298. insertHTML( html ) ;
  299. }
  300. // 在当前文档位置插入.
  301. function insertHTML(html) {
  302. if (!validateMode()) return;
  303. if (eWebEditor.document.selection.type.toLowerCase() != "none")
  304. eWebEditor.document.selection.clear() ;
  305. eWebEditor.document.selection.createRange().pasteHTML(html) ;
  306. }
  307. // 设置编辑器的内容
  308. /*function setHTML(html) {
  309. ContentEdit.value = html;
  310. switch (sCurrMode){
  311. case "CODE":
  312. eWebEditor.document.designMode="On";
  313. eWebEditor.document.open();
  314. eWebEditor.document.write(config.StyleEditorHeader);
  315. eWebEditor.document.body.innerText=html;
  316. eWebEditor.document.body.contentEditable="true";
  317. eWebEditor.document.close();
  318. bEditMode=false;
  319. break;
  320. case "EDIT":
  321. eWebEditor.document.designMode="On";
  322. eWebEditor.document.open();
  323. eWebEditor.document.write(config.StyleEditorHeader+html);
  324. eWebEditor.document.body.contentEditable="true";
  325. eWebEditor.document.execCommand("2D-Position",true,true);
  326. eWebEditor.document.execCommand("MultipleSelection", true, true);
  327. eWebEditor.document.execCommand("LiveResize", true, true);
  328. eWebEditor.document.close();
  329. doZoom(nCurrZoomSize);
  330. bEditMode=true;
  331. eWebEditor.document.onselectionchange = function () { doToolbar();}
  332. break;
  333. case "TEXT":
  334. eWebEditor.document.designMode="On";
  335. eWebEditor.document.open();
  336. eWebEditor.document.write(config.StyleEditorHeader);
  337. eWebEditor.document.body.innerText=html;
  338. eWebEditor.document.body.contentEditable="true";
  339. eWebEditor.document.close();
  340. bEditMode=false;
  341. break;
  342. case "VIEW":
  343. eWebEditor.document.designMode="off";
  344. eWebEditor.document.open();
  345. eWebEditor.document.write(config.StyleEditorHeader+html);
  346. eWebEditor.document.body.contentEditable="false";
  347. eWebEditor.document.close();
  348. bEditMode=false;
  349. break;
  350. }
  351. eWebEditor.document.body.onpaste = onPaste ;
  352. eWebEditor.document.body.onhelp = onHelp ;
  353. eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
  354. eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
  355. if ((borderShown != "0")&&bEditMode) {
  356. borderShown = "0";
  357. showBorders();
  358. }
  359. initHistory();
  360. }*/
  361. // 设置编辑器的内容
  362. function setHTML(html) {
  363. if (!validateMode()) return;
  364. ContentEdit.value = html;
  365. if(bEditMode){
  366. eWebEditor.document.body.innerHTML = html;
  367. }else{
  368. eWebEditor.document.body.innerText = html;
  369. }
  370. }
  371. // 取编辑器的内容
  372. function getHTML() {
  373. var html;
  374. if(bEditMode){
  375. html = eWebEditor.document.body.innerHTML;
  376. }else{
  377. html = eWebEditor.document.body.innerText;
  378. }
  379. var re = new RegExp(sBaseUrl.replace(/\//,"\/"),"gi");
  380. html = html.replace(re, "");
  381. if (html=="") { html = " ";}
  382. return html;
  383. }
  384. // 在尾部追加内容
  385. function appendHTML(html) {
  386. if (!validateMode()) return;
  387. if(bEditMode){
  388. eWebEditor.document.body.innerHTML += html;
  389. }else{
  390. eWebEditor.document.body.innerText += html;
  391. }
  392. }
  393. // 从Word中粘贴,去除格式
  394. function PasteWord(){
  395. if (!validateMode()) return;
  396. eWebEditor.focus();
  397. if (BrowserInfo.IsIE55OrMore)
  398. cleanAndPaste( GetClipboardHTML() ) ;
  399. else if ( confirm( "此功能要求IE5.5版本以上,你当前的浏览器不支持,是否按常规粘贴进行?" ) )
  400. format("paste") ;
  401. eWebEditor.focus();
  402. }
  403. // 粘贴纯文本
  404. function PasteText(){
  405. if (!validateMode()) return;
  406. eWebEditor.focus();
  407. var sText = HTMLEncode( clipboardData.getData("Text") ) ;
  408. insertHTML(sText);
  409. eWebEditor.focus();
  410. }
  411. // 检测当前是否允许编辑
  412. function validateMode() {
  413. if (bEditMode) return true;
  414. alert("需转换为编辑状态后才能使用编辑功能!");
  415. eWebEditor.focus();
  416. return false;
  417. }
  418. // 格式化编辑器中的内容
  419. function format(what,opt) {
  420. if (!validateMode()) return;
  421. eWebEditor.focus();
  422. if (opt=="RemoveFormat") {
  423. what=opt;
  424. opt=null;
  425. }
  426. if (opt==null) eWebEditor.document.execCommand(what);
  427. else eWebEditor.document.execCommand(what,"",opt);
  428. eWebEditor.focus();
  429. }
  430. // 确保焦点在 eWebEditor 内
  431. function VerifyFocus() {
  432. if ( eWebEditor )
  433. eWebEditor.focus();
  434. }
  435. // 改变模式:代码、编辑、预览
  436. function setMode(NewMode){
  437. if (NewMode!=sCurrMode){
  438. var sBody = "";
  439. switch(sCurrMode){
  440. case "CODE":
  441. sBody = eWebEditor.document.body.innerText;
  442. break;
  443. case "EDIT":
  444. case "VIEW":
  445. sBody = eWebEditor.document.body.innerHTML;
  446. break;
  447. default:
  448. sBody = ContentEdit.value;
  449. break;
  450. }
  451. // 换图片
  452. try{
  453. document.all["eWebEditor_CODE"].className = "StatusBarBtnOff";
  454. document.all["eWebEditor_EDIT"].className = "StatusBarBtnOff";
  455. document.all["eWebEditor_VIEW"].className = "StatusBarBtnOff";
  456. document.all["eWebEditor_"+NewMode].className = "StatusBarBtnOn";
  457. }
  458. catch(e){
  459. }
  460. // 换内容
  461. switch (NewMode){
  462. case "CODE":
  463. eWebEditor.document.designMode="On";
  464. eWebEditor.document.open();
  465. eWebEditor.document.write(config.StyleEditorHeader);
  466. eWebEditor.document.body.innerText=sBody;
  467. eWebEditor.document.body.contentEditable="true";
  468. eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
  469. eWebEditor.document.close();
  470. bEditMode=false;
  471. break;
  472. case "EDIT":
  473. eWebEditor.document.designMode="On";
  474. eWebEditor.document.open();
  475. eWebEditor.document.write(config.StyleEditorHeader);
  476. eWebEditor.document.body.innerHTML=sBody;
  477. eWebEditor.document.body.contentEditable="true";
  478. eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
  479. eWebEditor.document.execCommand("2D-Position",true,true);
  480. eWebEditor.document.execCommand("MultipleSelection", true, true);
  481. eWebEditor.document.execCommand("LiveResize", true, true);
  482. eWebEditor.document.close();
  483. doZoom(nCurrZoomSize);
  484. bEditMode=true;
  485. break;
  486. case "VIEW":
  487. eWebEditor.document.designMode="off";
  488. eWebEditor.document.open();
  489. eWebEditor.document.write(config.StyleEditorHeader+sBody);
  490. eWebEditor.document.body.contentEditable="false";
  491. eWebEditor.document.close();
  492. bEditMode=false;
  493. break;
  494. }
  495. sCurrMode=NewMode;
  496. disableChildren(eWebEditor_Toolbar);
  497. if ((borderShown != "no")&&bEditMode) {
  498. borderShown = "no";
  499. showBorders()
  500. }
  501. }
  502. eWebEditor.focus();
  503. }
  504. // 使工具栏无效
  505. function disableChildren(obj){
  506. if (obj){
  507. obj.disabled=(!bEditMode);
  508. for (var i=0; i<obj.children.length; i++){
  509. disableChildren(obj.children[i]);
  510. }
  511. }
  512. }
  513. // 显示无模式对话框
  514. function ShowDialog(url, width, height, optValidate) {
  515. if (optValidate) {
  516. if (!validateMode()) return;
  517. }
  518. eWebEditor.focus();
  519. var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
  520. eWebEditor.focus();
  521. }
  522. // 全屏编辑
  523. function Maximize() {
  524. if (!validateMode()) return;
  525. window.open("dialog/fullscreen.htm?style="+config.StyleName, 'FullScreen'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,fullscreen=yes');
  526. }
  527. // 替换特殊字符
  528. function HTMLEncode(text){
  529. text = text.replace(/&/g, "&amp;") ;
  530. text = text.replace(/"/g, "&quot;") ;
  531. text = text.replace(/</g, "&lt;") ;
  532. text = text.replace(/>/g, "&gt;") ;
  533. text = text.replace(/'/g, "&#146;") ;
  534. text = text.replace(/\ /g,"&nbsp;");
  535. text = text.replace(/\n/g,"<br>");
  536. text = text.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
  537. return text;
  538. }
  539. // 插入特殊对象
  540. function insert(what) {
  541. if (!validateMode()) return;
  542. eWebEditor.focus();
  543. var sel = eWebEditor.document.selection.createRange();
  544. switch(what){
  545. case "excel": // 插入EXCEL表格
  546. insertHTML("<object classid='clsid:0002E510-0000-0000-C000-000000000046' id='Spreadsheet1' codebase='file:\\Bob\software\office2000\msowc.cab' width='100%' height='250'><param name='HTMLURL' value><param name='HTMLData' value='&lt;html xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot;xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;&lt;head&gt;&lt;style type=&quot;text/css&quot;&gt;&lt;!--tr{mso-height-source:auto;}td{black-space:nowrap;}.wc4590F88{black-space:nowrap;font-family:宋体;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}--&gt;&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;&lt;x:ExcelWorkbook&gt;&lt;x:ExcelWorksheets&gt;&lt;x:ExcelWorksheet&gt;&lt;x:OWCVersion&gt;9.0.0.2710&lt;/x:OWCVersion&gt;&lt;x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver;border-right:solid .5pt silver;border-bottom:solid .5pt silver'&gt;&lt;x:Caption&gt;Microsoft Office Spreadsheet&lt;/x:Caption&gt; &lt;/x:Label&gt;&lt;x:Name&gt;Sheet1&lt;/x:Name&gt;&lt;x:WorksheetOptions&gt;&lt;x:Selected/&gt;&lt;x:Height&gt;7620&lt;/x:Height&gt;&lt;x:Width&gt;15240&lt;/x:Width&gt;&lt;x:TopRowVisible&gt;0&lt;/x:TopRowVisible&gt;&lt;x:LeftColumnVisible&gt;0&lt;/x:LeftColumnVisible&gt; &lt;x:ProtectContents&gt;False&lt;/x:ProtectContents&gt; &lt;x:DefaultRowHeight&gt;210&lt;/x:DefaultRowHeight&gt; &lt;x:StandardWidth&gt;2389&lt;/x:StandardWidth&gt; &lt;/x:WorksheetOptions&gt; &lt;/x:ExcelWorksheet&gt;&lt;/x:ExcelWorksheets&gt; &lt;x:MaxHeight&gt;80%&lt;/x:MaxHeight&gt;&lt;x:MaxWidth&gt;80%&lt;/x:MaxWidth&gt;&lt;/x:ExcelWorkbook&gt;&lt;/xml&gt;&lt;![endif]--&gt;&lt;table class=wc4590F88 x:str&gt;&lt;col width=&quot;56&quot;&gt;&lt;tr height=&quot;14&quot;&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;'> <param name='DataType' value='HTMLDATA'> <param name='AutoFit' value='0'><param name='DisplayColHeaders' value='-1'><param name='DisplayGridlines' value='-1'><param name='DisplayHorizontalScrollBar' value='-1'><param name='DisplayRowHeaders' value='-1'><param name='DisplayTitleBar' value='-1'><param name='DisplayToolbar' value='-1'><param name='DisplayVerticalScrollBar' value='-1'> <param name='EnableAutoCalculate' value='-1'> <param name='EnableEvents' value='-1'><param name='MoveAfterReturn' value='-1'><param name='MoveAfterReturnDirection' value='0'><param name='RightToLeft' value='0'><param name='ViewableRange' value='1:65536'></object>");
  547. break;
  548. case "nowdate": // 插入当前系统日期
  549. var d = new Date();
  550. insertHTML(d.toLocaleDateString());
  551. break;
  552. case "nowtime": // 插入当前系统时间
  553. var d = new Date();
  554. insertHTML(d.toLocaleTimeString());
  555. break;
  556. case "br": // 插入换行符
  557. insertHTML("<br>")
  558. break;
  559. case "code": // 代码片段样式
  560. insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#FDFDDF style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是代码片段:</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
  561. break;
  562. case "quote": // 引用片段样式
  563. insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#F3F3F3 style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是引用片段:</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
  564. break;
  565. case "big": // 字体变大
  566. insertHTML("<big>" + sel.text + "</big>");
  567. break;
  568. case "small": // 字体变小
  569. insertHTML("<small>" + sel.text + "</small>");
  570. break;
  571. default:
  572. alert("错误参数调用!");
  573. break;
  574. }
  575. sel=null;
  576. }
  577. // 显示或隐藏指导方针
  578. var borderShown = "no";
  579. function showBorders() {
  580. if (!validateMode()) return;
  581. var allForms = eWebEditor.document.body.getElementsByTagName("FORM");
  582. var allInputs = eWebEditor.document.body.getElementsByTagName("INPUT");
  583. var allTables = eWebEditor.document.body.getElementsByTagName("TABLE");
  584. var allLinks = eWebEditor.document.body.getElementsByTagName("A");
  585. // 表单
  586. for (a=0; a < allForms.length; a++) {
  587. if (borderShown == "no") {
  588. allForms[a].runtimeStyle.border = "1px dotted #FF0000"
  589. } else {
  590. allForms[a].runtimeStyle.cssText = ""
  591. }
  592. }
  593. // Input Hidden类
  594. for (b=0; b < allInputs.length; b++) {
  595. if (borderShown == "no") {
  596. if (allInputs[b].type.toUpperCase() == "HIDDEN") {
  597. allInputs[b].runtimeStyle.border = "1px dashed #000000"
  598. allInputs[b].runtimeStyle.width = "15px"
  599. allInputs[b].runtimeStyle.height = "15px"
  600. allInputs[b].runtimeStyle.backgroundColor = "#FDADAD"
  601. allInputs[b].runtimeStyle.color = "#FDADAD"
  602. }
  603. } else {
  604. if (allInputs[b].type.toUpperCase() == "HIDDEN")
  605. allInputs[b].runtimeStyle.cssText = ""
  606. }
  607. }
  608. // 表格
  609. for (i=0; i < allTables.length; i++) {
  610. if (borderShown == "no") {
  611. allTables[i].runtimeStyle.border = "1px dotted #BFBFBF"
  612. } else {
  613. allTables[i].runtimeStyle.cssText = ""
  614. }
  615. allRows = allTables[i].rows
  616. for (y=0; y < allRows.length; y++) {
  617. allCellsInRow = allRows[y].cells
  618. for (x=0; x < allCellsInRow.length; x++) {
  619. if (borderShown == "no") {
  620. allCellsInRow[x].runtimeStyle.border = "1px dotted #BFBFBF"
  621. } else {
  622. allCellsInRow[x].runtimeStyle.cssText = ""
  623. }
  624. }
  625. }
  626. }
  627. // 链接 A
  628. for (a=0; a < allLinks.length; a++) {
  629. if (borderShown == "no") {
  630. if (allLinks[a].href.toUpperCase() == "") {
  631. allLinks[a].runtimeStyle.border = "1px dashed #000000"
  632. allLinks[a].runtimeStyle.width = "20px"
  633. allLinks[a].runtimeStyle.height = "16px"
  634. allLinks[a].runtimeStyle.backgroundColor = "#FFFFCC"
  635. allLinks[a].runtimeStyle.color = "#FFFFCC"
  636. }
  637. } else {
  638. allLinks[a].runtimeStyle.cssText = ""
  639. }
  640. }
  641. if (borderShown == "no") {
  642. borderShown = "yes"
  643. } else {
  644. borderShown = "no"
  645. }
  646. scrollUp()
  647. }
  648. // 返回页面最上部
  649. function scrollUp() {
  650. eWebEditor.scrollBy(0,0);
  651. }
  652. // 缩放操作
  653. var nCurrZoomSize = 100;
  654. var aZoomSize = new Array(10, 25, 50, 75, 100, 150, 200, 500);
  655. function doZoom(size) {
  656. eWebEditor.document.body.runtimeStyle.zoom = size + "%";
  657. nCurrZoomSize = size;
  658. }
  659. // 拼写检查
  660. function spellCheck(){
  661. ShowDialog('dialog/spellcheck.htm', 300, 220, true)
  662. }
  663. // 查找替换
  664. function findReplace(){
  665. ShowDialog('dialog/findreplace.htm', 320, 165, true)
  666. }
  667. // 相对(absolute)或绝对位置(static)
  668. function absolutePosition(){
  669. var objReference = null;
  670. var RangeType = eWebEditor.document.selection.type;
  671. if (RangeType != "Control") return;
  672. var selectedRange = eWebEditor.document.selection.createRange();
  673. for (var i=0; i<selectedRange.length; i++){
  674. objReference = selectedRange.item(i);
  675. if (objReference.style.position != 'absolute') {
  676. objReference.style.position='absolute';
  677. }else{
  678. objReference.style.position='static';
  679. }
  680. }
  681. eWebEditor.content = false;
  682. eWebEditor.setActive();
  683. }
  684. // 上移(forward)或下移(backward)一层
  685. function zIndex(action){
  686. var objReference = null;
  687. var RangeType = eWebEditor.document.selection.type;
  688. if (RangeType != "Control") return;
  689. var selectedRange = eWebEditor.document.selection.createRange();
  690. for (var i=0; i<selectedRange.length; i++){
  691. objReference = selectedRange.item(i);
  692. if (action=='forward'){
  693. objReference.style.zIndex +=1;
  694. }else{
  695. objReference.style.zIndex -=1;
  696. }
  697. objReference.style.position='absolute';
  698. }
  699. eWebEditor.content = false;
  700. eWebEditor.setActive();
  701. }
  702. // 是否选中指定类型的控件
  703. function isControlSelected(tag){
  704. if (eWebEditor.document.selection.type == "Control") {
  705. var oControlRange = eWebEditor.document.selection.createRange();
  706. if (oControlRange(0).tagName.toUpperCase() == tag) {
  707. return true;
  708. }
  709. }
  710. return false;
  711. }
  712. // 改变编辑区高度
  713. function sizeChange(size){
  714. for (var i=0; i<parent.frames.length; i++){
  715. if (parent.frames[i].document==self.document){
  716. var obj=parent.frames[i].frameElement;
  717. var height = parseInt(obj.offsetHeight);
  718. if (height+size>=300){
  719. obj.height=height+size;
  720. }
  721. break;
  722. }
  723. }
  724. }
  725. // 大文件内容自动拆分
  726. function splitTextField(objField, html) {
  727. var strFieldName = objField.name;
  728. var objForm = objField.form;
  729. var objDocument = objField.document;
  730. objField.value = html;
  731. //表单限制值设定,限制值是102399,考虑到中文设为一半
  732. var FormLimit = 50000 ;
  733. // 再次处理时,先赋空值
  734. for (var i=1;i<objDocument.getElementsByName(strFieldName).length;i++) {
  735. objDocument.getElementsByName(strFieldName)[i].value = "";
  736. }
  737. //如果表单值超过限制,拆成多个对象
  738. if (html.length > FormLimit) {
  739. objField.value = html.substr(0, FormLimit) ;
  740. html = html.substr(FormLimit) ;
  741. while (html.length > 0) {
  742. var objTEXTAREA = objDocument.createElement("TEXTAREA") ;
  743. objTEXTAREA.name = strFieldName ;
  744. objTEXTAREA.style.display = "none" ;
  745. objTEXTAREA.value = html.substr(0, FormLimit) ;
  746. objForm.appendChild(objTEXTAREA) ;
  747. html = html.substr(FormLimit) ;
  748. }
  749. }
  750. }
  751. // 远程上传
  752. function remoteUpload() {
  753. if (sCurrMode=="TEXT") return;
  754. var objField = document.getElementsByName("eWebEditor_UploadText")[0];
  755. splitTextField(objField, getHTML());
  756. divProcessing.style.top = (document.body.clientHeight-parseFloat(divProcessing.style.height))/2;
  757. divProcessing.style.left = (document.body.clientWidth-parseFloat(divProcessing.style.width))/2;
  758. divProcessing.style.display = "";
  759. eWebEditor_UploadForm.submit();
  760. }
  761. // 远程上传完成
  762. function remoteUploadOK() {
  763. divProcessing.style.display = "none";
  764. if (bDoneAutoRemote){
  765. doSubmit();
  766. }
  767. }