Ticket #38342: 38342.4.diff
File 38342.4.diff, 20.0 KB (added by , 8 years ago) |
---|
-
src/wp-admin/css/dashboard.css
518 518 resize: none; 519 519 } 520 520 521 #quick-press.is-saving .spinner { 522 visibility: inherit; 523 } 524 521 525 /* Dashboard Quick Draft - Drafts list */ 522 526 523 527 .js #dashboard_quick_press .drafts { … … 541 545 margin: 0 12px; 542 546 } 543 547 548 #dashboard_quick_press .drafts ul.is-placeholder li { 549 padding: 3px 0; 550 color: transparent; 551 } 552 553 @keyframes loading-fade { 554 0% { opacity: .5; } 555 50% { opacity: 1; } 556 100% { opacity: .5; } 557 } 558 559 #dashboard_quick_press .drafts ul.is-placeholder li:before, 560 #dashboard_quick_press .drafts ul.is-placeholder li:after { 561 content: ''; 562 display: block; 563 height: 13px; 564 background: #eee; 565 animation: loading-fade 1.6s ease-in-out infinite; 566 } 567 568 #dashboard_quick_press .drafts ul.is-placeholder li:before { 569 margin-bottom: 5px; 570 width: 40%; 571 } 572 573 #dashboard_quick_press .drafts ul.is-placeholder li:after { 574 width: 80%; 575 } 576 544 577 #dashboard_quick_press .drafts li { 545 578 margin-bottom: 1em; 546 579 } 580 581 #dashboard_quick_press .drafts li.is-new { 582 background-color: #fffbe5; 583 } 584 547 585 #dashboard_quick_press .drafts li time { 548 586 color: #72777c; 549 587 } -
src/wp-admin/includes/dashboard.php
491 491 $post_ID = (int) $post->ID; 492 492 ?> 493 493 494 <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>"method="post" id="quick-press" class="initial-form hide-if-no-js">494 <form name="post" method="post" id="quick-press" class="initial-form hide-if-no-js"> 495 495 496 <?php if ( $error_msg ) : ?>497 <div class="error"><?php echo $error_msg; ?></div>498 <?php endif; ?>499 500 496 <div class="input-text-wrap" id="title-wrap"> 501 <label class=" screen-reader-textprompt" for="title" id="title-prompt-text">497 <label class="prompt" for="title" id="title-prompt-text"> 502 498 503 499 <?php 504 500 /** This filter is documented in wp-admin/edit-form-advanced.php */ … … 505 501 echo apply_filters( 'enter_title_here', __( 'Title' ), $post ); 506 502 ?> 507 503 </label> 508 <input type="text" name=" post_title" id="title" autocomplete="off" />504 <input type="text" name="title" id="title" autocomplete="off" /> 509 505 </div> 510 506 511 507 <div class="textarea-wrap" id="description-wrap"> 512 <label class=" screen-reader-textprompt" for="content" id="content-prompt-text"><?php _e( 'What’s on your mind?' ); ?></label>508 <label class="prompt" for="content" id="content-prompt-text"><?php _e( 'What’s on your mind?' ); ?></label> 513 509 <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea> 514 510 </div> 515 516 511 <p class="submit"> 517 <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" /> 518 <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" /> 519 <input type="hidden" name="post_type" value="post" /> 520 <?php wp_nonce_field( 'add-post' ); ?> 512 <div class="error inline" style="display: none;"><p></p></div> 513 <div class="spinner no-float"></div> 521 514 <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?> 522 515 <br class="clear" /> 523 516 </p> … … 524 517 525 518 </form> 526 519 <?php 527 wp_dashboard_recent_drafts();520 echo wp_dashboard_get_recent_drafts_js_template(); 528 521 } 529 522 530 523 /** … … 581 574 } 582 575 echo "</ul>\n</div>"; 583 576 } 577 /** 578 * Get the HTML template for the Quick Draft recent posts. 579 * 580 * @since 4.8.0 581 * 582 * @return string The template HTML. 583 */ 584 function wp_dashboard_get_recent_drafts_js_template() { 585 $template_html = '<div id="quick-press-drafts" class="drafts">'; 586 $template_html .= '<p class="view-all" style="display: none;"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '" aria-label="' . __( 'View all drafts' ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n"; 587 $template_html .= '<h2 class="hide-if-no-js">' . __( 'Drafts' ) . "</h2>\n"; 588 $template_html .= '<script id="tmpl-item-quick-press-draft" type="text/template">'; 589 /* translators: %s: post title */ 590 $template_html .= '<div class="draft-title"><a href="post.php?post={{ data.id }}&action=edit" aria-label="' . esc_attr( __( 'Edit Post' ) ) . '">{{ data.title }}</a>'; 591 $template_html .= '<time datetime="{{ data.date }}">{{ data.formattedDate }}</time></div>'; 592 $template_html .= '{{{ data.formattedContent }}}'; 593 $template_html .= '</script>'; 594 $template_html .= '<ul class="drafts-list is-placeholder">'; 584 595 596 // Add a placeholder for each draft. 597 $query_args = array( 598 'post_type' => 'post', 599 'post_status' => 'draft', 600 'author' => get_current_user_id(), 601 'posts_per_page' => 4, 602 'fields' => 'ids', 603 'no_found_rows' => true, 604 ); 605 606 /** This filter is documented in wp-admin/includes/dashboard.php */ 607 $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args ); 608 609 $count_query = new WP_Query( $query_args ); 610 if ( $count_query->have_posts() ) { 611 for ( $i = 0; $i < ( $count_query->post_count ? $count_query->post_count : 4 ); $i++ ) { 612 $template_html .= '<li><span class="screen-reader-text">' . esc_html( __( 'Loading…' ) ) . '</span></li>'; 613 } 614 } 615 $template_html .= '</ul></div>'; 616 617 return $template_html; 618 } 619 585 620 /** 586 621 * Outputs a row for the Recent Comments widget. 587 622 * -
src/wp-admin/js/dashboard.js
1 /* global pagenow, ajaxurl, postboxes, wpActiveEditor:true */2 var ajaxWidgets, ajaxPopulateWidgets , quickPressLoad;1 /* global _, wp, quickPress, pagenow, ajaxurl, postboxes, wpActiveEditor:true */ 2 var ajaxWidgets, ajaxPopulateWidgets; 3 3 4 4 jQuery(document).ready( function($) { 5 5 var welcomePanel = $( '#welcome-panel' ), … … 61 61 62 62 postboxes.add_postbox_toggles(pagenow, { pbshow: ajaxPopulateWidgets } ); 63 63 64 /* QuickPress */65 quickPressLoad = function() {66 var act = $('#quickpost-action'), t;67 68 $( '#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]' ).prop( 'disabled' , false );69 70 t = $('#quick-press').submit( function( e ) {71 e.preventDefault();72 $('#dashboard_quick_press #publishing-action .spinner').show();73 $('#quick-press .submit input[type="submit"], #quick-press .submit input[type="reset"]').prop('disabled', true);74 75 $.post( t.attr( 'action' ), t.serializeArray(), function( data ) {76 // Replace the form, and prepend the published post.77 $('#dashboard_quick_press .inside').html( data );78 $('#quick-press').removeClass('initial-form');79 quickPressLoad();80 highlightLatestPost();81 $('#title').focus();82 });83 84 function highlightLatestPost () {85 var latestPost = $('.drafts ul li').first();86 latestPost.css('background', '#fffbe5');87 setTimeout(function () {88 latestPost.css('background', 'none');89 }, 1000);90 }91 } );92 93 $('#publish').click( function() { act.val( 'post-quickpress-publish' ); } );94 95 $('#title, #tags-input, #content').each( function() {96 var input = $(this), prompt = $('#' + this.id + '-prompt-text');97 98 if ( '' === this.value ) {99 prompt.removeClass('screen-reader-text');100 }101 102 prompt.click( function() {103 $(this).addClass('screen-reader-text');104 input.focus();105 });106 107 input.blur( function() {108 if ( '' === this.value ) {109 prompt.removeClass('screen-reader-text');110 }111 });112 113 input.focus( function() {114 prompt.addClass('screen-reader-text');115 });116 });117 118 $('#quick-press').on( 'click focusin', function() {119 wpActiveEditor = 'content';120 });121 122 autoResizeTextarea();123 };124 quickPressLoad();125 126 64 $( '.meta-box-sortables' ).sortable( 'option', 'containment', '#wpwrap' ); 127 65 128 66 function autoResizeTextarea() { … … 186 124 }); 187 125 } 188 126 127 autoResizeTextarea(); 128 129 }); 130 131 wp.api.loadPromise.done( function() { 132 var $ = jQuery, 133 QuickPress = {}, 134 draftsCollection; 135 136 /** 137 * Models 138 */ 139 140 QuickPress.Models = {}; 141 142 QuickPress.Models.Draft = wp.api.models.Post.extend( { 143 initialize: function( attributes ) { 144 if ( attributes ) { 145 this.set( this.normalizeAttributes( attributes ) ); 146 } 147 }, 148 149 parse: function( response ) { 150 return this.normalizeAttributes( response ); 151 }, 152 153 normalizeAttributes: function( attributes ) { 154 var date; 155 156 if ( ! attributes ) { 157 return attributes; 158 } 159 160 // Post entities from the REST API include the content and title in 161 // nested objects, but our new form model will assign as a string, 162 // so we normalize to simplify display logic 163 164 if ( 'object' === typeof attributes.content ) { 165 attributes.content = attributes.content.rendered; 166 } 167 168 if ( 'object' === typeof attributes.title ) { 169 attributes.title = attributes.title.rendered; 170 } 171 172 attributes.formattedContent = wp.formatting.trimWords( attributes.content, 10 ); 173 174 // We can format dates using newer browser i18n features, but also 175 // provide a fallback to the not-as-nice Date#toLocaleDateString 176 date = new Date( wp.api.utils.parseISO8601( attributes.date ) ); 177 date.setTime( date.getTime() + ( date.getTimezoneOffset() * 60 * 1000 ) ); 178 if ( 'undefined' !== typeof Intl && Intl.DateTimeFormat ) { 179 attributes.formattedDate = new Intl.DateTimeFormat( undefined, { 180 month: 'long', 181 day: 'numeric', 182 year: 'numeric' 183 } ).format( date ); 184 } else { 185 attributes.formattedDate = date.toLocaleDateString(); 186 } 187 188 return attributes; 189 }, 190 191 validate: function( attributes ) { 192 if ( ! attributes.title && ! attributes.content ) { 193 return 'no-content'; 194 } 195 } 196 } ); 197 198 /** 199 * Collections 200 */ 201 202 QuickPress.Collections = {}; 203 204 QuickPress.Collections.Drafts = wp.api.collections.Posts.extend( { 205 model: QuickPress.Models.Draft, 206 207 comparator: function( a, b ) { 208 // Sort by date descending, date is an ISO8601 string and can be 209 // compared lexicographically 210 return a.get( 'date' ) < b.get( 'date' ); 211 } 212 } ); 213 214 /** 215 * Collections 216 */ 217 218 QuickPress.Views = {}; 219 220 QuickPress.Views.Form = wp.Backbone.View.extend( { 221 events: { 222 'click :input': 'hidePromptAndFocus', 223 'focus :input': 'hidePrompt', 224 'blur :input': 'showPrompt', 225 reset: 'showAllPrompts', 226 click: 'setActiveEditor', 227 focusin: 'setActiveEditor', 228 submit: 'submit' 229 }, 230 231 initialize: function() { 232 this.showAllPrompts(); 233 234 this.listenTo( this.model, 'invalid', this.render ); 235 this.listenTo( this.model, 'error', this.showSyncError ); 236 }, 237 238 togglePrompt: function( element, visible ) { 239 var $input = $( element ), 240 hasContent = $input.val().length > 0; 241 242 $( element ).siblings( '.prompt' ).toggleClass( 'screen-reader-text', ! visible || hasContent ); 243 }, 244 245 showAllPrompts: function() { 246 this.$el.find( ':input' ).each( _.bind( function( i, input ) { 247 // Prompt toggling must be deferred because the reset event is 248 // fired before the input values have been cleared 249 _.defer( _.bind( this.togglePrompt, this, input, true ) ); 250 }, this ) ); 251 }, 252 253 showPrompt: function( event ) { 254 this.togglePrompt( event.target, true ); 255 }, 256 257 hidePrompt: function( event ) { 258 this.togglePrompt( event.target, false ); 259 }, 260 261 hidePromptAndFocus: function( event ) { 262 this.togglePrompt( event.target, false ); 263 $( ':input', event.target ).focus(); 264 }, 265 266 setActiveEditor: function() { 267 wpActiveEditor = 'content'; 268 }, 269 270 showSyncError: function() { 271 this.syncError = true; 272 this.render(); 273 }, 274 275 submit: function( event ) { 276 var values; 277 278 delete this.syncError; 279 event.preventDefault(); 280 281 // jQuery's serializeArray returns an array of field tuples, which 282 // we need to transform into an object before sending to API 283 values = _.reduce( this.$el.serializeArray(), function( memo, field ) { 284 memo[ field.name ] = field.value; 285 return memo; 286 }, {} ); 287 288 // Ensure that by setting these fields on model that it is valid 289 // before proceeding with save 290 this.model.set( values ); 291 if ( ! this.model.isValid() ) { 292 return; 293 } 294 295 // Show a spinner during the callback. 296 this.$el.addClass( 'is-saving' ); 297 298 this.model.save() 299 .always( _.bind( function() { 300 this.$el.removeClass( 'is-saving' ); 301 }, this ) ) 302 .success( _.bind( function() { 303 this.collection.add( this.model ); 304 this.model = new QuickPress.Models.Draft(); 305 this.el.reset(); 306 }, this ) ); 307 }, 308 309 render: function() { 310 var $error = this.$el.find( '.error' ), 311 errorText; 312 313 if ( this.model.validationError ) { 314 // Error via submission validation 315 errorText = quickPress.l10n[ this.model.validationError ]; 316 } else if ( this.syncError ) { 317 // Error via API save failure 318 errorText = quickPress.l10n.error; 319 } 320 321 // Error notice is only visible if error text determined 322 $error.toggle( !! errorText ); 323 if ( errorText ) { 324 $error.html( $( '<p />', { text: errorText } ) ); 325 } 326 } 327 } ); 328 329 QuickPress.Views.DraftList = wp.Backbone.View.extend( { 330 initialize: function() { 331 this.listenTo( this.collection, 'sync', this.onDraftsLoaded ); 332 }, 333 334 onDraftsLoaded: function() { 335 this.listenTo( this.collection, 'add', this.renderNew ); 336 this.render(); 337 }, 338 339 renderNew: function() { 340 // Display highlight effect to first (added) item for one second 341 var $newEl = this.render().$el.find( 'li:first' ).addClass( 'is-new' ); 342 setTimeout( function() { 343 $newEl.removeClass( 'is-new' ); 344 }, 1000 ); 345 }, 346 347 render: function() { 348 349 // Hide drafts list if no drafts exist 350 this.$el.toggle( this.collection.length > 0 ); 351 352 // "View All" link is visible if 5 or more drafts, since we only 353 // show a maximum of 5 drafts in the list 354 this.$el.find( '.view-all' ).toggle( this.collection.length > 0 ); 355 356 // If after drafts load, this could be the first render, so remove 357 // placeholder effect and render the first four drafts 358 this.$el.find( '.drafts-list' ) 359 .removeClass( 'is-placeholder' ) 360 .html( _.map( this.collection.models, function( draft ) { 361 return new QuickPress.Views.DraftListItem( { 362 model: draft 363 } ).render().el; 364 } ) ); 365 366 return this; 367 } 368 } ); 369 370 QuickPress.Views.DraftListItem = wp.Backbone.View.extend( { 371 tagName: 'li', 372 373 template: wp.template( 'item-quick-press-draft' ), 374 375 render: function() { 376 this.$el.html( this.template( this.model.attributes ) ); 377 378 return this; 379 } 380 } ); 381 382 /** 383 * Initialize 384 */ 385 386 // Fetch drafts 387 draftsCollection = new QuickPress.Collections.Drafts(); 388 draftsCollection.fetch( { 389 data: { 390 status: 'draft', 391 author: quickPress.currentUserId, 392 per_page: 4, 393 'quick-draft-post-list': true 394 } 395 } ); 396 397 // Drafts list is initialized but not rendered until drafts load 398 new QuickPress.Views.DraftList( { 399 el: '#quick-press-drafts', 400 collection: draftsCollection 401 } ); 402 403 new QuickPress.Views.Form( { 404 el: '#quick-press', 405 model: new QuickPress.Models.Draft(), 406 collection: draftsCollection 407 } ).render(); 189 408 } ); -
src/wp-content/themes/twentyfourteen/functions.php
545 545 if ( ! class_exists( 'Featured_Content' ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { 546 546 require get_template_directory() . '/inc/featured-content.php'; 547 547 } 548 549 function filter_the_draft_list( $query_args ) { 550 $query_args['posts_per_page'] = 10; 551 return $query_args; 552 } 553 add_filter( 'dashboard_recent_drafts_query_args', 'filter_the_draft_list' ); -
src/wp-includes/js/wp-util.js
121 121 } 122 122 }; 123 123 124 // wp.formatting 125 // ------ 126 // 127 // Tools for formatting strings 128 wp.formatting = { 129 settings: settings.formatting || {}, 130 131 /** 132 * Trims text to a certain number of words. 133 * 134 * @see wp_trim_words 135 * 136 * @param {string} text Text to trim. 137 * @param {?number} numWords Number of words (default: 55). 138 * @param {?string} more What to append if text needs to be trimmed (default: '…'). 139 * @return {string} Trimmed text. 140 */ 141 trimWords: function( text, numWords, more ) { 142 var words, separator; 143 144 if ( 'undefined' === typeof numWords ) { 145 numWords = 55; 146 } 147 148 if ( 'undefined' === typeof more ) { 149 more = wp.formatting.settings.trimWordsMore; 150 } 151 152 text = text.replace( /[\n\r\t ]+/g, ' ' ).replace( /^ | $/g, '' ); 153 154 if ( wp.formatting.settings.trimWordsByCharacter ) { 155 separator = ''; 156 } else { 157 separator = ' '; 158 } 159 160 words = text.split( separator ); 161 162 if ( words.length <= numWords ) { 163 return words.join( separator ); 164 } 165 166 return words.slice( 0, numWords ).join( separator ) + more; 167 } 168 }; 169 124 170 }(jQuery)); -
src/wp-includes/rest-api.php
164 164 add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 ); 165 165 166 166 add_filter( 'rest_pre_dispatch', 'rest_handle_options_request', 10, 3 ); 167 168 // Legacy filter for Quick Draft recent posts. 169 add_filter( 'rest_post_query', 'rest_filter_quick_draft_query', 10, 2 ); 167 170 } 168 171 169 172 /** 173 * Filter query args used by he Quick Draft recent posts list. 174 * 175 * @param array $args Key value array of query var to query value. 176 * @param WP_REST_Request $request The request used. 177 */ 178 function rest_filter_quick_draft_query( $query_args, $request ) { 179 180 // Only modify Quick Draft queries. 181 $params = $request->get_query_params(); 182 183 if ( ! isset( $params['quick-draft-post-list'] ) ) { 184 return $response; 185 } 186 187 /** This filter is documented in wp-admin/includes/dashboard.php */ 188 $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args ); 189 190 return $query_args; 191 192 } 193 194 /** 170 195 * Registers default REST API routes. 171 196 * 172 197 * @since 4.7.0 -
src/wp-includes/script-loader.php
333 333 'ajax' => array( 334 334 'url' => admin_url( 'admin-ajax.php', 'relative' ), 335 335 ), 336 'formatting' => array( 337 'trimWordsMore' => __( '…' ), 338 /* 339 * translators: If your word count is based on single characters (e.g. East Asian characters), 340 * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'. 341 * Do not translate into your own language. 342 */ 343 'trimWordsByCharacter' => strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ), 344 ), 336 345 ) ); 337 346 338 347 $scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array('backbone', 'wp-util'), false, 1 ); … … 718 727 'current' => __( 'Current Color' ), 719 728 ) ); 720 729 721 $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox' ), false, 1 ); 730 $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-api', 'wp-backbone' ), false, 1 ); 731 did_action( 'init' ) && $scripts->localize( 'dashboard', 'quickPress', array( 732 'currentUserId' => get_current_user_id(), 733 'l10n' => array( 734 'no-content' => __( 'Post content cannot be empty.' ), 735 'error' => __( 'An error has occurred. Please reload the page and try again.' ) 736 ) 737 ) ); 722 738 723 739 $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" ); 724 740