1 /* global pagenow, ajaxurl, postboxes, wpActiveEditor:true */
2 var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad;
4 jQuery(document).ready( function($) {
5 var welcomePanel = $( '#welcome-panel' ),
6 welcomePanelHide = $('#wp_welcome_panel-hide'),
9 updateWelcomePanel = function( visible ) {
11 action: 'update-welcome-panel',
13 welcomepanelnonce: $( '#welcomepanelnonce' ).val()
17 if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) {
18 welcomePanel.removeClass('hidden');
21 $('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) {
23 welcomePanel.addClass('hidden');
24 updateWelcomePanel( 0 );
25 $('#wp_welcome_panel-hide').prop('checked', false);
28 welcomePanelHide.click( function() {
29 welcomePanel.toggleClass('hidden', ! this.checked );
30 updateWelcomePanel( this.checked ? 1 : 0 );
33 // These widgets are sometimes populated via ajax
34 ajaxWidgets = ['dashboard_primary'];
36 ajaxPopulateWidgets = function(el) {
37 function show(i, id) {
38 var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading');
41 setTimeout( function(){
42 p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
43 p.hide().slideDown('normal', function(){
44 $(this).css('display', '');
53 if ( $.inArray(el, ajaxWidgets) !== -1 ) {
57 $.each( ajaxWidgets, show );
60 ajaxPopulateWidgets();
62 postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } );
65 quickPressLoad = function() {
66 var act = $('#quickpost-action'), t;
67 t = $('#quick-press').submit( function() {
68 $('#dashboard_quick_press #publishing-action .spinner').show();
69 $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);
71 $.post( t.attr( 'action' ), t.serializeArray(), function( data ) {
72 // Replace the form, and prepend the published post.
73 $('#dashboard_quick_press .inside').html( data );
74 $('#quick-press').removeClass('initial-form');
76 highlightLatestPost();
80 function highlightLatestPost () {
81 var latestPost = $('.drafts ul li').first();
82 latestPost.css('background', '#fffbe5');
83 setTimeout(function () {
84 latestPost.css('background', 'none');
91 $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );
93 $('#title, #tags-input, #content').each( function() {
94 var input = $(this), prompt = $('#' + this.id + '-prompt-text');
96 if ( '' === this.value ) {
97 prompt.removeClass('screen-reader-text');
100 prompt.click( function() {
101 $(this).addClass('screen-reader-text');
105 input.blur( function() {
106 if ( '' === this.value ) {
107 prompt.removeClass('screen-reader-text');
111 input.focus( function() {
112 prompt.addClass('screen-reader-text');
116 $('#quick-press').on( 'click focusin', function() {
117 wpActiveEditor = 'content';
120 autoResizeTextarea();
124 $( '.meta-box-sortables' ).sortable( 'option', 'containment', 'document' );
126 function autoResizeTextarea() {
127 if ( document.documentMode && document.documentMode < 9 ) {
131 // Add a hidden div. We'll copy over the text from the textarea to measure its height.
132 $('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
134 var clone = $('.quick-draft-textarea-clone'),
135 editor = $('#content'),
136 editorHeight = editor.height(),
137 // 100px roughly accounts for browser chrome and allows the
138 // save draft button to show on-screen at the same time.
139 editorMaxHeight = $(window).height() - 100;
141 // Match up textarea and clone div as much as possible.
142 // Padding cannot be reliably retrieved using shorthand in all browsers.
144 'font-family': editor.css('font-family'),
145 'font-size': editor.css('font-size'),
146 'line-height': editor.css('line-height'),
147 'padding-bottom': editor.css('paddingBottom'),
148 'padding-left': editor.css('paddingLeft'),
149 'padding-right': editor.css('paddingRight'),
150 'padding-top': editor.css('paddingTop'),
151 'white-space': 'pre-wrap',
152 'word-wrap': 'break-word',
156 // propertychange is for IE < 9
157 editor.on('focus input propertychange', function() {
159 // is to ensure that the height of a final trailing newline is included.
160 textareaContent = $this.val() + ' ',
161 // 2px is for border-top & border-bottom
162 cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2;
164 // Default to having scrollbars
165 editor.css('overflow-y', 'auto');
167 // Only change the height if it has indeed changed and both heights are below the max.
168 if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) {
172 // Don't allow editor to exceed height of window.
173 // This is also bound in CSS to a max-height of 1300px to be extra safe.
174 if ( cloneHeight > editorMaxHeight ) {
175 editorHeight = editorMaxHeight;
177 editorHeight = cloneHeight;
180 // No scrollbars as we change height, not for IE < 9
181 editor.css('overflow', 'hidden');
183 $this.css('height', editorHeight + 'px');