Commit | Line | Data |
---|---|---|
696f20d5 MS |
1 | /*\r |
2 | TODO:\r | |
3 | - Tag do youtube\r | |
4 | - Ver botão de excluir elemento quando selecionado (img, retirar link...)(estudar isso)\r | |
5 | - Ver editar url(estudar isso)\r | |
6 | - Ver se tem como dar resize por php nas imagems\r | |
7 | \r | |
8 | Lembrar:\r | |
9 | - Na hora de gravar no banco, dar resize no php nas imagems\r | |
10 | - Limpar o html\r | |
11 | */\r | |
12 | \r | |
13 | //Requires include default.js\r | |
14 | try { var _test_htmleditor = __include_default; }\r | |
15 | catch(e) {\r | |
16 | alert("htmleditor.js : Include '_system/js/default.js' é obrigatório");\r | |
17 | }\r | |
18 | \r | |
19 | var __include_htmleditor = true;\r | |
20 | \r | |
21 | var HtmlEditor_ROOT = "../inc/htmleditor/";\r | |
22 | \r | |
23 | function HtmlEditor() {\r | |
24 | this.class_name = ""; //Name of instancied js var\r | |
25 | this.field_id = ""; //Textarea hidden id\r | |
26 | this.buttons = []; //array of removed buttons\r | |
27 | this.width = '100%';\r | |
28 | this.height = '300';\r | |
29 | this.images_path = "";\r | |
30 | this.root_path = "";\r | |
31 | this.is_window_opened = false;\r | |
32 | \r | |
33 | this.onLoad = new Function();\r | |
34 | \r | |
35 | this._toolbar = ["viewhtml", "|", "removeformat", "|", "bold", "italic", "underline", "|", "justifyleft", "justifycenter", "justifyright", "justifyfull", "|", "insertorderedlist", "insertunorderedlist", "|", "createlink", "unlink", "|", "image"];\r | |
36 | this._content = '';\r | |
37 | this._image_aba = 0;\r | |
38 | this._list_refresh = false;\r | |
39 | this._key_status = []; //Remember keys status\r | |
40 | this._is_view_html = false;\r | |
41 | this._last_range = null;\r | |
42 | \r | |
43 | this.make = function () {\r | |
44 | var html = '';\r | |
45 | \r | |
46 | html += '<table cellspacing="0" cellpadding="0" width="'+this.width+'">';\r | |
47 | html += '<tr><td class="bto_bar" id="' + this.class_name + '_td_bar"><table cellspacing="0" cellpadding="0"><tr>';\r | |
48 | \r | |
49 | var toolbar_ = this._toolbar.remove(this.buttons); //Remove buttons\r | |
50 | var self = this;\r | |
51 | var tab_order_ = 200;\r | |
52 | toolbar_.each(function (k, v) {\r | |
53 | if (v == '|') {\r | |
54 | html += '<td> </td>';\r | |
55 | } else {\r | |
56 | html += '<td><div class="bto_ext" onmouseover="javascript: { this.setAttribute(\'class\', \'bto_ext_over\'); this.setAttribute(\'className\', \'bto_ext_over\'); }" onmouseout="javascript: { this.setAttribute(\'class\', \'bto_ext\'); this.setAttribute(\'className\', \'bto_ext\'); }"><a taborder="' + tab_order_ + '" class="bto_' + v + '" href="javascript: nothing_func();" onclick="javascript: ' + self.class_name + '._command(\'' + v + '\')" title="' + self._getDescription(v) + '"><span>' + v + '</span></a></div>';\r | |
57 | \r | |
58 | if (v == 'image') {\r | |
59 | html += '<div id="' + self.class_name + '_image_box" class="image_box" style="display: none;">';\r | |
60 | html += '<table cellspacing="0" cellpadding="0"><tr><td>';\r | |
61 | html += '<div id="' + self.class_name + '_image_box_aba0" class="aba_sel" onmouseover="javascript: ' + self.class_name + '._imageAbaEvent(\'over\', 0);" onmouseout="javascript: ' + self.class_name + '._imageAbaEvent(\'out\', 0);" onclick="javascript: ' + self.class_name + '._imageAbaEvent(\'click\', 0);">Informações</div>';\r | |
62 | html += '<div id="' + self.class_name + '_image_box_aba1" class="aba" onmouseover="javascript: ' + self.class_name + '._imageAbaEvent(\'over\', 1);" onmouseout="javascript: ' + self.class_name + '._imageAbaEvent(\'out\', 1);" onclick="javascript: ' + self.class_name + '._imageAbaEvent(\'click\', 1);">Selecionar</div>';\r | |
63 | html += '<div id="' + self.class_name + '_image_box_aba2" class="aba" onmouseover="javascript: ' + self.class_name + '._imageAbaEvent(\'over\', 2);" onmouseout="javascript: ' + self.class_name + '._imageAbaEvent(\'out\', 2);" onclick="javascript: ' + self.class_name + '._imageAbaEvent(\'click\', 2);">Upload</div>';\r | |
64 | html += '<div class="aba_fechar" onclick="javascript: ' + self.class_name + '._command(\'image\');" title="Fechar">x</div>';\r | |
65 | html += '</td></tr><tr><td>';\r | |
66 | html += '<div id="' + self.class_name + '_image_box_content0" class="content">';\r | |
67 | html += 'Url:<br><input class="input" type="text" style="width: 285px;" id="' + self.class_name + '_image_box_url" onblur="javascript: ' + self.class_name + '._imageThumb();">';\r | |
68 | html += '<table cellspacing="0" cellpadding="0" width="100%">';\r | |
69 | html += '<tr><td width="140" height="140"><div class="thumb" id="' + self.class_name + '_image_thumb"><br><br><br><br>sem imagem</div></td>';\r | |
70 | html += '<td valign="top">';\r | |
71 | html += '<div class="bt bt_action" style="width: 100%;" onclick="javascript: ' + self.class_name + '._imageAbaEvent(\'click\', 1);">Selecionar do servidor</div>';\r | |
72 | html += '<div class="bt bt_action" style="width: 100%;" onclick="javascript: ' + self.class_name + '._imageAbaEvent(\'click\', 2);">Fazer upload para o servidor</div>'; \r | |
73 | html += '</td></tr>';\r | |
74 | html += '</table>';\r | |
75 | html += '</div>';\r | |
76 | html += '<div id="' + self.class_name + '_image_box_content1" class="content" style="display: none; overflow: auto;">carregando...</div>';\r | |
77 | html += '<div id="' + self.class_name + '_image_box_content2" class="content" style="display: none;">';\r | |
78 | html += '<form id="' + self.class_name + '_image_box_form">Arquivo:<br><input class="input" type="file" size="39" style="_width: 284px;" id="' + self.class_name + '_image_box_file" name="file"></form>';\r | |
79 | html += '<div class="alert">Apenas arquivos .jpg, .gif e .png</div>';\r | |
80 | html += '<div align="right"><div class="bt bt_action" id="' + self.class_name + '_image_box_upload" onclick="javascript: ' + self.class_name + '._imageUpload();">Enviar</div></div>';\r | |
81 | html += '</div>';\r | |
82 | html += '</td></tr>';\r | |
83 | html += '<tr><td height="34" align="right" valign="bottom"><div class="bt" style="margin-top: 0px;" onclick="' + self.class_name + '._imageOK();">OK</div></td></tr>';\r | |
84 | html += '</table>';\r | |
85 | html += '</div>';\r | |
86 | } else if (v == 'createlink') {\r | |
87 | html += '<div id="' + self.class_name + '_link_box" class="link_box" style="display: none;">';\r | |
88 | html += '<table cellspacing="0" cellpadding="0"><tr><td>';\r | |
89 | html += '<div id="' + self.class_name + '_link_box_aba0" class="aba_sel" onmouseover="javascript: ' + self.class_name + '._imageAbaEvent(\'over\', 0);" onmouseout="javascript: ' + self.class_name + '._imageAbaEvent(\'out\', 0);" onclick="javascript: ' + self.class_name + '._imageAbaEvent(\'click\', 0);">Informações</div>';\r | |
90 | html += '<div class="aba_fechar" onclick="javascript: ' + self.class_name + '._command(\'createlink\');" title="Fechar">x</div>';\r | |
91 | html += '</td></tr><tr><td>';\r | |
92 | html += '<div class="content">';\r | |
93 | html += 'Url:<br><input class="input" type="text" value="http://" style="width: 285px;" id="' + self.class_name + '_link_box_url"></td></tr>';\r | |
94 | html += '<tr><td align="right" valign="bottom"><div class="bt" id="' + self.class_name + '_link_box_ok" onclick="javascript: ' + self.class_name + '._linkOK();">OK</div>';\r | |
95 | html += '</div></td></tr></table>';\r | |
96 | html += '</div>';\r | |
97 | }\r | |
98 | \r | |
99 | html += '</td>';\r | |
100 | \r | |
101 | tab_order_++;\r | |
102 | }\r | |
103 | }, this);\r | |
104 | \r | |
105 | this._toolbar = toolbar_;\r | |
106 | \r | |
107 | html += '</tr></table></td></tr>';\r | |
108 | \r | |
109 | html += '<tr><td style="background: #FFF;" id="' + this.class_name + '_td_iframe">';\r | |
110 | html += ' <iframe id="' + this.class_name + '_iframe" width="' + this.width + '" height="' + this.height + '" frameborder="0"></iframe>';\r | |
111 | html += '</td></tr>';\r | |
112 | \r | |
113 | html += '<tr><td style="background: #FFF; display: none;" id="' + this.class_name + '_td_codehtml">';\r | |
114 | html += ' <table cellspacing="0" cellpadding="0" width="100%">';\r | |
115 | html += ' <tr><td class="bto_bar"><a class="bto_voltar" href="javascript: nothing_func();" onclick="javascript: ' + this.class_name + '._command(\'viewhtml\')">Voltar</a></td></tr>';\r | |
116 | html += ' <tr><td><textarea id="' + this.class_name + '_codehtml" style="width: ' + this.width + '; height: ' + this.height + ';"></textarea></td></tr>';\r | |
117 | html += ' </table>';\r | |
118 | html += '</td></tr>';\r | |
119 | \r | |
120 | html += '</html>';\r | |
121 | \r | |
122 | var d = document.createElement('div');\r | |
123 | d.setAttribute('id', this.class_name + '_div');\r | |
124 | d.setAttribute('className', 'html_editor');\r | |
125 | d.setAttribute('class', 'html_editor');\r | |
126 | d.innerHTML = html;\r | |
127 | $$(this.field_id).parentNode.appendChild(d);\r | |
128 | \r | |
129 | //get content from textarea element\r | |
130 | this._content = $$(this.field_id).value;\r | |
131 | \r | |
132 | //enable design mode to iframe\r | |
133 | setTimeout(this._enableIframe.bind(this), 50);\r | |
134 | \r | |
135 | //hidden textarea element\r | |
136 | $$(this.field_id).style.display = 'none';\r | |
137 | }\r | |
138 | \r | |
139 | this.loadFile = function (tmp_path) {\r | |
140 | var a = new Ajax();\r | |
141 | var self = this;\r | |
142 | \r | |
143 | a.onLoad = function () {\r | |
144 | this.html = this.html.replace(new RegExp('#ROOT#', 'g'), self.root_path);\r | |
145 | \r | |
146 | self._getIframeDocument().body.innerHTML = this.html;\r | |
147 | self._insertHTML('');\r | |
148 | }\r | |
149 | a.get(tmp_path);\r | |
150 | }\r | |
151 | \r | |
152 | this.getContent = function () {\r | |
153 | return $$(this.field_id).value;\r | |
154 | }\r | |
155 | \r | |
156 | this._enableIframe = function () {\r | |
157 | this._getIframeDocument().designMode = 'on';\r | |
158 | \r | |
159 | if (this._getIframeDocument().body) {\r | |
160 | this._getIframeDocument().body.innerHTML = '';\r | |
161 | }\r | |
162 | \r | |
163 | //set content to iframe\r | |
164 | setTimeout(this._initContent.bind(this), 300);\r | |
165 | \r | |
166 | //enable timer for copy text from iframe to textarea\r | |
167 | setTimeout(this._updateField.bind(this), 350);\r | |
168 | \r | |
169 | //set ok events for boxes\r | |
170 | var self = this;\r | |
171 | addEvent($$(this.class_name + '_link_box_url'), "keydown", function (e) { self._okEvent(e, self.class_name + '._linkOK()'); });\r | |
172 | addEvent($$(this.class_name + '_image_box_url'), "keydown", function (e) { self._okEvent(e, self.class_name + '._imageOK()'); });\r | |
173 | }\r | |
174 | \r | |
175 | this._initContent = function () {\r | |
176 | var self = this;\r | |
177 | \r | |
178 | this._getIframeDocument().body.innerHTML = this._content;\r | |
179 | this._insertHTML('');\r | |
180 | \r | |
181 | addEvent(this._getIframeDocument(), "keydown", function (e) { self._fireEvent('keydown', e); });\r | |
182 | addEvent(this._getIframeDocument(), "keyup", function (e) { self._fireEvent('keyup', e); });\r | |
183 | \r | |
184 | if (document.all) {\r | |
185 | addEvent(this._getIframeDocument(), "selectionchange", function (e) { self._fireEvent('selectionchange', e || event); });\r | |
186 | } else {\r | |
187 | addEvent(this._getIframeDocument(), "mouseup", function (e) { self._fireEvent('selectionchange', e || event); });\r | |
188 | }\r | |
189 | \r | |
190 | this.onLoad();\r | |
191 | }\r | |
192 | \r | |
193 | this._fireEvent = function (tmp_type, tmp_e) { \r | |
194 | var k = tmp_e.keyCode;\r | |
195 | \r | |
196 | switch (tmp_type) {\r | |
197 | case "keydown":\r | |
198 | this._key_status[k] = true;\r | |
199 | \r | |
200 | if (this._key_status[17] && (k == 13)) {\r | |
201 | //this._insertHTML('<h1>teste!</h1>');\r | |
202 | }\r | |
203 | \r | |
204 | break;\r | |
205 | \r | |
206 | case "keyup":\r | |
207 | this._key_status[k] = false;\r | |
208 | \r | |
209 | break;\r | |
210 | \r | |
211 | case "selectionchange":\r | |
212 | \r | |
213 | break;\r | |
214 | }\r | |
215 | }\r | |
216 | \r | |
217 | this._okEvent = function (tmp_e, tmp_func) {\r | |
218 | var k = tmp_e.keyCode;\r | |
219 | \r | |
220 | if (k == 13) {\r | |
221 | eval(tmp_func);\r | |
222 | }\r | |
223 | }\r | |
224 | \r | |
225 | this._getIframeDocument = function () {\r | |
226 | if ($$(this.class_name + '_iframe').contentDocument) {\r | |
227 | return $$(this.class_name + '_iframe').contentDocument;\r | |
228 | } else {\r | |
229 | return document.frames[this.class_name + '_iframe'].document;\r | |
230 | }\r | |
231 | }\r | |
232 | \r | |
233 | this._updateField = function () {\r | |
234 | if ($$(this.class_name + '_iframe') && (!this._is_view_html)) {\r | |
235 | var content = this._getIframeDocument().body.innerHTML;\r | |
236 | \r | |
237 | //clean content\r | |
238 | if (content.substr(-4) == '<br>') {\r | |
239 | content = content.substr(0, content.length - 4);\r | |
240 | }\r | |
241 | \r | |
242 | content = content.replace('<p class="MsoPlainText">', '<p>');\r | |
243 | content = content.replace('<o:p></o:p>', '');\r | |
244 | \r | |
245 | if (content == '<P> </P>') {\r | |
246 | content = '';\r | |
247 | }\r | |
248 | \r | |
249 | $$(this.field_id).value = content.trim();\r | |
250 | }\r | |
251 | \r | |
252 | setTimeout(this._updateField.bind(this), 500);\r | |
253 | }\r | |
254 | \r | |
255 | this._insertHTML = function (tmp_html) {\r | |
256 | if (document.all) {\r | |
257 | this._getIframeDocument().body.setActive();\r | |
258 | }\r | |
259 | \r | |
260 | if (document.all) {\r | |
261 | var r = this._last_range;\r | |
262 | \r | |
263 | if (r == null) {\r | |
264 | r = this._getIframeDocument().selection.createRange()\r | |
265 | }\r | |
266 | \r | |
267 | r.select();\r | |
268 | r.collapse(false);\r | |
269 | r.pasteHTML(tmp_html);\r | |
270 | } else {\r | |
271 | var rnd_str = "insert_html_" + Math.round(Math.random()*100000000);\r | |
272 | this._getIframeDocument().execCommand('insertimage', false, rnd_str);\r | |
273 | this._getIframeDocument().body.innerHTML = this._getIframeDocument().body.innerHTML.replace(new RegExp('<[^<]*' + rnd_str + '[^>]*>'), tmp_html);\r | |
274 | }\r | |
275 | }\r | |
276 | \r | |
277 | this._command = function (tmp_command) {\r | |
278 | switch (tmp_command) {\r | |
279 | case 'image':\r | |
280 | if ($$(this.class_name + '_image_box').style.display == 'none') {\r | |
281 | if (document.all) {\r | |
282 | this._last_range = this._getIframeDocument().selection.createRange();\r | |
283 | }\r | |
284 | \r | |
285 | $$(this.class_name + '_image_box').style.display = '';\r | |
286 | screenLock(true);\r | |
287 | \r | |
288 | this.is_window_opened = true;\r | |
289 | } else {\r | |
290 | $$(this.class_name + '_image_box').style.display = 'none';\r | |
291 | screenLock(false);\r | |
292 | \r | |
293 | this.is_window_opened = false;\r | |
294 | }\r | |
295 | \r | |
296 | break;\r | |
297 | case 'createlink':\r | |
298 | if ($$(this.class_name + '_link_box').style.display == 'none') {\r | |
299 | if (document.all) {\r | |
300 | this._last_range = this._getIframeDocument().selection.createRange();\r | |
301 | }\r | |
302 | \r | |
303 | $$(this.class_name + '_link_box').style.display = '';\r | |
304 | screenLock(true);\r | |
305 | \r | |
306 | this.is_window_opened = true;\r | |
307 | } else {\r | |
308 | $$(this.class_name + '_link_box').style.display = 'none';\r | |
309 | screenLock(false);\r | |
310 | \r | |
311 | this.is_window_opened = false;\r | |
312 | }\r | |
313 | \r | |
314 | break;\r | |
315 | case 'viewhtml':\r | |
316 | if (!this._is_view_html) {\r | |
317 | $$(this.class_name + '_td_iframe').style.display = 'none';\r | |
318 | $$(this.class_name + '_td_bar').style.display = 'none';\r | |
319 | \r | |
320 | $$(this.class_name + '_td_codehtml').style.display = '';\r | |
321 | \r | |
322 | $$(this.class_name + '_codehtml').value = this._getIframeDocument().body.innerHTML.replace(new RegExp("<br>", "gi"), "<br>\n").replace(new RegExp("<\p>", "gi"), "<\p>\n");\r | |
323 | \r | |
324 | $$(this.class_name + '_codehtml').focus();\r | |
325 | \r | |
326 | this._is_view_html = true;\r | |
327 | } else {\r | |
328 | this._is_view_html = false;\r | |
329 | \r | |
330 | $$(this.class_name + '_td_iframe').style.display = '';\r | |
331 | $$(this.class_name + '_td_bar').style.display = '';\r | |
332 | \r | |
333 | $$(this.class_name + '_td_codehtml').style.display = 'none';\r | |
334 | \r | |
335 | this._getIframeDocument().body.innerHTML = $$(this.class_name + '_codehtml').value;\r | |
336 | this._insertHTML('');\r | |
337 | }\r | |
338 | \r | |
339 | break;\r | |
340 | default:\r | |
341 | $$(this.class_name + '_iframe').focus();\r | |
342 | this._getIframeDocument().execCommand(tmp_command, false, '');\r | |
343 | \r | |
344 | break;\r | |
345 | }\r | |
346 | \r | |
347 | try {\r | |
348 | $$(this.class_name + '_iframe').contentWindow.focus();\r | |
349 | } catch (e) { }\r | |
350 | }\r | |
351 | \r | |
352 | this._getDescription = function (tmp_button) {\r | |
353 | switch (tmp_button) {\r | |
354 | case "removeformat": return "Remover formatação"; break;\r | |
355 | case "bold": return "Aplicar/Retirar negrito"; break;\r | |
356 | case "italic": return "Aplicar/Retirar itálico"; break;\r | |
357 | case "underline": return "Aplicar/Retirar underline"; break;\r | |
358 | case "justifyleft": return "Alinhar à esquerda"; break;\r | |
359 | case "justifylright": return "Alinhar ao centro"; break;\r | |
360 | case "justifylright": return "Alinhar à direita"; break;\r | |
361 | case "justifyfull": return "Justificar"; break;\r | |
362 | case "insertorderedlist": return "Inserir/Remover lista ordenada"; break;\r | |
363 | case "insertunorderedlist": return "Inserir/Remover lista não ordenada"; break;\r | |
364 | case "createlink": return "Inserir link"; break;\r | |
365 | case "unlink": return "Remover link"; break;\r | |
366 | case "image": return "Inserir imagem"; break;\r | |
367 | case "viewhtml": return "Editar html"; break;\r | |
368 | default: return ""; break;\r | |
369 | }\r | |
370 | }\r | |
371 | \r | |
372 | //Image\r | |
373 | this._imageAbaEvent = function (tmp_event, tmp_index) {\r | |
374 | this._image_aba++; this._image_aba--;\r | |
375 | tmp_index++; tmp_index--;\r | |
376 | \r | |
377 | switch (tmp_event) {\r | |
378 | case 'over':\r | |
379 | if (tmp_index != this._image_aba) {\r | |
380 | $$(this.class_name + '_image_box_aba' + tmp_index).setAttribute('className', 'aba_over');\r | |
381 | $$(this.class_name + '_image_box_aba' + tmp_index).setAttribute('class', 'aba_over');\r | |
382 | }\r | |
383 | \r | |
384 | break;\r | |
385 | case 'out':\r | |
386 | if (tmp_index != this._image_aba) {\r | |
387 | $$(this.class_name + '_image_box_aba' + tmp_index).setAttribute('className', 'aba');\r | |
388 | $$(this.class_name + '_image_box_aba' + tmp_index).setAttribute('class', 'aba');\r | |
389 | }\r | |
390 | \r | |
391 | break;\r | |
392 | case 'click':\r | |
393 | if (tmp_index != this._image_aba) {\r | |
394 | $$(this.class_name + '_image_box_aba' + this._image_aba).setAttribute('className', 'aba');\r | |
395 | $$(this.class_name + '_image_box_aba' + this._image_aba).setAttribute('class', 'aba');\r | |
396 | $$(this.class_name + '_image_box_content' + this._image_aba).style.display = 'none';\r | |
397 | \r | |
398 | this._image_aba = tmp_index;\r | |
399 | \r | |
400 | $$(this.class_name + '_image_box_aba' + tmp_index).setAttribute('className', 'aba_sel');\r | |
401 | $$(this.class_name + '_image_box_aba' + tmp_index).setAttribute('class', 'aba_sel');\r | |
402 | $$(this.class_name + '_image_box_content' + tmp_index).style.display = '';\r | |
403 | \r | |
404 | if ((this._image_aba == 1) && (!this._list_refresh)) {\r | |
405 | this._list_refresh = true;\r | |
406 | \r | |
407 | this._imageListRefresh();\r | |
408 | }\r | |
409 | }\r | |
410 | \r | |
411 | break;\r | |
412 | }\r | |
413 | }\r | |
414 | \r | |
415 | this._imageThumb = function () {\r | |
416 | var url = $$(this.class_name + '_image_box_url').value;\r | |
417 | var ext = url.substr(url.length - 3, 3).toLowerCase();\r | |
418 | var html = '<br><br><br><br>sem imagem';\r | |
419 | \r | |
420 | url = url.replace(this.root_path, '');\r | |
421 | \r | |
422 | if ((ext == 'jpg') || (ext == 'gif')) {\r | |
423 | html = '<img src="' + HtmlEditor_ROOT + 'routines.php?routine=thumb&file=' + url + '&w=118&h=118">';\r | |
424 | }\r | |
425 | \r | |
426 | $$(this.class_name + '_image_thumb').innerHTML = html;\r | |
427 | }\r | |
428 | \r | |
429 | this._imageListRefresh = function () {\r | |
430 | var a = new Ajax();\r | |
431 | var self = this;\r | |
432 | \r | |
433 | a.onLoad = function () {\r | |
434 | var ext, html = '';\r | |
435 | var arr = this.html.split('##');\r | |
436 | \r | |
437 | arr.each(function (k, v) {\r | |
438 | if (v != '') {\r | |
439 | ext = v.substr(v.length - 3, 3).toLowerCase();\r | |
440 | \r | |
441 | if ((ext == 'jpg') || (ext == 'gif')) {\r | |
442 | html += '<div class="thumb_list" onclick="javascript: ' + self.class_name + '._imageSelect(\'' + v + '\');"><img src="' + HtmlEditor_ROOT + 'routines.php?routine=thumb&method=2&file=' + v + '&w=70&h=70" width="70" height="70" title="' + v + '"></div>';\r | |
443 | }\r | |
444 | }\r | |
445 | }, this);\r | |
446 | \r | |
447 | $$(self.class_name + '_image_box_content1').innerHTML = html;\r | |
448 | }\r | |
449 | a.get(HtmlEditor_ROOT + "routines.php?routine=list&path=" + this.images_path);\r | |
450 | }\r | |
451 | \r | |
452 | this._imageSelect = function (tmp_path) {\r | |
453 | $$(this.class_name + '_image_box_url').value = tmp_path;\r | |
454 | \r | |
455 | this._imageAbaEvent('click', 0);\r | |
456 | this._imageThumb();\r | |
457 | }\r | |
458 | \r | |
459 | this._imageUpload = function () {\r | |
460 | var onload, input, form, iframe, self, ext;\r | |
461 | \r | |
462 | self = this;\r | |
463 | \r | |
464 | iframe = document.createElement("iframe");\r | |
465 | iframe.setAttribute("id","ifr_tmp");\r | |
466 | iframe.setAttribute("name","ifr_tmp");\r | |
467 | iframe.setAttribute("width","0");\r | |
468 | iframe.setAttribute("height","0");\r | |
469 | iframe.setAttribute("border","0");\r | |
470 | iframe.setAttribute("style","width: 0; height: 0; border: none;");\r | |
471 | $$(this.field_id).parentNode.appendChild(iframe);\r | |
472 | window.frames["ifr_tmp"].name = "ifr_tmp"; //Ie sux\r | |
473 | \r | |
474 | //Verify if input file is not empty\r | |
475 | input = $$(this.class_name + '_image_box_file');\r | |
476 | \r | |
477 | if (input.value != '') {\r | |
478 | //Verify extension\r | |
479 | ext = input.value.substr(input.value.length - 3, 3).toLowerCase();\r | |
480 | \r | |
481 | if ((ext == 'jpg') || (ext == 'gif') || (ext == 'png')) {\r | |
482 | onload = function () {\r | |
483 | self._imageAbaEvent('click', 1);\r | |
484 | \r | |
485 | //Removes iframe element\r | |
486 | setTimeout(function () { removeElement($$('ifr_tmp')); }, 250);\r | |
487 | \r | |
488 | $$(self.class_name + '_image_box_upload').style.display = '';\r | |
489 | removeElement($$(self.class_name + '_image_box_carregando'));\r | |
490 | \r | |
491 | self._imageListRefresh();\r | |
492 | }\r | |
493 | addEvent($$('ifr_tmp'), "load", onload);\r | |
494 | \r | |
495 | //Config form element\r | |
496 | form = $$(this.class_name + '_image_box_form');\r | |
497 | form.setAttribute("target", "ifr_tmp");\r | |
498 | form.setAttribute("action", HtmlEditor_ROOT + "routines.php?routine=upload&path=" + this.images_path);\r | |
499 | form.setAttribute("method", "post");\r | |
500 | form.setAttribute("enctype", "multipart/form-data");\r | |
501 | form.setAttribute("encoding", "multipart/form-data");\r | |
502 | \r | |
503 | form.submit();\r | |
504 | \r | |
505 | var d = document.createElement("div");\r | |
506 | d.id = this.class_name + "_image_box_carregando";\r | |
507 | d.innerHTML = "Carregando...";\r | |
508 | $$(this.class_name + '_image_box_upload').parentNode.appendChild(d);\r | |
509 | \r | |
510 | $$(this.class_name + '_image_box_upload').style.display = 'none';\r | |
511 | } else {\r | |
512 | alert("Arquivo inválido.\nSão permitidos apenas arquivos .jpg, .gif e .png"); \r | |
513 | }\r | |
514 | } else {\r | |
515 | alert("O campo 'Arquivo' está vazio");\r | |
516 | \r | |
517 | input.focus();\r | |
518 | }\r | |
519 | }\r | |
520 | \r | |
521 | this._imageOK = function () {\r | |
522 | var url = $$(this.class_name + '_image_box_url').value;\r | |
523 | var ext = url.substr(url.length - 3, 3).toLowerCase();\r | |
524 | \r | |
525 | if ((ext == 'jpg') || (ext == 'gif')) { \r | |
526 | if (url.indexOf('http://') == -1) {\r | |
527 | url = this.root_path + url; \r | |
528 | }\r | |
529 | \r | |
530 | this._insertHTML('<img src="' + url + '" border="0">');\r | |
531 | \r | |
532 | this._command('image');\r | |
533 | \r | |
534 | this._imageThumb();\r | |
535 | } else {\r | |
536 | alert('Imagem inválida, verifique a url informada.');\r | |
537 | }\r | |
538 | }\r | |
539 | \r | |
540 | //Link\r | |
541 | this._linkOK = function () {\r | |
542 | var url = $$(this.class_name + '_link_box_url').value;\r | |
543 | var http = url.substr(0, 4);\r | |
544 | \r | |
545 | if (http == 'http') { \r | |
546 | if (document.all) {\r | |
547 | this._getIframeDocument().body.setActive();\r | |
548 | \r | |
549 | var r = this._last_range;\r | |
550 | \r | |
551 | if (r == null) {\r | |
552 | r = this._getIframeDocument().selection.createRange()\r | |
553 | }\r | |
554 | \r | |
555 | r.select();\r | |
556 | \r | |
557 | r.collapse(false);\r | |
558 | }\r | |
559 | \r | |
560 | this._getIframeDocument().execCommand('createlink', false, url);\r | |
561 | \r | |
562 | this._command('createlink');\r | |
563 | \r | |
564 | $$(this.class_name + '_link_box_url').value = 'http://';\r | |
565 | } else {\r | |
566 | alert('Link inválido, verifique a url informada.');\r | |
567 | }\r | |
568 | }\r | |
569 | } |