wp/wp-admin/js/dashboard.js
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     1
/* global pagenow, ajaxurl, postboxes, wpActiveEditor:true */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
jQuery(document).ready( function($) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     5
	var welcomePanel = $( '#welcome-panel' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
		welcomePanelHide = $('#wp_welcome_panel-hide'),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     7
		updateWelcomePanel;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
	updateWelcomePanel = function( visible ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
		$.post( ajaxurl, {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
			action: 'update-welcome-panel',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
			visible: visible,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
			welcomepanelnonce: $( '#welcomepanelnonce' ).val()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	};
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
	if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
		welcomePanel.removeClass('hidden');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	$('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
		e.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
		welcomePanel.addClass('hidden');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		updateWelcomePanel( 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		$('#wp_welcome_panel-hide').prop('checked', false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	welcomePanelHide.click( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		welcomePanel.toggleClass('hidden', ! this.checked );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		updateWelcomePanel( this.checked ? 1 : 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	// These widgets are sometimes populated via ajax
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
	ajaxWidgets = ['dashboard_primary'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	ajaxPopulateWidgets = function(el) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
		function show(i, id) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
			var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
			if ( e.length ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
				p = e.parent();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
				setTimeout( function(){
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
					p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
						p.hide().slideDown('normal', function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
							$(this).css('display', '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
				}, i * 500 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
		if ( el ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			el = el.toString();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
			if ( $.inArray(el, ajaxWidgets) !== -1 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
				show(0, el);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
			$.each( ajaxWidgets, show );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	ajaxPopulateWidgets();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	/* QuickPress */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	quickPressLoad = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
		var act = $('#quickpost-action'), t;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
		$( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		t = $('#quick-press').submit( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
			$('#dashboard_quick_press #publishing-action .spinner').show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
			$('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
			$.post( t.attr( 'action' ), t.serializeArray(), function( data ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
				// Replace the form, and prepend the published post.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
				$('#dashboard_quick_press .inside').html( data );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
				$('#quick-press').removeClass('initial-form');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
				quickPressLoad();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
				highlightLatestPost();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
				$('#title').focus();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
			});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
			function highlightLatestPost () {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
				var latestPost = $('.drafts ul li').first();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
				latestPost.css('background', '#fffbe5');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
				setTimeout(function () {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
					latestPost.css('background', 'none');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
				}, 1000);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		$('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
		$('#title, #tags-input, #content').each( function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			var input = $(this), prompt = $('#' + this.id + '-prompt-text');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
			if ( '' === this.value ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
				prompt.removeClass('screen-reader-text');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
			prompt.click( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
				$(this).addClass('screen-reader-text');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
				input.focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
			input.blur( function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
				if ( '' === this.value ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
					prompt.removeClass('screen-reader-text');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
			input.focus( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
				prompt.addClass('screen-reader-text');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		$('#quick-press').on( 'click focusin', function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			wpActiveEditor = 'content';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
		autoResizeTextarea();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
	quickPressLoad();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	$( '.meta-box-sortables' ).sortable( 'option', 'containment', 'document' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
	function autoResizeTextarea() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
		if ( document.documentMode && document.documentMode < 9 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
		// Add a hidden div. We'll copy over the text from the textarea to measure its height.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
		$('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
		var clone = $('.quick-draft-textarea-clone'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
			editor = $('#content'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
			editorHeight = editor.height(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
			// 100px roughly accounts for browser chrome and allows the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
			// save draft button to show on-screen at the same time.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
			editorMaxHeight = $(window).height() - 100;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
		// Match up textarea and clone div as much as possible.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
		// Padding cannot be reliably retrieved using shorthand in all browsers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
		clone.css({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
			'font-family': editor.css('font-family'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
			'font-size':   editor.css('font-size'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
			'line-height': editor.css('line-height'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
			'padding-bottom': editor.css('paddingBottom'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
			'padding-left': editor.css('paddingLeft'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
			'padding-right': editor.css('paddingRight'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
			'padding-top': editor.css('paddingTop'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
			'white-space': 'pre-wrap',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
			'word-wrap': 'break-word',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
			'display': 'none'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
		// propertychange is for IE < 9
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
		editor.on('focus input propertychange', function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
			var $this = $(this),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
				// &nbsp; is to ensure that the height of a final trailing newline is included.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
				textareaContent = $this.val() + '&nbsp;',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
				// 2px is for border-top & border-bottom
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
				cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
			// Default to having scrollbars
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
			editor.css('overflow-y', 'auto');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
			// Only change the height if it has indeed changed and both heights are below the max.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
			if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
				return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
			// Don't allow editor to exceed height of window.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
			// This is also bound in CSS to a max-height of 1300px to be extra safe.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
			if ( cloneHeight > editorMaxHeight ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
				editorHeight = editorMaxHeight;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
				editorHeight = cloneHeight;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
			// No scrollbars as we change height, not for IE < 9
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
			editor.css('overflow', 'hidden');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
			$this.css('height', editorHeight + 'px');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
} );