1 | function cRichTextEditor(){ |
---|
2 | this.emwindow = new Array; |
---|
3 | this.editor = "body_1"; |
---|
4 | this.table = ""; |
---|
5 | this.id = "1"; |
---|
6 | this.buildEditor(); |
---|
7 | this.saveFlag = 0; |
---|
8 | } |
---|
9 | |
---|
10 | cRichTextEditor.prototype.loadEditor = function(ID) { |
---|
11 | var _this = this; |
---|
12 | _this.id = ID; |
---|
13 | parentDiv = document.getElementById("body_position_"+this.id); |
---|
14 | this.editor = "body_"+this.id; |
---|
15 | |
---|
16 | if(this.table.parentNode) |
---|
17 | this.table.parentNode.removeChild(this.table); |
---|
18 | |
---|
19 | if( parentDiv.firstChild ) |
---|
20 | { |
---|
21 | if (!parentDiv.firstChild.hasChildNodes()) |
---|
22 | parentDiv.insertBefore(this.table,parentDiv.firstChild); |
---|
23 | } |
---|
24 | else |
---|
25 | parentDiv.appendChild(this.table); |
---|
26 | |
---|
27 | if(!Element(this.editor)) |
---|
28 | { |
---|
29 | this.createElementEditor(this.editor); |
---|
30 | } |
---|
31 | else |
---|
32 | { |
---|
33 | Element("viewsource_rt_checkbox").checked=false; |
---|
34 | } |
---|
35 | |
---|
36 | document.getElementById('fontname').selectedIndex = 0; |
---|
37 | document.getElementById('fontsize').selectedIndex = 0; |
---|
38 | } |
---|
39 | |
---|
40 | cRichTextEditor.prototype.createElementEditor = function(pObj) |
---|
41 | { |
---|
42 | iframe = document.createElement("IFRAME"); |
---|
43 | iframe.id = pObj; |
---|
44 | iframe.name = pObj; |
---|
45 | iframe.width = "99%"; |
---|
46 | iframe.height = 300; |
---|
47 | iframe.setAttribute("unselectable","on"); |
---|
48 | iframe.setAttribute("tabIndex","1"); |
---|
49 | |
---|
50 | config_events( iframe, 'onload', function( ) |
---|
51 | { |
---|
52 | iframe.contentWindow.document.designMode = "on"; |
---|
53 | if ( iframe.contentWindow.document.documentElement ){ |
---|
54 | iframe.contentWindow.document.documentElement.style.background = '#fff'; |
---|
55 | iframe.contentWindow.document.documentElement.style.fontSize = '16px'; |
---|
56 | } |
---|
57 | }); |
---|
58 | |
---|
59 | var checkbox = document.createElement("INPUT"); |
---|
60 | checkbox.id = 'viewsource_rt_checkbox'; |
---|
61 | checkbox.type = "checkbox"; |
---|
62 | checkbox.setAttribute("tabIndex","-1"); |
---|
63 | checkbox.onclick = function () {RichTextEditor.viewsource(this.checked)}; |
---|
64 | var text = document.createTextNode(get_lang('View HTML source') + '.'); |
---|
65 | parentDiv.appendChild(iframe); |
---|
66 | parentDiv.appendChild(checkbox); |
---|
67 | parentDiv.appendChild(text); |
---|
68 | } |
---|
69 | |
---|
70 | cRichTextEditor.prototype.loadStyle = function(tag, css_file) { |
---|
71 | var theRules = new Array(); |
---|
72 | var stylePRE = ""; |
---|
73 | for(var s = 0; s < document.styleSheets.length; s++) { |
---|
74 | if(document.styleSheets[s].href != null && |
---|
75 | document.styleSheets[s].href.match("templates/"+template+"/"+css_file)){ |
---|
76 | if (document.styleSheets[s].cssRules) |
---|
77 | theRules = document.styleSheets[s].cssRules; |
---|
78 | else if (document.styleSheets[s].rules) |
---|
79 | theRules = document.styleSheets[s].rules; |
---|
80 | break; |
---|
81 | } |
---|
82 | } |
---|
83 | for(var s = 0;s < theRules.length; s++){ |
---|
84 | if(theRules[s].selectorText.toLowerCase() == tag.toLowerCase()){ |
---|
85 | stylePRE = theRules[s].style; |
---|
86 | break; |
---|
87 | } |
---|
88 | } |
---|
89 | var _body = Element(this.editor); |
---|
90 | var i_doc = (document.all) ? _body.contentWindow.document: _body.contentDocument; |
---|
91 | var hh1 = i_doc.getElementsByTagName('head')[0]; |
---|
92 | // For IE |
---|
93 | if(typeof(hh1) == 'undefined'){ |
---|
94 | hh1 = i_doc.createElement("head"); |
---|
95 | i_doc.appendChild(hh1); |
---|
96 | } |
---|
97 | var ss1 = i_doc.createElement('style'); |
---|
98 | ss1.setAttribute("type", "text/css"); |
---|
99 | var def = tag.toLowerCase()+' {'+stylePRE.cssText+'}'; |
---|
100 | if (ss1.styleSheet) { |
---|
101 | ss1.styleSheet.cssText = def; |
---|
102 | } else { |
---|
103 | var tt1 = i_doc.createTextNode(def); |
---|
104 | ss1.appendChild(tt1); |
---|
105 | } |
---|
106 | hh1.appendChild(ss1); |
---|
107 | } |
---|
108 | |
---|
109 | cRichTextEditor.prototype.viewsource = function(source) { |
---|
110 | var html; |
---|
111 | var mainField = document.getElementById(this.editor).contentWindow; |
---|
112 | if (source) { |
---|
113 | if (is_ie){ |
---|
114 | connector.loadScript('html2xhtml'); |
---|
115 | html = frames[this.editor].document.body; |
---|
116 | var xhtml = get_xhtml(html, 'en', 'iso-8859-1'); |
---|
117 | frames[this.editor].document.body.innerText = xhtml; |
---|
118 | document.getElementById("table_richtext_toolbar").style.visibility="hidden"; |
---|
119 | } |
---|
120 | else{ |
---|
121 | html = document.createTextNode(document.getElementById(this.editor).contentWindow.document.body.innerHTML); |
---|
122 | document.getElementById(this.editor).contentWindow.document.body.innerHTML = ""; |
---|
123 | html = document.getElementById(this.editor).contentWindow.document.importNode(html,false); |
---|
124 | document.getElementById(this.editor).contentWindow.document.body.appendChild(html); |
---|
125 | document.getElementById("table_richtext_toolbar").style.visibility="hidden"; |
---|
126 | } |
---|
127 | } else { |
---|
128 | if (is_ie){ |
---|
129 | var output = escape(frames[this.editor].document.body.innerText); |
---|
130 | output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E"); |
---|
131 | output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E"); |
---|
132 | frames[this.editor].document.body.innerHTML = unescape(output); |
---|
133 | document.getElementById("table_richtext_toolbar").style.visibility="visible"; |
---|
134 | } |
---|
135 | else{ |
---|
136 | html = document.getElementById(this.editor).contentWindow.document.body.ownerDocument.createRange(); |
---|
137 | html.selectNodeContents(document.getElementById(this.editor).contentWindow.document.body); |
---|
138 | document.getElementById(this.editor).contentWindow.document.body.innerHTML = html.toString(); |
---|
139 | document.getElementById("table_richtext_toolbar").style.visibility="visible"; |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | cRichTextEditor.prototype.buildEditor = function() { |
---|
145 | this.table = document.createElement("TABLE"); |
---|
146 | this.table.id = "table_richtext_toolbar"; |
---|
147 | this.table.className = "richtext_toolbar"; |
---|
148 | this.table.width = "100%"; |
---|
149 | var tbody = document.createElement("TBODY"); |
---|
150 | var tr = document.createElement("TR"); |
---|
151 | var td = document.createElement("TD"); |
---|
152 | var div_button_rt = document.createElement("DIV"); |
---|
153 | |
---|
154 | selectBox=document.createElement("SELECT"); |
---|
155 | selectBox.id="fontname"; |
---|
156 | selectBox.setAttribute("tabIndex","-1"); |
---|
157 | selectBox.onchange = function () {RichTextEditor.Select("fontname");}; |
---|
158 | selectBox.className = 'select_richtext'; |
---|
159 | var option1 = new Option(get_lang('Font'), 'Font'); |
---|
160 | var option2 = new Option('Arial', 'Arial'); |
---|
161 | var option3 = new Option('Courier', 'Courier'); |
---|
162 | var option4 = new Option('Times New Roman', 'Times'); |
---|
163 | if (is_ie){ |
---|
164 | selectBox.add(option1); |
---|
165 | selectBox.add(option2); |
---|
166 | selectBox.add(option3); |
---|
167 | selectBox.add(option4); |
---|
168 | } |
---|
169 | else{ |
---|
170 | selectBox.add(option1, null); |
---|
171 | selectBox.add(option2, null); |
---|
172 | selectBox.add(option3, null); |
---|
173 | selectBox.add(option4, null); |
---|
174 | } |
---|
175 | div_button_rt.appendChild(selectBox); |
---|
176 | |
---|
177 | selectBox=document.createElement("SELECT"); |
---|
178 | selectBox.id="fontsize"; |
---|
179 | selectBox.setAttribute("tabIndex","-1"); |
---|
180 | selectBox.setAttribute("unselectable","on"); |
---|
181 | selectBox.className = 'select_richtext'; |
---|
182 | selectBox.onchange = function () {RichTextEditor.Select("fontsize");}; |
---|
183 | var option1 = new Option(get_lang('Size'), 'Size'); |
---|
184 | var option2 = new Option('1 (8 pt)','1' ); |
---|
185 | var option3 = new Option('2 (10 pt)','2'); |
---|
186 | var option4 = new Option('3 (12 pt)','3'); |
---|
187 | var option5 = new Option('4 (14 pt)','4'); |
---|
188 | var option6 = new Option('5 (18 pt)','5'); |
---|
189 | var option7 = new Option('6 (24 pt)','6'); |
---|
190 | var option8 = new Option('7 (36 pt)','7'); |
---|
191 | if (is_ie){ |
---|
192 | selectBox.add(option1); |
---|
193 | selectBox.add(option2); |
---|
194 | selectBox.add(option3); |
---|
195 | selectBox.add(option4); |
---|
196 | selectBox.add(option5); |
---|
197 | selectBox.add(option6); |
---|
198 | selectBox.add(option7); |
---|
199 | selectBox.add(option8); |
---|
200 | } |
---|
201 | else{ |
---|
202 | selectBox.add(option1, null); |
---|
203 | selectBox.add(option2, null); |
---|
204 | selectBox.add(option3, null); |
---|
205 | selectBox.add(option4, null); |
---|
206 | selectBox.add(option5, null); |
---|
207 | selectBox.add(option6, null); |
---|
208 | selectBox.add(option7, null); |
---|
209 | selectBox.add(option8, null); |
---|
210 | } |
---|
211 | div_button_rt.appendChild(selectBox); |
---|
212 | |
---|
213 | var buttons = ['bold', 'italic', 'underline', 'forecolor', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', |
---|
214 | 'undo', 'redo', 'insertorderedlist', 'insertunorderedlist', 'outdent', 'indent', 'link', 'image', 'table', 'signature']; |
---|
215 | |
---|
216 | for (var i=0; i<buttons.length; i++){ |
---|
217 | var img = document.createElement("IMG"); |
---|
218 | img.id = buttons[i]; |
---|
219 | img.className = 'imagebutton'; |
---|
220 | img.align = 'center'; |
---|
221 | img.src = './templates/'+template+'/images/'+buttons[i]+'.gif'; |
---|
222 | img.title = get_lang(buttons[i]); |
---|
223 | img.style.cursor = 'pointer'; |
---|
224 | |
---|
225 | if (buttons[i] == 'forecolor') |
---|
226 | img.onclick = function () {RichTextEditor.show_pc('forecolor')}; |
---|
227 | else if (buttons[i] == 'link') |
---|
228 | img.onclick = function () {RichTextEditor.createLink();}; |
---|
229 | else if (buttons[i] == 'image') |
---|
230 | img.onclick = function () {RichTextEditor.createImage();}; |
---|
231 | else if (buttons[i] == 'table') |
---|
232 | img.onclick = function () {RichTextEditor.createTable();}; |
---|
233 | else |
---|
234 | img.onclick = function () {RichTextEditor.editorCommand(this.id,'');}; |
---|
235 | |
---|
236 | img.onmouseover = function () {this.style.border="outset 2px";}; |
---|
237 | img.onmouseout = function () {this.style.border="solid 2px #C0C0C0";}; |
---|
238 | div_button_rt.appendChild(img); |
---|
239 | } |
---|
240 | if(preferences.use_SpellChecker != '0'){ |
---|
241 | selectBox=document.createElement("SELECT"); |
---|
242 | selectBox.id="selectLanguage"; |
---|
243 | selectBox.setAttribute("tabIndex","-1"); |
---|
244 | selectBox.setAttribute("unselectable","on"); |
---|
245 | selectBox.className = 'select_richtext'; |
---|
246 | selectBox.onchange = function () {RichTextEditor.Select("selectLanguage");}; |
---|
247 | var option1 = new Option(get_lang("Portuguese"),"pt_BR" ); |
---|
248 | option1.selected = true; |
---|
249 | var option2 = new Option(get_lang("English"),'en'); |
---|
250 | var option3 = new Option(get_lang("Spanish"),'es'); |
---|
251 | if (is_ie){ |
---|
252 | selectBox.add(option1); |
---|
253 | selectBox.add(option2); |
---|
254 | selectBox.add(option3); |
---|
255 | } |
---|
256 | else{ |
---|
257 | selectBox.add(option1, null); |
---|
258 | selectBox.add(option2, null); |
---|
259 | selectBox.add(option3, null); |
---|
260 | } |
---|
261 | div_button_rt.appendChild(selectBox); |
---|
262 | |
---|
263 | // spellCheck button |
---|
264 | var img = document.createElement("IMG"); |
---|
265 | img.id = "spellCheck"; |
---|
266 | img.className = 'imagebutton'; |
---|
267 | img.align = 'center'; |
---|
268 | img.src = './templates/'+template+'/images/'+img.id+'.gif'; |
---|
269 | img.title = get_lang(img.id); |
---|
270 | img.style.cursor = 'pointer'; |
---|
271 | img.onclick = function () {RichTextEditor.editorCommand(this.id,'');}; |
---|
272 | img.onmouseover = function () {this.style.border="outset 2px";}; |
---|
273 | img.onmouseout = function () {this.style.border="solid 2px #C0C0C0";}; |
---|
274 | div_button_rt.appendChild(img); |
---|
275 | } |
---|
276 | |
---|
277 | |
---|
278 | td.appendChild(div_button_rt); |
---|
279 | tr.appendChild(td); |
---|
280 | tbody.appendChild(tr); |
---|
281 | this.table.appendChild(tbody); |
---|
282 | } |
---|
283 | |
---|
284 | cRichTextEditor.prototype.editorCommand = function(command, option) { |
---|
285 | try { |
---|
286 | var mainField = document.getElementById(this.editor).contentWindow; |
---|
287 | mainField.focus(); |
---|
288 | var signature = preferences.type_signature == 'html' ? preferences.signature : preferences.signature.replace(/\n/g, "<br>"); |
---|
289 | if (command == 'signature'){ |
---|
290 | if (is_ie){ |
---|
291 | var sel = document.selection; |
---|
292 | if (sel!=null) |
---|
293 | { |
---|
294 | var rng = sel.createRange(); |
---|
295 | if (rng!=null) |
---|
296 | rng.pasteHTML(signature); |
---|
297 | } |
---|
298 | } |
---|
299 | else{ |
---|
300 | mainField.document.execCommand('inserthtml', false, signature); |
---|
301 | } |
---|
302 | } |
---|
303 | else if (command == 'CreateLink') |
---|
304 | mainField.document.execCommand('CreateLink', false, option); |
---|
305 | else if (command == 'Table'){ |
---|
306 | if (is_ie){ |
---|
307 | var sel = document.selection; |
---|
308 | if (sel!=null) |
---|
309 | { |
---|
310 | var rng = sel.createRange(); |
---|
311 | if (rng!=null) |
---|
312 | rng.pasteHTML(option); |
---|
313 | } |
---|
314 | } |
---|
315 | else |
---|
316 | mainField.document.execCommand('inserthtml', false, option); |
---|
317 | } |
---|
318 | else if (command == 'Image') |
---|
319 | mainField.document.execCommand('InsertImage', false, option); |
---|
320 | else if (command == 'spellCheck' && preferences.use_SpellChecker != '0'){ |
---|
321 | beginSpellCheck(); // configure |
---|
322 | spellCheck(); // run spellChecker |
---|
323 | } |
---|
324 | else |
---|
325 | mainField.document.execCommand(command, false, option); |
---|
326 | //mainField.focus(); |
---|
327 | } catch (e) {/* alert(e);*/ } |
---|
328 | } |
---|
329 | |
---|
330 | cRichTextEditor.prototype.createLink = function(){ |
---|
331 | var mainField = document.getElementById(this.editor).contentWindow; |
---|
332 | if (is_ie){ |
---|
333 | if ((mainField.document.selection.createRange().text) == ''){ |
---|
334 | alert(get_lang('Chose the text you want transform in link before.')); |
---|
335 | return; |
---|
336 | } |
---|
337 | } |
---|
338 | else{ |
---|
339 | if (mainField.window.getSelection() == ''){ |
---|
340 | alert(get_lang('Chose the text you want transform in link before.')); |
---|
341 | return; |
---|
342 | } |
---|
343 | } |
---|
344 | var szURL = prompt(get_lang('Enter with link URL:'), 'http://'); |
---|
345 | if ((szURL != null) && (szURL != "")){ |
---|
346 | this.editorCommand("CreateLink", szURL); |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | // It include the image file in emails body |
---|
351 | // It saves and attach in drafts folder and open it |
---|
352 | cRichTextEditor.prototype.addInputFile = function() |
---|
353 | { |
---|
354 | //Begin: Verify if the image extension is allowed. |
---|
355 | var imgExtensions = new Array("jpeg", "jpg", "gif", "png", "bmp", "xbm", "tiff", "pcx"); |
---|
356 | var inputFile = document.getElementById('inputFile_img'); |
---|
357 | if(!inputFile.value) return false; |
---|
358 | var fileExtension = inputFile.value.split("."); |
---|
359 | fileExtension = fileExtension[(fileExtension.length-1)]; |
---|
360 | var deniedExtension = true; |
---|
361 | for(var i=0; i<imgExtensions.length; i++) { |
---|
362 | if(imgExtensions[i].toUpperCase() == fileExtension.toUpperCase()) { |
---|
363 | deniedExtension = false; |
---|
364 | break; |
---|
365 | } |
---|
366 | } |
---|
367 | if(deniedExtension) { |
---|
368 | alert(get_lang('File extension forbidden or invalid file') + '.'); |
---|
369 | return false; |
---|
370 | } |
---|
371 | // End: Verify image extension. |
---|
372 | var id = this.editor.substr(5); // border_id |
---|
373 | divFiles = document.getElementById("divFiles_"+id); |
---|
374 | var countDivFiles = divFiles.childNodes.length + 1; |
---|
375 | |
---|
376 | var divFiles = document.getElementById('divFiles_'+id); |
---|
377 | inputFile.id = 'inputFile_'+id +"_"+countDivFiles; |
---|
378 | inputFile.name = 'file_'+countDivFiles; |
---|
379 | divFile = document.createElement('DIV'); |
---|
380 | divFile.appendChild(inputFile); |
---|
381 | divFiles.appendChild(divFile); |
---|
382 | |
---|
383 | var form_upload = document.getElementById('form_upload'); |
---|
384 | form_upload.parentNode.removeChild(form_upload); |
---|
385 | win.close(); |
---|
386 | |
---|
387 | RichTextEditor.saveFlag = 0; // See if save function finished |
---|
388 | var save_link = document.getElementById("save_message_options_"+id); |
---|
389 | //save_link.onclick = function () {}; |
---|
390 | save_msg(id,true); |
---|
391 | setTimeout("RichTextEditor.insertImgHtml("+id+")",1000); |
---|
392 | } |
---|
393 | |
---|
394 | cRichTextEditor.prototype.insertImgHtml = function (id){ |
---|
395 | if (RichTextEditor.saveFlag == 0) |
---|
396 | setTimeout("RichTextEditor.insertImgHtml("+id+")",500); |
---|
397 | else |
---|
398 | if (RichTextEditor.saveFlag == 1) |
---|
399 | this.editorCommand('Image', './inc/show_embedded_attach.php?msg_folder=INBOX/'+draftsfolder+'&msg_num='+openTab.imapUid[id]+'&msg_part='+(openTab.countFile[id]+1)); |
---|
400 | // this.editorCommand('Image', '.inc/gotodownload.php?msg_folder="+msg_folder+"&msg_number="+msg_number+"&idx_file="+idx_file+"&msg_part="+msg_part+params')); |
---|
401 | } |
---|
402 | |
---|
403 | cRichTextEditor.prototype.insertTableHtml = function (){ |
---|
404 | var id = this.editor.substr(5); // border_id |
---|
405 | var rows = document.getElementById('rows').value; |
---|
406 | var cols = document.getElementById('cols').value; |
---|
407 | var border = document.getElementById('border').value; |
---|
408 | var insertTable = '<table border="'+border+'px"><tbody>'; |
---|
409 | for (var i = 0; i < rows; i++){ |
---|
410 | insertTable += "<tr>"; |
---|
411 | for (var j = 0; j < cols; j++) |
---|
412 | insertTable += "<td> </td>"; |
---|
413 | insertTable += "</tr>"; |
---|
414 | } |
---|
415 | insertTable += "</tbody></table>"; |
---|
416 | this.editorCommand('Table', insertTable); |
---|
417 | } |
---|
418 | |
---|
419 | cRichTextEditor.prototype.createTable = function(){ |
---|
420 | var form = document.getElementById("table_window"); |
---|
421 | if (form == null){ |
---|
422 | form = document.createElement("DIV"); |
---|
423 | form.id = "table_window"; |
---|
424 | form.style.visibility = "hidden"; |
---|
425 | form.style.position = "absolute"; |
---|
426 | form.style.background = "#eeeeee"; |
---|
427 | form.style.left = "0px"; |
---|
428 | form.style.top = "0px"; |
---|
429 | form.style.width = "0px"; |
---|
430 | form.style.height = "0px"; |
---|
431 | document.body.appendChild(form); |
---|
432 | } |
---|
433 | |
---|
434 | var form_table = document.createElement("DIV"); |
---|
435 | form_table.id = "form_table"; |
---|
436 | form_table.style.position = "absolute"; |
---|
437 | form_table.style.top = "5px"; |
---|
438 | form_table.style.left = "5px"; |
---|
439 | form_table.style.width = "190px"; |
---|
440 | form_table.style.height = "90px"; |
---|
441 | form_table.name = get_lang("Insert Table"); |
---|
442 | form_table.innerHTML = get_lang('Select the table size')+':<br><br><table cellspacing="0"><tbody><tr><td align="center">'+ |
---|
443 | get_lang('Rows')+':</td><td></td><td align="center">'+get_lang('Cols')+':</td><td></td><td align="center">'+get_lang('Border')+':</td></tr>'+ |
---|
444 | '<tr><td align="right"><input type="text" readonly="true" id="rows" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'rows\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'rows\');"></img></td>'+ |
---|
445 | '<td align="right"><input type="text" readonly="true" id="cols" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'cols\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'cols\');"></img></td>'+ |
---|
446 | '<td align="right"><input type="text" readonly="true" id="border" size="2" maxlength="2" value="1"></input></td><td align="left"><img src="templates/'+template+'/images/plus.png" onclick="javascript:RichTextEditor.incrementField(\'border\');"></img><br><img src="templates/'+template+'/images/minus.png" onclick="javascript:RichTextEditor.decrementField(\'border\');"></img></td>'+ |
---|
447 | '</tr></tbody></table>'+ |
---|
448 | ' <input title="'+get_lang('Close')+'" value="' + get_lang('Close') + '" type="button" onclick="win.close()"> '+ |
---|
449 | '<input title="' + get_lang('Include') + '" value="' + get_lang('Include') + '" type="button" onclick="RichTextEditor.insertTableHtml();win.close();">'; |
---|
450 | form.appendChild(form_table); |
---|
451 | |
---|
452 | this.showWindow(form); |
---|
453 | } |
---|
454 | |
---|
455 | cRichTextEditor.prototype.incrementField = function(id_val){ |
---|
456 | var field_text = document.getElementById(id_val); |
---|
457 | field_text.value = parseInt(field_text.value)+1; |
---|
458 | } |
---|
459 | |
---|
460 | cRichTextEditor.prototype.decrementField = function(id_val){ |
---|
461 | var field_text = document.getElementById(id_val); |
---|
462 | if (parseInt(field_text.value) > 0) |
---|
463 | field_text.value = parseInt(field_text.value)-1; |
---|
464 | } |
---|
465 | |
---|
466 | cRichTextEditor.prototype.createImage = function(){ |
---|
467 | if (preferences.auto_save_draft == 1){ |
---|
468 | autosave_time = 200000; |
---|
469 | clearTimeout(openTab.autosave_timer[currentTab]); |
---|
470 | } |
---|
471 | var form = document.getElementById("attachment_window"); |
---|
472 | if (form == null){ |
---|
473 | form = document.createElement("DIV"); |
---|
474 | form.id = "attachment_window"; |
---|
475 | form.style.visibility = "hidden"; |
---|
476 | form.style.position = "absolute"; |
---|
477 | form.style.background = "#eeeeee"; |
---|
478 | form.style.left = "0px"; |
---|
479 | form.style.top = "0px"; |
---|
480 | form.style.width = "0px"; |
---|
481 | form.style.height = "0px"; |
---|
482 | document.body.appendChild(form); |
---|
483 | } |
---|
484 | var form_upload = Element('form_upload'); |
---|
485 | if (form_upload == null) |
---|
486 | form_upload = document.createElement("DIV"); |
---|
487 | form_upload.id = "form_upload"; |
---|
488 | form_upload.style.position = "absolute"; |
---|
489 | form_upload.style.top = "5px"; |
---|
490 | form_upload.style.left = "5px"; |
---|
491 | form_upload.name = get_lang("Upload File"); |
---|
492 | form_upload.style.width = "450px"; |
---|
493 | form_upload.style.height = "75px"; |
---|
494 | form_upload.innerHTML = get_lang('Select the desired image file')+':<br>'+ |
---|
495 | '<input name="image_at" maxlength="255" size="50" id="inputFile_img" type="file"><br>' + |
---|
496 | '<input title="' + get_lang('Include') + '" value="' + get_lang('Include') + '"' + 'type="button" onclick="RichTextEditor.addInputFile();"> ' + |
---|
497 | '<input title="' + get_lang('Close') + '" value="' + get_lang('Close') + '"' + |
---|
498 | ' type="button" onclick="win.close()">'; |
---|
499 | form.appendChild(form_upload); |
---|
500 | |
---|
501 | this.showWindow(form); |
---|
502 | } |
---|
503 | cRichTextEditor.prototype.showWindow = function (div){ |
---|
504 | |
---|
505 | if(! div) { |
---|
506 | return; |
---|
507 | } |
---|
508 | |
---|
509 | if(! this.emwindow[div.id]) { |
---|
510 | div.style.width = div.firstChild.style.width; |
---|
511 | div.style.height = div.firstChild.style.height; |
---|
512 | div.style.zIndex = "10000"; |
---|
513 | var title = div.firstChild.name; |
---|
514 | var wHeight = div.offsetHeight + "px"; |
---|
515 | var wWidth = div.offsetWidth + "px"; |
---|
516 | div.style.width = div.offsetWidth - 5; |
---|
517 | |
---|
518 | win = new dJSWin({ |
---|
519 | id: 'win_'+div.id, |
---|
520 | content_id: div.id, |
---|
521 | width: wWidth, |
---|
522 | height: wHeight, |
---|
523 | title_color: '#3978d6', |
---|
524 | bg_color: '#eee', |
---|
525 | title: title, |
---|
526 | title_text_color: 'white', |
---|
527 | button_x_img: '../phpgwapi/images/winclose.gif', |
---|
528 | border: true }); |
---|
529 | |
---|
530 | this.emwindow[div.id] = win; |
---|
531 | win.draw(); |
---|
532 | } |
---|
533 | else |
---|
534 | win = this.emwindow[div.id]; |
---|
535 | win.open(); |
---|
536 | } |
---|
537 | |
---|
538 | cRichTextEditor.prototype.Select = function(selectname) |
---|
539 | { |
---|
540 | var mainField = Element(this.editor).contentWindow; |
---|
541 | var cursel = document.getElementById(selectname).selectedIndex; |
---|
542 | |
---|
543 | if (cursel != 0) { |
---|
544 | var selected = document.getElementById(selectname).options[cursel].value; |
---|
545 | mainField.document.execCommand(selectname, false, selected); |
---|
546 | document.getElementById(selectname).selectedIndex = "Size"; //cursel; |
---|
547 | } |
---|
548 | mainField.focus(); |
---|
549 | } |
---|
550 | |
---|
551 | cRichTextEditor.prototype.show_pc = function(command) |
---|
552 | { |
---|
553 | connector.loadScript("color_palette"); |
---|
554 | ColorPalette.loadPalette(this.id); |
---|
555 | if (ColorPalette.div.style.visibility != "visible") |
---|
556 | ColorPalette.div.style.visibility="visible"; |
---|
557 | else |
---|
558 | this.hide_pc(); |
---|
559 | } |
---|
560 | |
---|
561 | cRichTextEditor.prototype.hide_pc = function() |
---|
562 | { |
---|
563 | document.getElementById("palettecolor").style.visibility="hidden"; |
---|
564 | } |
---|
565 | |
---|
566 | cRichTextEditor.prototype.getOffsetTop = function(elm) { |
---|
567 | var mOffsetTop = elm.offsetTop;1 |
---|
568 | var mOffsetParent = elm.offsetParent; |
---|
569 | while(mOffsetParent){ |
---|
570 | mOffsetTop += mOffsetParent.offsetTop; |
---|
571 | mOffsetParent = mOffsetParent.offsetParent; |
---|
572 | } |
---|
573 | return mOffsetTop; |
---|
574 | } |
---|
575 | |
---|
576 | cRichTextEditor.prototype.getOffsetLeft = function(elm) { |
---|
577 | var mOffsetLeft = elm.offsetLeft; |
---|
578 | var mOffsetParent = elm.offsetParent; |
---|
579 | while(mOffsetParent){ |
---|
580 | mOffsetLeft += mOffsetParent.offsetLeft; |
---|
581 | mOffsetParent = mOffsetParent.offsetParent; |
---|
582 | } |
---|
583 | return mOffsetLeft; |
---|
584 | } |
---|
585 | |
---|
586 | //Build the Object |
---|
587 | RichTextEditor = new cRichTextEditor(); |
---|