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 tinymce.each(args, function(value, name) {
99 ed.execCommand('mceInsertContent', false, tinyMCEPopup.editor.dom.createHTML('img', args), {skip_undo : 1});
100 ed.undoManager.add();
103 tinyMCEPopup.close();
106 updateStyle : function() {
107 var dom = tinyMCEPopup.dom, st = {}, v, f = document.forms[0];
109 if (tinyMCEPopup.editor.settings.inline_styles) {
110 tinymce.each(tinyMCEPopup.dom.parseStyle(this.styleVal), function(value, key) {
115 v = getSelectValue(f, 'align');
117 if (v == 'left' || v == 'right') {
119 delete st['vertical-align'];
121 st['vertical-align'] = v;
126 delete st['vertical-align'];
135 st['border'] = v + 'px solid black';
143 st['margin-left'] = v + 'px';
144 st['margin-right'] = v + 'px';
146 delete st['margin-left'];
147 delete st['margin-right'];
154 st['margin-top'] = v + 'px';
155 st['margin-bottom'] = v + 'px';
157 delete st['margin-top'];
158 delete st['margin-bottom'];
162 st = tinyMCEPopup.dom.parseStyle(dom.serializeStyle(st), 'img');
163 this.styleVal = dom.serializeStyle(st, 'img');
167 getAttrib : function(e, at) {
168 var ed = tinyMCEPopup.editor, dom = ed.dom, v, v2;
170 if (ed.settings.inline_styles) {
173 if (v = dom.getStyle(e, 'float'))
176 if (v = dom.getStyle(e, 'vertical-align'))
182 v = dom.getStyle(e, 'margin-left')
183 v2 = dom.getStyle(e, 'margin-right');
185 return parseInt(v.replace(/[^0-9]/g, ''));
190 v = dom.getStyle(e, 'margin-top')
191 v2 = dom.getStyle(e, 'margin-bottom');
193 return parseInt(v.replace(/[^0-9]/g, ''));
200 tinymce.each(['top', 'right', 'bottom', 'left'], function(sv) {
201 sv = dom.getStyle(e, 'border-' + sv + '-width');
203 // False or not the same as prev
204 if (!sv || (sv != v && v !== 0)) {
214 return parseInt(v.replace(/[^0-9]/g, ''));
220 if (v = dom.getAttrib(e, at))
226 resetImageData : function() {
227 var f = document.forms[0];
229 f.width.value = f.height.value = "";
232 updateImageData : function() {
233 var f = document.forms[0], t = ImageDialog;
235 if (f.width.value == "")
236 f.width.value = t.preloadImg.width;
238 if (f.height.value == "")
239 f.height.value = t.preloadImg.height;
242 getImageData : function() {
243 var f = document.forms[0];
245 this.preloadImg = new Image();
246 this.preloadImg.onload = this.updateImageData;
247 this.preloadImg.onerror = this.resetImageData;
248 this.preloadImg.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.src.value);
252 ImageDialog.preInit();
253 tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);