wp/wp-admin/js/wp-fullscreen.js
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
       
     1 /* global deleteUserSetting, setUserSetting, switchEditors, tinymce, tinyMCEPreInit */
     1 /**
     2 /**
     2  * PubSub
     3  * Distraction-Free Writing
     3  *
       
     4  * A lightweight publish/subscribe implementation.
       
     5  * Private use only!
       
     6  */
       
     7 var PubSub, fullscreen, wptitlehint;
       
     8 
       
     9 PubSub = function() {
       
    10 	this.topics = {};
       
    11 };
       
    12 
       
    13 PubSub.prototype.subscribe = function( topic, callback ) {
       
    14 	if ( ! this.topics[ topic ] )
       
    15 		this.topics[ topic ] = [];
       
    16 
       
    17 	this.topics[ topic ].push( callback );
       
    18 	return callback;
       
    19 };
       
    20 
       
    21 PubSub.prototype.unsubscribe = function( topic, callback ) {
       
    22 	var i, l,
       
    23 		topics = this.topics[ topic ];
       
    24 
       
    25 	if ( ! topics )
       
    26 		return callback || [];
       
    27 
       
    28 	// Clear matching callbacks
       
    29 	if ( callback ) {
       
    30 		for ( i = 0, l = topics.length; i < l; i++ ) {
       
    31 			if ( callback == topics[i] )
       
    32 				topics.splice( i, 1 );
       
    33 		}
       
    34 		return callback;
       
    35 
       
    36 	// Clear all callbacks
       
    37 	} else {
       
    38 		this.topics[ topic ] = [];
       
    39 		return topics;
       
    40 	}
       
    41 };
       
    42 
       
    43 PubSub.prototype.publish = function( topic, args ) {
       
    44 	var i, l, broken,
       
    45 		topics = this.topics[ topic ];
       
    46 
       
    47 	if ( ! topics )
       
    48 		return;
       
    49 
       
    50 	args = args || [];
       
    51 
       
    52 	for ( i = 0, l = topics.length; i < l; i++ ) {
       
    53 		broken = ( topics[i].apply( null, args ) === false || broken );
       
    54 	}
       
    55 	return ! broken;
       
    56 };
       
    57 
       
    58 /**
       
    59  * Distraction Free Writing
       
    60  * (wp-fullscreen)
     4  * (wp-fullscreen)
    61  *
     5  *
    62  * Access the API globally using the fullscreen variable.
     6  * Access the API globally using the window.wp.editor.fullscreen variable.
    63  */
     7  */
    64 
     8 ( function( $, window ) {
    65 (function($){
     9 	var api, ps, s, toggleUI, uiTimer, PubSub,
    66 	var api, ps, bounder, s;
    10 		uiScrollTop = 0,
       
    11 		transitionend = 'transitionend webkitTransitionEnd',
       
    12 		$body = $( document.body ),
       
    13 		$document = $( document );
       
    14 
       
    15 	/**
       
    16 	 * PubSub
       
    17 	 *
       
    18 	 * A lightweight publish/subscribe implementation.
       
    19 	 *
       
    20 	 * @access private
       
    21 	 */
       
    22 	PubSub = function() {
       
    23 		this.topics = {};
       
    24 
       
    25 		this.subscribe = function( topic, callback ) {
       
    26 			if ( ! this.topics[ topic ] )
       
    27 				this.topics[ topic ] = [];
       
    28 
       
    29 			this.topics[ topic ].push( callback );
       
    30 			return callback;
       
    31 		};
       
    32 
       
    33 		this.unsubscribe = function( topic, callback ) {
       
    34 			var i, l,
       
    35 				topics = this.topics[ topic ];
       
    36 
       
    37 			if ( ! topics )
       
    38 				return callback || [];
       
    39 
       
    40 			// Clear matching callbacks
       
    41 			if ( callback ) {
       
    42 				for ( i = 0, l = topics.length; i < l; i++ ) {
       
    43 					if ( callback == topics[i] )
       
    44 						topics.splice( i, 1 );
       
    45 				}
       
    46 				return callback;
       
    47 
       
    48 			// Clear all callbacks
       
    49 			} else {
       
    50 				this.topics[ topic ] = [];
       
    51 				return topics;
       
    52 			}
       
    53 		};
       
    54 
       
    55 		this.publish = function( topic, args ) {
       
    56 			var i, l, broken,
       
    57 				topics = this.topics[ topic ];
       
    58 
       
    59 			if ( ! topics )
       
    60 				return;
       
    61 
       
    62 			args = args || [];
       
    63 
       
    64 			for ( i = 0, l = topics.length; i < l; i++ ) {
       
    65 				broken = ( topics[i].apply( null, args ) === false || broken );
       
    66 			}
       
    67 			return ! broken;
       
    68 		};
       
    69 	};
    67 
    70 
    68 	// Initialize the fullscreen/api object
    71 	// Initialize the fullscreen/api object
    69 	fullscreen = api = {};
    72 	api = {};
    70 
    73 
    71 	// Create the PubSub (publish/subscribe) interface.
    74 	// Create the PubSub (publish/subscribe) interface.
    72 	ps = api.pubsub = new PubSub();
    75 	ps = api.pubsub = new PubSub();
    73 	timer = 0;
       
    74 	block = false;
       
    75 
    76 
    76 	s = api.settings = { // Settings
    77 	s = api.settings = { // Settings
    77 		visible : false,
    78 		visible: false,
    78 		mode : 'tinymce',
    79 		mode: 'tinymce',
    79 		editor_id : 'content',
    80 		id: '',
    80 		title_id : '',
    81 		title_id: '',
    81 		timer : 0,
    82 		timer: 0,
    82 		toolbar_shown : false
    83 		toolbar_shown: false
       
    84 	};
       
    85 
       
    86 	function _hideUI() {
       
    87 		$body.removeClass('wp-dfw-show-ui');
    83 	}
    88 	}
    84 
    89 
    85 	/**
    90 	/**
    86 	 * Bounder
    91 	 * toggleUI
    87 	 *
    92 	 *
    88 	 * Creates a function that publishes start/stop topics.
    93 	 * Toggle the CSS class to show/hide the toolbar, borders and statusbar.
    89 	 * Used to throttle events.
       
    90 	 */
    94 	 */
    91 	bounder = api.bounder = function( start, stop, delay, e ) {
    95 	toggleUI = api.toggleUI = function( show ) {
    92 		var y, top;
    96 		clearTimeout( uiTimer );
    93 
    97 
    94 		delay = delay || 1250;
    98 		if ( ! $body.hasClass('wp-dfw-show-ui') || show === 'show' ) {
    95 
    99 			$body.addClass('wp-dfw-show-ui');
    96 		if ( e ) {
   100 		} else if ( show !== 'autohide' ) {
    97 			y = e.pageY || e.clientY || e.offsetY;
   101 			$body.removeClass('wp-dfw-show-ui');
    98 			top = $(document).scrollTop();
   102 		}
    99 
   103 
   100 			if ( !e.isDefaultPrevented ) // test if e ic jQuery normalized
   104 		if ( show === 'autohide' ) {
   101 				y = 135 + y;
   105 			uiTimer = setTimeout( _hideUI, 2000 );
   102 
   106 		}
   103 			if ( y - top > 120 )
   107 	};
   104 				return;
   108 
   105 		}
   109 	function resetCssPosition( add ) {
   106 
   110 		s.$dfwWrap.parents().each( function( i, parent ) {
   107 		if ( block )
   111 			var cssPosition, $parent = $(parent);
   108 			return;
   112 
   109 
   113 			if ( add ) {
   110 		block = true;
   114 				if ( parent.style.position ) {
   111 
   115 					$parent.data( 'wp-dfw-css-position', parent.style.position );
   112 		setTimeout( function() {
   116 				}
   113 			block = false;
   117 
   114 		}, 400 );
   118 				$parent.css( 'position', 'static' );
   115 
   119 			} else {
   116 		if ( s.timer )
   120 				cssPosition = $parent.data( 'wp-dfw-css-position' );
   117 			clearTimeout( s.timer );
   121 				cssPosition = cssPosition || '';
   118 		else
   122 				$parent.css( 'position', cssPosition );
   119 			ps.publish( start );
   123 			}
   120 
   124 
   121 		function timed() {
   125 			if ( parent.nodeName === 'BODY' ) {
   122 			ps.publish( stop );
   126 				return false;
   123 			s.timer = 0;
   127 			}
   124 		}
   128 		});
   125 
   129 	}
   126 		s.timer = setTimeout( timed, delay );
       
   127 	};
       
   128 
   130 
   129 	/**
   131 	/**
   130 	 * on()
   132 	 * on()
   131 	 *
   133 	 *
   132 	 * Turns fullscreen on.
   134 	 * Turns fullscreen on.
   133 	 *
   135 	 *
   134 	 * @param string mode Optional. Switch to the given mode before opening.
   136 	 * @param string mode Optional. Switch to the given mode before opening.
   135 	 */
   137 	 */
   136 	api.on = function() {
   138 	api.on = function() {
   137 		if ( s.visible )
   139 		var id, $dfwWrap, titleId;
       
   140 
       
   141 		if ( s.visible ) {
   138 			return;
   142 			return;
       
   143 		}
       
   144 
       
   145 		if ( ! s.$fullscreenFader ) {
       
   146 			api.ui.init();
       
   147 		}
   139 
   148 
   140 		// Settings can be added or changed by defining "wp_fullscreen_settings" JS object.
   149 		// Settings can be added or changed by defining "wp_fullscreen_settings" JS object.
   141 		if ( typeof(wp_fullscreen_settings) == 'object' )
   150 		if ( typeof window.wp_fullscreen_settings === 'object' )
   142 			$.extend( s, wp_fullscreen_settings );
   151 			$.extend( s, window.wp_fullscreen_settings );
   143 
   152 
   144 		s.editor_id = wpActiveEditor || 'content';
   153 		id = s.id || window.wpActiveEditor;
   145 
   154 
   146 		if ( $('input#title').length && s.editor_id == 'content' )
   155 		if ( ! id ) {
   147 			s.title_id = 'title';
   156 			if ( s.hasTinymce ) {
   148 		else if ( $('input#' + s.editor_id + '-title').length ) // the title input field should have [editor_id]-title HTML ID to be auto detected
   157 				id = tinymce.activeEditor.id;
   149 			s.title_id = s.editor_id + '-title';
   158 			} else {
   150 		else
   159 				return;
   151 			$('#wp-fullscreen-title, #wp-fullscreen-title-prompt-text').hide();
   160 			}
   152 
   161 		}
   153 		s.mode = $('#' + s.editor_id).is(':hidden') ? 'tinymce' : 'html';
   162 
   154 		s.qt_canvas = $('#' + s.editor_id).get(0);
   163 		s.id = id;
   155 
   164 		$dfwWrap = s.$dfwWrap = $( '#wp-' + id + '-wrap' );
   156 		if ( ! s.element )
   165 
   157 			api.ui.init();
   166 		if ( ! $dfwWrap.length ) {
   158 
   167 			return;
   159 		s.is_mce_on = s.has_tinymce && typeof( tinyMCE.get(s.editor_id) ) != 'undefined';
   168 		}
       
   169 
       
   170 		s.$dfwTextarea = $( '#' + id );
       
   171 		s.$editorContainer = $dfwWrap.find( '.wp-editor-container' );
       
   172 		uiScrollTop = $document.scrollTop();
       
   173 
       
   174 		if ( s.hasTinymce ) {
       
   175 			s.editor = tinymce.get( id );
       
   176 		}
       
   177 
       
   178 		if ( s.editor && ! s.editor.isHidden() ) {
       
   179 			s.origHeight = $( '#' + id + '_ifr' ).height();
       
   180 			s.mode = 'tinymce';
       
   181 		} else {
       
   182 			s.origHeight = s.$dfwTextarea.height();
       
   183 			s.mode = 'html';
       
   184 		}
       
   185 
       
   186 		// Try to find title field
       
   187 		if ( typeof window.adminpage !== 'undefined' &&
       
   188 			( window.adminpage === 'post-php' || window.adminpage === 'post-new-php' ) ) {
       
   189 
       
   190 			titleId = 'title';
       
   191 		} else {
       
   192 			titleId = id + '-title';
       
   193 		}
       
   194 
       
   195 		s.$dfwTitle = $( '#' + titleId );
       
   196 
       
   197 		if ( ! s.$dfwTitle.length ) {
       
   198 			s.$dfwTitle = null;
       
   199 		}
   160 
   200 
   161 		api.ui.fade( 'show', 'showing', 'shown' );
   201 		api.ui.fade( 'show', 'showing', 'shown' );
   162 	};
   202 	};
   163 
   203 
   164 	/**
   204 	/**
   184 	 * @eventparam string from - The old mode.
   224 	 * @eventparam string from - The old mode.
   185 	 */
   225 	 */
   186 	api.switchmode = function( to ) {
   226 	api.switchmode = function( to ) {
   187 		var from = s.mode;
   227 		var from = s.mode;
   188 
   228 
   189 		if ( ! to || ! s.visible || ! s.has_tinymce )
   229 		if ( ! to || ! s.visible || ! s.hasTinymce || typeof switchEditors === 'undefined' ) {
   190 			return from;
   230 			return from;
       
   231 		}
   191 
   232 
   192 		// Don't switch if the mode is the same.
   233 		// Don't switch if the mode is the same.
   193 		if ( from == to )
   234 		if ( from == to )
   194 			return from;
   235 			return from;
   195 
   236 
   196 		ps.publish( 'switchMode', [ from, to ] );
   237 		if ( to === 'tinymce' && ! s.editor ) {
       
   238 			s.editor = tinymce.get( s.id );
       
   239 
       
   240 			if ( ! s.editor &&  typeof tinyMCEPreInit !== 'undefined' &&
       
   241 				tinyMCEPreInit.mceInit && tinyMCEPreInit.mceInit[ s.id ] ) {
       
   242 
       
   243 				// If the TinyMCE instance hasn't been created, set the "wp_fulscreen" flag on creating it
       
   244 				tinyMCEPreInit.mceInit[ s.id ].wp_fullscreen = true;
       
   245 			}
       
   246 		}
       
   247 
   197 		s.mode = to;
   248 		s.mode = to;
   198 		ps.publish( 'switchedMode', [ from, to ] );
   249 		switchEditors.go( s.id, to );
       
   250 		api.refreshButtons( true );
       
   251 
       
   252 		if ( to === 'html' ) {
       
   253 			setTimeout( api.resizeTextarea, 200 );
       
   254 		}
   199 
   255 
   200 		return to;
   256 		return to;
   201 	};
   257 	};
   202 
   258 
   203 	/**
   259 	/**
   204 	 * General
   260 	 * General
   205 	 */
   261 	 */
   206 
   262 
   207 	api.save = function() {
   263 	api.save = function() {
   208 		var hidden = $('#hiddenaction'), old = hidden.val(), spinner = $('#wp-fullscreen-save .spinner'),
   264 		var $hidden = $('#hiddenaction'),
   209 			message = $('#wp-fullscreen-save span');
   265 			oldVal = $hidden.val(),
   210 
   266 			$spinner = $('#wp-fullscreen-save .spinner'),
   211 		spinner.show();
   267 			$saveMessage = $('#wp-fullscreen-save .wp-fullscreen-saved-message'),
   212 		api.savecontent();
   268 			$errorMessage = $('#wp-fullscreen-save .wp-fullscreen-error-message');
   213 
   269 
   214 		hidden.val('wp-fullscreen-save-post');
   270 		$spinner.addClass( 'is-active' );
   215 
   271 		$errorMessage.hide();
   216 		$.post( ajaxurl, $('form#post').serialize(), function(r){
   272 		$saveMessage.hide();
   217 			spinner.hide();
   273 		$hidden.val('wp-fullscreen-save-post');
   218 			message.show();
   274 
   219 
   275 		if ( s.editor && ! s.editor.isHidden() ) {
   220 			setTimeout( function(){
   276 			s.editor.save();
   221 				message.fadeOut(1000);
   277 		}
   222 			}, 3000 );
   278 
   223 
   279 		$.ajax({
   224 			if ( r.last_edited )
   280 			url: window.ajaxurl,
   225 				$('#wp-fullscreen-save input').attr( 'title',  r.last_edited );
   281 			type: 'post',
   226 
   282 			data: $('form#post').serialize(),
   227 		}, 'json');
   283 			dataType: 'json'
   228 
   284 		}).done( function( response ) {
   229 		hidden.val(old);
   285 			$spinner.removeClass( 'is-active' );
   230 	}
   286 
   231 
   287 			if ( response && response.success ) {
   232 	api.savecontent = function() {
   288 				$saveMessage.show();
   233 		var ed, content;
   289 
   234 
   290 				setTimeout( function() {
   235 		if ( s.title_id )
   291 					$saveMessage.fadeOut(300);
   236 			$('#' + s.title_id).val( $('#wp-fullscreen-title').val() );
   292 				}, 3000 );
   237 
   293 
   238 		if ( s.mode === 'tinymce' && (ed = tinyMCE.get('wp_mce_fullscreen')) ) {
   294 				if ( response.data && response.data.last_edited ) {
   239 			content = ed.save();
   295 					$('#wp-fullscreen-save input').attr( 'title',  response.data.last_edited );
   240 		} else {
   296 				}
   241 			content = $('#wp_mce_fullscreen').val();
   297 			} else {
   242 		}
   298 				$errorMessage.show();
   243 
   299 			}
   244 		$('#' + s.editor_id).val( content );
   300 		}).fail( function() {
   245 		$(document).triggerHandler('wpcountwords', [ content ]);
   301 			$spinner.removeClass( 'is-active' );
   246 	}
   302 			$errorMessage.show();
   247 
   303 		});
   248 	set_title_hint = function( title ) {
   304 
   249 		if ( ! title.val().length )
   305 		$hidden.val( oldVal );
   250 			title.siblings('label').css( 'visibility', '' );
   306 	};
   251 		else
   307 
   252 			title.siblings('label').css( 'visibility', 'hidden' );
   308 	api.dfwWidth = function( pixels, total ) {
   253 	}
   309 		var width;
   254 
   310 
   255 	api.dfw_width = function(n) {
   311 		if ( pixels && pixels.toString().indexOf('%') !== -1 ) {
   256 		var el = $('#wp-fullscreen-wrap'), w = el.width();
   312 			s.$editorContainer.css( 'width', pixels );
   257 
   313 			s.$statusbar.css( 'width', pixels );
   258 		if ( !n ) { // reset to theme width
   314 
   259 			el.width( $('#wp-fullscreen-central-toolbar').width() );
   315 			if ( s.$dfwTitle ) {
       
   316 				s.$dfwTitle.css( 'width', pixels );
       
   317 			}
       
   318 			return;
       
   319 		}
       
   320 
       
   321 		if ( ! pixels ) {
       
   322 			// Reset to theme width
       
   323 			width = $('#wp-fullscreen-body').data('theme-width') || 800;
       
   324 			s.$editorContainer.width( width );
       
   325 			s.$statusbar.width( width );
       
   326 
       
   327 			if ( s.$dfwTitle ) {
       
   328 				s.$dfwTitle.width( width - 16 );
       
   329 			}
       
   330 
   260 			deleteUserSetting('dfw_width');
   331 			deleteUserSetting('dfw_width');
   261 			return;
   332 			return;
   262 		}
   333 		}
   263 
   334 
   264 		w = n + w;
   335 		if ( total ) {
   265 
   336 			width = pixels;
   266 		if ( w < 200 || w > 1200 ) // sanity check
   337 		} else {
       
   338 			width = s.$editorContainer.width();
       
   339 			width += pixels;
       
   340 		}
       
   341 
       
   342 		if ( width < 200 || width > 1200 ) {
       
   343 			// sanity check
   267 			return;
   344 			return;
   268 
   345 		}
   269 		el.width( w );
   346 
   270 		setUserSetting('dfw_width', w);
   347 		s.$editorContainer.width( width );
   271 	}
   348 		s.$statusbar.width( width );
   272 
   349 
   273 	ps.subscribe( 'showToolbar', function() {
   350 		if ( s.$dfwTitle ) {
   274 		s.toolbars.removeClass('fade-1000').addClass('fade-300');
   351 			s.$dfwTitle.width( width - 16 );
   275 		api.fade.In( s.toolbars, 300, function(){ ps.publish('toolbarShown'); }, true );
   352 		}
   276 		$('#wp-fullscreen-body').addClass('wp-fullscreen-focus');
   353 
   277 		s.toolbar_shown = true;
   354 		setUserSetting( 'dfw_width', width );
       
   355 	};
       
   356 
       
   357 	// This event occurs before the overlay blocks the UI.
       
   358 	ps.subscribe( 'show', function() {
       
   359 		var title = $('#last-edit').text();
       
   360 
       
   361 		if ( title ) {
       
   362 			$('#wp-fullscreen-save input').attr( 'title', title );
       
   363 		}
   278 	});
   364 	});
   279 
   365 
   280 	ps.subscribe( 'hideToolbar', function() {
   366 	// This event occurs while the overlay blocks the UI.
   281 		s.toolbars.removeClass('fade-300').addClass('fade-1000');
   367 	ps.subscribe( 'showing', function() {
   282 		api.fade.Out( s.toolbars, 1000, function(){ ps.publish('toolbarHidden'); }, true );
   368 		$body.addClass( 'wp-fullscreen-active' );
   283 		$('#wp-fullscreen-body').removeClass('wp-fullscreen-focus');
   369 		s.$dfwWrap.addClass( 'wp-fullscreen-wrap' );
   284 	});
   370 
   285 
   371 		if ( s.$dfwTitle ) {
   286 	ps.subscribe( 'toolbarShown', function() {
   372 			s.$dfwTitle.after( '<span id="wp-fullscreen-title-placeholder">' );
   287 		s.toolbars.removeClass('fade-300');
   373 			s.$dfwWrap.prepend( s.$dfwTitle.addClass('wp-fullscreen-title') );
   288 	});
   374 		}
   289 
   375 
   290 	ps.subscribe( 'toolbarHidden', function() {
   376 		api.refreshButtons();
   291 		s.toolbars.removeClass('fade-1000');
   377 		resetCssPosition( true );
   292 		s.toolbar_shown = false;
   378 		$('#wpadminbar').hide();
   293 	});
   379 
   294 
   380 		// Show the UI for 2 sec. when opening
   295 	ps.subscribe( 'show', function() { // This event occurs before the overlay blocks the UI.
   381 		toggleUI('autohide');
   296 		var title;
       
   297 
       
   298 		if ( s.title_id ) {
       
   299 			title = $('#wp-fullscreen-title').val( $('#' + s.title_id).val() );
       
   300 			set_title_hint( title );
       
   301 		}
       
   302 
       
   303 		$('#wp-fullscreen-save input').attr( 'title',  $('#last-edit').text() );
       
   304 
       
   305 		s.textarea_obj.value = s.qt_canvas.value;
       
   306 
       
   307 		if ( s.has_tinymce && s.mode === 'tinymce' )
       
   308 			tinyMCE.execCommand('wpFullScreenInit');
       
   309 
       
   310 		s.orig_y = $(window).scrollTop();
       
   311 	});
       
   312 
       
   313 	ps.subscribe( 'showing', function() { // This event occurs while the DFW overlay blocks the UI.
       
   314 		$( document.body ).addClass( 'fullscreen-active' );
       
   315 		api.refresh_buttons();
       
   316 
       
   317 		$( document ).bind( 'mousemove.fullscreen', function(e) { bounder( 'showToolbar', 'hideToolbar', 2000, e ); } );
       
   318 		bounder( 'showToolbar', 'hideToolbar', 2000 );
       
   319 
   382 
   320 		api.bind_resize();
   383 		api.bind_resize();
   321 		setTimeout( api.resize_textarea, 200 );
   384 
       
   385 		if ( s.editor ) {
       
   386 			s.editor.execCommand( 'wpFullScreenOn' );
       
   387 		}
       
   388 
       
   389 		if ( 'ontouchstart' in window ) {
       
   390 			api.dfwWidth( '90%' );
       
   391 		} else {
       
   392 			api.dfwWidth( $( '#wp-fullscreen-body' ).data('dfw-width') || 800, true );
       
   393 		}
   322 
   394 
   323 		// scroll to top so the user is not disoriented
   395 		// scroll to top so the user is not disoriented
   324 		scrollTo(0, 0);
   396 		scrollTo(0, 0);
   325 
       
   326 		// needed it for IE7 and compat mode
       
   327 		$('#wpadminbar').hide();
       
   328 	});
   397 	});
   329 
   398 
   330 	ps.subscribe( 'shown', function() { // This event occurs after the DFW overlay is shown
   399 	// This event occurs after the overlay unblocks the UI
   331 		var interim_init;
   400 	ps.subscribe( 'shown', function() {
   332 
       
   333 		s.visible = true;
   401 		s.visible = true;
   334 
   402 
   335 		// init the standard TinyMCE instance if missing
   403 		if ( s.editor && ! s.editor.isHidden() ) {
   336 		if ( s.has_tinymce && ! s.is_mce_on ) {
   404 			s.editor.execCommand( 'wpAutoResize' );
   337 
   405 		} else {
   338 			interim_init = function(mce, ed) {
   406 			api.resizeTextarea( 'force' );
   339 				var el = ed.getElement(), old_val = el.value, settings = tinyMCEPreInit.mceInit[s.editor_id];
   407 		}
   340 
       
   341 				if ( settings && settings.wpautop && typeof(switchEditors) != 'undefined' )
       
   342 					el.value = switchEditors.wpautop( el.value );
       
   343 
       
   344 				ed.onInit.add(function(ed) {
       
   345 					ed.hide();
       
   346 					ed.getElement().value = old_val;
       
   347 					tinymce.onAddEditor.remove(interim_init);
       
   348 				});
       
   349 			};
       
   350 
       
   351 			tinymce.onAddEditor.add(interim_init);
       
   352 			tinyMCE.init(tinyMCEPreInit.mceInit[s.editor_id]);
       
   353 
       
   354 			s.is_mce_on = true;
       
   355 		}
       
   356 
       
   357 		wpActiveEditor = 'wp_mce_fullscreen';
       
   358 	});
   408 	});
   359 
   409 
   360 	ps.subscribe( 'hide', function() { // This event occurs before the overlay blocks DFW.
   410 	ps.subscribe( 'hide', function() { // This event occurs before the overlay blocks DFW.
   361 		var htmled_is_hidden = $('#' + s.editor_id).is(':hidden');
   411 		$document.unbind( '.fullscreen' );
   362 		// Make sure the correct editor is displaying.
   412 		s.$dfwTextarea.unbind('.wp-dfw-resize');
   363 		if ( s.has_tinymce && s.mode === 'tinymce' && !htmled_is_hidden ) {
       
   364 			switchEditors.go(s.editor_id, 'tmce');
       
   365 		} else if ( s.mode === 'html' && htmled_is_hidden ) {
       
   366 			switchEditors.go(s.editor_id, 'html');
       
   367 		}
       
   368 
       
   369 		// Save content must be after switchEditors or content will be overwritten. See #17229.
       
   370 		api.savecontent();
       
   371 
       
   372 		$( document ).unbind( '.fullscreen' );
       
   373 		$(s.textarea_obj).unbind('.grow');
       
   374 
       
   375 		if ( s.has_tinymce && s.mode === 'tinymce' )
       
   376 			tinyMCE.execCommand('wpFullScreenSave');
       
   377 
       
   378 		if ( s.title_id )
       
   379 			set_title_hint( $('#' + s.title_id) );
       
   380 
       
   381 		s.qt_canvas.value = s.textarea_obj.value;
       
   382 	});
   413 	});
   383 
   414 
   384 	ps.subscribe( 'hiding', function() { // This event occurs while the overlay blocks the DFW UI.
   415 	ps.subscribe( 'hiding', function() { // This event occurs while the overlay blocks the DFW UI.
   385 
   416 		$body.removeClass( 'wp-fullscreen-active' );
   386 		$( document.body ).removeClass( 'fullscreen-active' );
   417 
   387 		scrollTo(0, s.orig_y);
   418 		if ( s.$dfwTitle ) {
       
   419 			$( '#wp-fullscreen-title-placeholder' ).before( s.$dfwTitle.removeClass('wp-fullscreen-title').css( 'width', '' ) ).remove();
       
   420 		}
       
   421 
       
   422 		s.$dfwWrap.removeClass( 'wp-fullscreen-wrap' );
       
   423 		s.$editorContainer.css( 'width', '' );
       
   424 		s.$dfwTextarea.add( '#' + s.id + '_ifr' ).height( s.origHeight );
       
   425 
       
   426 		if ( s.editor ) {
       
   427 			s.editor.execCommand( 'wpFullScreenOff' );
       
   428 		}
       
   429 
       
   430 		resetCssPosition( false );
       
   431 
       
   432 		window.scrollTo( 0, uiScrollTop );
   388 		$('#wpadminbar').show();
   433 		$('#wpadminbar').show();
   389 	});
   434 	});
   390 
   435 
   391 	ps.subscribe( 'hidden', function() { // This event occurs after DFW is removed.
   436 	// This event occurs after DFW is removed.
       
   437 	ps.subscribe( 'hidden', function() {
   392 		s.visible = false;
   438 		s.visible = false;
   393 		$('#wp_mce_fullscreen, #wp-fullscreen-title').removeAttr('style');
       
   394 
       
   395 		if ( s.has_tinymce && s.is_mce_on )
       
   396 			tinyMCE.execCommand('wpFullScreenClose');
       
   397 
       
   398 		s.textarea_obj.value = '';
       
   399 		api.oldheight = 0;
       
   400 		wpActiveEditor = s.editor_id;
       
   401 	});
   439 	});
   402 
   440 
   403 	ps.subscribe( 'switchMode', function( from, to ) {
   441 	api.refreshButtons = function( fade ) {
   404 		var ed;
       
   405 
       
   406 		if ( !s.has_tinymce || !s.is_mce_on )
       
   407 			return;
       
   408 
       
   409 		ed = tinyMCE.get('wp_mce_fullscreen');
       
   410 
       
   411 		if ( from === 'html' && to === 'tinymce' ) {
       
   412 
       
   413 			if ( tinyMCE.get(s.editor_id).getParam('wpautop') && typeof(switchEditors) != 'undefined' )
       
   414 				s.textarea_obj.value = switchEditors.wpautop( s.textarea_obj.value );
       
   415 
       
   416 			if ( 'undefined' == typeof(ed) )
       
   417 				tinyMCE.execCommand('wpFullScreenInit');
       
   418 			else
       
   419 				ed.show();
       
   420 
       
   421 		} else if ( from === 'tinymce' && to === 'html' ) {
       
   422 			if ( ed )
       
   423 				ed.hide();
       
   424 		}
       
   425 	});
       
   426 
       
   427 	ps.subscribe( 'switchedMode', function( from, to ) {
       
   428 		api.refresh_buttons(true);
       
   429 
       
   430 		if ( to === 'html' )
       
   431 			setTimeout( api.resize_textarea, 200 );
       
   432 	});
       
   433 
       
   434 	/**
       
   435 	 * Buttons
       
   436 	 */
       
   437 	api.b = function() {
       
   438 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   439 			tinyMCE.execCommand('Bold');
       
   440 	}
       
   441 
       
   442 	api.i = function() {
       
   443 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   444 			tinyMCE.execCommand('Italic');
       
   445 	}
       
   446 
       
   447 	api.ul = function() {
       
   448 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   449 			tinyMCE.execCommand('InsertUnorderedList');
       
   450 	}
       
   451 
       
   452 	api.ol = function() {
       
   453 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   454 			tinyMCE.execCommand('InsertOrderedList');
       
   455 	}
       
   456 
       
   457 	api.link = function() {
       
   458 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   459 			tinyMCE.execCommand('WP_Link');
       
   460 		else
       
   461 			wpLink.open();
       
   462 	}
       
   463 
       
   464 	api.unlink = function() {
       
   465 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   466 			tinyMCE.execCommand('unlink');
       
   467 	}
       
   468 
       
   469 	api.atd = function() {
       
   470 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   471 			tinyMCE.execCommand('mceWritingImprovementTool');
       
   472 	}
       
   473 
       
   474 	api.help = function() {
       
   475 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   476 			tinyMCE.execCommand('WP_Help');
       
   477 	}
       
   478 
       
   479 	api.blockquote = function() {
       
   480 		if ( s.has_tinymce && 'tinymce' === s.mode )
       
   481 			tinyMCE.execCommand('mceBlockQuote');
       
   482 	}
       
   483 
       
   484 	api.medialib = function() {
       
   485 		if ( typeof wp !== 'undefined' && wp.media && wp.media.editor )
       
   486 			wp.media.editor.open(s.editor_id);
       
   487 	}
       
   488 
       
   489 	api.refresh_buttons = function( fade ) {
       
   490 		fade = fade || false;
       
   491 
       
   492 		if ( s.mode === 'html' ) {
   442 		if ( s.mode === 'html' ) {
   493 			$('#wp-fullscreen-mode-bar').removeClass('wp-tmce-mode').addClass('wp-html-mode');
   443 			$('#wp-fullscreen-mode-bar').removeClass('wp-tmce-mode').addClass('wp-html-mode')
   494 
   444 				.find('a').removeClass( 'active' ).filter('.wp-fullscreen-mode-html').addClass( 'active' );
   495 			if ( fade )
   445 
       
   446 			if ( fade ) {
   496 				$('#wp-fullscreen-button-bar').fadeOut( 150, function(){
   447 				$('#wp-fullscreen-button-bar').fadeOut( 150, function(){
   497 					$(this).addClass('wp-html-mode').fadeIn( 150 );
   448 					$(this).addClass('wp-html-mode').fadeIn( 150 );
   498 				});
   449 				});
   499 			else
   450 			} else {
   500 				$('#wp-fullscreen-button-bar').addClass('wp-html-mode');
   451 				$('#wp-fullscreen-button-bar').addClass('wp-html-mode');
   501 
   452 			}
   502 		} else if ( s.mode === 'tinymce' ) {
   453 		} else if ( s.mode === 'tinymce' ) {
   503 			$('#wp-fullscreen-mode-bar').removeClass('wp-html-mode').addClass('wp-tmce-mode');
   454 			$('#wp-fullscreen-mode-bar').removeClass('wp-html-mode').addClass('wp-tmce-mode')
   504 
   455 				.find('a').removeClass( 'active' ).filter('.wp-fullscreen-mode-tinymce').addClass( 'active' );
   505 			if ( fade )
   456 
       
   457 			if ( fade ) {
   506 				$('#wp-fullscreen-button-bar').fadeOut( 150, function(){
   458 				$('#wp-fullscreen-button-bar').fadeOut( 150, function(){
   507 					$(this).removeClass('wp-html-mode').fadeIn( 150 );
   459 					$(this).removeClass('wp-html-mode').fadeIn( 150 );
   508 				});
   460 				});
   509 			else
   461 			} else {
   510 				$('#wp-fullscreen-button-bar').removeClass('wp-html-mode');
   462 				$('#wp-fullscreen-button-bar').removeClass('wp-html-mode');
   511 		}
   463 			}
   512 	}
   464 		}
       
   465 	};
   513 
   466 
   514 	/**
   467 	/**
   515 	 * UI Elements
   468 	 * UI Elements
   516 	 *
   469 	 *
   517 	 * Used for transitioning between states.
   470 	 * Used for transitioning between states.
   518 	 */
   471 	 */
   519 	api.ui = {
   472 	api.ui = {
   520 		init: function() {
   473 		init: function() {
   521 			var topbar = $('#fullscreen-topbar'), txtarea = $('#wp_mce_fullscreen'), last = 0;
   474 			var toolbar;
   522 
   475 
   523 			s.toolbars = topbar.add( $('#wp-fullscreen-status') );
   476 			s.toolbar = toolbar = $('#fullscreen-topbar');
   524 			s.element = $('#fullscreen-fader');
   477 			s.$fullscreenFader = $('#fullscreen-fader');
   525 			s.textarea_obj = txtarea[0];
   478 			s.$statusbar = $('#wp-fullscreen-status');
   526 			s.has_tinymce = typeof(tinymce) != 'undefined';
   479 			s.hasTinymce = typeof tinymce !== 'undefined';
   527 
   480 
   528 			if ( !s.has_tinymce )
   481 			if ( ! s.hasTinymce )
   529 				$('#wp-fullscreen-mode-bar').hide();
   482 				$('#wp-fullscreen-mode-bar').hide();
   530 
   483 
   531 			if ( wptitlehint && $('#wp-fullscreen-title').length )
   484 			$document.keyup( function(e) {
   532 				wptitlehint('wp-fullscreen-title');
   485 				var c = e.keyCode || e.charCode, modKey;
   533 
   486 
   534 			$(document).keyup(function(e){
   487 				if ( ! s.visible ) {
   535 				var c = e.keyCode || e.charCode, a, data;
   488 					return;
   536 
   489 				}
   537 				if ( !fullscreen.settings.visible )
   490 
   538 					return true;
   491 				if ( navigator.platform && navigator.platform.indexOf('Mac') !== -1 ) {
   539 
   492 					modKey = e.ctrlKey; // Ctrl key for Mac
   540 				if ( navigator.platform && navigator.platform.indexOf('Mac') != -1 )
   493 				} else {
   541 					a = e.ctrlKey; // Ctrl key for Mac
   494 					modKey = e.altKey; // Alt key for Win & Linux
   542 				else
   495 				}
   543 					a = e.altKey; // Alt key for Win & Linux
   496 
   544 
   497 				if ( modKey && ( 61 === c || 107 === c || 187 === c ) ) { // +
   545 				if ( 27 == c ) { // Esc
   498 					api.dfwWidth( 25 );
   546 					data = {
   499 					e.preventDefault();
   547 						event: e,
   500 				}
   548 						what: 'dfw',
   501 
   549 						cb: fullscreen.off,
   502 				if ( modKey && ( 45 === c || 109 === c || 189 === c ) ) { // -
   550 						condition: function(){
   503 					api.dfwWidth( -25 );
   551 							if ( $('#TB_window').is(':visible') || $('.wp-dialog').is(':visible') )
   504 					e.preventDefault();
   552 								return false;
   505 				}
   553 							return true;
   506 
   554 						}
   507 				if ( modKey && 48 === c ) { // 0
   555 					};
   508 					api.dfwWidth( 0 );
   556 
   509 					e.preventDefault();
   557 					if ( ! jQuery(document).triggerHandler( 'wp_CloseOnEscape', [data] ) )
   510 				}
   558 						fullscreen.off();
       
   559 				}
       
   560 
       
   561 				if ( a && (61 == c || 107 == c || 187 == c) ) // +
       
   562 					api.dfw_width(25);
       
   563 
       
   564 				if ( a && (45 == c || 109 == c || 189 == c) ) // -
       
   565 					api.dfw_width(-25);
       
   566 
       
   567 				if ( a && 48 == c ) // 0
       
   568 					api.dfw_width(0);
       
   569 
       
   570 				return false;
       
   571 			});
   511 			});
   572 
   512 
   573 			// word count in Text mode
   513 			$( window ).on( 'keydown.wp-fullscreen', function( event ) {
   574 			if ( typeof(wpWordCount) != 'undefined' ) {
   514 				// Turn fullscreen off when Esc is pressed.
   575 
   515 				if ( 27 === event.keyCode && s.visible ) {
   576 				txtarea.keyup( function(e) {
   516 					api.off();
   577 					var k = e.keyCode || e.charCode;
   517 					event.stopImmediatePropagation();
   578 
   518 				}
   579 					if ( k == last )
   519 			});
   580 						return true;
   520 
   581 
   521 			if ( 'ontouchstart' in window ) {
   582 					if ( 13 == k || 8 == last || 46 == last )
   522 				$body.addClass('wp-dfw-touch');
   583 						$(document).triggerHandler('wpcountwords', [ txtarea.val() ]);
   523 			}
   584 
   524 
   585 					last = k;
   525 			toolbar.on( 'mouseenter', function() {
   586 					return true;
   526 				toggleUI('show');
   587 				});
   527 			}).on( 'mouseleave', function() {
   588 			}
   528 				toggleUI('autohide');
   589 
   529 			});
   590 			topbar.mouseenter(function(e){
   530 
   591 				s.toolbars.addClass('fullscreen-make-sticky');
   531 			// Bind buttons
   592 				$( document ).unbind( '.fullscreen' );
   532 			$('#wp-fullscreen-buttons').on( 'click.wp-fullscreen', 'button', function( event ) {
   593 				clearTimeout( s.timer );
   533 				var command = event.currentTarget.id ? event.currentTarget.id.substr(6) : null;
   594 				s.timer = 0;
   534 
   595 			}).mouseleave(function(e){
   535 				if ( s.editor && 'tinymce' === s.mode ) {
   596 				s.toolbars.removeClass('fullscreen-make-sticky');
   536 					switch( command ) {
   597 
   537 						case 'bold':
   598 				if ( s.visible )
   538 							s.editor.execCommand('Bold');
   599 					$( document ).bind( 'mousemove.fullscreen', function(e) { bounder( 'showToolbar', 'hideToolbar', 2000, e ); } );
   539 							break;
       
   540 						case 'italic':
       
   541 							s.editor.execCommand('Italic');
       
   542 							break;
       
   543 						case 'bullist':
       
   544 							s.editor.execCommand('InsertUnorderedList');
       
   545 							break;
       
   546 						case 'numlist':
       
   547 							s.editor.execCommand('InsertOrderedList');
       
   548 							break;
       
   549 						case 'link':
       
   550 							s.editor.execCommand('WP_Link');
       
   551 							break;
       
   552 						case 'unlink':
       
   553 							s.editor.execCommand('unlink');
       
   554 							break;
       
   555 						case 'help':
       
   556 							s.editor.execCommand('WP_Help');
       
   557 							break;
       
   558 						case 'blockquote':
       
   559 							s.editor.execCommand('mceBlockQuote');
       
   560 							break;
       
   561 					}
       
   562 				} else if ( command === 'link' && window.wpLink ) {
       
   563 					window.wpLink.open();
       
   564 				}
       
   565 
       
   566 				if ( command === 'wp-media-library' && typeof wp !== 'undefined' && wp.media && wp.media.editor ) {
       
   567 					wp.media.editor.open( s.id );
       
   568 				}
   600 			});
   569 			});
   601 		},
   570 		},
   602 
   571 
   603 		fade: function( before, during, after ) {
   572 		fade: function( before, during, after ) {
   604 			if ( ! s.element )
   573 			if ( ! s.$fullscreenFader ) {
   605 				api.ui.init();
   574 				api.ui.init();
       
   575 			}
   606 
   576 
   607 			// If any callback bound to before returns false, bail.
   577 			// If any callback bound to before returns false, bail.
   608 			if ( before && ! ps.publish( before ) )
   578 			if ( before && ! ps.publish( before ) ) {
   609 				return;
   579 				return;
   610 
   580 			}
   611 			api.fade.In( s.element, 600, function() {
   581 
   612 				if ( during )
   582 			api.fade.In( s.$fullscreenFader, 200, function() {
       
   583 				if ( during ) {
   613 					ps.publish( during );
   584 					ps.publish( during );
   614 
   585 				}
   615 				api.fade.Out( s.element, 600, function() {
   586 
   616 					if ( after )
   587 				api.fade.Out( s.$fullscreenFader, 200, function() {
       
   588 					if ( after ) {
   617 						ps.publish( after );
   589 						ps.publish( after );
   618 				})
   590 					}
       
   591 				});
   619 			});
   592 			});
   620 		}
   593 		}
   621 	};
   594 	};
   622 
   595 
   623 	api.fade = {
   596 	api.fade = {
   624 		transitionend: 'transitionend webkitTransitionEnd oTransitionEnd',
       
   625 
       
   626 		// Sensitivity to allow browsers to render the blank element before animating.
   597 		// Sensitivity to allow browsers to render the blank element before animating.
   627 		sensitivity: 100,
   598 		sensitivity: 100,
   628 
   599 
   629 		In: function( element, speed, callback, stop ) {
   600 		In: function( element, speed, callback, stop ) {
   630 
   601 
   637 					element.addClass( 'fade-trigger' );
   608 					element.addClass( 'fade-trigger' );
   638 					return element;
   609 					return element;
   639 				}
   610 				}
   640 
   611 
   641 				element.show();
   612 				element.show();
   642 				element.first().one( this.transitionend, function() {
   613 				element.first().one( transitionend, function() {
   643 					callback();
   614 					callback();
   644 				});
   615 				});
       
   616 
   645 				setTimeout( function() { element.addClass( 'fade-trigger' ); }, this.sensitivity );
   617 				setTimeout( function() { element.addClass( 'fade-trigger' ); }, this.sensitivity );
   646 			} else {
   618 			} else {
   647 				if ( stop )
   619 				if ( stop ) {
   648 					element.stop();
   620 					element.stop();
       
   621 				}
   649 
   622 
   650 				element.css( 'opacity', 1 );
   623 				element.css( 'opacity', 1 );
   651 				element.first().fadeIn( speed, callback );
   624 				element.first().fadeIn( speed, callback );
   652 
   625 
   653 				if ( element.length > 1 )
   626 				if ( element.length > 1 ) {
   654 					element.not(':first').fadeIn( speed );
   627 					element.not(':first').fadeIn( speed );
       
   628 				}
   655 			}
   629 			}
   656 
   630 
   657 			return element;
   631 			return element;
   658 		},
   632 		},
   659 
   633 
   661 
   635 
   662 			callback = callback || $.noop;
   636 			callback = callback || $.noop;
   663 			speed = speed || 400;
   637 			speed = speed || 400;
   664 			stop = stop || false;
   638 			stop = stop || false;
   665 
   639 
   666 			if ( ! element.is(':visible') )
   640 			if ( ! element.is(':visible') ) {
   667 				return element;
   641 				return element;
       
   642 			}
   668 
   643 
   669 			if ( api.fade.transitions ) {
   644 			if ( api.fade.transitions ) {
   670 				element.first().one( api.fade.transitionend, function() {
   645 				element.first().one( transitionend, function() {
   671 					if ( element.hasClass('fade-trigger') )
   646 					if ( element.hasClass('fade-trigger') ) {
   672 						return;
   647 						return;
       
   648 					}
   673 
   649 
   674 					element.hide();
   650 					element.hide();
   675 					callback();
   651 					callback();
   676 				});
   652 				});
   677 				setTimeout( function() { element.removeClass( 'fade-trigger' ); }, this.sensitivity );
   653 				setTimeout( function() { element.removeClass( 'fade-trigger' ); }, this.sensitivity );
   678 			} else {
   654 			} else {
   679 				if ( stop )
   655 				if ( stop ) {
   680 					element.stop();
   656 					element.stop();
       
   657 				}
   681 
   658 
   682 				element.first().fadeOut( speed, callback );
   659 				element.first().fadeOut( speed, callback );
   683 
   660 
   684 				if ( element.length > 1 )
   661 				if ( element.length > 1 ) {
   685 					element.not(':first').fadeOut( speed );
   662 					element.not(':first').fadeOut( speed );
       
   663 				}
   686 			}
   664 			}
   687 
   665 
   688 			return element;
   666 			return element;
   689 		},
   667 		},
   690 
   668 
   691 		transitions: (function() { // Check if the browser supports CSS 3.0 transitions
   669 		// Check if the browser supports CSS 3.0 transitions
   692 			var s = document.documentElement.style;
   670 		transitions: ( function() {
   693 
   671 			var style = document.documentElement.style;
   694 			return ( typeof ( s.WebkitTransition ) == 'string' ||
   672 
   695 				typeof ( s.MozTransition ) == 'string' ||
   673 			return ( typeof style.WebkitTransition === 'string' ||
   696 				typeof ( s.OTransition ) == 'string' ||
   674 				typeof style.MozTransition === 'string' ||
   697 				typeof ( s.transition ) == 'string' );
   675 				typeof style.OTransition === 'string' ||
       
   676 				typeof style.transition === 'string' );
   698 		})()
   677 		})()
   699 	};
   678 	};
   700 
   679 
   701 	/**
   680 	/**
   702 	 * Resize API
   681 	 * Resize API
   703 	 *
   682 	 *
   704 	 * Automatically updates textarea height.
   683 	 * Automatically updates textarea height.
   705 	 */
   684 	 */
   706 
       
   707 	api.bind_resize = function() {
   685 	api.bind_resize = function() {
   708 		$(s.textarea_obj).bind('keypress.grow click.grow paste.grow', function(){
   686 		s.$dfwTextarea.on( 'keydown.wp-dfw-resize click.wp-dfw-resize paste.wp-dfw-resize', function() {
   709 			setTimeout( api.resize_textarea, 200 );
   687 			api.resizeTextarea();
   710 		});
   688 		});
   711 	}
   689 	};
   712 
   690 
   713 	api.oldheight = 0;
   691 	api.resizeTextarea = function() {
   714 	api.resize_textarea = function() {
   692 		var node = s.$dfwTextarea[0];
   715 		var txt = s.textarea_obj, newheight;
   693 
   716 
   694 		if ( node.scrollHeight > node.clientHeight ) {
   717 		newheight = txt.scrollHeight > 300 ? txt.scrollHeight : 300;
   695 			node.style.height = node.scrollHeight + 50 + 'px';
   718 
   696 		}
   719 		if ( newheight != api.oldheight ) {
   697 	};
   720 			txt.style.height = newheight + 'px';
   698 
   721 			api.oldheight = newheight;
   699 	// Export
   722 		}
   700 	window.wp = window.wp || {};
   723 	};
   701 	window.wp.editor = window.wp.editor || {};
   724 
   702 	window.wp.editor.fullscreen = api;
   725 })(jQuery);
   703 
       
   704 })( jQuery, window );