web/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.dev.js
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
     8 			t.url = url;
     8 			t.url = url;
     9 			t._createButtons();
     9 			t._createButtons();
    10 
    10 
    11 			// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
    11 			// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
    12 			ed.addCommand('WP_Gallery', function() {
    12 			ed.addCommand('WP_Gallery', function() {
    13 				var el = ed.selection.getNode(), post_id, vp = tinymce.DOM.getViewPort(), H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w;
    13 				var el = ed.selection.getNode(), post_id, vp = tinymce.DOM.getViewPort(),
       
    14 					H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w;
    14 
    15 
    15 				if ( el.nodeName != 'IMG' ) return;
    16 				if ( el.nodeName != 'IMG' ) return;
    16 				if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 )	return;
    17 				if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 )	return;
    17 
    18 
    18 				post_id = tinymce.DOM.get('post_ID').value;
    19 				post_id = tinymce.DOM.get('post_ID').value;
    19 				tb_show('', tinymce.documentBaseURL + '/media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H);
    20 				tb_show('', tinymce.documentBaseURL + '/media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H);
    20 
    21 
    21 				tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
    22 				tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
    22 			});
    23 			});
    23 
    24 
    24 			ed.onInit.add(function(ed) {
       
    25 				tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
       
    26 					ed.plugins.wpgallery.hideButtons();
       
    27 				});
       
    28 			});
       
    29 
       
    30 			ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
       
    31 				ed.plugins.wpgallery.hideButtons();
       
    32 			});
       
    33 
       
    34 			ed.onSaveContent.add(function(ed, o) {
       
    35 				ed.plugins.wpgallery.hideButtons();
       
    36 			});
       
    37 
       
    38 			ed.onMouseUp.add(function(ed, e) {
       
    39 				if ( tinymce.isOpera ) {
       
    40 					if ( e.target.nodeName == 'IMG' )
       
    41 						ed.plugins.wpgallery.showButtons(e.target);
       
    42 				}
       
    43 
       
    44 			});
       
    45 
       
    46 			ed.onMouseDown.add(function(ed, e) {
    25 			ed.onMouseDown.add(function(ed, e) {
    47 				if ( tinymce.isOpera || e.target.nodeName != 'IMG' ) {
    26 				if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') )
    48 					t.hideButtons();
    27 					ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns');
    49 					return;
       
    50 				}
       
    51 				ed.plugins.wpgallery.showButtons(e.target);
       
    52 			});
    28 			});
    53 
    29 
    54 			ed.onBeforeSetContent.add(function(ed, o) {
    30 			ed.onBeforeSetContent.add(function(ed, o) {
    55 				o.content = t._do_gallery(o.content);
    31 				o.content = t._do_gallery(o.content);
    56 			});
    32 			});
    82 
    58 
    83 				return a;
    59 				return a;
    84 			});
    60 			});
    85 		},
    61 		},
    86 
    62 
    87 		showButtons : function(n) {
       
    88 			var t = this, ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
       
    89 
       
    90 			if (ed.dom.getAttrib(n, 'class').indexOf('wpGallery') == -1)
       
    91 				return;
       
    92 
       
    93 			vp = ed.dom.getViewPort(ed.getWin());
       
    94 			p1 = DOM.getPos(ed.getContentAreaContainer());
       
    95 			p2 = ed.dom.getPos(n);
       
    96 
       
    97 			X = Math.max(p2.x - vp.x, 0) + p1.x;
       
    98 			Y = Math.max(p2.y - vp.y, 0) + p1.y;
       
    99 
       
   100 			DOM.setStyles('wp_gallerybtns', {
       
   101 				'top' : Y+5+'px',
       
   102 				'left' : X+5+'px',
       
   103 				'display' : 'block'
       
   104 			});
       
   105 
       
   106 			t.btnsTout = window.setTimeout( function(){ed.plugins.wpgallery.hideButtons();}, 5000 );
       
   107 		},
       
   108 
       
   109 		hideButtons : function() {
       
   110 			if ( tinymce.DOM.isHidden('wp_gallerybtns') ) return;
       
   111 
       
   112 			tinymce.DOM.hide('wp_gallerybtns');
       
   113 			window.clearTimeout(this.btnsTout);
       
   114 		},
       
   115 
       
   116 		_createButtons : function() {
    63 		_createButtons : function() {
   117 			var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, wp_gallerybtns, wp_editgallery, wp_delgallery;
    64 			var t = this, ed = tinyMCE.activeEditor, DOM = tinymce.DOM, editButton, dellButton;
   118 
    65 
   119 			DOM.remove('wp_gallerybtns');
    66 			DOM.remove('wp_gallerybtns');
   120 
    67 
   121 			wp_gallerybtns = DOM.add(document.body, 'div', {
    68 			DOM.add(document.body, 'div', {
   122 				id : 'wp_gallerybtns',
    69 				id : 'wp_gallerybtns',
   123 				style : 'display:none;'
    70 				style : 'display:none;'
   124 			});
    71 			});
   125 
    72 
   126 			wp_editgallery = DOM.add('wp_gallerybtns', 'img', {
    73 			editButton = DOM.add('wp_gallerybtns', 'img', {
   127 				src : t.url+'/img/edit.png',
    74 				src : t.url+'/img/edit.png',
   128 				id : 'wp_editgallery',
    75 				id : 'wp_editgallery',
   129 				width : '24',
    76 				width : '24',
   130 				height : '24',
    77 				height : '24',
   131 				title : ed.getLang('wordpress.editgallery')
    78 				title : ed.getLang('wordpress.editgallery')
   132 			});
    79 			});
   133 
    80 
   134 			wp_editgallery.onmousedown = function(e) {
    81 			tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
   135 				var ed = tinyMCE.activeEditor;
    82 				var ed = tinyMCE.activeEditor;
   136 				ed.windowManager.bookmark = ed.selection.getBookmark('simple');
    83 				ed.windowManager.bookmark = ed.selection.getBookmark('simple');
   137 				ed.execCommand("WP_Gallery");
    84 				ed.execCommand("WP_Gallery");
   138 				this.parentNode.style.display = 'none';
    85 			});
   139 			};
       
   140 
    86 
   141 			wp_delgallery = DOM.add('wp_gallerybtns', 'img', {
    87 			dellButton = DOM.add('wp_gallerybtns', 'img', {
   142 				src : t.url+'/img/delete.png',
    88 				src : t.url+'/img/delete.png',
   143 				id : 'wp_delgallery',
    89 				id : 'wp_delgallery',
   144 				width : '24',
    90 				width : '24',
   145 				height : '24',
    91 				height : '24',
   146 				title : ed.getLang('wordpress.delgallery')
    92 				title : ed.getLang('wordpress.delgallery')
   147 			});
    93 			});
   148 
    94 
   149 			wp_delgallery.onmousedown = function(e) {
    95 			tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
   150 				var ed = tinyMCE.activeEditor, el = ed.selection.getNode();
    96 				var ed = tinyMCE.activeEditor, el = ed.selection.getNode();
   151 
    97 
   152 				if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('wpGallery') != -1 ) {
    98 				if ( el.nodeName == 'IMG' && ed.dom.hasClass(el, 'wpGallery') ) {
   153 					ed.dom.remove(el);
    99 					ed.dom.remove(el);
   154 
   100 
   155 					this.parentNode.style.display = 'none';
       
   156 					ed.execCommand('mceRepaint');
   101 					ed.execCommand('mceRepaint');
   157 					return false;
   102 					return false;
   158 				}
   103 				}
   159 			};
   104 			});
   160 		},
   105 		},
   161 
   106 
   162 		getInfo : function() {
   107 		getInfo : function() {
   163 			return {
   108 			return {
   164 				longname : 'Gallery Settings',
   109 				longname : 'Gallery Settings',