-
+ 9D5AF17E5CDFE480CF5632F211F14CC03372457411F5C97CC23C1FEA4ECEC84DD0519CB01E1E529990B787F78573BADE57B343841600E45163A102CA617F2DE9
mp-wp/wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.js
(0 . 0)(1 . 607)
125922
125923 var tinymce = null, tinyMCEPopup, tinyMCE;
125924
125925 tinyMCEPopup = {
125926 init: function() {
125927 var t = this, w, ti, li, q, i, it;
125928
125929 li = ('' + document.location.search).replace(/^\?/, '').split('&');
125930 q = {};
125931 for (i=0; i<li.length; i++) {
125932 it = li[i].split('=');
125933 q[unescape(it[0])] = unescape(it[1]);
125934 }
125935
125936 if (q.mce_rdomain)
125937 document.domain = q.mce_rdomain;
125938
125939 // Find window & API
125940 w = t.getWin();
125941 tinymce = w.tinymce;
125942 tinyMCE = w.tinyMCE;
125943 t.editor = tinymce.EditorManager.activeEditor;
125944 t.params = t.editor.windowManager.params;
125945
125946 // Setup local DOM
125947 t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
125948 t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);
125949 },
125950
125951 getWin : function() {
125952 return window.dialogArguments || opener || parent || top;
125953 },
125954
125955 getParam : function(n, dv) {
125956 return this.editor.getParam(n, dv);
125957 },
125958
125959 close : function() {
125960 var t = this, win = t.getWin();
125961
125962 // To avoid domain relaxing issue in Opera
125963 function close() {
125964 win.tb_remove();
125965 tinymce = tinyMCE = t.editor = t.dom = t.dom.doc = null; // Cleanup
125966 };
125967
125968 if (tinymce.isOpera)
125969 win.setTimeout(close, 0);
125970 else
125971 close();
125972 },
125973
125974 execCommand : function(cmd, ui, val, a) {
125975 a = a || {};
125976 a.skip_focus = 1;
125977
125978 this.restoreSelection();
125979 return this.editor.execCommand(cmd, ui, val, a);
125980 },
125981
125982 storeSelection : function() {
125983 this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
125984 },
125985
125986 restoreSelection : function() {
125987 var t = tinyMCEPopup;
125988
125989 if (tinymce.isIE)
125990 t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
125991 }
125992 }
125993 tinyMCEPopup.init();
125994
125995 var wpImage = {
125996 preInit : function() {
125997 // import colors stylesheet from parent
125998 var win = tinyMCEPopup.getWin();
125999 var styles = win.document.styleSheets;
126000
126001 for ( i = 0; i < styles.length; i++ ) {
126002 var url = styles.item(i).href;
126003 if ( url && url.indexOf('colors') != -1 )
126004 document.write( '<link rel="stylesheet" href="'+url+'" type="text/css" media="all" />' );
126005 }
126006 },
126007
126008 I : function(e) {
126009 return document.getElementById(e);
126010 },
126011
126012 current : '',
126013 link : '',
126014 link_rel : '',
126015 target_value : '',
126016 current_size_sel : 's100',
126017 width : '',
126018 height : '',
126019 align : '',
126020 img_alt : '',
126021
126022 setTabs : function(tab) {
126023 var t = this;
126024
126025 if ( 'current' == tab.className ) return false;
126026 t.I('div_advanced').style.display = ( 'tab_advanced' == tab.id ) ? 'block' : 'none';
126027 t.I('div_basic').style.display = ( 'tab_basic' == tab.id ) ? 'block' : 'none';
126028 t.I('tab_basic').className = t.I('tab_advanced').className = '';
126029 tab.className = 'current';
126030 return false;
126031 },
126032
126033 img_seturl : function(u) {
126034 var t = this, rel = t.I('link_rel').value;
126035
126036 if ( 'current' == u ) {
126037 t.I('link_href').value = t.current;
126038 t.I('link_rel').value = t.link_rel;
126039 } else {
126040 t.I('link_href').value = t.link;
126041 if ( rel ) {
126042 rel = rel.replace( /attachment|wp-att-[0-9]+/gi, '' );
126043 t.I('link_rel').value = tinymce.trim(rel);
126044 }
126045 }
126046 },
126047
126048 imgAlignCls : function(v) {
126049 var t = this, cls = t.I('img_classes').value;
126050
126051 t.I('img_demo').className = t.align = v;
126052
126053 cls = cls.replace( /align[^ "']+/gi, '' );
126054 cls += (' ' + v);
126055 cls = cls.replace( /\s+/g, ' ' ).replace( /^\s/, '' );
126056
126057 if ( 'aligncenter' == v ) {
126058 t.I('hspace').value = '';
126059 t.updateStyle('hspace');
126060 }
126061
126062 t.I('img_classes').value = cls;
126063 },
126064
126065 showSize : function(el) {
126066 var t = this, demo = t.I('img_demo'), w = t.width, h = t.height, id = el.id || 's100', size;
126067
126068 size = parseInt(id.substring(1)) / 200;
126069 demo.width = Math.round(w * size);
126070 demo.height = Math.round(h * size);
126071
126072 t.showSizeClear();
126073 el.style.borderColor = '#A3A3A3';
126074 el.style.backgroundColor = '#E5E5E5';
126075 },
126076
126077 showSizeSet : function() {
126078 var t = this;
126079
126080 if ( (t.width * 1.3) > parseInt(t.preloadImg.width) ) {
126081 var s130 = t.I('s130'), s120 = t.I('s120'), s110 = t.I('s110');
126082
126083 s130.onclick = s120.onclick = s110.onclick = null;
126084 s130.onmouseover = s120.onmouseover = s110.onmouseover = null;
126085 s130.style.color = s120.style.color = s110.style.color = '#aaa';
126086 }
126087 },
126088
126089 showSizeRem : function() {
126090 var t = this, demo = t.I('img_demo'), f = document.forms[0];
126091
126092 demo.width = Math.round(f.width.value * 0.5);
126093 demo.height = Math.round(f.height.value * 0.5);
126094 t.showSizeClear();
126095 t.I(t.current_size_sel).style.borderColor = '#A3A3A3';
126096 t.I(t.current_size_sel).style.backgroundColor = '#E5E5E5';
126097
126098 return false;
126099 },
126100
126101 showSizeClear : function() {
126102 var divs = this.I('img_size').getElementsByTagName('div');
126103
126104 for ( i = 0; i < divs.length; i++ ) {
126105 divs[i].style.borderColor = '#f1f1f1';
126106 divs[i].style.backgroundColor = '#f1f1f1';
126107 }
126108 },
126109
126110 imgEditSize : function(el) {
126111 var t = this, f = document.forms[0];
126112
126113 if ( ! t.preloadImg || ! t.preloadImg.width || ! t.preloadImg.height ) return;
126114 var W = parseInt(t.preloadImg.width), H = parseInt(t.preloadImg.height), w = t.width || W, h = t.height || H, id = el.id || 's100';
126115
126116 size = parseInt(id.substring(1)) / 100;
126117
126118 w = Math.round(w * size);
126119 h = Math.round(h * size);
126120
126121 f.width.value = Math.min(W, w);
126122 f.height.value = Math.min(H, h);
126123
126124 t.current_size_sel = id;
126125 t.demoSetSize();
126126 },
126127
126128 demoSetSize : function(img) {
126129 var demo = this.I('img_demo'), f = document.forms[0];
126130
126131 demo.width = f.width.value ? Math.round(f.width.value * 0.5) : '';
126132 demo.height = f.height.value ? Math.round(f.height.value * 0.5) : '';
126133 },
126134
126135 demoSetStyle : function() {
126136 var f = document.forms[0], demo = this.I('img_demo'), dom = tinyMCEPopup.editor.dom;
126137
126138 if (demo) {
126139 dom.setAttrib(demo, 'style', f.img_style.value);
126140 dom.setStyle(demo, 'width', '');
126141 dom.setStyle(demo, 'height', '');
126142 }
126143 },
126144
126145 origSize : function() {
126146 var t = this, f = document.forms[0], el = t.I('s100');
126147
126148 f.width.value = t.width = t.preloadImg.width;
126149 f.height.value = t.height = t.preloadImg.height;
126150 t.showSizeSet();
126151 t.demoSetSize();
126152 t.showSize(el);
126153 },
126154
126155 init : function() {
126156 var ed = tinyMCEPopup.editor, h;
126157
126158 h = document.body.innerHTML;
126159
126160 // Replace a=x with a="x" in IE
126161 if (tinymce.isIE)
126162 h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"')
126163
126164 document.body.innerHTML = ed.translate(h);
126165 window.setTimeout( function(){wpImage.setup();}, 100 );
126166 },
126167
126168 setup : function() {
126169 var t = this, h, c, el, id, link, fname, f = document.forms[0], ed = tinyMCEPopup.editor, d = t.I('img_demo'), dom = tinyMCEPopup.dom, DL, caption = '';
126170 document.dir = tinyMCEPopup.editor.getParam('directionality','');
126171
126172 if ( tinyMCEPopup.editor.getParam('wpeditimage_disable_captions', false) )
126173 t.I('cap_field').style.display = 'none';
126174
126175 tinyMCEPopup.restoreSelection();
126176 el = ed.selection.getNode();
126177 if (el.nodeName != 'IMG') return;
126178
126179 f.img_src.value = d.src = link = ed.dom.getAttrib(el, 'src');
126180 ed.dom.setStyle(el, 'float', '');
126181 t.getImageData();
126182 c = ed.dom.getAttrib(el, 'class');
126183
126184 if ( DL = dom.getParent(el, 'dl') ) {
126185 var dlc = ed.dom.getAttrib(DL, 'class');
126186 dlc = dlc.match(/align[^ "']+/i);
126187 if ( dlc && ! dom.hasClass(el, dlc) ) {
126188 c += ' '+dlc;
126189 tinymce.trim(c);
126190 }
126191
126192 tinymce.each(DL.childNodes, function(e) {
126193 if ( e.nodeName == 'DD' && dom.hasClass(e, 'wp-caption-dd') ) {
126194 caption = e.innerHTML;
126195 return;
126196 }
126197 });
126198 }
126199
126200 f.img_cap.value = caption;
126201 f.img_title.value = ed.dom.getAttrib(el, 'title');
126202 f.img_alt.value = ed.dom.getAttrib(el, 'alt');
126203 f.border.value = ed.dom.getAttrib(el, 'border');
126204 f.vspace.value = ed.dom.getAttrib(el, 'vspace');
126205 f.hspace.value = ed.dom.getAttrib(el, 'hspace');
126206 f.align.value = ed.dom.getAttrib(el, 'align');
126207 f.width.value = t.width = ed.dom.getAttrib(el, 'width');
126208 f.height.value = t.height = ed.dom.getAttrib(el, 'height');
126209 f.img_classes.value = c;
126210 f.img_style.value = ed.dom.getAttrib(el, 'style');
126211
126212 // Move attribs to styles
126213 if (dom.getAttrib(el, 'hspace'))
126214 t.updateStyle('hspace');
126215
126216 if (dom.getAttrib(el, 'border'))
126217 t.updateStyle('border');
126218
126219 if (dom.getAttrib(el, 'vspace'))
126220 t.updateStyle('vspace');
126221
126222 if (pa = ed.dom.getParent(el, 'A')) {
126223 f.link_href.value = t.current = ed.dom.getAttrib(pa, 'href');
126224 f.link_title.value = ed.dom.getAttrib(pa, 'title');
126225 f.link_rel.value = t.link_rel = ed.dom.getAttrib(pa, 'rel');
126226 f.link_style.value = ed.dom.getAttrib(pa, 'style');
126227 t.target_value = ed.dom.getAttrib(pa, 'target');
126228 f.link_classes.value = ed.dom.getAttrib(pa, 'class');
126229 }
126230
126231 f.link_target.checked = ( t.target_value && t.target_value == '_blank' ) ? 'checked' : '';
126232
126233 fname = link.substring( link.lastIndexOf('/') );
126234 fname = fname.replace(/-[0-9]{2,4}x[0-9]{2,4}/, '' );
126235 t.link = link.substring( 0, link.lastIndexOf('/') ) + fname;
126236
126237 if ( c.indexOf('alignleft') != -1 ) {
126238 t.I('alignleft').checked = "checked";
126239 d.className = t.align = "alignleft";
126240 } else if ( c.indexOf('aligncenter') != -1 ) {
126241 t.I('aligncenter').checked = "checked";
126242 d.className = t.align = "aligncenter";
126243 } else if ( c.indexOf('alignright') != -1 ) {
126244 t.I('alignright').checked = "checked";
126245 d.className = t.align = "alignright";
126246 } else if ( c.indexOf('alignnone') != -1 ) {
126247 t.I('alignnone').checked = "checked";
126248 d.className = t.align = "alignnone";
126249 }
126250
126251 if ( t.width && t.preloadImg.width ) t.showSizeSet();
126252 document.body.style.display = '';
126253 },
126254
126255 remove : function() {
126256 var ed = tinyMCEPopup.editor, p, el;
126257
126258 tinyMCEPopup.restoreSelection();
126259 el = ed.selection.getNode();
126260 if (el.nodeName != 'IMG') return;
126261
126262 if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
126263 ed.dom.remove(p);
126264 else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
126265 ed.dom.remove(p);
126266 else ed.dom.remove(el);
126267
126268 ed.execCommand('mceRepaint');
126269 tinyMCEPopup.close();
126270 return;
126271 },
126272
126273 update : function() {
126274 var t = this, f = document.forms[0], ed = tinyMCEPopup.editor, el, b, fixSafari = null, DL, P, A, DIV, do_caption = null, img_class = f.img_classes.value, html;
126275
126276 tinyMCEPopup.restoreSelection();
126277 el = ed.selection.getNode();
126278
126279 if (el.nodeName != 'IMG') return;
126280 if (f.img_src.value === '') {
126281 t.remove();
126282 return;
126283 }
126284
126285 if ( f.img_cap.value != '' && f.width.value != '' ) {
126286 do_caption = 1;
126287 img_class = img_class.replace( /align[^ "']+\s?/gi, '' );
126288 }
126289
126290 A = ed.dom.getParent(el, 'a');
126291 P = ed.dom.getParent(el, 'p');
126292 DL = ed.dom.getParent(el, 'dl');
126293 DIV = ed.dom.getParent(el, 'div');
126294
126295 tinyMCEPopup.execCommand("mceBeginUndoLevel");
126296
126297 ed.dom.setAttribs(el, {
126298 src : f.img_src.value,
126299 title : f.img_title.value,
126300 alt : f.img_alt.value,
126301 width : f.width.value,
126302 height : f.height.value,
126303 style : f.img_style.value,
126304 'class' : img_class
126305 });
126306
126307 if ( f.link_href.value ) {
126308 // Create new anchor elements
126309 if ( A == null ) {
126310 if ( ! f.link_href.value.match(/https?:\/\//i) )
126311 f.link_href.value = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.link_href.value);
126312
126313 if ( tinymce.isWebKit && ed.dom.hasClass(el, 'aligncenter') ) {
126314 ed.dom.removeClass(el, 'aligncenter');
126315 fixSafari = 1;
126316 }
126317
126318 tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
126319 if ( fixSafari ) ed.dom.addClass(el, 'aligncenter');
126320
126321 tinymce.each(ed.dom.select("a"), function(n) {
126322 if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
126323
126324 ed.dom.setAttribs(n, {
126325 href : f.link_href.value,
126326 title : f.link_title.value,
126327 rel : f.link_rel.value,
126328 target : (f.link_target.checked == true) ? '_blank' : '',
126329 'class' : f.link_classes.value,
126330 style : f.link_style.value
126331 });
126332 }
126333 });
126334 } else {
126335 ed.dom.setAttribs(A, {
126336 href : f.link_href.value,
126337 title : f.link_title.value,
126338 rel : f.link_rel.value,
126339 target : (f.link_target.checked == true) ? '_blank' : '',
126340 'class' : f.link_classes.value,
126341 style : f.link_style.value
126342 });
126343 }
126344 }
126345
126346 if ( do_caption ) {
126347 var id, cap_id = '', cap, DT, DD, cap_width = 10 + parseInt(f.width.value), align = t.align.substring(5), div_cls = (t.align == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
126348
126349 if ( DL ) {
126350 ed.dom.setAttribs(DL, {
126351 'class' : 'wp-caption '+t.align,
126352 style : 'width: '+cap_width+'px;'
126353 });
126354
126355 if ( DIV )
126356 ed.dom.setAttrib(DIV, 'class', div_cls);
126357
126358 if ( (DT = ed.dom.getParent(el, 'dt')) && (DD = DT.nextSibling) && ed.dom.hasClass(DD, 'wp-caption-dd') )
126359 ed.dom.setHTML(DD, f.img_cap.value);
126360
126361 } else {
126362 var lnk = '', pa;
126363 if ( (id = f.img_classes.value.match( /wp-image-([0-9]{1,6})/ )) && id[1] )
126364 cap_id = 'attachment_'+id[1];
126365
126366 if ( f.link_href.value && (lnk = ed.dom.getParent(el, 'a')) ) {
126367 if ( lnk.childNodes.length == 1 )
126368 html = ed.dom.getOuterHTML(lnk);
126369 else {
126370 html = ed.dom.getOuterHTML(lnk);
126371 html = html.match(/<a[^>]+>/i);
126372 html = html+ed.dom.getOuterHTML(el)+'</a>';
126373 }
126374 } else html = ed.dom.getOuterHTML(el);
126375
126376 html = '<dl id="'+cap_id+'" class="wp-caption '+t.align+'" style="width: '+cap_width+
126377 'px"><dt class="wp-caption-dt">'+html+'</dt><dd class="wp-caption-dd">'+f.img_cap.value+'</dd></dl>';
126378
126379 cap = ed.dom.create('div', {'class': div_cls}, html);
126380
126381 if ( P ) {
126382 P.parentNode.insertBefore(cap, P);
126383 if ( P.childNodes.length == 1 )
126384 ed.dom.remove(P);
126385 else if ( lnk && lnk.childNodes.length == 1 )
126386 ed.dom.remove(lnk);
126387 else ed.dom.remove(el);
126388 } else if ( pa = ed.dom.getParent(el, 'TD,TH,LI') ) {
126389 pa.appendChild(cap);
126390 if ( lnk && lnk.childNodes.length == 1 )
126391 ed.dom.remove(lnk);
126392 else ed.dom.remove(el);
126393 }
126394 }
126395
126396 } else {
126397 if ( DL && DIV ) {
126398 var aa;
126399 if ( f.link_href.value && (aa = ed.dom.getParent(el, 'a')) ) html = ed.dom.getOuterHTML(aa);
126400 else html = ed.dom.getOuterHTML(el);
126401
126402 P = ed.dom.create('p', {}, html);
126403 DIV.parentNode.insertBefore(P, DIV);
126404 ed.dom.remove(DIV);
126405 }
126406 }
126407
126408 if ( f.img_classes.value.indexOf('aligncenter') != -1 ) {
126409 if ( P && ( ! P.style || P.style.textAlign != 'center' ) )
126410 ed.dom.setStyle(P, 'textAlign', 'center');
126411 } else {
126412 if ( P && P.style && P.style.textAlign == 'center' )
126413 ed.dom.setStyle(P, 'textAlign', '');
126414 }
126415
126416 if ( ! f.link_href.value && A ) {
126417 b = ed.selection.getBookmark();
126418 ed.dom.remove(A, 1);
126419 ed.selection.moveToBookmark(b);
126420 }
126421
126422 tinyMCEPopup.execCommand("mceEndUndoLevel");
126423 ed.execCommand('mceRepaint');
126424 tinyMCEPopup.close();
126425 },
126426
126427 updateStyle : function(ty) {
126428 var dom = tinyMCEPopup.dom, st, v, f = document.forms[0], img = dom.create('img', {style : f.img_style.value});
126429
126430 if (tinyMCEPopup.editor.settings.inline_styles) {
126431 // Handle align
126432 if (ty == 'align') {
126433 dom.setStyle(img, 'float', '');
126434 dom.setStyle(img, 'vertical-align', '');
126435
126436 v = f.align.value;
126437 if (v) {
126438 if (v == 'left' || v == 'right')
126439 dom.setStyle(img, 'float', v);
126440 else
126441 img.style.verticalAlign = v;
126442 }
126443 }
126444
126445 // Handle border
126446 if (ty == 'border') {
126447 dom.setStyle(img, 'border', '');
126448
126449 v = f.border.value;
126450 if (v || v == '0') {
126451 if (v == '0')
126452 img.style.border = '0';
126453 else
126454 img.style.border = v + 'px solid black';
126455 }
126456 }
126457
126458 // Handle hspace
126459 if (ty == 'hspace') {
126460 dom.setStyle(img, 'marginLeft', '');
126461 dom.setStyle(img, 'marginRight', '');
126462
126463 v = f.hspace.value;
126464 if (v) {
126465 img.style.marginLeft = v + 'px';
126466 img.style.marginRight = v + 'px';
126467 }
126468 }
126469
126470 // Handle vspace
126471 if (ty == 'vspace') {
126472 dom.setStyle(img, 'marginTop', '');
126473 dom.setStyle(img, 'marginBottom', '');
126474
126475 v = f.vspace.value;
126476 if (v) {
126477 img.style.marginTop = v + 'px';
126478 img.style.marginBottom = v + 'px';
126479 }
126480 }
126481
126482 // Merge
126483 f.img_style.value = dom.serializeStyle(dom.parseStyle(img.style.cssText));
126484 this.demoSetStyle();
126485 }
126486 },
126487
126488 checkVal : function(f) {
126489
126490 if ( f.value == '' ) {
126491 // if ( f.id == 'width' ) f.value = this.width || this.preloadImg.width;
126492 // if ( f.id == 'height' ) f.value = this.height || this.preloadImg.height;
126493 if ( f.id == 'img_src' ) f.value = this.I('img_demo').src || this.preloadImg.src;
126494 }
126495 },
126496
126497 resetImageData : function() {
126498 var f = document.forms[0];
126499
126500 f.width.value = f.height.value = '';
126501 },
126502
126503 updateImageData : function() {
126504 var f = document.forms[0], t = wpImage;
126505
126506 if ( f.width.value == '' || f.height.value == '' ) {
126507 f.width.value = t.width = t.preloadImg.width;
126508 f.height.value = t.height = t.preloadImg.height;
126509 }
126510
126511 t.showSizeSet();
126512 t.demoSetSize();
126513 if ( f.img_style.value )
126514 t.demoSetStyle();
126515 },
126516
126517 getImageData : function() {
126518 var t = wpImage, f = document.forms[0];
126519
126520 t.preloadImg = new Image();
126521 t.preloadImg.onload = t.updateImageData;
126522 t.preloadImg.onerror = t.resetImageData;
126523 t.preloadImg.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(f.img_src.value);
126524 }
126525 };
126526
126527 window.onload = function(){wpImage.init();}
126528 wpImage.preInit();