bgneal@312: var ImageDialog = {
bgneal@312: preInit : function() {
bgneal@312: var url;
bgneal@312:
bgneal@312: tinyMCEPopup.requireLangPack();
bgneal@312:
bgneal@312: if (url = tinyMCEPopup.getParam("external_image_list_url"))
bgneal@312: document.write('');
bgneal@312: },
bgneal@312:
bgneal@312: init : function() {
bgneal@312: var f = document.forms[0], ed = tinyMCEPopup.editor;
bgneal@312:
bgneal@312: // Setup browse button
bgneal@312: document.getElementById('srcbrowsercontainer').innerHTML = getBrowserHTML('srcbrowser','src','image','theme_advanced_image');
bgneal@312: if (isVisible('srcbrowser'))
bgneal@312: document.getElementById('src').style.width = '180px';
bgneal@312:
bgneal@312: e = ed.selection.getNode();
bgneal@312:
bgneal@312: this.fillFileList('image_list', 'tinyMCEImageList');
bgneal@312:
bgneal@312: if (e.nodeName == 'IMG') {
bgneal@312: f.src.value = ed.dom.getAttrib(e, 'src');
bgneal@312: f.alt.value = ed.dom.getAttrib(e, 'alt');
bgneal@312: f.border.value = this.getAttrib(e, 'border');
bgneal@312: f.vspace.value = this.getAttrib(e, 'vspace');
bgneal@312: f.hspace.value = this.getAttrib(e, 'hspace');
bgneal@312: f.width.value = ed.dom.getAttrib(e, 'width');
bgneal@312: f.height.value = ed.dom.getAttrib(e, 'height');
bgneal@312: f.insert.value = ed.getLang('update');
bgneal@312: this.styleVal = ed.dom.getAttrib(e, 'style');
bgneal@312: selectByValue(f, 'image_list', f.src.value);
bgneal@312: selectByValue(f, 'align', this.getAttrib(e, 'align'));
bgneal@312: this.updateStyle();
bgneal@312: }
bgneal@312: },
bgneal@312:
bgneal@312: fillFileList : function(id, l) {
bgneal@312: var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
bgneal@312:
bgneal@312: l = window[l];
bgneal@312:
bgneal@312: if (l && l.length > 0) {
bgneal@312: lst.options[lst.options.length] = new Option('', '');
bgneal@312:
bgneal@312: tinymce.each(l, function(o) {
bgneal@312: lst.options[lst.options.length] = new Option(o[0], o[1]);
bgneal@312: });
bgneal@312: } else
bgneal@312: dom.remove(dom.getParent(id, 'tr'));
bgneal@312: },
bgneal@312:
bgneal@312: update : function() {
bgneal@312: var f = document.forms[0], nl = f.elements, ed = tinyMCEPopup.editor, args = {}, el;
bgneal@312:
bgneal@312: tinyMCEPopup.restoreSelection();
bgneal@312:
bgneal@312: if (f.src.value === '') {
bgneal@312: if (ed.selection.getNode().nodeName == 'IMG') {
bgneal@312: ed.dom.remove(ed.selection.getNode());
bgneal@312: ed.execCommand('mceRepaint');
bgneal@312: }
bgneal@312:
bgneal@312: tinyMCEPopup.close();
bgneal@312: return;
bgneal@312: }
bgneal@312:
bgneal@312: if (!ed.settings.inline_styles) {
bgneal@312: args = tinymce.extend(args, {
bgneal@312: vspace : nl.vspace.value,
bgneal@312: hspace : nl.hspace.value,
bgneal@312: border : nl.border.value,
bgneal@312: align : getSelectValue(f, 'align')
bgneal@312: });
bgneal@312: } else
bgneal@312: args.style = this.styleVal;
bgneal@312:
bgneal@312: tinymce.extend(args, {
bgneal@442: src : f.src.value.replace(/ /g, '%20'),
bgneal@312: alt : f.alt.value,
bgneal@312: width : f.width.value,
bgneal@312: height : f.height.value
bgneal@312: });
bgneal@312:
bgneal@312: el = ed.selection.getNode();
bgneal@312:
bgneal@312: if (el && el.nodeName == 'IMG') {
bgneal@312: ed.dom.setAttribs(el, args);
bgneal@442: tinyMCEPopup.editor.execCommand('mceRepaint');
bgneal@442: tinyMCEPopup.editor.focus();
bgneal@312: } else {
bgneal@312: ed.execCommand('mceInsertContent', false, '', {skip_undo : 1});
bgneal@312: ed.dom.setAttribs('__mce_tmp', args);
bgneal@312: ed.dom.setAttrib('__mce_tmp', 'id', '');
bgneal@312: ed.undoManager.add();
bgneal@312: }
bgneal@312:
bgneal@312: tinyMCEPopup.close();
bgneal@312: },
bgneal@312:
bgneal@312: updateStyle : function() {
bgneal@312: var dom = tinyMCEPopup.dom, st, v, f = document.forms[0];
bgneal@312:
bgneal@312: if (tinyMCEPopup.editor.settings.inline_styles) {
bgneal@312: st = tinyMCEPopup.dom.parseStyle(this.styleVal);
bgneal@312:
bgneal@312: // Handle align
bgneal@312: v = getSelectValue(f, 'align');
bgneal@312: if (v) {
bgneal@312: if (v == 'left' || v == 'right') {
bgneal@312: st['float'] = v;
bgneal@312: delete st['vertical-align'];
bgneal@312: } else {
bgneal@312: st['vertical-align'] = v;
bgneal@312: delete st['float'];
bgneal@312: }
bgneal@312: } else {
bgneal@312: delete st['float'];
bgneal@312: delete st['vertical-align'];
bgneal@312: }
bgneal@312:
bgneal@312: // Handle border
bgneal@312: v = f.border.value;
bgneal@312: if (v || v == '0') {
bgneal@312: if (v == '0')
bgneal@312: st['border'] = '0';
bgneal@312: else
bgneal@312: st['border'] = v + 'px solid black';
bgneal@312: } else
bgneal@312: delete st['border'];
bgneal@312:
bgneal@312: // Handle hspace
bgneal@312: v = f.hspace.value;
bgneal@312: if (v) {
bgneal@312: delete st['margin'];
bgneal@312: st['margin-left'] = v + 'px';
bgneal@312: st['margin-right'] = v + 'px';
bgneal@312: } else {
bgneal@312: delete st['margin-left'];
bgneal@312: delete st['margin-right'];
bgneal@312: }
bgneal@312:
bgneal@312: // Handle vspace
bgneal@312: v = f.vspace.value;
bgneal@312: if (v) {
bgneal@312: delete st['margin'];
bgneal@312: st['margin-top'] = v + 'px';
bgneal@312: st['margin-bottom'] = v + 'px';
bgneal@312: } else {
bgneal@312: delete st['margin-top'];
bgneal@312: delete st['margin-bottom'];
bgneal@312: }
bgneal@312:
bgneal@312: // Merge
bgneal@312: st = tinyMCEPopup.dom.parseStyle(dom.serializeStyle(st), 'img');
bgneal@312: this.styleVal = dom.serializeStyle(st, 'img');
bgneal@312: }
bgneal@312: },
bgneal@312:
bgneal@312: getAttrib : function(e, at) {
bgneal@312: var ed = tinyMCEPopup.editor, dom = ed.dom, v, v2;
bgneal@312:
bgneal@312: if (ed.settings.inline_styles) {
bgneal@312: switch (at) {
bgneal@312: case 'align':
bgneal@312: if (v = dom.getStyle(e, 'float'))
bgneal@312: return v;
bgneal@312:
bgneal@312: if (v = dom.getStyle(e, 'vertical-align'))
bgneal@312: return v;
bgneal@312:
bgneal@312: break;
bgneal@312:
bgneal@312: case 'hspace':
bgneal@312: v = dom.getStyle(e, 'margin-left')
bgneal@312: v2 = dom.getStyle(e, 'margin-right');
bgneal@312: if (v && v == v2)
bgneal@312: return parseInt(v.replace(/[^0-9]/g, ''));
bgneal@312:
bgneal@312: break;
bgneal@312:
bgneal@312: case 'vspace':
bgneal@312: v = dom.getStyle(e, 'margin-top')
bgneal@312: v2 = dom.getStyle(e, 'margin-bottom');
bgneal@312: if (v && v == v2)
bgneal@312: return parseInt(v.replace(/[^0-9]/g, ''));
bgneal@312:
bgneal@312: break;
bgneal@312:
bgneal@312: case 'border':
bgneal@312: v = 0;
bgneal@312:
bgneal@312: tinymce.each(['top', 'right', 'bottom', 'left'], function(sv) {
bgneal@312: sv = dom.getStyle(e, 'border-' + sv + '-width');
bgneal@312:
bgneal@312: // False or not the same as prev
bgneal@312: if (!sv || (sv != v && v !== 0)) {
bgneal@312: v = 0;
bgneal@312: return false;
bgneal@312: }
bgneal@312:
bgneal@312: if (sv)
bgneal@312: v = sv;
bgneal@312: });
bgneal@312:
bgneal@312: if (v)
bgneal@312: return parseInt(v.replace(/[^0-9]/g, ''));
bgneal@312:
bgneal@312: break;
bgneal@312: }
bgneal@312: }
bgneal@312:
bgneal@312: if (v = dom.getAttrib(e, at))
bgneal@312: return v;
bgneal@312:
bgneal@312: return '';
bgneal@312: },
bgneal@312:
bgneal@312: resetImageData : function() {
bgneal@312: var f = document.forms[0];
bgneal@312:
bgneal@312: f.width.value = f.height.value = "";
bgneal@312: },
bgneal@312:
bgneal@312: updateImageData : function() {
bgneal@312: var f = document.forms[0], t = ImageDialog;
bgneal@312:
bgneal@312: if (f.width.value == "")
bgneal@312: f.width.value = t.preloadImg.width;
bgneal@312:
bgneal@312: if (f.height.value == "")
bgneal@312: f.height.value = t.preloadImg.height;
bgneal@312: },
bgneal@312:
bgneal@312: getImageData : function() {
bgneal@312: var f = document.forms[0];
bgneal@312:
bgneal@312: this.preloadImg = new Image();
bgneal@312: this.preloadImg.onload = this.updateImageData;
bgneal@312: this.preloadImg.onerror = this.resetImageData;
bgneal@312: this.preloadImg.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.src.value);
bgneal@312: }
bgneal@312: };
bgneal@312:
bgneal@312: ImageDialog.preInit();
bgneal@312: tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);