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 * Initializes the dashboard widget functionality. 7 * 8 * @since 2.7.0 9 */ 5 10 jQuery(document).ready( function($) { 6 11 var welcomePanel = $( '#welcome-panel' ), … … 8 13 updateWelcomePanel; 9 14 15 /** 16 * Saves the visibility of the welcome panel. 17 * 18 * @since 3.3.0 19 * 20 * @param {boolean} visible Should it be visible or not. 21 * 22 * @returns {void} 23 */ 10 24 updateWelcomePanel = function( visible ) { 11 25 $.post( ajaxurl, { … … 16 30 }; 17 31 32 // Unhide the welcome panel if the Welcome Option checkbox is checked. 18 33 if ( welcomePanel.hasClass('hidden') && welcomePanelHide.prop('checked') ) { 19 34 welcomePanel.removeClass('hidden'); 20 35 } 21 36 37 // Hide the welcome panel when the dismiss button or close button is clicked. 22 38 $('.welcome-panel-close, .welcome-panel-dismiss a', welcomePanel).click( function(e) { 23 39 e.preventDefault(); … … 27 43 }); 28 44 45 // Set welcome panel visibility based on Welcome Option checkbox value. 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 * Triggers widget updates via AJAX. 64 * 65 * @since 2.7.0 66 * 67 * @global 68 * 69 * @param {string} el Optional. Widget to fetch or none to update all. 70 * 71 * @returns {void} 72 */ 37 73 ajaxPopulateWidgets = function(el) { 74 /** 75 * Fetch the latest representation of the widget via Ajax and show it. 76 * 77 * @param {number} i Number of half-seconds to use as the timeout. 78 * @param {string} id ID of the element which is going to be checked for changes. 79 * 80 * @returns {void} 81 */ 38 82 function show(i, id) { 39 83 var p, e = $('#' + id + ' div.inside:visible').find('.widget-loading'); 84 // If the element is found in the dom, queue to load latest representation. 40 85 if ( e.length ) { 41 86 p = e.parent(); 42 87 setTimeout( function(){ 88 // Request the widget content. 43 89 p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() { 90 // Hide the parent and slide it out for visual fancyness. 44 91 p.hide().slideDown('normal', function(){ 45 92 $(this).css('display', ''); … … 50 97 } 51 98 99 // If we have received a specific element to fetch, check if it is valid. 52 100 if ( el ) { 53 101 el = el.toString(); 102 // If the element is available as AJAX widget, show it. 54 103 if ( $.inArray(el, ajaxWidgets) !== -1 ) { 104 // Show element without any delay. 55 105 show(0, el); 56 106 } 57 107 } else { 108 // Walk through all ajaxWidgets, loading them after each other. 58 109 $.each( ajaxWidgets, show ); 59 110 } 60 111 }; 112 113 // Initially populate ajax widgets. 61 114 ajaxPopulateWidgets(); 62 115 116 // Register ajax widgets as postbox toggles. 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 // Enable the submit buttons. 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 // Show a spinner. 73 138 $('#dashboard_quick_press #publishing-action .spinner').show(); 139 140 // Disable the submit button to prevent duplicate submissions. 74 141 $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true); 75 142 143 // Post the entered data to save it. 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 // Focus the title to allow for quickly drafting another post. 82 152 $('#title').focus(); 83 153 }); 84 154 155 /** 156 * Highlights the latest post for one second. 157 * 158 * @returns {void} 159 */ 85 160 function highlightLatestPost () { 86 161 var latestPost = $('.drafts ul li').first(); … … 92 167 } ); 93 168 169 // Change the QuickPost action to the publish value. 94 170 $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } ); 95 171 172 /** 173 * Adds accessibility context to inputs. 174 * 175 * Use the 'screen-reader-text' class to hide the label when entering a value. 176 * Apply it when the input is not empty or the input has focus. 177 * 178 * @returns {void} 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 // Enable the dragging functionality of the widgets. 127 212 $( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' ); 128 213 214 /** 215 * Adjust the height of the textarea based on the content. 216 * 217 * @since 3.6.0 218 * 219 * @returns {void} 220 */ 129 221 function autoResizeTextarea() { 222 // When IE8 or older is used to render this document, exit. 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 // The 'propertychange' is used in IE < 9. 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 // Add 2px to compensate for border-top & border-bottom. 165 263 cloneHeight = clone.css('width', $this.css('width')).text(textareaContent).outerHeight() + 2; 166 264 167 // Default to having scrollbars265 // Default to show a vertical scrollbar, if needed. 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 // Disable scrollbars because we adjust the height to the content. 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 * @returns {void} 206 316 */ 207 317 init: function() { … … 234 344 $container.on( 'click', '.community-events-toggle-location, .community-events-cancel', app.toggleLocationForm ); 235 345 346 /** 347 * Filters events based on entered location. 348 * 349 * @returns {void} 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 * @returns {void} 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 * @returns {void} 365 486 */ 366 487 renderEventsTemplate: function( templateParams, initiatedBy ) {
Note: See TracChangeset
for help on using the changeset viewer.