editor_function.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. function uploadEdit(obj) {
  2. mainForm = obj.form;
  3. forms = $('attachbody').getElementsByTagName("FORM");
  4. albumid = $('uploadalbum').value;
  5. edit_save();
  6. upload();
  7. }
  8. function edit_save() {
  9. var p = window.frames['uchome-ifrHtmlEditor'];
  10. var obj = p.window.frames['HtmlEditor'];
  11. var status = p.document.getElementById('uchome-editstatus').value;
  12. if(status == 'code') {
  13. $('uchome-ttHtmlEditor').value = p.document.getElementById('sourceEditor').value;
  14. } else if(status == 'text') {
  15. if(BROWSER.ie) {
  16. obj.document.body.innerText = p.document.getElementById('dvtext').value;
  17. $('uchome-ttHtmlEditor').value = obj.document.body.innerHTML;
  18. } else {
  19. obj.document.body.textContent = p.document.getElementById('dvtext').value;
  20. var sOutText = obj.document.body.innerHTML;
  21. $('uchome-ttHtmlEditor').value = sOutText.replace(/\r\n|\n/g,"<br>");
  22. }
  23. } else {
  24. $('uchome-ttHtmlEditor').value = obj.document.body.innerHTML;
  25. }
  26. backupContent($('uchome-ttHtmlEditor').value);
  27. }
  28. function relatekw() {
  29. edit_save();
  30. var subject = cnCode($('subject').value);
  31. var message = cnCode($('uchome-ttHtmlEditor').value);
  32. if(message) {
  33. message = message.substr(0, 500);
  34. }
  35. var x = new Ajax();
  36. x.get('home.php?mod=spacecp&ac=relatekw&inajax=1&subjectenc=' + subject + '&messageenc=' + message, function(s){
  37. $('tag').value = s;
  38. });
  39. }
  40. function downRemoteFile() {
  41. edit_save();
  42. var formObj = $("articleform");
  43. var oldAction = formObj.action;
  44. formObj.action = "portal.php?mod=portalcp&ac=upload&op=downremotefile";
  45. formObj.onSubmit = "";
  46. formObj.target = "uploadframe";
  47. formObj.submit();
  48. formObj.action = oldAction;
  49. formObj.target = "";
  50. }
  51. function backupContent(sHTML) {
  52. if(sHTML.length > 11) {
  53. var obj = $('uchome-ttHtmlEditor').form;
  54. if(!obj) return;
  55. var data = subject = message = '';
  56. for(var i = 0; i < obj.elements.length; i++) {
  57. var el = obj.elements[i];
  58. if(el.name != '' && (el.tagName == 'TEXTAREA' || el.tagName == 'INPUT' && (el.type == 'text' || el.type == 'checkbox' || el.type == 'radio')) && el.name.substr(0, 6) != 'attach') {
  59. var elvalue = el.value;
  60. if(el.name == 'subject' || el.name == 'title') {
  61. subject = trim(elvalue);
  62. } else if(el.name == 'message' || el.name == 'content') {
  63. message = trim(elvalue);
  64. }
  65. if((el.type == 'checkbox' || el.type == 'radio') && !el.checked) {
  66. continue;
  67. }
  68. if(trim(elvalue)) {
  69. data += el.name + String.fromCharCode(9) + el.tagName + String.fromCharCode(9) + el.type + String.fromCharCode(9) + elvalue + String.fromCharCode(9, 9);
  70. }
  71. }
  72. }
  73. if(!subject && !message) {
  74. return;
  75. }
  76. saveUserdata('home', data);
  77. }
  78. }
  79. function edit_insert(html) {
  80. var p = window.frames['uchome-ifrHtmlEditor'];
  81. var obj = p.window.frames['HtmlEditor'];
  82. var status = p.document.getElementById('uchome-editstatus').value;
  83. if(status != 'html') {
  84. alert('本操作只在多媒体编辑模式下才有效');
  85. return;
  86. }
  87. obj.focus();
  88. if(BROWSER.ie){
  89. var f = obj.document.selection.createRange();
  90. f.pasteHTML(html);
  91. f.collapse(false);
  92. f.select();
  93. } else {
  94. obj.document.execCommand('insertHTML', false, html);
  95. }
  96. }
  97. function insertImage(image, url, width, height) {
  98. url = typeof url == 'undefined' || url === null ? image : url;
  99. width = typeof width == 'undefined' || width === null ? 0 : parseInt(width);
  100. height = typeof height == 'undefined' || height === null ? 0 : parseInt(height);
  101. var html = '<p><a href="' + url + '" target="_blank"><img src="'+image+'"'+(width?' width="'+width+'"':'')+(height?' height="'+height+'"':'')+'></a></p>';
  102. edit_insert(html);
  103. }
  104. function insertFile(file, url) {
  105. url = typeof url == 'undefined' || url === null ? image : url;
  106. var html = '<p><a href="' + url + '" target="_blank" class="attach">' + file + '</a></p>';
  107. edit_insert(html);
  108. }
  109. function createImageBox(fn) {
  110. if(typeof fn == 'function' && !fn()) {
  111. return false;
  112. }
  113. var menu = $('icoImg_image_menu');
  114. if(menu) {
  115. if(menu.style.visibility == 'hidden') {
  116. menu.style.visibility = 'visible';
  117. } else {
  118. menu.style.width = '600px';
  119. showMenu({'ctrlid':'icoImg_image','mtype':'win','evt':'click','pos':'00','timeout':250,'duration':3,'drag':'icoImg_image_ctrl'});
  120. }
  121. }
  122. }
  123. function createAttachBox(fn) {
  124. if(typeof fn == 'function' && !fn()) {
  125. return false;
  126. }
  127. var menu = $('icoAttach_attach_menu');
  128. if(menu) {
  129. if(menu.style.visibility == 'hidden') {
  130. menu.style.visibility = 'visible';
  131. } else {
  132. menu.style.width = '600px';
  133. showMenu({'ctrlid':'icoAttach_attach','mtype':'win','evt':'click','pos':'00','timeout':250,'duration':3,'drag':'icoAttach_attach_ctrl'});
  134. }
  135. }
  136. }
  137. function switchButton(btn, type) {
  138. var btnpre = 'icoImg_btn_';
  139. if(!$(btnpre + btn) || !$('icoImg_' + btn)) {
  140. return;
  141. }
  142. var tabs = $('icoImg_' + type + '_ctrl').getElementsByTagName('LI');
  143. $(btnpre + btn).style.display = '';
  144. $('icoImg_' + btn).style.display = '';
  145. $(btnpre + btn).className = 'current';
  146. var btni = '';
  147. for(i = 0;i < tabs.length;i++) {
  148. if(tabs[i].id.indexOf(btnpre) !== -1) {
  149. btni = tabs[i].id.substr(btnpre.length);
  150. }
  151. if(btni != btn) {
  152. if(!$('icoImg_' + btni) || !$('icoImg_btn_' + btni)) {
  153. continue;
  154. }
  155. $('icoImg_' + btni).style.display = 'none';
  156. $('icoImg_btn_' + btni).className = '';
  157. }
  158. }
  159. }
  160. function changeEditFull(flag) {
  161. var ifrHtmlEditor = $('uchome-ifrHtmlEditor');
  162. var editor = ifrHtmlEditor.parentNode;
  163. if(flag) {
  164. document.body.scroll = 'no';
  165. document.body.style.overflow = 'hidden';
  166. window.resize = function(){changeEditFull(1)};
  167. editor.style.top = '0';
  168. editor.style.left = '0';
  169. editor.style.position = 'fixed';
  170. editor.style.width = '100%';
  171. editor.setAttribute('srcheight', editor.style.height);
  172. editor.style.height = '100%';
  173. editor.style.minWidth = '800px';
  174. editor.style.zIndex = '300';
  175. ifrHtmlEditor.style.height = '100%';
  176. ifrHtmlEditor.style.zoom = ifrHtmlEditor.style.zoom=="1"?"100%":"1";
  177. } else {
  178. document.body.scroll = 'yes';
  179. document.body.style.overflow = 'auto';
  180. window.resize = null;
  181. editor.style.position = '';
  182. editor.style.width = '';
  183. editor.style.height = editor.getAttribute('srcheight');
  184. }
  185. doane();
  186. }
  187. function showInnerNav(){
  188. var navtitle = $('innernavele');
  189. var pagetitle = $('pagetitle');
  190. if(navtitle && navtitle.style.display == 'none') {
  191. navtitle.style.display = '';
  192. }
  193. if(pagetitle && pagetitle.style.display == 'none') {
  194. pagetitle.style.display = '';
  195. }
  196. }