]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js
WordPress 3.6.1-scripts
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wpeditimage / editor_plugin.js
index f24d0bafae768e88baec9874c27bcaff445147bb..e4d1984a3ac2b754347233ed287648fd6ea0e8b9 100644 (file)
@@ -1,236 +1 @@
-
-(function() {
-       tinymce.create('tinymce.plugins.wpEditImage', {
-
-               init : function(ed, url) {
-                       var t = this;
-
-                       t.url = url;
-                       t._createButtons();
-
-                       // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
-                       ed.addCommand('WP_EditImage', function() {
-                               var el = ed.selection.getNode(), vp = tinymce.DOM.getViewPort(), H = vp.h, W = ( 720 < vp.w ) ? 720 : vp.w;
-                               var cls = ed.dom.getAttrib(el, 'class');
-
-                               if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' )
-                                       return;
-
-                               tb_show('', url + '/editimage.html?ver=321&TB_iframe=true');
-                               tinymce.DOM.setStyles('TB_window', {
-                                       'width':( W - 50 )+'px',
-                                       'height':( H - 45 )+'px',
-                                       'margin-left':'-'+parseInt((( W - 50 ) / 2),10) + 'px'
-                               });
-
-                               if ( ! tinymce.isIE6 ) {
-                                       tinymce.DOM.setStyles('TB_window', {
-                                               'top':'20px',
-                                               'marginTop':'0'
-                                       });
-                               }
-
-                               tinymce.DOM.setStyles('TB_iframeContent', {
-                                       'width':( W - 50 )+'px',
-                                       'height':( H - 75 )+'px'
-                               });
-                               tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
-                       });
-
-                       ed.onInit.add(function(ed) {
-                               tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
-                                       ed.plugins.wpeditimage.hideButtons();
-                               });
-                       });
-
-                       ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
-                               ed.plugins.wpeditimage.hideButtons();
-                       });
-
-                       ed.onSaveContent.add(function(ed, o) {
-                               ed.plugins.wpeditimage.hideButtons();
-                       });
-
-                       ed.onMouseUp.add(function(ed, e) {
-                               if ( tinymce.isOpera ) {
-                                       if ( e.target.nodeName == 'IMG' )
-                                               ed.plugins.wpeditimage.showButtons(e.target);
-                               } else if ( ! tinymce.isWebKit ) {
-                                       var n = ed.selection.getNode(), DL;
-                                       
-                                       if ( n.nodeName == 'IMG' && (DL = ed.dom.getParent(n, 'DL')) ) {                                        
-                                               window.setTimeout(function(){
-                                                       var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'DL');
-                                               
-                                                       if ( n.width != (parseInt(ed.dom.getStyle(DL, 'width')) - 10) ) {
-                                                               ed.dom.setStyle(DL, 'width', parseInt(n.width)+10);
-                                                               ed.execCommand('mceRepaint');
-                                                       }
-                                               }, 100);
-                                       }
-                               }
-                       });
-
-                       ed.onMouseDown.add(function(ed, e) {
-                               if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
-                                       t.hideButtons();
-                                       return;
-                               }
-                               ed.plugins.wpeditimage.showButtons(e.target);
-                       });
-
-                       ed.onKeyPress.add(function(ed, e) {
-                               var DL, DIV;
-
-                               if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
-                                       var P = ed.dom.create('p', {}, '&nbsp;');
-                                       if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' ) 
-                                               ed.dom.insertAfter( P, DIV );
-                                       else ed.dom.insertAfter( P, DL );
-
-                                       tinymce.dom.Event.cancel(e);
-                                       ed.selection.select(P);
-                                       return false;
-                               }
-                       });
-
-                       ed.onBeforeSetContent.add(function(ed, o) {
-                               o.content = t._do_shcode(o.content);
-                       });
-
-                       ed.onPostProcess.add(function(ed, o) {
-                               if (o.get)
-                                       o.content = t._get_shcode(o.content);
-                       });
-               },
-
-               _do_shcode : function(co) {
-                       return co.replace(/\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\][\s\u00a0]*/g, function(a,b,c){
-                               b = b.replace(/\\'|\\&#39;|\\&#039;/g, '&#39;').replace(/\\"|\\&quot;/g, '&quot;');
-                               c = c.replace(/\\&#39;|\\&#039;/g, '&#39;').replace(/\\&quot;/g, '&quot;');
-                               var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/align=['"]([^'"]+)/i);
-                               var w = b.match(/width=['"]([0-9]+)/), cap = b.match(/caption=['"]([^'"]+)/i);
-
-                               id = ( id && id[1] ) ? id[1] : '';
-                               cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
-                               w = ( w && w[1] ) ? w[1] : '';
-                               cap = ( cap && cap[1] ) ? cap[1] : '';
-                               if ( ! w || ! cap ) return c;
-                               
-                               var div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
-
-                               return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
-                               'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
-                       });
-               },
-
-               _get_shcode : function(co) {
-                       return co.replace(/<div class="mceTemp[^"]*">\s*<dl([^>]+)>\s*<dt[^>]+>([\s\S]+?)<\/dt>\s*<dd[^>]+>(.+?)<\/dd>\s*<\/dl>\s*<\/div>\s*/gi, function(a,b,c,cap){
-                               var id = b.match(/id=['"]([^'"]+)/i), cls = b.match(/class=['"]([^'"]+)/i);
-                               var w = c.match(/width=['"]([0-9]+)/);
-
-                               id = ( id && id[1] ) ? id[1] : '';
-                               cls = ( cls && cls[1] ) ? cls[1] : 'alignnone';
-                               w = ( w && w[1] ) ? w[1] : '';
-
-                               if ( ! w || ! cap ) return c;
-                               cls = cls.match(/align[^ '"]+/) || 'alignnone';
-                               cap = cap.replace(/<\S[^<>]*>/gi, '').replace(/'/g, '&#39;').replace(/"/g, '&quot;');
-
-                               return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
-                       });
-               },
-
-               showButtons : function(n) {
-                       var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
-                       var cls = ed.dom.getAttrib(n, 'class');
-
-                       if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 )
-                               return;
-
-                       vp = ed.dom.getViewPort(ed.getWin());
-                       p1 = DOM.getPos(ed.getContentAreaContainer());
-                       p2 = ed.dom.getPos(n);
-
-                       X = Math.max(p2.x - vp.x, 0) + p1.x;
-                       Y = Math.max(p2.y - vp.y, 0) + p1.y;
-
-                       DOM.setStyles('wp_editbtns', {
-                               'top' : Y+5+'px',
-                               'left' : X+5+'px',
-                               'display' : 'block'
-                       });
-
-                       t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 );
-               },
-
-               hideButtons : function() {
-                       if ( tinymce.DOM.isHidden('wp_editbtns') ) return;
-
-                       tinymce.DOM.hide('wp_editbtns');
-                       window.clearTimeout(this.btnsTout);
-               },
-
-               _createButtons : function() {
-                       var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM;
-
-                       DOM.remove('wp_editbtns');
-
-                       var wp_editbtns = DOM.add(document.body, 'div', {
-                               id : 'wp_editbtns',
-                               style : 'display:none;'
-                       });
-
-                       var wp_editimgbtn = DOM.add('wp_editbtns', 'img', {
-                               src : t.url+'/img/image.png',
-                               id : 'wp_editimgbtn',
-                               width : '24',
-                               height : '24',
-                               title : ed.getLang('wpeditimage.edit_img')
-                       });
-
-                       wp_editimgbtn.onmousedown = function(e) {
-                               var ed = tinyMCE.activeEditor;
-                               ed.windowManager.bookmark = ed.selection.getBookmark('simple');
-                               ed.execCommand("WP_EditImage");
-                               this.parentNode.style.display = 'none';
-                       };
-
-                       var wp_delimgbtn = DOM.add('wp_editbtns', 'img', {
-                               src : t.url+'/img/delete.png',
-                               id : 'wp_delimgbtn',
-                               width : '24',
-                               height : '24',
-                               title : ed.getLang('wpeditimage.del_img')
-                       });
-
-                       wp_delimgbtn.onmousedown = function(e) {
-                               var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
-
-                               if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
-                                       if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
-                                               ed.dom.remove(p);
-                                       else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
-                                               ed.dom.remove(p);
-                                       else ed.dom.remove(el);
-
-                                       this.parentNode.style.display = 'none';
-                                       ed.execCommand('mceRepaint');
-                                       return false;
-                               }
-                       };
-               },
-
-               getInfo : function() {
-                       return {
-                               longname : 'Edit Image',
-                               author : 'WordPress',
-                               authorurl : 'http://wordpress.org',
-                               infourl : '',
-                               version : "1.0"
-                       };
-               }
-       });
-
-       tinymce.PluginManager.add('wpeditimage', tinymce.plugins.wpEditImage);
-})();
+(function(){tinymce.create("tinymce.plugins.wpEditImage",{url:"",editor:{},init:function(a,c){var d=this,b={};d.url=c;d.editor=a;d._createButtons();a.addCommand("WP_EditImage",d._editImage);a.onInit.add(function(e){e.dom.events.add(e.getBody(),"mousedown",function(g){var f;if(g.target.nodeName=="IMG"&&(f=e.dom.getParent(g.target,"div.mceTemp"))){if(tinymce.isGecko){e.selection.select(f)}else{if(tinymce.isWebKit){e.dom.events.prevent(g)}}}});e.dom.events.add(e.getBody(),"keydown",function(j){var k,f,i,h,g;if(j.keyCode==13){k=e.selection.getNode();f=e.dom.getParent(k,"dl.wp-caption");if(f){i=e.dom.getParent(f,"div.mceTemp")}if(i){e.dom.events.cancel(j);h=e.dom.create("p",{},"\uFEFF");e.dom.insertAfter(h,i);e.selection.setCursorLocation(h,0);return false}}});if("ontouchstart" in window){e.dom.events.add(e.getBody(),"touchstart",function(f){d._showButtons(f)})}});a.onMouseUp.add(function(f,g){if(tinymce.isWebKit||tinymce.isOpera){return}if(b.x&&(g.clientX!=b.x||g.clientY!=b.y)){var h=f.selection.getNode();if("IMG"==h.nodeName){window.setTimeout(function(){var e=f.dom.getParent(h,"dl.wp-caption"),i;if(h.width!=b.img_w||h.height!=b.img_h){h.className=h.className.replace(/size-[^ "']+/,"")}if(e){i=f.dom.getAttrib(h,"width")||h.width;i=parseInt(i,10);f.dom.setStyle(e,"width",10+i);f.execCommand("mceRepaint")}},100)}}b={}});a.onMouseDown.add(function(f,g){d._showButtons(g)});a.onBeforeSetContent.add(function(e,f){f.content=e.wpSetImgCaption(f.content)});a.onPostProcess.add(function(e,f){if(f.get){f.content=e.wpGetImgCaption(f.content)}});a.wpSetImgCaption=function(e){return d._do_shcode(e)};a.wpGetImgCaption=function(e){return d._get_shcode(e)};a.onBeforeExecCommand.add(function(e,h,g,j){var f,i;if(h=="mceInsertContent"){f=e.dom.getParent(e.selection.getNode(),"div.mceTemp");if(!f){return}i=e.dom.create("p");e.dom.insertAfter(i,f);e.selection.setCursorLocation(i,0)}})},_do_shcode:function(a){return a.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g,function(j,i,h){var d,m,k,l,f,g,e=tinymce.trim;d=i.match(/id=['"]([^'"]*)['"] ?/);if(d){i=i.replace(d[0],"")}m=i.match(/align=['"]([^'"]*)['"] ?/);if(m){i=i.replace(m[0],"")}k=i.match(/width=['"]([0-9]*)['"] ?/);if(k){i=i.replace(k[0],"")}h=e(h);g=h.match(/((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)([\s\S]*)/i);if(g&&g[2]){l=e(g[2]);g=e(g[1])}else{l=e(i).replace(/caption=['"]/,"").replace(/['"]$/,"");g=h}d=(d&&d[1])?d[1]:"";m=(m&&m[1])?m[1]:"alignnone";k=(k&&k[1])?k[1]:"";if(!k||!l){return h}f="mceTemp";if(m=="aligncenter"){f+=" mceIEcenter"}return'<div class="'+f+'"><dl id="'+d+'" class="wp-caption '+m+'" style="width: '+(10+parseInt(k))+'px"><dt class="wp-caption-dt">'+g+'</dt><dd class="wp-caption-dd">'+l+"</dd></dl></div>"})},_get_shcode:function(a){return a.replace(/<div (?:id="attachment_|class="mceTemp)[^>]*>([\s\S]+?)<\/div>/g,function(d,c){var e=c.replace(/<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>/gi,function(i,f,l,j){var k,h,g;g=l.match(/width="([0-9]*)"/);g=(g&&g[1])?g[1]:"";if(!g||!j){return l}k=f.match(/id="([^"]*)"/);k=(k&&k[1])?k[1]:"";h=f.match(/class="([^"]*)"/);h=(h&&h[1])?h[1]:"";h=h.match(/align[a-z]+/)||"alignnone";j=j.replace(/\r\n|\r/g,"\n").replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g,function(b){return b.replace(/[\r\n\t]+/," ")});j=j.replace(/\s*\n\s*/g,"<br />");return'[caption id="'+k+'" align="'+h+'" width="'+g+'"]'+l+" "+j+"[/caption]"});if(e.indexOf("[caption")!==0){e=c.replace(/[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi,"<p>$1</p>$2")}return e})},_createButtons:function(){var b=this,a=tinymce.activeEditor,d=tinymce.DOM,e,c,f;if(d.get("wp_editbtns")){return}f=(window.devicePixelRatio&&window.devicePixelRatio>1)||(window.matchMedia&&window.matchMedia("(min-resolution:130dpi)").matches);d.add(document.body,"div",{id:"wp_editbtns",style:"display:none;"});e=d.add("wp_editbtns","img",{src:f?b.url+"/img/image-2x.png":b.url+"/img/image.png",id:"wp_editimgbtn",width:"24",height:"24",title:a.getLang("wpeditimage.edit_img")});tinymce.dom.Event.add(e,"mousedown",function(g){b._editImage();a.plugins.wordpress._hideButtons()});c=d.add("wp_editbtns","img",{src:f?b.url+"/img/delete-2x.png":b.url+"/img/delete.png",id:"wp_delimgbtn",width:"24",height:"24",title:a.getLang("wpeditimage.del_img")});tinymce.dom.Event.add(c,"mousedown",function(j){var g=tinymce.activeEditor,i=g.selection.getNode(),h;if(i.nodeName=="IMG"&&g.dom.getAttrib(i,"class").indexOf("mceItem")==-1){if((h=g.dom.getParent(i,"div"))&&g.dom.hasClass(h,"mceTemp")){g.dom.remove(h)}else{if(i.parentNode.nodeName=="A"&&i.parentNode.childNodes.length==1){i=i.parentNode}if(i.parentNode.nodeName=="P"&&i.parentNode.childNodes.length==1){i=i.parentNode}g.dom.remove(i)}g.execCommand("mceRepaint");return false}g.plugins.wordpress._hideButtons()})},_editImage:function(){var d=tinymce.activeEditor,e=this.url,g=d.selection.getNode(),c,f,a,b=g.className;if(b.indexOf("mceItem")!=-1||b.indexOf("wpGallery")!=-1||g.nodeName!="IMG"){return}c=tinymce.DOM.getViewPort();f=680<(c.h-70)?680:c.h-70;a=650<c.w?650:c.w;d.windowManager.open({file:e+"/editimage.html",width:a+"px",height:f+"px",inline:true})},_showButtons:function(c){var a=this.editor,b=c.target;if(b.nodeName!="IMG"){if(b.firstChild&&b.firstChild.nodeName=="IMG"&&b.childNodes.length==1){b=b.firstChild}else{a.plugins.wordpress._hideButtons();return}}if(a.dom.getAttrib(b,"class").indexOf("mceItem")==-1){mouse={x:c.clientX,y:c.clientY,img_w:b.clientWidth,img_h:b.clientHeight};if(c.type=="touchstart"){a.selection.select(b);a.dom.events.cancel(c)}a.plugins.wordpress._hideButtons();a.plugins.wordpress._showButtons(b,"wp_editbtns")}},getInfo:function(){return{longname:"Edit Image",author:"WordPress",authorurl:"http://wordpress.org",infourl:"",version:"1.0"}}});tinymce.PluginManager.add("wpeditimage",tinymce.plugins.wpEditImage)})();
\ No newline at end of file