2 var tinymce = null, tinyMCEPopup, tinyMCE, wpImage;
6 var t = this, w, li, q, i, it;
8 li = ('' + document.location.search).replace(/^\?/, '').split('&');
10 for ( i = 0; i < li.length; i++ ) {
11 it = li[i].split('=');
12 q[unescape(it[0])] = unescape(it[1]);
16 document.domain = q.mce_rdomain;
22 t.editor = tinymce.EditorManager.activeEditor;
23 t.params = t.editor.windowManager.params;
26 t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
27 t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);
31 return window.dialogArguments || opener || parent || top;
34 getParam : function(n, dv) {
35 return this.editor.getParam(n, dv);
39 var t = this, win = t.getWin();
41 // To avoid domain relaxing issue in Opera
44 tinymce = tinyMCE = t.editor = t.dom = t.dom.doc = null; // Cleanup
48 win.setTimeout(close, 0);
53 execCommand : function(cmd, ui, val, a) {
57 this.restoreSelection();
58 return this.editor.execCommand(cmd, ui, val, a);
61 storeSelection : function() {
62 this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
65 restoreSelection : function() {
69 t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
75 preInit : function() {
76 // import colors stylesheet from parent
77 var win = tinyMCEPopup.getWin(), styles = win.document.styleSheets, url, i;
79 for ( i = 0; i < styles.length; i++ ) {
80 url = styles.item(i).href;
81 if ( url && url.indexOf('colors') != -1 )
82 document.write( '<link rel="stylesheet" href="'+url+'" type="text/css" media="all" />' );
87 return document.getElementById(e);
94 current_size_sel : 's100',
100 setTabs : function(tab) {
103 if ( 'current' == tab.className ) return false;
104 t.I('div_advanced').style.display = ( 'tab_advanced' == tab.id ) ? 'block' : 'none';
105 t.I('div_basic').style.display = ( 'tab_basic' == tab.id ) ? 'block' : 'none';
106 t.I('tab_basic').className = t.I('tab_advanced').className = '';
107 tab.className = 'current';
111 img_seturl : function(u) {
112 var t = this, rel = t.I('link_rel').value;
114 if ( 'current' == u ) {
115 t.I('link_href').value = t.current;
116 t.I('link_rel').value = t.link_rel;
118 t.I('link_href').value = t.link;
120 rel = rel.replace( /attachment|wp-att-[0-9]+/gi, '' );
121 t.I('link_rel').value = tinymce.trim(rel);
126 imgAlignCls : function(v) {
127 var t = this, cls = t.I('img_classes').value;
129 t.I('img_demo').className = t.align = v;
131 cls = cls.replace( /align[^ "']+/gi, '' );
133 cls = cls.replace( /\s+/g, ' ' ).replace( /^\s/, '' );
135 if ( 'aligncenter' == v ) {
136 t.I('hspace').value = '';
137 t.updateStyle('hspace');
140 t.I('img_classes').value = cls;
143 showSize : function(el) {
144 var t = this, demo = t.I('img_demo'), w = t.width, h = t.height, id = el.id || 's100', size;
146 size = parseInt(id.substring(1)) / 200;
147 demo.width = Math.round(w * size);
148 demo.height = Math.round(h * size);
151 el.style.borderColor = '#A3A3A3';
152 el.style.backgroundColor = '#E5E5E5';
155 showSizeSet : function() {
156 var t = this, s130, s120, s110;
158 if ( (t.width * 1.3) > parseInt(t.preloadImg.width) ) {
159 s130 = t.I('s130'), s120 = t.I('s120'), s110 = t.I('s110');
161 s130.onclick = s120.onclick = s110.onclick = null;
162 s130.onmouseover = s120.onmouseover = s110.onmouseover = null;
163 s130.style.color = s120.style.color = s110.style.color = '#aaa';
167 showSizeRem : function() {
168 var t = this, demo = t.I('img_demo'), f = document.forms[0];
170 demo.width = Math.round(f.width.value * 0.5);
171 demo.height = Math.round(f.height.value * 0.5);
173 t.I(t.current_size_sel).style.borderColor = '#A3A3A3';
174 t.I(t.current_size_sel).style.backgroundColor = '#E5E5E5';
179 showSizeClear : function() {
180 var divs = this.I('img_size').getElementsByTagName('div'), i;
182 for ( i = 0; i < divs.length; i++ ) {
183 divs[i].style.borderColor = '#f1f1f1';
184 divs[i].style.backgroundColor = '#f1f1f1';
188 imgEditSize : function(el) {
189 var t = this, f = document.forms[0], W, H, w, h, id;
191 if ( ! t.preloadImg || ! t.preloadImg.width || ! t.preloadImg.height )
194 W = parseInt(t.preloadImg.width), H = parseInt(t.preloadImg.height), w = t.width || W, h = t.height || H, id = el.id || 's100';
196 size = parseInt(id.substring(1)) / 100;
198 w = Math.round(w * size);
199 h = Math.round(h * size);
201 f.width.value = Math.min(W, w);
202 f.height.value = Math.min(H, h);
204 t.current_size_sel = id;
208 demoSetSize : function(img) {
209 var demo = this.I('img_demo'), f = document.forms[0];
211 demo.width = f.width.value ? Math.round(f.width.value * 0.5) : '';
212 demo.height = f.height.value ? Math.round(f.height.value * 0.5) : '';
215 demoSetStyle : function() {
216 var f = document.forms[0], demo = this.I('img_demo'), dom = tinyMCEPopup.editor.dom;
219 dom.setAttrib(demo, 'style', f.img_style.value);
220 dom.setStyle(demo, 'width', '');
221 dom.setStyle(demo, 'height', '');
225 origSize : function() {
226 var t = this, f = document.forms[0], el = t.I('s100');
228 f.width.value = t.width = t.preloadImg.width;
229 f.height.value = t.height = t.preloadImg.height;
236 var ed = tinyMCEPopup.editor, h;
238 h = document.body.innerHTML;
239 document.body.innerHTML = ed.translate(h);
240 window.setTimeout( function(){wpImage.setup();}, 500 );
244 var t = this, c, el, link, fname, f = document.forms[0], ed = tinyMCEPopup.editor,
245 d = t.I('img_demo'), dom = tinyMCEPopup.dom, DL, caption = '', dlc, pa;
247 document.dir = tinyMCEPopup.editor.getParam('directionality','');
249 if ( tinyMCEPopup.editor.getParam('wpeditimage_disable_captions', false) )
250 t.I('cap_field').style.display = 'none';
252 tinyMCEPopup.restoreSelection();
253 el = ed.selection.getNode();
254 if (el.nodeName != 'IMG')
257 f.img_src.value = d.src = link = ed.dom.getAttrib(el, 'src');
258 ed.dom.setStyle(el, 'float', '');
260 c = ed.dom.getAttrib(el, 'class');
262 if ( DL = dom.getParent(el, 'dl') ) {
263 dlc = ed.dom.getAttrib(DL, 'class');
264 dlc = dlc.match(/align[^ "']+/i);
265 if ( dlc && ! dom.hasClass(el, dlc) ) {
270 tinymce.each(DL.childNodes, function(e) {
271 if ( e.nodeName == 'DD' && dom.hasClass(e, 'wp-caption-dd') ) {
272 caption = e.innerHTML;
278 f.img_cap.value = caption;
279 f.img_title.value = ed.dom.getAttrib(el, 'title');
280 f.img_alt.value = ed.dom.getAttrib(el, 'alt');
281 f.border.value = ed.dom.getAttrib(el, 'border');
282 f.vspace.value = ed.dom.getAttrib(el, 'vspace');
283 f.hspace.value = ed.dom.getAttrib(el, 'hspace');
284 f.align.value = ed.dom.getAttrib(el, 'align');
285 f.width.value = t.width = ed.dom.getAttrib(el, 'width');
286 f.height.value = t.height = ed.dom.getAttrib(el, 'height');
287 f.img_classes.value = c;
288 f.img_style.value = ed.dom.getAttrib(el, 'style');
290 // Move attribs to styles
291 if ( dom.getAttrib(el, 'hspace') )
292 t.updateStyle('hspace');
294 if ( dom.getAttrib(el, 'border') )
295 t.updateStyle('border');
297 if ( dom.getAttrib(el, 'vspace') )
298 t.updateStyle('vspace');
300 if ( pa = ed.dom.getParent(el, 'A') ) {
301 f.link_href.value = t.current = ed.dom.getAttrib(pa, 'href');
302 f.link_title.value = ed.dom.getAttrib(pa, 'title');
303 f.link_rel.value = t.link_rel = ed.dom.getAttrib(pa, 'rel');
304 f.link_style.value = ed.dom.getAttrib(pa, 'style');
305 t.target_value = ed.dom.getAttrib(pa, 'target');
306 f.link_classes.value = ed.dom.getAttrib(pa, 'class');
309 f.link_target.checked = ( t.target_value && t.target_value == '_blank' ) ? 'checked' : '';
311 fname = link.substring( link.lastIndexOf('/') );
312 fname = fname.replace(/-[0-9]{2,4}x[0-9]{2,4}/, '' );
313 t.link = link.substring( 0, link.lastIndexOf('/') ) + fname;
315 if ( c.indexOf('alignleft') != -1 ) {
316 t.I('alignleft').checked = "checked";
317 d.className = t.align = "alignleft";
318 } else if ( c.indexOf('aligncenter') != -1 ) {
319 t.I('aligncenter').checked = "checked";
320 d.className = t.align = "aligncenter";
321 } else if ( c.indexOf('alignright') != -1 ) {
322 t.I('alignright').checked = "checked";
323 d.className = t.align = "alignright";
324 } else if ( c.indexOf('alignnone') != -1 ) {
325 t.I('alignnone').checked = "checked";
326 d.className = t.align = "alignnone";
329 if ( t.width && t.preloadImg.width ) t.showSizeSet();
330 document.body.style.display = '';
333 remove : function() {
334 var ed = tinyMCEPopup.editor, p, el;
336 tinyMCEPopup.restoreSelection();
337 el = ed.selection.getNode();
338 if (el.nodeName != 'IMG') return;
340 if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
342 else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
344 else ed.dom.remove(el);
346 ed.execCommand('mceRepaint');
347 tinyMCEPopup.close();
351 update : function() {
352 var t = this, f = document.forms[0], ed = tinyMCEPopup.editor, el, b, fixSafari = null,
353 DL, P, A, DIV, do_caption = null, img_class = f.img_classes.value, html,
354 id, cap_id = '', cap, DT, DD, cap_width, div_cls, lnk = '', pa, aa;
356 tinyMCEPopup.restoreSelection();
357 el = ed.selection.getNode();
359 if (el.nodeName != 'IMG') return;
360 if (f.img_src.value === '') {
365 if ( f.img_cap.value != '' && f.width.value != '' ) {
367 img_class = img_class.replace( /align[^ "']+\s?/gi, '' );
370 A = ed.dom.getParent(el, 'a');
371 P = ed.dom.getParent(el, 'p');
372 DL = ed.dom.getParent(el, 'dl');
373 DIV = ed.dom.getParent(el, 'div');
375 tinyMCEPopup.execCommand("mceBeginUndoLevel");
377 if ( f.width.value != el.width || f.height.value != el.height )
378 img_class = img_class.replace(/size-[^ "']+/, '');
380 ed.dom.setAttribs(el, {
381 src : f.img_src.value,
382 title : f.img_title.value,
383 alt : f.img_alt.value,
384 width : f.width.value,
385 height : f.height.value,
386 style : f.img_style.value,
390 if ( f.link_href.value ) {
391 // Create new anchor elements
393 if ( ! f.link_href.value.match(/https?:\/\//i) )
394 f.link_href.value = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.link_href.value);
396 if ( tinymce.isWebKit && ed.dom.hasClass(el, 'aligncenter') ) {
397 ed.dom.removeClass(el, 'aligncenter');
401 tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
402 if ( fixSafari ) ed.dom.addClass(el, 'aligncenter');
404 tinymce.each(ed.dom.select("a"), function(n) {
405 if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
407 ed.dom.setAttribs(n, {
408 href : f.link_href.value,
409 title : f.link_title.value,
410 rel : f.link_rel.value,
411 target : (f.link_target.checked == true) ? '_blank' : '',
412 'class' : f.link_classes.value,
413 style : f.link_style.value
418 ed.dom.setAttribs(A, {
419 href : f.link_href.value,
420 title : f.link_title.value,
421 rel : f.link_rel.value,
422 target : (f.link_target.checked == true) ? '_blank' : '',
423 'class' : f.link_classes.value,
424 style : f.link_style.value
430 cap_width = 10 + parseInt(f.width.value);
431 div_cls = (t.align == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
434 ed.dom.setAttribs(DL, {
435 'class' : 'wp-caption '+t.align,
436 style : 'width: '+cap_width+'px;'
440 ed.dom.setAttrib(DIV, 'class', div_cls);
442 if ( (DT = ed.dom.getParent(el, 'dt')) && (DD = DT.nextSibling) && ed.dom.hasClass(DD, 'wp-caption-dd') )
443 ed.dom.setHTML(DD, f.img_cap.value);
446 if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] )
447 cap_id = 'attachment_'+id[1];
449 if ( f.link_href.value && (lnk = ed.dom.getParent(el, 'a')) ) {
450 if ( lnk.childNodes.length == 1 )
451 html = ed.dom.getOuterHTML(lnk);
453 html = ed.dom.getOuterHTML(lnk);
454 html = html.match(/<a[^>]+>/i);
455 html = html+ed.dom.getOuterHTML(el)+'</a>';
457 } else html = ed.dom.getOuterHTML(el);
459 html = '<dl id="'+cap_id+'" class="wp-caption '+t.align+'" style="width: '+cap_width+
460 'px"><dt class="wp-caption-dt">'+html+'</dt><dd class="wp-caption-dd">'+f.img_cap.value+'</dd></dl>';
462 cap = ed.dom.create('div', {'class': div_cls}, html);
465 P.parentNode.insertBefore(cap, P);
466 if ( P.childNodes.length == 1 )
468 else if ( lnk && lnk.childNodes.length == 1 )
470 else ed.dom.remove(el);
471 } else if ( pa = ed.dom.getParent(el, 'TD,TH,LI') ) {
473 if ( lnk && lnk.childNodes.length == 1 )
475 else ed.dom.remove(el);
481 if ( f.link_href.value && (aa = ed.dom.getParent(el, 'a')) ) html = ed.dom.getOuterHTML(aa);
482 else html = ed.dom.getOuterHTML(el);
484 P = ed.dom.create('p', {}, html);
485 DIV.parentNode.insertBefore(P, DIV);
490 if ( f.img_classes.value.indexOf('aligncenter') != -1 ) {
491 if ( P && ( ! P.style || P.style.textAlign != 'center' ) )
492 ed.dom.setStyle(P, 'textAlign', 'center');
494 if ( P && P.style && P.style.textAlign == 'center' )
495 ed.dom.setStyle(P, 'textAlign', '');
498 if ( ! f.link_href.value && A ) {
499 b = ed.selection.getBookmark();
501 ed.selection.moveToBookmark(b);
504 tinyMCEPopup.execCommand("mceEndUndoLevel");
505 ed.execCommand('mceRepaint');
506 tinyMCEPopup.close();
509 updateStyle : function(ty) {
510 var dom = tinyMCEPopup.dom, v, f = document.forms[0], img = dom.create('img', {style : f.img_style.value});
512 if (tinyMCEPopup.editor.settings.inline_styles) {
515 dom.setStyle(img, 'float', '');
516 dom.setStyle(img, 'vertical-align', '');
520 if (v == 'left' || v == 'right')
521 dom.setStyle(img, 'float', v);
523 img.style.verticalAlign = v;
528 if (ty == 'border') {
529 dom.setStyle(img, 'border', '');
534 img.style.border = '0';
536 img.style.border = v + 'px solid black';
541 if (ty == 'hspace') {
542 dom.setStyle(img, 'marginLeft', '');
543 dom.setStyle(img, 'marginRight', '');
547 img.style.marginLeft = v + 'px';
548 img.style.marginRight = v + 'px';
553 if (ty == 'vspace') {
554 dom.setStyle(img, 'marginTop', '');
555 dom.setStyle(img, 'marginBottom', '');
559 img.style.marginTop = v + 'px';
560 img.style.marginBottom = v + 'px';
565 f.img_style.value = dom.serializeStyle(dom.parseStyle(img.style.cssText));
570 checkVal : function(f) {
572 if ( f.value == '' ) {
573 // if ( f.id == 'width' ) f.value = this.width || this.preloadImg.width;
574 // if ( f.id == 'height' ) f.value = this.height || this.preloadImg.height;
575 if ( f.id == 'img_src' ) f.value = this.I('img_demo').src || this.preloadImg.src;
579 resetImageData : function() {
580 var f = document.forms[0];
582 f.width.value = f.height.value = '';
585 updateImageData : function() {
586 var f = document.forms[0], t = wpImage, w = f.width.value, h = f.height.value;
589 w = f.width.value = t.width = Math.round( t.preloadImg.width / (t.preloadImg.height / h) );
591 h = f.height.value = t.height = Math.round( t.preloadImg.height / (t.preloadImg.width / w) );
594 f.width.value = t.width = t.preloadImg.width;
597 f.height.value = t.height = t.preloadImg.height;
601 if ( f.img_style.value )
605 getImageData : function() {
606 var t = wpImage, f = document.forms[0];
608 t.preloadImg = new Image();
609 t.preloadImg.onload = t.updateImageData;
610 t.preloadImg.onerror = t.resetImageData;
611 t.preloadImg.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.img_src.value);
615 window.onload = function(){wpImage.init();}