5 tinyMCEPopup.requireLangPack();
7 if (url = tinyMCEPopup.getParam("external_image_list_url"))
8 document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
12 var f = document.forms[0], nl = f.elements, ed = tinyMCEPopup.editor, dom = ed.dom, n = ed.selection.getNode(), fl = tinyMCEPopup.getParam('external_image_list', 'tinyMCEImageList');
14 tinyMCEPopup.resizeToInnerSize();
15 this.fillClassList('class_list');
16 this.fillFileList('src_list', fl);
17 this.fillFileList('over_list', fl);
18 this.fillFileList('out_list', fl);
19 TinyMCE_EditableSelects.init();
21 if (n.nodeName == 'IMG') {
22 nl.src.value = dom.getAttrib(n, 'src');
23 nl.width.value = dom.getAttrib(n, 'width');
24 nl.height.value = dom.getAttrib(n, 'height');
25 nl.alt.value = dom.getAttrib(n, 'alt');
26 nl.title.value = dom.getAttrib(n, 'title');
27 nl.vspace.value = this.getAttrib(n, 'vspace');
28 nl.hspace.value = this.getAttrib(n, 'hspace');
29 nl.border.value = this.getAttrib(n, 'border');
30 selectByValue(f, 'align', this.getAttrib(n, 'align'));
31 selectByValue(f, 'class_list', dom.getAttrib(n, 'class'), true, true);
32 nl.style.value = dom.getAttrib(n, 'style');
33 nl.id.value = dom.getAttrib(n, 'id');
34 nl.dir.value = dom.getAttrib(n, 'dir');
35 nl.lang.value = dom.getAttrib(n, 'lang');
36 nl.usemap.value = dom.getAttrib(n, 'usemap');
37 nl.longdesc.value = dom.getAttrib(n, 'longdesc');
38 nl.insert.value = ed.getLang('update');
40 if (/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/.test(dom.getAttrib(n, 'onmouseover')))
41 nl.onmouseoversrc.value = dom.getAttrib(n, 'onmouseover').replace(/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/, '$1');
43 if (/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/.test(dom.getAttrib(n, 'onmouseout')))
44 nl.onmouseoutsrc.value = dom.getAttrib(n, 'onmouseout').replace(/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/, '$1');
46 if (ed.settings.inline_styles) {
47 // Move attribs to styles
48 if (dom.getAttrib(n, 'align'))
49 this.updateStyle('align');
51 if (dom.getAttrib(n, 'hspace'))
52 this.updateStyle('hspace');
54 if (dom.getAttrib(n, 'border'))
55 this.updateStyle('border');
57 if (dom.getAttrib(n, 'vspace'))
58 this.updateStyle('vspace');
62 // Setup browse button
63 document.getElementById('srcbrowsercontainer').innerHTML = getBrowserHTML('srcbrowser','src','image','theme_advanced_image');
64 if (isVisible('srcbrowser'))
65 document.getElementById('src').style.width = '260px';
67 // Setup browse button
68 document.getElementById('onmouseoversrccontainer').innerHTML = getBrowserHTML('overbrowser','onmouseoversrc','image','theme_advanced_image');
69 if (isVisible('overbrowser'))
70 document.getElementById('onmouseoversrc').style.width = '260px';
72 // Setup browse button
73 document.getElementById('onmouseoutsrccontainer').innerHTML = getBrowserHTML('outbrowser','onmouseoutsrc','image','theme_advanced_image');
74 if (isVisible('outbrowser'))
75 document.getElementById('onmouseoutsrc').style.width = '260px';
77 // If option enabled default contrain proportions to checked
78 if (ed.getParam("advimage_constrain_proportions", true))
79 f.constrain.checked = true;
81 // Check swap image if valid data
82 if (nl.onmouseoversrc.value || nl.onmouseoutsrc.value)
83 this.setSwapImage(true);
85 this.setSwapImage(false);
87 this.changeAppearance();
88 this.showPreviewImage(nl.src.value, 1);
91 insert : function(file, title) {
92 var ed = tinyMCEPopup.editor, t = this, f = document.forms[0];
94 if (f.src.value === '') {
95 if (ed.selection.getNode().nodeName == 'IMG') {
96 ed.dom.remove(ed.selection.getNode());
97 ed.execCommand('mceRepaint');
100 tinyMCEPopup.close();
104 if (tinyMCEPopup.getParam("accessibility_warnings", 1)) {
106 tinyMCEPopup.confirm(tinyMCEPopup.getLang('advimage_dlg.missing_alt'), function(s) {
118 insertAndClose : function() {
119 var ed = tinyMCEPopup.editor, f = document.forms[0], nl = f.elements, v, args = {}, el;
121 tinyMCEPopup.restoreSelection();
123 // Fixes crash in Safari
124 if (tinymce.isWebKit)
127 if (!ed.settings.inline_styles) {
129 vspace : nl.vspace.value,
130 hspace : nl.hspace.value,
131 border : nl.border.value,
132 align : getSelectValue(f, 'align')
135 // Remove deprecated values
144 tinymce.extend(args, {
145 src : nl.src.value.replace(/ /g, '%20'),
146 width : nl.width.value,
147 height : nl.height.value,
149 title : nl.title.value,
150 'class' : getSelectValue(f, 'class_list'),
151 style : nl.style.value,
154 lang : nl.lang.value,
155 usemap : nl.usemap.value,
156 longdesc : nl.longdesc.value
159 args.onmouseover = args.onmouseout = '';
161 if (f.onmousemovecheck.checked) {
162 if (nl.onmouseoversrc.value)
163 args.onmouseover = "this.src='" + nl.onmouseoversrc.value + "';";
165 if (nl.onmouseoutsrc.value)
166 args.onmouseout = "this.src='" + nl.onmouseoutsrc.value + "';";
169 el = ed.selection.getNode();
171 if (el && el.nodeName == 'IMG') {
172 ed.dom.setAttribs(el, args);
174 ed.execCommand('mceInsertContent', false, '<img id="__mce_tmp" />', {skip_undo : 1});
175 ed.dom.setAttribs('__mce_tmp', args);
176 ed.dom.setAttrib('__mce_tmp', 'id', '');
177 ed.undoManager.add();
180 tinyMCEPopup.editor.execCommand('mceRepaint');
181 tinyMCEPopup.editor.focus();
182 tinyMCEPopup.close();
185 getAttrib : function(e, at) {
186 var ed = tinyMCEPopup.editor, dom = ed.dom, v, v2;
188 if (ed.settings.inline_styles) {
191 if (v = dom.getStyle(e, 'float'))
194 if (v = dom.getStyle(e, 'vertical-align'))
200 v = dom.getStyle(e, 'margin-left')
201 v2 = dom.getStyle(e, 'margin-right');
204 return parseInt(v.replace(/[^0-9]/g, ''));
209 v = dom.getStyle(e, 'margin-top')
210 v2 = dom.getStyle(e, 'margin-bottom');
212 return parseInt(v.replace(/[^0-9]/g, ''));
219 tinymce.each(['top', 'right', 'bottom', 'left'], function(sv) {
220 sv = dom.getStyle(e, 'border-' + sv + '-width');
222 // False or not the same as prev
223 if (!sv || (sv != v && v !== 0)) {
233 return parseInt(v.replace(/[^0-9]/g, ''));
239 if (v = dom.getAttrib(e, at))
245 setSwapImage : function(st) {
246 var f = document.forms[0];
248 f.onmousemovecheck.checked = st;
249 setBrowserDisabled('overbrowser', !st);
250 setBrowserDisabled('outbrowser', !st);
253 f.over_list.disabled = !st;
256 f.out_list.disabled = !st;
258 f.onmouseoversrc.disabled = !st;
259 f.onmouseoutsrc.disabled = !st;
262 fillClassList : function(id) {
263 var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
265 if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
268 tinymce.each(v.split(';'), function(v) {
269 var p = v.split('=');
271 cl.push({'title' : p[0], 'class' : p[1]});
274 cl = tinyMCEPopup.editor.dom.getClasses();
277 lst.options.length = 0;
278 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
280 tinymce.each(cl, function(o) {
281 lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
284 dom.remove(dom.getParent(id, 'tr'));
287 fillFileList : function(id, l) {
288 var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
290 l = typeof(l) === 'function' ? l() : window[l];
291 lst.options.length = 0;
293 if (l && l.length > 0) {
294 lst.options[lst.options.length] = new Option('', '');
296 tinymce.each(l, function(o) {
297 lst.options[lst.options.length] = new Option(o[0], o[1]);
300 dom.remove(dom.getParent(id, 'tr'));
303 resetImageData : function() {
304 var f = document.forms[0];
306 f.elements.width.value = f.elements.height.value = '';
309 updateImageData : function(img, st) {
310 var f = document.forms[0];
313 f.elements.width.value = img.width;
314 f.elements.height.value = img.height;
317 this.preloadImg = img;
320 changeAppearance : function() {
321 var ed = tinyMCEPopup.editor, f = document.forms[0], img = document.getElementById('alignSampleImg');
324 if (ed.getParam('inline_styles')) {
325 ed.dom.setAttrib(img, 'style', f.style.value);
327 img.align = f.align.value;
328 img.border = f.border.value;
329 img.hspace = f.hspace.value;
330 img.vspace = f.vspace.value;
335 changeHeight : function() {
336 var f = document.forms[0], tp, t = this;
338 if (!f.constrain.checked || !t.preloadImg) {
342 if (f.width.value == "" || f.height.value == "")
345 tp = (parseInt(f.width.value) / parseInt(t.preloadImg.width)) * t.preloadImg.height;
346 f.height.value = tp.toFixed(0);
349 changeWidth : function() {
350 var f = document.forms[0], tp, t = this;
352 if (!f.constrain.checked || !t.preloadImg) {
356 if (f.width.value == "" || f.height.value == "")
359 tp = (parseInt(f.height.value) / parseInt(t.preloadImg.height)) * t.preloadImg.width;
360 f.width.value = tp.toFixed(0);
363 updateStyle : function(ty) {
364 var dom = tinyMCEPopup.dom, b, bStyle, bColor, v, isIE = tinymce.isIE, f = document.forms[0], img = dom.create('img', {style : dom.get('style').value});
366 if (tinyMCEPopup.editor.settings.inline_styles) {
369 dom.setStyle(img, 'float', '');
370 dom.setStyle(img, 'vertical-align', '');
372 v = getSelectValue(f, 'align');
374 if (v == 'left' || v == 'right')
375 dom.setStyle(img, 'float', v);
377 img.style.verticalAlign = v;
382 if (ty == 'border') {
383 b = img.style.border ? img.style.border.split(' ') : [];
384 bStyle = dom.getStyle(img, 'border-style');
385 bColor = dom.getStyle(img, 'border-color');
387 dom.setStyle(img, 'border', '');
392 img.style.border = isIE ? '0' : '0 none none';
394 if (b.length == 3 && b[isIE ? 2 : 1])
395 bStyle = b[isIE ? 2 : 1];
396 else if (!bStyle || bStyle == 'none')
398 if (b.length == 3 && b[isIE ? 0 : 2])
399 bColor = b[isIE ? 0 : 2];
400 else if (!bColor || bColor == 'none')
402 img.style.border = v + 'px ' + bStyle + ' ' + bColor;
408 if (ty == 'hspace') {
409 dom.setStyle(img, 'marginLeft', '');
410 dom.setStyle(img, 'marginRight', '');
414 img.style.marginLeft = v + 'px';
415 img.style.marginRight = v + 'px';
420 if (ty == 'vspace') {
421 dom.setStyle(img, 'marginTop', '');
422 dom.setStyle(img, 'marginBottom', '');
426 img.style.marginTop = v + 'px';
427 img.style.marginBottom = v + 'px';
432 dom.get('style').value = dom.serializeStyle(dom.parseStyle(img.style.cssText), 'img');
436 changeMouseMove : function() {
439 showPreviewImage : function(u, st) {
441 tinyMCEPopup.dom.setHTML('prev', '');
445 if (!st && tinyMCEPopup.getParam("advimage_update_dimensions_onchange", true))
446 this.resetImageData();
448 u = tinyMCEPopup.editor.documentBaseURI.toAbsolute(u);
451 tinyMCEPopup.dom.setHTML('prev', '<img id="previewImg" src="' + u + '" border="0" onload="ImageDialog.updateImageData(this);" onerror="ImageDialog.resetImageData();" />');
453 tinyMCEPopup.dom.setHTML('prev', '<img id="previewImg" src="' + u + '" border="0" onload="ImageDialog.updateImageData(this, 1);" />');
457 ImageDialog.preInit();
458 tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);