Changeset 42393
- Timestamp:
- 12/14/2017 02:10:11 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/dashboard.js
r41978 r42393 3 3 window.wp = window.wp || {}; 4 4 5 6 7 8 9 5 10 jQuery(document).ready( function($) { 6 11 var welcomePanel = $( '#welcome-panel' ), … … 8 13 updateWelcomePanel; 9 14 15 16 17 18 19 20 21 22 23 10 24 updateWelcomePanel = function( visible ) { 11 25 $.post( ajaxurl, { … … 16 30 }; 17 31 32 18 33 if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) { 19 34 welcomePanel.removeClass('hidden'); 20 35 } 21 36 37 22 38 $('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) { 23 39 e.preventDefault(); … … 27 43 }); 28 44 45 29 46 welcomePanelHide.click( function() { 30 47 welcomePanel.toggleClass('hidden', ! this.checked ); … … 32 49 }); 33 50 34 // These widgets are sometimes populated via ajax 51 /** 52 * These widgets can be populated via ajax. 53 * 54 * @since 2.7.0 55 * 56 * @type {string[]} 57 * 58 * @global 59 */ 35 60 ajaxWidgets = ['dashboard_primary']; 36 61 62 63 64 65 66 67 68 69 70 71 72 37 73 ajaxPopulateWidgets = function(el) { 74 75 76 77 78 79 80 81 38 82 function show(i, id) { 39 83 var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading'); 84 40 85 if ( e.length ) { 41 86 p = e.parent(); 42 87 setTimeout( function(){ 88 43 89 p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() { 90 44 91 p.hide().slideDown('normal', function(){ 45 92 $(this).css('display', ''); … … 50 97 } 51 98 99 52 100 if ( el ) { 53 101 el = el.toString(); 102 54 103 if ( $.inArray(el, ajaxWidgets) !== -1 ) { 104 55 105 show(0, el); 56 106 } 57 107 } else { 108 58 109 $.each( ajaxWidgets, show ); 59 110 } 60 111 }; 112 113 61 114 ajaxPopulateWidgets(); 62 115 116 63 117 postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } ); 64 118 65 /* QuickPress */ 119 /** 120 * Control the Quick Press (Quick Draft) widget. 121 * 122 * @since 2.7.0 123 * 124 * @global 125 * 126 * @returns {void} 127 */ 66 128 quickPressLoad = function() { 67 129 var act = $('#quickpost-action'), t; 68 130 131 69 132 $( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false ); 70 133 71 134 t = $('#quick-press').submit( function( e ) { 72 135 e.preventDefault(); 136 137 73 138 $('#dashboard_quick_press #publishing-action .spinner').show(); 139 140 74 141 $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true); 75 142 143 76 144 $.post( t.attr( 'action' ), t.serializeArray(), function( data ) { 77 145 // Replace the form, and prepend the published post. … … 80 148 quickPressLoad(); 81 149 highlightLatestPost(); 150 151 82 152 $('#title').focus(); 83 153 }); 84 154 155 156 157 158 159 85 160 function highlightLatestPost () { 86 161 var latestPost = $('.drafts ul li').first(); … … 92 167 } ); 93 168 169 94 170 $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } ); 95 171 172 173 174 175 176 177 178 179 96 180 $('#title, #tags-input, #content').each( function() { 97 181 var input = $(this), prompt = $('#' + this.id + '-prompt-text'); … … 125 209 quickPressLoad(); 126 210 211 127 212 $( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' ); 128 213 214 215 216 217 218 219 220 129 221 function autoResizeTextarea() { 222 130 223 if ( document.documentMode && document.documentMode < 9 ) { 131 224 return; … … 138 231 editor = $('#content'), 139 232 editorHeight = editor.height(), 140 // 100px roughly accounts for browser chrome and allows the 141 // save draft button to show on-screen at the same time. 233 /* 234 * 100px roughly accounts for browser chrome and allows the 235 * save draft button to show on-screen at the same time. 236 */ 142 237 editorMaxHeight = $(window).height() - 100; 143 238 144 // Match up textarea and clone div as much as possible. 145 // Padding cannot be reliably retrieved using shorthand in all browsers. 239 /* 240 * Match up textarea and clone div as much as possible. 241 * Padding cannot be reliably retrieved using shorthand in all browsers. 242 */ 146 243 clone.css({ 147 244 'font-family': editor.css('font-family'), … … 157 254 }); 158 255 159 // propertychange is for IE < 9256 // 160 257 editor.on('focus input propertychange', function() { 161 258 var $this = $(this), 162 // is to ensure that the height of a final trailing newline is included. 259 // Add a non-breaking space to ensure that the height of a trailing newline is 260 // included. 163 261 textareaContent = $this.val() + ' ', 164 // 2px is for border-top & border-bottom262 // 165 263 cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2; 166 264 167 // Default to having scrollbars265 // Default to 168 266 editor.css('overflow-y', 'auto'); 169 267 170 // Only change the height if it has indeedchanged and both heights are below the max.268 // Only change the height if it has changed and both heights are below the max. 171 269 if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) { 172 270 return; 173 271 } 174 272 175 // Don't allow editor to exceed height of window. 176 // This is also bound in CSS to a max-height of 1300px to be extra safe. 273 /* 274 * Don't allow editor to exceed the height of the window. 275 * This is also bound in CSS to a max-height of 1300px to be extra safe. 276 */ 177 277 if ( cloneHeight > editorMaxHeight ) { 178 278 editorHeight = editorMaxHeight; … … 181 281 } 182 282 183 // No scrollbars as we change height, not for IE < 9283 // 184 284 editor.css('overflow', 'hidden'); 185 285 … … 196 296 app; 197 297 198 app = window.wp.communityEvents = { 298 /** 299 * Global Community Events namespace. 300 * 301 * @since 4.8.0 302 * 303 * @memberOf wp 304 * @namespace wp.communityEvents 305 */ 306 app = window.wp.communityEvents = /** @lends wp.communityEvents */{ 199 307 initialized: false, 200 308 model: null, … … 204 312 * 205 313 * @since 4.8.0 314 315 206 316 */ 207 317 init: function() { … … 234 344 $container.on( 'click', '.community-events-toggle-location, .community-events-cancel', app.toggleLocationForm ); 235 345 346 347 348 349 350 236 351 $container.on( 'submit', '.community-events-form', function( event ) { 237 352 var location = $.trim( $( '#community-events-location' ).val() ); … … 268 383 * @param {event|string} action 'show' or 'hide' to specify a state; 269 384 * or an event object to flip between states. 385 386 270 387 */ 271 388 toggleLocationForm: function( action ) { … … 310 427 * @since 4.8.0 311 428 * 312 * @param {object} requestParams 429 * @param {Object} requestParams REST API Request parameters object. 430 * 431 * @returns {void} 313 432 */ 314 433 getEvents: function( requestParams ) { … … 363 482 * @param {string} initiatedBy 'user' to indicate that this was triggered manually by the user; 364 483 * 'app' to indicate it was triggered automatically by the app itself. 484 485 365 486 */ 366 487 renderEventsTemplate: function( templateParams, initiatedBy ) {
Note: See TracChangeset
for help on using the changeset viewer.