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], ed = tinyMCEPopup.editor;
14 // Setup browse button
15 document.getElementById('srcbrowsercontainer').innerHTML = getBrowserHTML('srcbrowser','src','image','theme_advanced_image');
16 if (isVisible('srcbrowser'))
17 document.getElementById('src').style.width = '180px';
19 e = ed.selection.getNode();
21 this.fillFileList('image_list', tinyMCEPopup.getParam('external_image_list', 'tinyMCEImageList'));
23 if (e.nodeName == 'IMG') {
24 f.src.value = ed.dom.getAttrib(e, 'src');
25 f.alt.value = ed.dom.getAttrib(e, 'alt');
26 f.border.value = this.getAttrib(e, 'border');
27 f.vspace.value = this.getAttrib(e, 'vspace');
28 f.hspace.value = this.getAttrib(e, 'hspace');
29 f.width.value = ed.dom.getAttrib(e, 'width');
30 f.height.value = ed.dom.getAttrib(e, 'height');
31 f.insert.value = ed.getLang('update');
32 this.styleVal = ed.dom.getAttrib(e, 'style');
33 selectByValue(f, 'image_list', f.src.value);
34 selectByValue(f, 'align', this.getAttrib(e, 'align'));
39 fillFileList : function(id, l) {
40 var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
42 l = typeof(l) === 'function' ? l() : window[l];
44 if (l && l.length > 0) {
45 lst.options[lst.options.length] = new Option('', '');
47 tinymce.each(l, function(o) {
48 lst.options[lst.options.length] = new Option(o[0], o[1]);
51 dom.remove(dom.getParent(id, 'tr'));
55 var f = document.forms[0], nl = f.elements, ed = tinyMCEPopup.editor, args = {}, el;
57 tinyMCEPopup.restoreSelection();
59 if (f.src.value === '') {
60 if (ed.selection.getNode().nodeName == 'IMG') {
61 ed.dom.remove(ed.selection.getNode());
62 ed.execCommand('mceRepaint');
69 if (!ed.settings.inline_styles) {
70 args = tinymce.extend(args, {
71 vspace : nl.vspace.value,
72 hspace : nl.hspace.value,
73 border : nl.border.value,
74 align : getSelectValue(f, 'align')
77 args.style = this.styleVal;
79 tinymce.extend(args, {
80 src : f.src.value.replace(/ /g, '%20'),
82 width : f.width.value,
83 height : f.height.value
86 el = ed.selection.getNode();
88 if (el && el.nodeName == 'IMG') {
89 ed.dom.setAttribs(el, args);
90 tinyMCEPopup.editor.execCommand('mceRepaint');
91 tinyMCEPopup.editor.focus();
93 ed.execCommand('mceInsertContent', false, '<img id="__mce_tmp" />', {skip_undo : 1});
94 ed.dom.setAttribs('__mce_tmp', args);
95 ed.dom.setAttrib('__mce_tmp', 'id', '');
102 updateStyle : function() {
103 var dom = tinyMCEPopup.dom, st, v, f = document.forms[0];
105 if (tinyMCEPopup.editor.settings.inline_styles) {
106 st = tinyMCEPopup.dom.parseStyle(this.styleVal);
109 v = getSelectValue(f, 'align');
111 if (v == 'left' || v == 'right') {
113 delete st['vertical-align'];
115 st['vertical-align'] = v;
120 delete st['vertical-align'];
129 st['border'] = v + 'px solid black';
137 st['margin-left'] = v + 'px';
138 st['margin-right'] = v + 'px';
140 delete st['margin-left'];
141 delete st['margin-right'];
148 st['margin-top'] = v + 'px';
149 st['margin-bottom'] = v + 'px';
151 delete st['margin-top'];
152 delete st['margin-bottom'];
156 st = tinyMCEPopup.dom.parseStyle(dom.serializeStyle(st), 'img');
157 this.styleVal = dom.serializeStyle(st, 'img');
161 getAttrib : function(e, at) {
162 var ed = tinyMCEPopup.editor, dom = ed.dom, v, v2;
164 if (ed.settings.inline_styles) {
167 if (v = dom.getStyle(e, 'float'))
170 if (v = dom.getStyle(e, 'vertical-align'))
176 v = dom.getStyle(e, 'margin-left')
177 v2 = dom.getStyle(e, 'margin-right');
179 return parseInt(v.replace(/[^0-9]/g, ''));
184 v = dom.getStyle(e, 'margin-top')
185 v2 = dom.getStyle(e, 'margin-bottom');
187 return parseInt(v.replace(/[^0-9]/g, ''));
194 tinymce.each(['top', 'right', 'bottom', 'left'], function(sv) {
195 sv = dom.getStyle(e, 'border-' + sv + '-width');
197 // False or not the same as prev
198 if (!sv || (sv != v && v !== 0)) {
208 return parseInt(v.replace(/[^0-9]/g, ''));
214 if (v = dom.getAttrib(e, at))
220 resetImageData : function() {
221 var f = document.forms[0];
223 f.width.value = f.height.value = "";
226 updateImageData : function() {
227 var f = document.forms[0], t = ImageDialog;
229 if (f.width.value == "")
230 f.width.value = t.preloadImg.width;
232 if (f.height.value == "")
233 f.height.value = t.preloadImg.height;
236 getImageData : function() {
237 var f = document.forms[0];
239 this.preloadImg = new Image();
240 this.preloadImg.onload = this.updateImageData;
241 this.preloadImg.onerror = this.resetImageData;
242 this.preloadImg.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.src.value);
246 ImageDialog.preInit();
247 tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);