Editor.js
资源名称:1.rar [点击查看]
上传用户:yrf020
上传日期:2007-07-24
资源大小:1287k
文件大小:30k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

HTML/CSS

  1. // 当前模式
  2. var sCurrMode = null;
  3. var bEditMode = null;
  4. // 连接对象
  5. var oLinkField = null;
  6. // 浏览器版本检测
  7. var BrowserInfo = new Object() ;
  8. BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;
  9. BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE ..(.)/)[1] ;
  10. BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 && BrowserInfo.MinorVer >= 5 ) ;
  11. var yToolbars = new Array();  // 工具栏数组
  12. // 当文档完全调入时,进行初始化
  13. var bInitialized = false;
  14. function document.onreadystatechange(){
  15. if (document.readyState!="complete") return;
  16. if (bInitialized) return;
  17. bInitialized = true;
  18. var i, s, curr;
  19. // 初始每个工具栏
  20. for (i=0; i<document.body.all.length;i++){
  21. curr=document.body.all[i];
  22. if (curr.className == "yToolbar"){
  23. InitTB(curr);
  24. yToolbars[yToolbars.length] = curr;
  25. }
  26. }
  27. oLinkField = parent.document.getElementsByName(sLinkFieldName)[0];
  28. if (!config.License){
  29. try{
  30. eWebEditor_License.innerHTML = "";
  31. }
  32. catch(e){
  33. }
  34. }
  35. // IE5.5以下版本只能使用纯文本模式
  36. if (!BrowserInfo.IsIE55OrMore){
  37. config.InitMode = "TEXT";
  38. }
  39. if (ContentFlag.value=="0") { 
  40. ContentEdit.value = oLinkField.value;
  41. ContentLoad.value = oLinkField.value;
  42. ModeEdit.value = config.InitMode;
  43. ContentFlag.value = "1";
  44. }
  45. setMode(ModeEdit.value);
  46. setLinkedField() ;
  47. }
  48. // 初始化一个工具栏上的按钮
  49. function InitBtn(btn) {
  50. btn.onmouseover = BtnMouseOver;
  51. btn.onmouseout = BtnMouseOut;
  52. btn.onmousedown = BtnMouseDown;
  53. btn.onmouseup = BtnMouseUp;
  54. btn.ondragstart = YCancelEvent;
  55. btn.onselectstart = YCancelEvent;
  56. btn.onselect = YCancelEvent;
  57. btn.YUSERONCLICK = btn.onclick;
  58. btn.onclick = YCancelEvent;
  59. btn.YINITIALIZED = true;
  60. return true;
  61. }
  62. //Initialize a toolbar. 
  63. function InitTB(y) {
  64. // Set initial size of toolbar to that of the handle
  65. y.TBWidth = 0;
  66. // Populate the toolbar with its contents
  67. if (! PopulateTB(y)) return false;
  68. // Set the toolbar width and put in the handle
  69. y.style.posWidth = y.TBWidth;
  70. return true;
  71. }
  72. // Hander that simply cancels an event
  73. function YCancelEvent() {
  74. event.returnValue=false;
  75. event.cancelBubble=true;
  76. return false;
  77. }
  78. // Toolbar button onmouseover handler
  79. function BtnMouseOver() {
  80. if (event.srcElement.tagName != "IMG") return false;
  81. var image = event.srcElement;
  82. var element = image.parentElement;
  83. // Change button look based on current state of image.
  84. if (image.className == "Ico") element.className = "BtnMouseOverUp";
  85. else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";
  86. event.cancelBubble = true;
  87. }
  88. // Toolbar button onmouseout handler
  89. function BtnMouseOut() {
  90. if (event.srcElement.tagName != "IMG") {
  91. event.cancelBubble = true;
  92. return false;
  93. }
  94. var image = event.srcElement;
  95. var element = image.parentElement;
  96. yRaisedElement = null;
  97. element.className = "Btn";
  98. image.className = "Ico";
  99. event.cancelBubble = true;
  100. }
  101. // Toolbar button onmousedown handler
  102. function BtnMouseDown() {
  103. if (event.srcElement.tagName != "IMG") {
  104. event.cancelBubble = true;
  105. event.returnValue=false;
  106. return false;
  107. }
  108. var image = event.srcElement;
  109. var element = image.parentElement;
  110. element.className = "BtnMouseOverDown";
  111. image.className = "IcoDown";
  112. event.cancelBubble = true;
  113. event.returnValue=false;
  114. return false;
  115. }
  116. // Toolbar button onmouseup handler
  117. function BtnMouseUp() {
  118. if (event.srcElement.tagName != "IMG") {
  119. event.cancelBubble = true;
  120. return false;
  121. }
  122. var image = event.srcElement;
  123. var element = image.parentElement;
  124. if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");
  125. element.className = "BtnMouseOverUp";
  126. image.className = "Ico";
  127. event.cancelBubble = true;
  128. return false;
  129. }
  130. // Populate a toolbar with the elements within it
  131. function PopulateTB(y) {
  132. var i, elements, element;
  133. // Iterate through all the top-level elements in the toolbar
  134. elements = y.children;
  135. for (i=0; i<elements.length; i++) {
  136. element = elements[i];
  137. if (element.tagName == "SCRIPT" || element.tagName == "!") continue;
  138. switch (element.className) {
  139. case "Btn":
  140. if (element.YINITIALIZED == null) {
  141. if (! InitBtn(element)) {
  142. alert("Problem initializing:" + element.id);
  143. return false;
  144. }
  145. }
  146. element.style.posLeft = y.TBWidth;
  147. y.TBWidth += element.offsetWidth + 1;
  148. break;
  149. case "TBGen":
  150. element.style.posLeft = y.TBWidth;
  151. y.TBWidth += element.offsetWidth + 1;
  152. break;
  153. case "TBSep":
  154. element.style.posLeft = y.TBWidth + 2;
  155. y.TBWidth += 5;
  156. break;
  157. case "TBHandle":
  158. element.style.posLeft = 2;
  159. y.TBWidth += element.offsetWidth + 7;
  160. break;
  161. default:
  162. alert("Invalid class: " + element.className + " on Element: " + element.id + " <" + element.tagName + ">");
  163. return false;
  164. }
  165. }
  166. y.TBWidth += 1;
  167. return true;
  168. }
  169. // 设置所属表单的提交或reset事件
  170. function setLinkedField() {
  171. if (! oLinkField) return ;
  172. var oForm = oLinkField.form ;
  173. if (!oForm) return ;
  174. // 附加submit事件
  175. oForm.attachEvent("onsubmit", AttachSubmit) ;
  176. if (! oForm.submitEditor) oForm.submitEditor = new Array() ;
  177. oForm.submitEditor[oForm.submitEditor.length] = AttachSubmit ;
  178. if (! oForm.originalSubmit) {
  179. oForm.originalSubmit = oForm.submit ;
  180. oForm.submit = function() {
  181. if (this.submitEditor) {
  182. for (var i = 0 ; i < this.submitEditor.length ; i++) {
  183. this.submitEditor[i]() ;
  184. }
  185. }
  186. this.originalSubmit() ;
  187. }
  188. }
  189. // 附加reset事件
  190. oForm.attachEvent("onreset", AttachReset) ;
  191. if (! oForm.resetEditor) oForm.resetEditor = new Array() ;
  192. oForm.resetEditor[oForm.resetEditor.length] = AttachReset ;
  193. if (! oForm.originalReset) {
  194. oForm.originalReset = oForm.reset ;
  195. oForm.reset = function() {
  196. if (this.resetEditor) {
  197. for (var i = 0 ; i < this.resetEditor.length ; i++) {
  198. this.resetEditor[i]() ;
  199. }
  200. }
  201. this.originalReset() ;
  202. }
  203. }
  204. }
  205. // 附加submit提交事件,大表单数据提交,远程文件获取,保存eWebEditor中的内容
  206. function AttachSubmit() { 
  207. var oForm = oLinkField.form ;
  208. if (!oForm) return;
  209. var html = getHTML();
  210. ContentEdit.value = html;
  211. if (sCurrMode=="TEXT"){
  212. html = HTMLEncode(html);
  213. }
  214. splitTextField(oLinkField, html);
  215. // 提交表单
  216. function doSubmit(){
  217. var oForm = oLinkField.form ;
  218. if (!oForm) return ;
  219. oForm.submit();
  220. }
  221. // 附加Reset事件
  222. function AttachReset() {
  223. if(bEditMode){
  224. eWebEditor.document.body.innerHTML = ContentLoad.value;
  225. }else{
  226. eWebEditor.document.body.innerText = ContentLoad.value;
  227. }
  228. }
  229. // 显示帮助
  230. function onHelp(){
  231. ShowDialog('dialog/help.htm','400','310');
  232. return false;
  233. }
  234. // 粘贴时自动检测是否来源于Word格式
  235. function onPaste() {
  236. if (sCurrMode=="VIEW") return false;
  237. if (sCurrMode=="EDIT"){
  238. var sHTML = GetClipboardHTML() ;
  239. if (config.AutoDetectPasteFromWord && BrowserInfo.IsIE55OrMore) {
  240. var re = /<w[^>]* class="?MsoNormal"?/gi ;
  241. if ( re.test(sHTML)){
  242. if ( confirm( "你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?" ) ){
  243. cleanAndPaste( sHTML ) ;
  244. return false ;
  245. }
  246. }
  247. }
  248. eWebEditor.document.selection.createRange().pasteHTML(sHTML) ;
  249. return false;
  250. }else{
  251. eWebEditor.document.selection.createRange().pasteHTML(HTMLEncode( clipboardData.getData("Text"))) ;
  252. return false;
  253. }
  254. }
  255. // 快捷键
  256. function onKeyDown(event){
  257. var key = String.fromCharCode(event.keyCode).toUpperCase();
  258. // F2:显示或隐藏指导方针
  259. if (event.keyCode==113){
  260. showBorders();
  261. return false;
  262. }
  263. if (event.ctrlKey){
  264. // Ctrl+Enter:提交
  265. if (event.keyCode==10){
  266. doSubmit();
  267. return false;
  268. }
  269. // Ctrl++:增加编辑区
  270. if (key=="+"){
  271. sizeChange(300);
  272. return false;
  273. }
  274. // Ctrl+-:减小编辑区
  275. if (key=="-"){
  276. sizeChange(-300);
  277. return false;
  278. }
  279. // Ctrl+1:代码模式
  280. if (key=="1"){
  281. setMode("CODE");
  282. return false;
  283. }
  284. // Ctrl+2:设计模式
  285. if (key=="2"){
  286. setMode("EDIT");
  287. return false;
  288. }
  289. // Ctrl+3:纯文本
  290. if (key=="3"){
  291. setMode("TEXT");
  292. return false;
  293. }
  294. // Ctrl+4:预览
  295. if (key=="4"){
  296. setMode("VIEW");
  297. return false;
  298. }
  299. }
  300. switch(sCurrMode){
  301. case "VIEW":
  302. return true;
  303. break;
  304. case "EDIT":
  305. if (event.ctrlKey){
  306. // Ctrl+D:从Word粘贴
  307. if (key == "D"){
  308. PasteWord();
  309. return false;
  310. }
  311. // Ctrl+R:查找替换
  312. if (key == "R"){
  313. findReplace();
  314. return false;
  315. }
  316. // Ctrl+Z:Undo
  317. if (key == "Z"){
  318. goHistory(-1);
  319. return false;
  320. }
  321. // Ctrl+Y:Redo
  322. if (key == "Y"){
  323. goHistory(1);
  324. return false;
  325. }
  326. }
  327. if(!event.ctrlKey && event.keyCode != 90 && event.keyCode != 89) {
  328. if (event.keyCode == 32 || event.keyCode == 13){
  329. saveHistory()
  330. }
  331. }
  332. return true;
  333. break;
  334. default:
  335. if (event.keyCode==13){
  336. var sel = eWebEditor.document.selection.createRange();
  337. sel.pasteHTML("<BR>");
  338. event.cancelBubble = true;
  339. event.returnValue = false;
  340. sel.select();
  341. sel.moveEnd("character", 1);
  342. sel.moveStart("character", 1);
  343. sel.collapse(false);
  344. return false;
  345. }
  346. // 屏蔽事件
  347. if (event.ctrlKey){
  348. // Ctrl+B,I,U
  349. if ((key == "B")||(key == "I")||(key == "U")){
  350. return false;
  351. }
  352. }
  353. }
  354. }
  355. // 取剪粘板中的HTML格式数据
  356. function GetClipboardHTML() {
  357. var oDiv = document.getElementById("eWebEditor_Temp_HTML")
  358. oDiv.innerHTML = "" ;
  359. var oTextRange = document.body.createTextRange() ;
  360. oTextRange.moveToElementText(oDiv) ;
  361. oTextRange.execCommand("Paste") ;
  362. var sData = oDiv.innerHTML ;
  363. oDiv.innerHTML = "" ;
  364. return sData ;
  365. }
  366. // 清除WORD冗余格式并粘贴
  367. function cleanAndPaste( html ) {
  368. // Remove all SPAN tags
  369. html = html.replace(/</?SPAN[^>]*>/gi, "" );
  370. // Remove Class attributes
  371. html = html.replace(/<(w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  372. // Remove Style attributes
  373. html = html.replace(/<(w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
  374. // Remove Lang attributes
  375. html = html.replace(/<(w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  376. // Remove XML elements and declarations
  377. html = html.replace(/<\??xml[^>]*>/gi, "") ;
  378. // Remove Tags with XML namespace declarations: <o:p></o:p>
  379. html = html.replace(/</?w+:[^>]*>/gi, "") ;
  380. // Replace the &nbsp;
  381. html = html.replace(/&nbsp;/, " " );
  382. // Transform <P> to <DIV>
  383. var re = new RegExp("(<P)([^>]*>.*?)(</P>)","gi") ; // Different because of a IE 5.0 error
  384. html = html.replace( re, "<div$2</div>" ) ;
  385. insertHTML( html ) ;
  386. }
  387. // 在当前文档位置插入.
  388. function insertHTML(html) {
  389. if (isModeView()) return false;
  390. if (eWebEditor.document.selection.type.toLowerCase() != "none"){
  391. eWebEditor.document.selection.clear() ;
  392. }
  393. if (sCurrMode!="EDIT"){
  394. html=HTMLEncode(html);
  395. }
  396. eWebEditor.document.selection.createRange().pasteHTML(html) ; 
  397. }
  398. // 设置编辑器的内容
  399. function setHTML(html) {
  400. ContentEdit.value = html;
  401. switch (sCurrMode){
  402. case "CODE":
  403. eWebEditor.document.designMode="On";
  404. eWebEditor.document.open();
  405. eWebEditor.document.write(config.StyleEditorHeader);
  406. eWebEditor.document.body.innerText=html;
  407. eWebEditor.document.body.contentEditable="true";
  408. eWebEditor.document.close();
  409. bEditMode=false;
  410. break;
  411. case "EDIT":
  412. eWebEditor.document.designMode="On";
  413. eWebEditor.document.open();
  414. eWebEditor.document.write(config.StyleEditorHeader+html);
  415. eWebEditor.document.body.contentEditable="true";
  416. eWebEditor.document.execCommand("2D-Position",true,true);
  417. eWebEditor.document.execCommand("MultipleSelection", true, true);
  418. eWebEditor.document.execCommand("LiveResize", true, true);
  419. eWebEditor.document.close();
  420. doZoom(nCurrZoomSize);
  421. bEditMode=true;
  422. eWebEditor.document.onselectionchange = function () { doToolbar();}
  423. break;
  424. case "TEXT":
  425. eWebEditor.document.designMode="On";
  426. eWebEditor.document.open();
  427. eWebEditor.document.write(config.StyleEditorHeader);
  428. eWebEditor.document.body.innerText=html;
  429. eWebEditor.document.body.contentEditable="true";
  430. eWebEditor.document.close();
  431. bEditMode=false;
  432. break;
  433. case "VIEW":
  434. eWebEditor.document.designMode="off";
  435. eWebEditor.document.open();
  436. eWebEditor.document.write(config.StyleEditorHeader+html);
  437. eWebEditor.document.body.contentEditable="false";
  438. eWebEditor.document.close();
  439. bEditMode=false;
  440. break;
  441. }
  442. eWebEditor.document.body.onpaste = onPaste ;
  443. eWebEditor.document.body.onhelp = onHelp ;
  444. eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
  445. eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");
  446. if ((borderShown != "0")&&bEditMode) {
  447. borderShown = "0";
  448. showBorders();
  449. }
  450. initHistory();
  451. }
  452. // 取编辑器的内容
  453. function getHTML() {
  454. var html;
  455. if((sCurrMode=="EDIT")||(sCurrMode=="VIEW")){
  456. html = eWebEditor.document.body.innerHTML;
  457. }else{
  458. html = eWebEditor.document.body.innerText;
  459. }
  460. if (sCurrMode!="TEXT"){
  461. if ((html.toLowerCase()=="<p>&nbsp;</p>")||(html.toLowerCase()=="<p></p>")){
  462. html = "";
  463. }
  464. }
  465. return html;
  466. }
  467. // 在尾部追加内容
  468. function appendHTML(html) {
  469. if (isModeView()) return false;
  470. if(sCurrMode=="EDIT"){
  471. eWebEditor.document.body.innerHTML += html;
  472. }else{
  473. eWebEditor.document.body.innerText += html;
  474. }
  475. }
  476. // 从Word中粘贴,去除格式
  477. function PasteWord(){
  478. if (!validateMode()) return;
  479. eWebEditor.focus();
  480. if (BrowserInfo.IsIE55OrMore)
  481. cleanAndPaste( GetClipboardHTML() ) ;
  482. else if ( confirm( "此功能要求IE5.5版本以上,你当前的浏览器不支持,是否按常规粘贴进行?" ) )
  483. format("paste") ;
  484. eWebEditor.focus();
  485. }
  486. // 粘贴纯文本
  487. function PasteText(){
  488. if (!validateMode()) return;
  489. eWebEditor.focus();
  490. var sText = HTMLEncode( clipboardData.getData("Text") ) ;
  491. insertHTML(sText);
  492. eWebEditor.focus();
  493. }
  494. // 检测当前是否允许编辑
  495. function validateMode() {
  496. if (sCurrMode=="EDIT") return true;
  497. alert("需转换为编辑状态后才能使用编辑功能!");
  498. eWebEditor.focus();
  499. return false;
  500. }
  501. // 检测当前是否在预览模式
  502. function isModeView(){
  503. if (sCurrMode=="VIEW"){
  504. alert("预览时不允许设置编辑区内容。");
  505. return true;
  506. }
  507. return false;
  508. }
  509. // 格式化编辑器中的内容
  510. function format(what,opt) {
  511. if (!validateMode()) return;
  512. eWebEditor.focus();
  513. if (opt=="RemoveFormat") {
  514. what=opt;
  515. opt=null;
  516. }
  517. if (opt==null) eWebEditor.document.execCommand(what);
  518. else eWebEditor.document.execCommand(what,"",opt);
  519. eWebEditor.focus();
  520. }
  521. // 确保焦点在 eWebEditor 内
  522. function VerifyFocus() {
  523. if ( eWebEditor )
  524. eWebEditor.focus();
  525. }
  526. // 改变模式:代码、编辑、文本、预览
  527. function setMode(NewMode){
  528. if (NewMode!=sCurrMode){
  529. if (!BrowserInfo.IsIE55OrMore){
  530. if ((NewMode=="CODE") || (NewMode=="EDIT") || (NewMode=="VIEW")){
  531. alert("HTML编辑模式需要IE5.5版本以上的支持!");
  532. return false;
  533. }
  534. }
  535. if (NewMode=="TEXT"){
  536. if (sCurrMode==ModeEdit.value){
  537. if (!confirm("警告!切换到纯文本模式会丢失您所有的HTML格式,您确认切换吗?")){
  538. return false;
  539. }
  540. }
  541. }
  542. var sBody = "";
  543. switch(sCurrMode){
  544. case "CODE":
  545. if (NewMode=="TEXT"){
  546. eWebEditor_Temp_HTML.innerHTML = eWebEditor.document.body.innerText;
  547. sBody = eWebEditor_Temp_HTML.innerText;
  548. }else{
  549. sBody = eWebEditor.document.body.innerText;
  550. }
  551. break;
  552. case "TEXT":
  553. sBody = eWebEditor.document.body.innerText;
  554. sBody = HTMLEncode(sBody);
  555. break;
  556. case "EDIT":
  557. case "VIEW":
  558. if (NewMode=="TEXT"){
  559. sBody = eWebEditor.document.body.innerText;
  560. }else{
  561. sBody = eWebEditor.document.body.innerHTML;
  562. }
  563. break;
  564. default:
  565. sBody = ContentEdit.value;
  566. break;
  567. }
  568. // 换图片
  569. try{
  570. document.all["eWebEditor_CODE"].className = "StatusBarBtnOff";
  571. document.all["eWebEditor_EDIT"].className = "StatusBarBtnOff";
  572. document.all["eWebEditor_TEXT"].className = "StatusBarBtnOff";
  573. document.all["eWebEditor_VIEW"].className = "StatusBarBtnOff";
  574. document.all["eWebEditor_"+NewMode].className = "StatusBarBtnOn";
  575. }
  576. catch(e){
  577. }
  578. sCurrMode = NewMode;
  579. ModeEdit.value = NewMode;
  580. setHTML(sBody);
  581. disableChildren(eWebEditor_Toolbar);
  582. }
  583. }
  584. // 使工具栏无效
  585. function disableChildren(obj){
  586. if (obj){
  587. obj.disabled=(!bEditMode);
  588. for (var i=0; i<obj.children.length; i++){
  589. disableChildren(obj.children[i]);
  590. }
  591. }
  592. }
  593. // 显示无模式对话框
  594. function ShowDialog(url, width, height, optValidate) {
  595. if (optValidate) {
  596. if (!validateMode()) return;
  597. }
  598. eWebEditor.focus();
  599. var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
  600. eWebEditor.focus();
  601. }
  602. // 全屏编辑
  603. function Maximize() {
  604. if (!validateMode()) return;
  605. 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');
  606. }
  607. // 创建或修改超级链接
  608. function createLink(){
  609. if (!validateMode()) return;
  610. if (eWebEditor.document.selection.type == "Control") {
  611. var oControlRange = eWebEditor.document.selection.createRange();
  612. if (oControlRange(0).tagName.toUpperCase() != "IMG") {
  613. alert("链接只能是图片或文本");
  614. return;
  615. }
  616. }
  617. ShowDialog("dialog/hyperlink.htm", 350, 180, true);
  618. }
  619. // 替换特殊字符
  620. function HTMLEncode(text){
  621. text = text.replace(/&/g, "&amp;") ;
  622. text = text.replace(/"/g, "&quot;") ;
  623. text = text.replace(/</g, "&lt;") ;
  624. text = text.replace(/>/g, "&gt;") ;
  625. text = text.replace(/'/g, "&#146;") ;
  626. text = text.replace(/ /g,"&nbsp;");
  627. text = text.replace(/n/g,"<br>");
  628. text = text.replace(/t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");
  629. return text;
  630. }
  631. // 插入特殊对象
  632. function insert(what) {
  633. if (!validateMode()) return;
  634. eWebEditor.focus();
  635. var sel = eWebEditor.document.selection.createRange();
  636. switch(what){
  637. case "excel": // 插入EXCEL表格
  638. insertHTML("<object classid='clsid:0002E510-0000-0000-C000-000000000046' id='Spreadsheet1' codebase='file:\Bobsoftwareoffice2000msowc.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>");
  639. break;
  640. case "nowdate": // 插入当前系统日期
  641. var d = new Date();
  642. insertHTML(d.toLocaleDateString());
  643. break;
  644. case "nowtime": // 插入当前系统时间
  645. var d = new Date();
  646. insertHTML(d.toLocaleTimeString());
  647. break;
  648. case "br": // 插入换行符
  649. insertHTML("<br>")
  650. break;
  651. case "code": // 代码片段样式
  652. 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>');
  653. break;
  654. case "quote": // 引用片段样式
  655. 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>');
  656. break;
  657. case "big": // 字体变大
  658. insertHTML("<big>" + sel.text + "</big>");
  659. break;
  660. case "small": // 字体变小
  661. insertHTML("<small>" + sel.text + "</small>");
  662. break;
  663. default:
  664. alert("错误参数调用!");
  665. break;
  666. }
  667. sel=null;
  668. }
  669. // 显示或隐藏指导方针
  670. var borderShown = config.ShowBorder;
  671. function showBorders() {
  672. if (!validateMode()) return;
  673. var allForms = eWebEditor.document.body.getElementsByTagName("FORM");
  674. var allInputs = eWebEditor.document.body.getElementsByTagName("INPUT");
  675. var allTables = eWebEditor.document.body.getElementsByTagName("TABLE");
  676. var allLinks = eWebEditor.document.body.getElementsByTagName("A");
  677. // 表单
  678. for (a=0; a < allForms.length; a++) {
  679. if (borderShown == "0") {
  680. allForms[a].runtimeStyle.border = "1px dotted #FF0000"
  681. } else {
  682. allForms[a].runtimeStyle.cssText = ""
  683. }
  684. }
  685. // Input Hidden类
  686. for (b=0; b < allInputs.length; b++) {
  687. if (borderShown == "0") {
  688. if (allInputs[b].type.toUpperCase() == "HIDDEN") {
  689. allInputs[b].runtimeStyle.border = "1px dashed #000000"
  690. allInputs[b].runtimeStyle.width = "15px"
  691. allInputs[b].runtimeStyle.height = "15px"
  692. allInputs[b].runtimeStyle.backgroundColor = "#FDADAD"
  693. allInputs[b].runtimeStyle.color = "#FDADAD"
  694. }
  695. } else {
  696. if (allInputs[b].type.toUpperCase() == "HIDDEN")
  697. allInputs[b].runtimeStyle.cssText = ""
  698. }
  699. }
  700. // 表格
  701. for (i=0; i < allTables.length; i++) {
  702. if (borderShown == "0") {
  703. allTables[i].runtimeStyle.border = "1px dotted #BFBFBF"
  704. } else {
  705. allTables[i].runtimeStyle.cssText = ""
  706. }
  707. allRows = allTables[i].rows
  708. for (y=0; y < allRows.length; y++) {
  709.   allCellsInRow = allRows[y].cells
  710. for (x=0; x < allCellsInRow.length; x++) {
  711. if (borderShown == "0") {
  712. allCellsInRow[x].runtimeStyle.border = "1px dotted #BFBFBF"
  713. } else {
  714. allCellsInRow[x].runtimeStyle.cssText = ""
  715. }
  716. }
  717. }
  718. }
  719. // 链接 A
  720. for (a=0; a < allLinks.length; a++) {
  721. if (borderShown == "0") {
  722. if (allLinks[a].href.toUpperCase() == "") {
  723. allLinks[a].runtimeStyle.borderBottom = "1px dashed #000000"
  724. }
  725. } else {
  726. allLinks[a].runtimeStyle.cssText = ""
  727. }
  728. }
  729. if (borderShown == "0") {
  730. borderShown = "1"
  731. } else {
  732. borderShown = "0"
  733. }
  734. scrollUp()
  735. }
  736. // 返回页面最上部
  737. function scrollUp() {
  738. eWebEditor.scrollBy(0,0);
  739. }
  740. // 缩放操作
  741. var nCurrZoomSize = 100;
  742. var aZoomSize = new Array(10, 25, 50, 75, 100, 150, 200, 500);
  743. function doZoom(size) {
  744. eWebEditor.document.body.runtimeStyle.zoom = size + "%";
  745. nCurrZoomSize = size;
  746. }
  747. // 拼写检查
  748. function spellCheck(){
  749. ShowDialog('dialog/spellcheck.htm', 300, 230, true)
  750. }
  751. // 查找替换
  752. function findReplace(){
  753. ShowDialog('dialog/findreplace.htm', 320, 175, true)
  754. }
  755. // 相对(absolute)或绝对位置(static)
  756. function absolutePosition(){
  757. var objReference = null;
  758. var RangeType = eWebEditor.document.selection.type;
  759. if (RangeType != "Control") return;
  760. var selectedRange = eWebEditor.document.selection.createRange();
  761. for (var i=0; i<selectedRange.length; i++){
  762. objReference = selectedRange.item(i);
  763. if (objReference.style.position != 'absolute') {
  764. objReference.style.position='absolute';
  765. }else{
  766. objReference.style.position='static';
  767. }
  768. }
  769. }
  770. // 上移(forward)或下移(backward)一层
  771. function zIndex(action){
  772. var objReference = null;
  773. var RangeType = eWebEditor.document.selection.type;
  774. if (RangeType != "Control") return;
  775. var selectedRange = eWebEditor.document.selection.createRange();
  776. for (var i=0; i<selectedRange.length; i++){
  777. objReference = selectedRange.item(i);
  778. if (action=='forward'){
  779. objReference.style.zIndex  +=1;
  780. }else{
  781. objReference.style.zIndex  -=1;
  782. }
  783. objReference.style.position='absolute';
  784. }
  785. }
  786. // 是否选中指定类型的控件
  787. function isControlSelected(tag){
  788. if (eWebEditor.document.selection.type == "Control") {
  789. var oControlRange = eWebEditor.document.selection.createRange();
  790. if (oControlRange(0).tagName.toUpperCase() == tag) {
  791. return true;
  792. }
  793. }
  794. return false;
  795. }
  796. // 改变编辑区高度
  797. function sizeChange(size){
  798. if (!BrowserInfo.IsIE55OrMore){
  799. alert("此功能需要IE5.5版本以上的支持!");
  800. return false;
  801. }
  802. for (var i=0; i<parent.frames.length; i++){
  803. if (parent.frames[i].document==self.document){
  804. var obj=parent.frames[i].frameElement;
  805. var height = parseInt(obj.offsetHeight);
  806. if (height+size>=300){
  807. obj.height=height+size;
  808. }
  809. break;
  810. }
  811. }
  812. }
  813. // 热点链接
  814. function mapEdit(){
  815. if (!validateMode()) return;
  816. var b = false;
  817. if (eWebEditor.document.selection.type == "Control") {
  818. var oControlRange = eWebEditor.document.selection.createRange();
  819. if (oControlRange(0).tagName.toUpperCase() == "IMG") {
  820. b = true;
  821. }
  822. }
  823. if (!b){
  824. alert("热点链接只能作用于图片");
  825. return;
  826. }
  827. window.open("dialog/map.htm", 'mapEdit'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=not,menubar=no,scrollbars=no,resizable=yes,width=450,height=300');
  828. }
  829. // 上传文件成功返回原文件名、保存后的文件名、保存后的路径文件名,提供接口
  830. function addUploadFile(originalFileName, saveFileName, savePathFileName){
  831. doInterfaceUpload(sLinkOriginalFileName, originalFileName);
  832. doInterfaceUpload(sLinkSaveFileName, saveFileName);
  833. doInterfaceUpload(sLinkSavePathFileName, savePathFileName);
  834. }
  835. // 文件上传成功接口操作
  836. function doInterfaceUpload(strLinkName, strValue){
  837. if (strValue=="") return;
  838. if (strLinkName){
  839. var objLinkUpload = parent.document.getElementsByName(strLinkName)[0];
  840. if (objLinkUpload){
  841. if (objLinkUpload.value!=""){
  842. objLinkUpload.value = objLinkUpload.value + "|";
  843. }
  844. objLinkUpload.value = objLinkUpload.value + strValue;
  845. objLinkUpload.fireEvent("onchange");
  846. }
  847. }
  848. }
  849. // 大文件内容自动拆分
  850. function splitTextField(objField, html) { 
  851. var strFieldName = objField.name;
  852. var objForm = objField.form;
  853. var objDocument = objField.document;
  854. objField.value = html;
  855. //表单限制值设定,限制值是102399,考虑到中文设为一半
  856. var FormLimit = 50000 ;
  857. // 再次处理时,先赋空值
  858. for (var i=1;i<objDocument.getElementsByName(strFieldName).length;i++) {
  859. objDocument.getElementsByName(strFieldName)[i].value = "";
  860. }
  861. //如果表单值超过限制,拆成多个对象
  862. if (html.length > FormLimit) { 
  863. objField.value = html.substr(0, FormLimit) ;
  864. html = html.substr(FormLimit) ;
  865. while (html.length > 0) { 
  866. var objTEXTAREA = objDocument.createElement("TEXTAREA") ;
  867. objTEXTAREA.name = strFieldName ;
  868. objTEXTAREA.style.display = "none" ;
  869. objTEXTAREA.value = html.substr(0, FormLimit) ;
  870. objForm.appendChild(objTEXTAREA) ;
  871. html = html.substr(FormLimit) ;
  872. // 远程上传
  873. function remoteUpload() { 
  874. if (sCurrMode=="TEXT") return;
  875. var objField = document.getElementsByName("eWebEditor_UploadText")[0];
  876. splitTextField(objField, getHTML());
  877. divProcessing.style.top = (document.body.clientHeight-parseFloat(divProcessing.style.height))/2;
  878. divProcessing.style.left = (document.body.clientWidth-parseFloat(divProcessing.style.width))/2;
  879. divProcessing.style.display = "";
  880. eWebEditor_UploadForm.submit();
  881. // 远程上传完成
  882. function remoteUploadOK() {
  883. divProcessing.style.display = "none";
  884. }
  885. // 修正Undo/Redo
  886. var history = new Object;
  887. history.data = [];
  888. history.position = 0;
  889. history.bookmark = [];
  890. // 保存历史
  891. function saveHistory() {
  892. if (bEditMode){
  893. if (history.data[history.position] != eWebEditor.document.body.innerHTML){
  894. var nBeginLen = history.data.length;
  895. var nPopLen = history.data.length - history.position;
  896. for (var i=1; i<nPopLen; i++){
  897. history.data.pop();
  898. history.bookmark.pop();
  899. }
  900. history.data[history.data.length] = eWebEditor.document.body.innerHTML;
  901. if (eWebEditor.document.selection.type != "Control"){
  902. history.bookmark[history.bookmark.length] = eWebEditor.document.selection.createRange().getBookmark();
  903. } else {
  904. var oControl = eWebEditor.document.selection.createRange();
  905. history.bookmark[history.bookmark.length] = oControl[0];
  906. }
  907. if (nBeginLen!=0){
  908. history.position++;
  909. }
  910. }
  911. }
  912. }
  913. // 初始历史
  914. function initHistory() {
  915. history.data.length = 0;
  916. history.bookmark.length = 0;
  917. history.position = 0;
  918. }
  919. // 返回历史
  920. function goHistory(value) {
  921. saveHistory();
  922. // undo
  923. if (value == -1){
  924. if (history.position > 0){
  925. eWebEditor.document.body.innerHTML = history.data[--history.position];
  926. setHistoryCursor();
  927. }
  928. // redo
  929. } else {
  930. if (history.position < history.data.length -1){
  931. eWebEditor.document.body.innerHTML = history.data[++history.position];
  932. setHistoryCursor();
  933. }
  934. }
  935. }
  936. // 设置当前书签
  937. function setHistoryCursor() {
  938. if (history.bookmark[history.position]){
  939. r = eWebEditor.document.body.createTextRange()
  940. if (history.bookmark[history.position] != "[object]"){
  941. if (r.moveToBookmark(history.bookmark[history.position])){
  942. r.collapse(false);
  943. r.select();
  944. }
  945. }
  946. }
  947. }
  948. // End Undo / Redo Fix
  949. // 工具栏事件发生
  950. function doToolbar(){
  951. if (bEditMode){
  952. saveHistory();
  953. }
  954. }