bgneal@45: var ImageDialog = {
bgneal@45: preInit : function() {
bgneal@45: var url;
bgneal@45:
bgneal@45: tinyMCEPopup.requireLangPack();
bgneal@45:
bgneal@45: if (url = tinyMCEPopup.getParam("external_image_list_url"))
bgneal@45: document.write('');
bgneal@45: },
bgneal@45:
bgneal@45: init : function(ed) {
bgneal@45: 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');
bgneal@45:
bgneal@45: tinyMCEPopup.resizeToInnerSize();
bgneal@45: this.fillClassList('class_list');
bgneal@45: this.fillFileList('src_list', fl);
bgneal@45: this.fillFileList('over_list', fl);
bgneal@45: this.fillFileList('out_list', fl);
bgneal@45: TinyMCE_EditableSelects.init();
bgneal@45:
bgneal@45: if (n.nodeName == 'IMG') {
bgneal@45: nl.src.value = dom.getAttrib(n, 'src');
bgneal@45: nl.width.value = dom.getAttrib(n, 'width');
bgneal@45: nl.height.value = dom.getAttrib(n, 'height');
bgneal@45: nl.alt.value = dom.getAttrib(n, 'alt');
bgneal@45: nl.title.value = dom.getAttrib(n, 'title');
bgneal@45: nl.vspace.value = this.getAttrib(n, 'vspace');
bgneal@45: nl.hspace.value = this.getAttrib(n, 'hspace');
bgneal@45: nl.border.value = this.getAttrib(n, 'border');
bgneal@45: selectByValue(f, 'align', this.getAttrib(n, 'align'));
bgneal@45: selectByValue(f, 'class_list', dom.getAttrib(n, 'class'), true, true);
bgneal@45: nl.style.value = dom.getAttrib(n, 'style');
bgneal@45: nl.id.value = dom.getAttrib(n, 'id');
bgneal@45: nl.dir.value = dom.getAttrib(n, 'dir');
bgneal@45: nl.lang.value = dom.getAttrib(n, 'lang');
bgneal@45: nl.usemap.value = dom.getAttrib(n, 'usemap');
bgneal@45: nl.longdesc.value = dom.getAttrib(n, 'longdesc');
bgneal@45: nl.insert.value = ed.getLang('update');
bgneal@45:
bgneal@45: if (/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/.test(dom.getAttrib(n, 'onmouseover')))
bgneal@45: nl.onmouseoversrc.value = dom.getAttrib(n, 'onmouseover').replace(/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/, '$1');
bgneal@45:
bgneal@45: if (/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/.test(dom.getAttrib(n, 'onmouseout')))
bgneal@45: nl.onmouseoutsrc.value = dom.getAttrib(n, 'onmouseout').replace(/^\s*this.src\s*=\s*\'([^\']+)\';?\s*$/, '$1');
bgneal@45:
bgneal@45: if (ed.settings.inline_styles) {
bgneal@45: // Move attribs to styles
bgneal@45: if (dom.getAttrib(n, 'align'))
bgneal@45: this.updateStyle('align');
bgneal@45:
bgneal@45: if (dom.getAttrib(n, 'hspace'))
bgneal@45: this.updateStyle('hspace');
bgneal@45:
bgneal@45: if (dom.getAttrib(n, 'border'))
bgneal@45: this.updateStyle('border');
bgneal@45:
bgneal@45: if (dom.getAttrib(n, 'vspace'))
bgneal@45: this.updateStyle('vspace');
bgneal@45: }
bgneal@45: }
bgneal@45:
bgneal@45: // Setup browse button
bgneal@45: document.getElementById('srcbrowsercontainer').innerHTML = getBrowserHTML('srcbrowser','src','image','theme_advanced_image');
bgneal@45: if (isVisible('srcbrowser'))
bgneal@45: document.getElementById('src').style.width = '260px';
bgneal@45:
bgneal@45: // Setup browse button
bgneal@45: document.getElementById('onmouseoversrccontainer').innerHTML = getBrowserHTML('overbrowser','onmouseoversrc','image','theme_advanced_image');
bgneal@45: if (isVisible('overbrowser'))
bgneal@45: document.getElementById('onmouseoversrc').style.width = '260px';
bgneal@45:
bgneal@45: // Setup browse button
bgneal@45: document.getElementById('onmouseoutsrccontainer').innerHTML = getBrowserHTML('outbrowser','onmouseoutsrc','image','theme_advanced_image');
bgneal@45: if (isVisible('outbrowser'))
bgneal@45: document.getElementById('onmouseoutsrc').style.width = '260px';
bgneal@45:
bgneal@45: // If option enabled default contrain proportions to checked
bgneal@45: if (ed.getParam("advimage_constrain_proportions", true))
bgneal@45: f.constrain.checked = true;
bgneal@45:
bgneal@45: // Check swap image if valid data
bgneal@45: if (nl.onmouseoversrc.value || nl.onmouseoutsrc.value)
bgneal@45: this.setSwapImage(true);
bgneal@45: else
bgneal@45: this.setSwapImage(false);
bgneal@45:
bgneal@45: this.changeAppearance();
bgneal@45: this.showPreviewImage(nl.src.value, 1);
bgneal@45: },
bgneal@45:
bgneal@45: insert : function(file, title) {
bgneal@45: var ed = tinyMCEPopup.editor, t = this, f = document.forms[0];
bgneal@45:
bgneal@45: if (f.src.value === '') {
bgneal@45: if (ed.selection.getNode().nodeName == 'IMG') {
bgneal@45: ed.dom.remove(ed.selection.getNode());
bgneal@45: ed.execCommand('mceRepaint');
bgneal@45: }
bgneal@45:
bgneal@45: tinyMCEPopup.close();
bgneal@45: return;
bgneal@45: }
bgneal@45:
bgneal@45: if (tinyMCEPopup.getParam("accessibility_warnings", 1)) {
bgneal@45: if (!f.alt.value) {
bgneal@45: tinyMCEPopup.confirm(tinyMCEPopup.getLang('advimage_dlg.missing_alt'), function(s) {
bgneal@45: if (s)
bgneal@45: t.insertAndClose();
bgneal@45: });
bgneal@45:
bgneal@45: return;
bgneal@45: }
bgneal@45: }
bgneal@45:
bgneal@45: t.insertAndClose();
bgneal@45: },
bgneal@45:
bgneal@45: insertAndClose : function() {
bgneal@45: var ed = tinyMCEPopup.editor, f = document.forms[0], nl = f.elements, v, args = {}, el;
bgneal@45:
bgneal@45: tinyMCEPopup.restoreSelection();
bgneal@45:
bgneal@45: // Fixes crash in Safari
bgneal@45: if (tinymce.isWebKit)
bgneal@45: ed.getWin().focus();
bgneal@45:
bgneal@45: if (!ed.settings.inline_styles) {
bgneal@45: args = {
bgneal@45: vspace : nl.vspace.value,
bgneal@45: hspace : nl.hspace.value,
bgneal@45: border : nl.border.value,
bgneal@45: align : getSelectValue(f, 'align')
bgneal@45: };
bgneal@45: } else {
bgneal@45: // Remove deprecated values
bgneal@45: args = {
bgneal@45: vspace : '',
bgneal@45: hspace : '',
bgneal@45: border : '',
bgneal@45: align : ''
bgneal@45: };
bgneal@45: }
bgneal@45:
bgneal@45: tinymce.extend(args, {
bgneal@45: src : nl.src.value.replace(/ /g, '%20'),
bgneal@45: width : nl.width.value,
bgneal@45: height : nl.height.value,
bgneal@45: alt : nl.alt.value,
bgneal@45: title : nl.title.value,
bgneal@45: 'class' : getSelectValue(f, 'class_list'),
bgneal@45: style : nl.style.value,
bgneal@45: id : nl.id.value,
bgneal@45: dir : nl.dir.value,
bgneal@45: lang : nl.lang.value,
bgneal@45: usemap : nl.usemap.value,
bgneal@45: longdesc : nl.longdesc.value
bgneal@45: });
bgneal@45:
bgneal@45: args.onmouseover = args.onmouseout = '';
bgneal@45:
bgneal@45: if (f.onmousemovecheck.checked) {
bgneal@45: if (nl.onmouseoversrc.value)
bgneal@45: args.onmouseover = "this.src='" + nl.onmouseoversrc.value + "';";
bgneal@45:
bgneal@45: if (nl.onmouseoutsrc.value)
bgneal@45: args.onmouseout = "this.src='" + nl.onmouseoutsrc.value + "';";
bgneal@45: }
bgneal@45:
bgneal@45: el = ed.selection.getNode();
bgneal@45:
bgneal@45: if (el && el.nodeName == 'IMG') {
bgneal@45: ed.dom.setAttribs(el, args);
bgneal@45: } else {
bgneal@45: tinymce.each(args, function(value, name) {
bgneal@45: if (value === "") {
bgneal@45: delete args[name];
bgneal@45: }
bgneal@45: });
bgneal@45:
bgneal@45: ed.execCommand('mceInsertContent', false, tinyMCEPopup.editor.dom.createHTML('img', args), {skip_undo : 1});
bgneal@45: ed.undoManager.add();
bgneal@45: }
bgneal@45:
bgneal@45: tinyMCEPopup.editor.execCommand('mceRepaint');
bgneal@45: tinyMCEPopup.editor.focus();
bgneal@45: tinyMCEPopup.close();
bgneal@45: },
bgneal@45:
bgneal@45: getAttrib : function(e, at) {
bgneal@45: var ed = tinyMCEPopup.editor, dom = ed.dom, v, v2;
bgneal@45:
bgneal@45: if (ed.settings.inline_styles) {
bgneal@45: switch (at) {
bgneal@45: case 'align':
bgneal@45: if (v = dom.getStyle(e, 'float'))
bgneal@45: return v;
bgneal@45:
bgneal@45: if (v = dom.getStyle(e, 'vertical-align'))
bgneal@45: return v;
bgneal@45:
bgneal@45: break;
bgneal@45:
bgneal@45: case 'hspace':
bgneal@45: v = dom.getStyle(e, 'margin-left')
bgneal@45: v2 = dom.getStyle(e, 'margin-right');
bgneal@45:
bgneal@45: if (v && v == v2)
bgneal@45: return parseInt(v.replace(/[^0-9]/g, ''));
bgneal@45:
bgneal@45: break;
bgneal@45:
bgneal@45: case 'vspace':
bgneal@45: v = dom.getStyle(e, 'margin-top')
bgneal@45: v2 = dom.getStyle(e, 'margin-bottom');
bgneal@45: if (v && v == v2)
bgneal@45: return parseInt(v.replace(/[^0-9]/g, ''));
bgneal@45:
bgneal@45: break;
bgneal@45:
bgneal@45: case 'border':
bgneal@45: v = 0;
bgneal@45:
bgneal@45: tinymce.each(['top', 'right', 'bottom', 'left'], function(sv) {
bgneal@45: sv = dom.getStyle(e, 'border-' + sv + '-width');
bgneal@45:
bgneal@45: // False or not the same as prev
bgneal@45: if (!sv || (sv != v && v !== 0)) {
bgneal@45: v = 0;
bgneal@45: return false;
bgneal@45: }
bgneal@45:
bgneal@45: if (sv)
bgneal@45: v = sv;
bgneal@45: });
bgneal@45:
bgneal@45: if (v)
bgneal@45: return parseInt(v.replace(/[^0-9]/g, ''));
bgneal@45:
bgneal@45: break;
bgneal@45: }
bgneal@45: }
bgneal@45:
bgneal@45: if (v = dom.getAttrib(e, at))
bgneal@45: return v;
bgneal@45:
bgneal@45: return '';
bgneal@45: },
bgneal@45:
bgneal@45: setSwapImage : function(st) {
bgneal@45: var f = document.forms[0];
bgneal@45:
bgneal@45: f.onmousemovecheck.checked = st;
bgneal@45: setBrowserDisabled('overbrowser', !st);
bgneal@45: setBrowserDisabled('outbrowser', !st);
bgneal@45:
bgneal@45: if (f.over_list)
bgneal@45: f.over_list.disabled = !st;
bgneal@45:
bgneal@45: if (f.out_list)
bgneal@45: f.out_list.disabled = !st;
bgneal@45:
bgneal@45: f.onmouseoversrc.disabled = !st;
bgneal@45: f.onmouseoutsrc.disabled = !st;
bgneal@45: },
bgneal@45:
bgneal@45: fillClassList : function(id) {
bgneal@45: var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
bgneal@45:
bgneal@45: if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
bgneal@45: cl = [];
bgneal@45:
bgneal@45: tinymce.each(v.split(';'), function(v) {
bgneal@45: var p = v.split('=');
bgneal@45:
bgneal@45: cl.push({'title' : p[0], 'class' : p[1]});
bgneal@45: });
bgneal@45: } else
bgneal@45: cl = tinyMCEPopup.editor.dom.getClasses();
bgneal@45:
bgneal@45: if (cl.length > 0) {
bgneal@45: lst.options.length = 0;
bgneal@45: lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
bgneal@45:
bgneal@45: tinymce.each(cl, function(o) {
bgneal@45: lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
bgneal@45: });
bgneal@45: } else
bgneal@45: dom.remove(dom.getParent(id, 'tr'));
bgneal@45: },
bgneal@45:
bgneal@45: fillFileList : function(id, l) {
bgneal@45: var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
bgneal@45:
bgneal@45: l = typeof(l) === 'function' ? l() : window[l];
bgneal@45: lst.options.length = 0;
bgneal@45:
bgneal@45: if (l && l.length > 0) {
bgneal@45: lst.options[lst.options.length] = new Option('', '');
bgneal@45:
bgneal@45: tinymce.each(l, function(o) {
bgneal@45: lst.options[lst.options.length] = new Option(o[0], o[1]);
bgneal@45: });
bgneal@45: } else
bgneal@45: dom.remove(dom.getParent(id, 'tr'));
bgneal@45: },
bgneal@45:
bgneal@45: resetImageData : function() {
bgneal@45: var f = document.forms[0];
bgneal@45:
bgneal@45: f.elements.width.value = f.elements.height.value = '';
bgneal@45: },
bgneal@45:
bgneal@45: updateImageData : function(img, st) {
bgneal@45: var f = document.forms[0];
bgneal@45:
bgneal@45: if (!st) {
bgneal@45: f.elements.width.value = img.width;
bgneal@45: f.elements.height.value = img.height;
bgneal@45: }
bgneal@45:
bgneal@45: this.preloadImg = img;
bgneal@45: },
bgneal@45:
bgneal@45: changeAppearance : function() {
bgneal@45: var ed = tinyMCEPopup.editor, f = document.forms[0], img = document.getElementById('alignSampleImg');
bgneal@45:
bgneal@45: if (img) {
bgneal@45: if (ed.getParam('inline_styles')) {
bgneal@45: ed.dom.setAttrib(img, 'style', f.style.value);
bgneal@45: } else {
bgneal@45: img.align = f.align.value;
bgneal@45: img.border = f.border.value;
bgneal@45: img.hspace = f.hspace.value;
bgneal@45: img.vspace = f.vspace.value;
bgneal@45: }
bgneal@45: }
bgneal@45: },
bgneal@45:
bgneal@45: changeHeight : function() {
bgneal@45: var f = document.forms[0], tp, t = this;
bgneal@45:
bgneal@45: if (!f.constrain.checked || !t.preloadImg) {
bgneal@45: return;
bgneal@45: }
bgneal@45:
bgneal@45: if (f.width.value == "" || f.height.value == "")
bgneal@45: return;
bgneal@45:
bgneal@45: tp = (parseInt(f.width.value) / parseInt(t.preloadImg.width)) * t.preloadImg.height;
bgneal@45: f.height.value = tp.toFixed(0);
bgneal@45: },
bgneal@45:
bgneal@45: changeWidth : function() {
bgneal@45: var f = document.forms[0], tp, t = this;
bgneal@45:
bgneal@45: if (!f.constrain.checked || !t.preloadImg) {
bgneal@45: return;
bgneal@45: }
bgneal@45:
bgneal@45: if (f.width.value == "" || f.height.value == "")
bgneal@45: return;
bgneal@45:
bgneal@45: tp = (parseInt(f.height.value) / parseInt(t.preloadImg.height)) * t.preloadImg.width;
bgneal@45: f.width.value = tp.toFixed(0);
bgneal@45: },
bgneal@45:
bgneal@45: updateStyle : function(ty) {
bgneal@45: var dom = tinyMCEPopup.dom, b, bStyle, bColor, v, isIE = tinymce.isIE, f = document.forms[0], img = dom.create('img', {style : dom.get('style').value});
bgneal@45:
bgneal@45: if (tinyMCEPopup.editor.settings.inline_styles) {
bgneal@45: // Handle align
bgneal@45: if (ty == 'align') {
bgneal@45: dom.setStyle(img, 'float', '');
bgneal@45: dom.setStyle(img, 'vertical-align', '');
bgneal@45:
bgneal@45: v = getSelectValue(f, 'align');
bgneal@45: if (v) {
bgneal@45: if (v == 'left' || v == 'right')
bgneal@45: dom.setStyle(img, 'float', v);
bgneal@45: else
bgneal@45: img.style.verticalAlign = v;
bgneal@45: }
bgneal@45: }
bgneal@45:
bgneal@45: // Handle border
bgneal@45: if (ty == 'border') {
bgneal@45: b = img.style.border ? img.style.border.split(' ') : [];
bgneal@45: bStyle = dom.getStyle(img, 'border-style');
bgneal@45: bColor = dom.getStyle(img, 'border-color');
bgneal@45:
bgneal@45: dom.setStyle(img, 'border', '');
bgneal@45:
bgneal@45: v = f.border.value;
bgneal@45: if (v || v == '0') {
bgneal@45: if (v == '0')
bgneal@45: img.style.border = isIE ? '0' : '0 none none';
bgneal@45: else {
bgneal@45: if (b.length == 3 && b[isIE ? 2 : 1])
bgneal@45: bStyle = b[isIE ? 2 : 1];
bgneal@45: else if (!bStyle || bStyle == 'none')
bgneal@45: bStyle = 'solid';
bgneal@45: if (b.length == 3 && b[isIE ? 0 : 2])
bgneal@45: bColor = b[isIE ? 0 : 2];
bgneal@45: else if (!bColor || bColor == 'none')
bgneal@45: bColor = 'black';
bgneal@45: img.style.border = v + 'px ' + bStyle + ' ' + bColor;
bgneal@45: }
bgneal@45: }
bgneal@45: }
bgneal@45:
bgneal@45: // Handle hspace
bgneal@45: if (ty == 'hspace') {
bgneal@45: dom.setStyle(img, 'marginLeft', '');
bgneal@45: dom.setStyle(img, 'marginRight', '');
bgneal@45:
bgneal@45: v = f.hspace.value;
bgneal@45: if (v) {
bgneal@45: img.style.marginLeft = v + 'px';
bgneal@45: img.style.marginRight = v + 'px';
bgneal@45: }
bgneal@45: }
bgneal@45:
bgneal@45: // Handle vspace
bgneal@45: if (ty == 'vspace') {
bgneal@45: dom.setStyle(img, 'marginTop', '');
bgneal@45: dom.setStyle(img, 'marginBottom', '');
bgneal@45:
bgneal@45: v = f.vspace.value;
bgneal@45: if (v) {
bgneal@45: img.style.marginTop = v + 'px';
bgneal@45: img.style.marginBottom = v + 'px';
bgneal@45: }
bgneal@45: }
bgneal@45:
bgneal@45: // Merge
bgneal@45: dom.get('style').value = dom.serializeStyle(dom.parseStyle(img.style.cssText), 'img');
bgneal@45: }
bgneal@45: },
bgneal@45:
bgneal@45: changeMouseMove : function() {
bgneal@45: },
bgneal@45:
bgneal@45: showPreviewImage : function(u, st) {
bgneal@45: if (!u) {
bgneal@45: tinyMCEPopup.dom.setHTML('prev', '');
bgneal@45: return;
bgneal@45: }
bgneal@45:
bgneal@45: if (!st && tinyMCEPopup.getParam("advimage_update_dimensions_onchange", true))
bgneal@45: this.resetImageData();
bgneal@45:
bgneal@45: u = tinyMCEPopup.editor.documentBaseURI.toAbsolute(u);
bgneal@45:
bgneal@45: if (!st)
bgneal@45: tinyMCEPopup.dom.setHTML('prev', '');
bgneal@45: else
bgneal@45: tinyMCEPopup.dom.setHTML('prev', '');
bgneal@45: }
bgneal@45: };
bgneal@45:
bgneal@45: ImageDialog.preInit();
bgneal@45: tinyMCEPopup.onInit.add(ImageDialog.init, ImageDialog);