web/wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
     4  * Contains code from Moxiecode Systems AB released under LGPL License http://tinymce.moxiecode.com/license
     4  * Contains code from Moxiecode Systems AB released under LGPL License http://tinymce.moxiecode.com/license
     5  */
     5  */
     6 
     6 
     7 (function() {
     7 (function() {
     8 	tinymce.create('tinymce.plugins.wpFullscreenPlugin', {
     8 	tinymce.create('tinymce.plugins.wpFullscreenPlugin', {
       
     9 		resize_timeout: false,
     9 
    10 
    10 		init : function(ed, url) {
    11 		init : function(ed, url) {
    11 			var t = this, oldHeight = 0, s = {}, DOM = tinymce.DOM;
    12 			var t = this, oldHeight = 0, s = {}, DOM = tinymce.DOM;
    12 
    13 
    13 			// Register commands
    14 			// Register commands
    91 						fullscreen.bounder( 'showToolbar', 'hideToolbar', 2000, e );
    92 						fullscreen.bounder( 'showToolbar', 'hideToolbar', 2000, e );
    92 					});
    93 					});
    93 				}
    94 				}
    94 			});
    95 			});
    95 
    96 
       
    97 			ed.addCommand('wpFullScreen', function() {
       
    98 				if ( typeof(fullscreen) == 'undefined' )
       
    99 					return;
       
   100 
       
   101 				if ( 'wp_mce_fullscreen' == ed.id )
       
   102 					fullscreen.off();
       
   103 				else
       
   104 					fullscreen.on();
       
   105 			});
       
   106 
    96 			// Register buttons
   107 			// Register buttons
    97 			if ( 'undefined' != fullscreen ) {
   108 			ed.addButton('wp_fullscreen', {
    98 				ed.addButton('wp_fullscreen', {
   109 				title : 'wordpress.wp_fullscreen_desc',
    99 					title : 'fullscreen.desc',
   110 				cmd : 'wpFullScreen'
   100 					onclick : function(){ fullscreen.on(); }
   111 			});
   101 				});
       
   102 			}
       
   103 
   112 
   104 			// END fullscreen
   113 			// END fullscreen
   105 //----------------------------------------------------------------
   114 //----------------------------------------------------------------
   106 			// START autoresize
   115 			// START autoresize
   107 
   116 
   109 				return;
   118 				return;
   110 
   119 
   111 			/**
   120 			/**
   112 			 * This method gets executed each time the editor needs to resize.
   121 			 * This method gets executed each time the editor needs to resize.
   113 			 */
   122 			 */
   114 			function resize() {
   123 			function resize(editor, e) {
   115 				var d = ed.getDoc(), DOM = tinymce.DOM, resizeHeight, myHeight;
   124 				var DOM = tinymce.DOM, body = ed.getBody(), ifr = DOM.get(ed.id + '_ifr'), height, y = ed.dom.win.scrollY;
   116 
   125 
   117 				// Get height differently depending on the browser used
   126 				if ( t.resize_timeout )
   118 				if ( tinymce.isWebKit )
   127 					return;
   119 					myHeight = d.body.offsetHeight;
       
   120 				else
       
   121 					myHeight = d.body.scrollHeight;
       
   122 
   128 
   123 				// Don't make it smaller than 300px
   129 				// sometimes several events are fired few ms apart, trottle down resizing a little
   124 				resizeHeight = (myHeight > 300) ? myHeight : 300;
   130 				t.resize_timeout = true;
       
   131 				setTimeout(function(){
       
   132 					t.resize_timeout = false;
       
   133 				}, 500);
   125 
   134 
   126 				// Resize content element
   135 				height = body.scrollHeight > 300 ? body.scrollHeight : 300;
   127 				if ( oldHeight != resizeHeight ) {
   136 
   128 					DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px');
   137 				if ( height != ifr.scrollHeight ) {
   129 					oldHeight = resizeHeight;
   138 					DOM.setStyle(ifr, 'height', height + 'px');
   130 					ed.getWin().scrollTo(0,0);
   139 					ed.getWin().scrollTo(0, 0); // iframe window object, make sure there's no scrolling
       
   140 				}
       
   141 
       
   142 				// WebKit scrolls to top on paste...
       
   143 				if ( e && e.type == 'paste' && tinymce.isWebKit ) {
       
   144 					setTimeout(function(){
       
   145 						ed.dom.win.scrollTo(0, y);
       
   146 					}, 40);
   131 				}
   147 				}
   132 			};
   148 			};
   133 
   149 
   134 			// Add appropriate listeners for resizing content area
   150 			// Add appropriate listeners for resizing content area
   135 			ed.onInit.add(function(ed, l) {
   151 			ed.onInit.add(function(ed, l) {
   140 				ed.onPostRender.add(resize);
   156 				ed.onPostRender.add(resize);
   141 
   157 
   142 				ed.getBody().style.overflowY = "hidden";
   158 				ed.getBody().style.overflowY = "hidden";
   143 			});
   159 			});
   144 
   160 
   145 			if (ed.getParam('autoresize_on_init', true)) {
   161 			if ( ed.getParam('autoresize_on_init', true) ) {
   146 				ed.onLoadContent.add(function(ed, l) {
   162 				ed.onLoadContent.add(function(ed, l) {
   147 					// Because the content area resizes when its content CSS loads,
   163 					// Because the content area resizes when its content CSS loads,
   148 					// and we can't easily add a listener to its onload event,
   164 					// and we can't easily add a listener to its onload event,
   149 					// we'll just trigger a resize after a short loading period
   165 					// we'll just trigger a resize after a short loading period
   150 					setTimeout(function() {
   166 					setTimeout(function() {