web/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.dev.js
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
    35 				});
    35 				});
    36 				tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
    36 				tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
    37 			});
    37 			});
    38 
    38 
    39 			ed.onInit.add(function(ed) {
    39 			ed.onInit.add(function(ed) {
    40 				tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
    40 				tinymce.dom.Event.add(ed.getBody(), 'dragstart', function(e) {
    41 					ed.plugins.wpeditimage.hideButtons();
    41 					if ( !tinymce.isGecko && e.target.nodeName == 'IMG' && ed.dom.getParent(e.target, 'dl.wp-caption') )
       
    42 						return tinymce.dom.Event.cancel(e);
    42 				});
    43 				});
    43 			});
    44 			});
    44 
    45 
    45 			ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
       
    46 				ed.plugins.wpeditimage.hideButtons();
       
    47 			});
       
    48 
       
    49 			ed.onSaveContent.add(function(ed, o) {
       
    50 				ed.plugins.wpeditimage.hideButtons();
       
    51 			});
       
    52 
       
    53 			ed.onMouseUp.add(function(ed, e) {
    46 			ed.onMouseUp.add(function(ed, e) {
    54 				var n, DL;
    47 				if ( tinymce.isWebKit || tinymce.isOpera )
    55 				
    48 					return;
    56 				if ( tinymce.isOpera ) {
    49 
    57 					if ( e.target.nodeName == 'IMG' )
    50 				if ( ed.dom.getParent(e.target, 'div.mceTemp') || ed.dom.is(e.target, 'div.mceTemp') ) {					
    58 						ed.plugins.wpeditimage.showButtons(e.target);
    51 					window.setTimeout(function(){
    59 				} else if ( ! tinymce.isWebKit ) {
    52 						var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'dl.wp-caption');
    60 					n = ed.selection.getNode();
    53 
    61 					
    54 						if ( DL && n.width != ( parseInt(ed.dom.getStyle(DL, 'width'), 10) - 10 ) ) {
    62 					if ( n.nodeName == 'IMG' && (DL = ed.dom.getParent(n, 'DL')) ) {					
    55 							ed.dom.setStyle(DL, 'width', parseInt(n.width, 10) + 10);
    63 						window.setTimeout(function(){
    56 							ed.execCommand('mceRepaint');
    64 							var ed = tinyMCE.activeEditor, n = ed.selection.getNode(), DL = ed.dom.getParent(n, 'DL');
    57 						}
    65 						
    58 					}, 100);
    66 							if ( n.width != (parseInt(ed.dom.getStyle(DL, 'width')) - 10) ) {
       
    67 								ed.dom.setStyle(DL, 'width', parseInt(n.width)+10);
       
    68 								ed.execCommand('mceRepaint');
       
    69 							}
       
    70 						}, 100);
       
    71 					}
       
    72 				}
    59 				}
    73 			});
    60 			});
    74 
    61 
    75 			ed.onMouseDown.add(function(ed, e) {
    62 			ed.onMouseDown.add(function(ed, e) {
    76 				if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
    63 				var p;
    77 					t.hideButtons();
    64 
    78 					return;
    65 				if ( e.target.nodeName == 'IMG' && ed.dom.getAttrib(e.target, 'class').indexOf('mceItem') == -1 ) {
    79 				}
    66 					ed.plugins.wordpress._showButtons(e.target, 'wp_editbtns');
    80 				ed.plugins.wpeditimage.showButtons(e.target);
    67 					if ( tinymce.isGecko && (p = ed.dom.getParent(e.target, 'dl.wp-caption')) && ed.dom.hasClass(p.parentNode, 'mceTemp') )
       
    68 						ed.selection.select(p.parentNode);
       
    69 				}
    81 			});
    70 			});
    82 
    71 
    83 			ed.onKeyPress.add(function(ed, e) {
    72 			ed.onKeyPress.add(function(ed, e) {
    84 				var DL, DIV, P;
    73 				var DL, DIV, P;
    85 
    74 
    86 				if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) ) {
    75 				if ( e.keyCode == 13 && (DL = ed.dom.getParent(ed.selection.getNode(), 'DL')) && ed.dom.hasClass(DL, 'wp-caption') ) {
    87 					P = ed.dom.create('p', {}, ' ');
    76 					P = ed.dom.create('p', {}, ' ');
    88 					if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' ) 
    77 					if ( (DIV = DL.parentNode) && DIV.nodeName == 'DIV' ) 
    89 						ed.dom.insertAfter( P, DIV );
    78 						ed.dom.insertAfter( P, DIV );
    90 					else ed.dom.insertAfter( P, DL );
    79 					else
       
    80 						ed.dom.insertAfter( P, DL );
       
    81 
       
    82 					if ( P.firstChild )
       
    83 						ed.selection.select(P.firstChild);
       
    84 					else
       
    85 						ed.selection.select(P);
    91 
    86 
    92 					tinymce.dom.Event.cancel(e);
    87 					tinymce.dom.Event.cancel(e);
    93 					ed.selection.select(P);
       
    94 					return false;
    88 					return false;
    95 				}
    89 				}
    96 			});
    90 			});
    97 
    91 
    98 			ed.onBeforeSetContent.add(function(ed, o) {
    92 			ed.onBeforeSetContent.add(function(ed, o) {
   122 				cap = ( cap && cap[1] ) ? cap[1] : '';
   116 				cap = ( cap && cap[1] ) ? cap[1] : '';
   123 				if ( ! w || ! cap ) return c;
   117 				if ( ! w || ! cap ) return c;
   124 				
   118 				
   125 				div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
   119 				div_cls = (cls == 'aligncenter') ? 'mceTemp mceIEcenter' : 'mceTemp';
   126 
   120 
   127 				return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
   121 				return '<div class="'+div_cls+'" draggable><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+(10+parseInt(w))+
   128 				'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
   122 				'px"><dt class="wp-caption-dt">'+c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';
   129 			});
   123 			});
   130 		},
   124 		},
   131 
   125 
   132 		_get_shcode : function(co) {
   126 		_get_shcode : function(co) {
   147 
   141 
   148 				return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
   142 				return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';
   149 			});
   143 			});
   150 		},
   144 		},
   151 
   145 
   152 		showButtons : function(n) {
       
   153 			var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y, cls = ed.dom.getAttrib(n, 'class');
       
   154 
       
   155 			if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 )
       
   156 				return;
       
   157 
       
   158 			vp = ed.dom.getViewPort(ed.getWin());
       
   159 			p1 = DOM.getPos(ed.getContentAreaContainer());
       
   160 			p2 = ed.dom.getPos(n);
       
   161 
       
   162 			X = Math.max(p2.x - vp.x, 0) + p1.x;
       
   163 			Y = Math.max(p2.y - vp.y, 0) + p1.y;
       
   164 
       
   165 			DOM.setStyles('wp_editbtns', {
       
   166 				'top' : Y+5+'px',
       
   167 				'left' : X+5+'px',
       
   168 				'display' : 'block'
       
   169 			});
       
   170 
       
   171 			t.btnsTout = window.setTimeout( function(){ed.plugins.wpeditimage.hideButtons();}, 5000 );
       
   172 		},
       
   173 
       
   174 		hideButtons : function() {
       
   175 			if ( tinymce.DOM.isHidden('wp_editbtns') ) return;
       
   176 
       
   177 			tinymce.DOM.hide('wp_editbtns');
       
   178 			window.clearTimeout(this.btnsTout);
       
   179 		},
       
   180 
       
   181 		_createButtons : function() {
   146 		_createButtons : function() {
   182 			var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, wp_editbtns, wp_editimgbtn, wp_delimgbtn;
   147 			var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, editButton, dellButton;
   183 
   148 
   184 			DOM.remove('wp_editbtns');
   149 			DOM.remove('wp_editbtns');
   185 
   150 
   186 			wp_editbtns = DOM.add(document.body, 'div', {
   151 			DOM.add(document.body, 'div', {
   187 				id : 'wp_editbtns',
   152 				id : 'wp_editbtns',
   188 				style : 'display:none;'
   153 				style : 'display:none;'
   189 			});
   154 			});
   190 
   155 
   191 			wp_editimgbtn = DOM.add('wp_editbtns', 'img', {
   156 			editButton = DOM.add('wp_editbtns', 'img', {
   192 				src : t.url+'/img/image.png',
   157 				src : t.url+'/img/image.png',
   193 				id : 'wp_editimgbtn',
   158 				id : 'wp_editimgbtn',
   194 				width : '24',
   159 				width : '24',
   195 				height : '24',
   160 				height : '24',
   196 				title : ed.getLang('wpeditimage.edit_img')
   161 				title : ed.getLang('wpeditimage.edit_img')
   197 			});
   162 			});
   198 
   163 
   199 			wp_editimgbtn.onmousedown = function(e) {
   164 			tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
   200 				var ed = tinyMCE.activeEditor;
   165 				var ed = tinyMCE.activeEditor;
   201 				ed.windowManager.bookmark = ed.selection.getBookmark('simple');
   166 				ed.windowManager.bookmark = ed.selection.getBookmark('simple');
   202 				ed.execCommand("WP_EditImage");
   167 				ed.execCommand("WP_EditImage");
   203 				this.parentNode.style.display = 'none';
   168 			});
   204 			};
   169 
   205 
   170 			dellButton = DOM.add('wp_editbtns', 'img', {
   206 			wp_delimgbtn = DOM.add('wp_editbtns', 'img', {
       
   207 				src : t.url+'/img/delete.png',
   171 				src : t.url+'/img/delete.png',
   208 				id : 'wp_delimgbtn',
   172 				id : 'wp_delimgbtn',
   209 				width : '24',
   173 				width : '24',
   210 				height : '24',
   174 				height : '24',
   211 				title : ed.getLang('wpeditimage.del_img')
   175 				title : ed.getLang('wpeditimage.del_img')
   212 			});
   176 			});
   213 
   177 
   214 			wp_delimgbtn.onmousedown = function(e) {
   178 			tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
   215 				var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
   179 				var ed = tinyMCE.activeEditor, el = ed.selection.getNode(), p;
   216 
   180 
   217 				if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
   181 				if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
   218 					if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
   182 					if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
   219 						ed.dom.remove(p);
   183 						ed.dom.remove(p);
   220 					else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
   184 					else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
   221 						ed.dom.remove(p);
   185 						ed.dom.remove(p);
   222 					else ed.dom.remove(el);
   186 					else
   223 
   187 						ed.dom.remove(el);
   224 					this.parentNode.style.display = 'none';
   188 
   225 					ed.execCommand('mceRepaint');
   189 					ed.execCommand('mceRepaint');
   226 					return false;
   190 					return false;
   227 				}
   191 				}
   228 			};
   192 			});
   229 		},
   193 		},
   230 
   194 
   231 		getInfo : function() {
   195 		getInfo : function() {
   232 			return {
   196 			return {
   233 				longname : 'Edit Image',
   197 				longname : 'Edit Image',