WordPress.org

Make WordPress Core

Changeset 28183 for trunk


Ignore:
Timestamp:
04/22/2014 06:20:54 PM (7 years ago)
Author:
wonderboymusic
Message:

Persisting <track> elements as the body of a [video] shortcode in MCE Views:

  • When generating the view's HTML, ensure that the shortcode's content is added to the model
  • Add a PostProcess event in the wpview plugin to properly return the shortcode when the editor mode is toggled, ensuring that elements in the body are not dropped.

Props azaozz, wonderboymusic.
See #27915.

Location:
trunk/src/wp-includes/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/mce-view.js

    r28182 r28183  
    484484         */
    485485        getHtml: function() {
    486             var attrs = _.defaults(
    487                 this.shortcode.attrs.named,
    488                 wp.media[ this.shortcode.tag ].defaults
    489             );
    490             return this.template({ model: attrs });
     486            var attrs = this.shortcode.attrs.named;
     487            attrs.content = this.shortcode.content;
     488
     489            return this.template({ model: _.defaults(
     490                attrs,
     491                wp.media[ this.shortcode.tag ].defaults )
     492            });
    491493        },
    492494
  • trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js

    r28084 r28183  
    333333            // Empty the wrap node
    334334            if ( 'textContent' in node ) {
    335                 node.textContent = '';
     335                node.textContent = '\u00a0';
    336336            } else {
    337                 node.innerText = '';
    338             }
    339 
    340             // This makes all views into block tags (as we use <div>).
    341             // Can use 'PostProcess' and a regex instead.
    342             dom.replace( dom.create( 'p', null, window.decodeURIComponent( dom.getAttrib( node, 'data-wpview-text' ) ) ), node );
     337                node.innerText = '\u00a0';
     338            }
    343339        });
    344340    });
     341
     342    editor.on( 'PostProcess', function( event ) {
     343        if ( event.content ) {
     344            event.content = event.content.replace( /<div [^>]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g, function( match, shortcode ) {
     345                if ( shortcode ) {
     346                    return '<p>' + window.decodeURIComponent( shortcode ) + '</p>';
     347                }
     348                return ''; // If error, remove the view wrapper
     349            });
     350        }
     351    });
    345352
    346353    editor.on( 'keydown', function( event ) {
Note: See TracChangeset for help on using the changeset viewer.