]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js
Wordpress 3.3
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / plugins / wpeditimage / editor_plugin.dev.js
index 2e256a07a4290e3c16d242a79e7cbff601f29cb8..f79b6250ee4ec84c6231d79848b7320566be227a 100644 (file)
@@ -3,7 +3,7 @@
        tinymce.create('tinymce.plugins.wpEditImage', {
 
                init : function(ed, url) {
-                       var t = this;
+                       var t = this, mouse = {};
 
                        t.url = url;
                        t._createButtons();
                        });
 
                        ed.onInit.add(function(ed) {
-                               tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
-                                       ed.plugins.wpeditimage.hideButtons();
+                               tinymce.dom.Event.add(ed.getBody(), 'dragstart', function(e) {
+                                       if ( !tinymce.isGecko && e.target.nodeName == 'IMG' && ed.dom.getParent(e.target, 'dl.wp-caption') )
+                                               return tinymce.dom.Event.cancel(e);
                                });
                        });
 
-                       ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
-                               ed.plugins.wpeditimage.hideButtons();
-                       });
+                       // resize the caption <dl> when the image is soft-resized by the user (only possible in Firefox and IE)
+                       ed.onMouseUp.add(function(ed, e) {
+                               if ( tinymce.isWebKit || tinymce.isOpera )
+                                       return;
 
-                       ed.onSaveContent.add(function(ed, o) {
-                               ed.plugins.wpeditimage.hideButtons();
-                       });
+                               if ( mouse.x && (e.clientX != mouse.x || e.clientY != mouse.y) ) {
+                                       var n = ed.selection.getNode();
 
-                       ed.onMouseUp.add(function(ed, e) {
-                               var n, DL;
-                               
-                               if ( tinymce.isOpera ) {
-                                       if ( e.target.nodeName == 'IMG' )
-                                               ed.plugins.wpeditimage.showButtons(e.target);
-                               } else if ( ! tinymce.isWebKit ) {
-                                       n = ed.selection.getNode();
-                                       
-                                       if ( n.nodeName == 'IMG' && (DL = ed.dom.getParent(n, 'DL')) ) {                                        
+                                       if ( 'IMG' == n.nodeName ) {
                                                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');
+                                                       var DL, width;
+
+                                                       if ( n.width != mouse.img_w || n.height != mouse.img_h )
+                                                               n.className = n.className.replace(/size-[^ "']+/, '');
+
+                                                       if ( ed.dom.getParent(n, 'div.mceTemp') ) {
+                                                               DL = ed.dom.getParent(n, 'dl.wp-caption');
+
+                                                               if ( DL ) {
+                                                                       width = ed.dom.getAttrib(n, 'width') || n.width;
+                                                                       width = parseInt(width, 10);
+                                                                       ed.dom.setStyle(DL, 'width', 10 + width);
+                                                                       ed.execCommand('mceRepaint');
+                                                               }
+
                                                        }
                                                }, 100);
                                        }
                                }
+                               mouse = {};
                        });
 
+                       // show editimage buttons
                        ed.onMouseDown.add(function(ed, e) {
-                               if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
-                                       t.hideButtons();
-                                       return;
+
+                               if ( e.target && ( e.target.nodeName == 'IMG' || (e.target.firstChild && e.target.firstChild.nodeName == 'IMG') ) ) {
+                                       mouse = {
+                                               x: e.clientX,
+                                               y: e.clientY,
+                                               img_w: e.target.clientWidth,
+                                               img_h: e.target.clientHeight
+                                       };
+
+                                       if ( ed.dom.getAttrib(e.target, 'class').indexOf('mceItem') == -1 )
+                                               ed.plugins.wordpress._showButtons(e.target, 'wp_editbtns');
                                }
-                               ed.plugins.wpeditimage.showButtons(e.target);
                        });
 
+                       // when pressing Return inside a caption move the cursor to a new parapraph under it
                        ed.onKeyPress.add(function(ed, e) {
-                               var DL, DIV, P;
+                               var n, DL, DIV, P;
 
-                               if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
-                                       P = ed.dom.create('p', {}, '&nbsp;');
-                                       if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' ) 
-                                               ed.dom.insertAfter( P, DIV );
-                                       else ed.dom.insertAfter( P, DL );
+                               if ( e.keyCode == 13 ) {
+                                       n = ed.selection.getNode();
+                                       DL = ed.dom.getParent(n, 'dl.wp-caption');
+                                       DIV = ed.dom.getParent(DL, 'div.mceTemp');
 
-                                       tinymce.dom.Event.cancel(e);
-                                       ed.selection.select(P);
-                                       return false;
+                                       if ( DL && DIV ) {
+                                               P = ed.dom.create('p', {}, '&nbsp;');
+                                               ed.dom.insertAfter( P, DIV );
+                                               
+                                               if ( P.firstChild )
+                                                       ed.selection.select(P.firstChild);
+                                               else
+                                                       ed.selection.select(P);
+                                               
+                                               tinymce.dom.Event.cancel(e);
+                                               return false;
+                                       }
                                }
                        });
 
                },
 
                _do_shcode : function(co) {
-                       return co.replace(/\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\][\s\u00a0]*/g, function(a,b,c){
+                       return co.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?[\s\u00a0]*/g, function(a,b,c){
                                var id, cls, w, cap, div_cls;
                                
                                b = b.replace(/\\'|\\&#39;|\\&#039;/g, '&#39;').replace(/\\"|\\&quot;/g, '&quot;');
                                
                                div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
 
-                               return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
+                               return '<div class="'+div_cls+'" draggable><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>';
                        });
                },
                        });
                },
 
-               showButtons : function(n) {
-                       var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y, 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, wp_editbtns, wp_editimgbtn, wp_delimgbtn;
+                       var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, editButton, dellButton;
 
                        DOM.remove('wp_editbtns');
 
-                       wp_editbtns = DOM.add(document.body, 'div', {
+                       DOM.add(document.body, 'div', {
                                id : 'wp_editbtns',
                                style : 'display:none;'
                        });
 
-                       wp_editimgbtn = DOM.add('wp_editbtns', 'img', {
+                       editButton = DOM.add('wp_editbtns', 'img', {
                                src : t.url+'/img/image.png',
                                id : 'wp_editimgbtn',
                                width : '24',
                                title : ed.getLang('wpeditimage.edit_img')
                        });
 
-                       wp_editimgbtn.onmousedown = function(e) {
+                       tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
                                var ed = tinyMCE.activeEditor;
                                ed.windowManager.bookmark = ed.selection.getBookmark('simple');
                                ed.execCommand("WP_EditImage");
-                               this.parentNode.style.display = 'none';
-                       };
+                       });
 
-                       wp_delimgbtn = DOM.add('wp_editbtns', 'img', {
+                       dellButton = DOM.add('wp_editbtns', 'img', {
                                src : t.url+'/img/delete.png',
                                id : 'wp_delimgbtn',
                                width : '24',
                                title : ed.getLang('wpeditimage.del_img')
                        });
 
-                       wp_delimgbtn.onmousedown = function(e) {
+                       tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
                                var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
 
                                if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
                                                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);
+                                       else
+                                               ed.dom.remove(el);
 
-                                       this.parentNode.style.display = 'none';
                                        ed.execCommand('mceRepaint');
                                        return false;
                                }
-                       };
+                       });
                },
 
                getInfo : function() {