Make WordPress Core

Changeset 31919


Ignore:
Timestamp:
03/29/2015 03:13:45 AM (11 years ago)
Author:
azaozz
Message:

Press This:

  • When saving, replace emoji images with chars in the title text.
  • Clean up the title text on paste.

See #31768.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/press-this.js

    r31868 r31919  
    119119
    120120                /**
     121                 * Replace emoji images with chars and sanitize the text content.
     122                 */
     123                function getTitleText() {
     124                        var $element = $( '#title-container' );
     125
     126                        $element.find( 'img.emoji' ).each( function() {
     127                                var $image = $( this );
     128                                $image.replaceWith( $( '<span>' ).text( $image.attr( 'alt' ) ) );
     129                        });
     130
     131                        return sanitizeText( $element.text() );
     132                }
     133
     134                /**
    121135                 * Prepare the form data for saving.
    122136                 */
     
    127141                        editor && editor.save();
    128142
    129                         $( '#post_title' ).val( sanitizeText( $( '#title-container' ).text() ) );
     143                        $( '#post_title' ).val( getTitleText() );
    130144
    131145                        // Make sure to flush out the tags with tagBox before saving
     
    503517                 */
    504518                function monitorPlaceholder() {
    505                         var $titleField = $( '#title-container'),
    506                                 $placeholder = $('.post-title-placeholder');
     519                        var $titleField = $( '#title-container' ),
     520                                $placeholder = $( '.post-title-placeholder' );
    507521
    508522                        $titleField.on( 'focus', function() {
    509                                 $placeholder.addClass('is-hidden');
     523                                $placeholder.addClass( 'is-hidden' );
    510524                        }).on( 'blur', function() {
    511                                 if ( ! $titleField.text() ) {
    512                                         $placeholder.removeClass('is-hidden');
    513                                 }
     525                                if ( ! $titleField.text() && ! $titleField.html() ) {
     526                                        $placeholder.removeClass( 'is-hidden' );
     527                                }
     528                        }).on( 'keyup', function() {
     529                                saveAlert = true;
     530                        }).on( 'paste', function() {
     531                                saveAlert = true;
     532
     533                                setTimeout( function() {
     534                                        $titleField.text( getTitleText() );
     535                                }, 100 );
    514536                        });
    515537
    516                         if ( $titleField.text() ) {
     538                        if ( $titleField.text() || $titleField.html() ) {
    517539                                $placeholder.addClass('is-hidden');
    518540                        }
Note: See TracChangeset for help on using the changeset viewer.