Make WordPress Core

Changeset 28358


Ignore:
Timestamp:
05/10/2014 11:35:08 PM (12 years ago)
Author:
wonderboymusic
Message:

First pass at wpview logic for the [embed] shortcode. URLs on a their own line are parsed as well. The toolbar will appear with the "remove" button when the view is clicked. Edit has not been implemented yet.

Props avryl, wonderboymusic.
See #28195.

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/admin-ajax.php

    r28126 r28358  
    5959        'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    6060        'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
    61         'save-user-color-scheme', 'update-widget', 'query-themes',
     61        'save-user-color-scheme', 'update-widget', 'query-themes', 'filter-content'
    6262);
    6363
  • trunk/src/wp-admin/includes/ajax-actions.php

    r28356 r28358  
    25072507        wp_send_json_success( $api );
    25082508}
     2509
     2510/**
     2511 * Apply `the_content` filters to a string based on the post ID.
     2512 *
     2513 * @since 4.0.0
     2514 */
     2515function wp_ajax_filter_content() {
     2516        global $post;
     2517
     2518        if ( ! $post = get_post( (int) $_REQUEST['post_ID'] ) ) {
     2519                wp_send_json_error();
     2520        }
     2521
     2522        if ( ! current_user_can( 'read_post', $post->ID ) ) {
     2523                wp_send_json_error();
     2524        }
     2525
     2526        setup_postdata( $post );
     2527
     2528        wp_send_json_success( apply_filters( 'the_content', wp_unslash( $_POST['content'] ) ) );
     2529}
  • trunk/src/wp-includes/js/mce-view.js

    r28183 r28358  
    355355        wp.mce.media = {
    356356                loaded: false,
    357                 /**
    358                  * @global wp.shortcode
    359                  *
    360                  * @param {string} content
    361                  * @returns {Object}
    362                  */
    363                 toView:  function( content ) {
    364                         var match = wp.shortcode.next( this.shortcode, content );
    365 
    366                         if ( ! match ) {
    367                                 return;
    368                         }
    369 
    370                         return {
    371                                 index:   match.index,
    372                                 content: match.content,
    373                                 options: {
    374                                         shortcode: match.shortcode
    375                                 }
    376                         };
    377                 },
     357                toView: wp.mce.gallery.toView,
    378358
    379359                /**
    … …  
    691671        } );
    692672        wp.mce.views.register( 'playlist', wp.mce.playlist );
     673
     674        wp.mce.embed = {
     675                shortcode: 'embed',
     676                toView: wp.mce.gallery.toView,
     677                View: wp.mce.View.extend( {
     678                        className: 'editor-embed',
     679                        template: media.template( 'editor-embed' ),
     680                        initialize: function( options ) {
     681                                this.players = [];
     682                                this.content = options.content;
     683                                this.parsed = false;
     684                                this.shortcode = options.shortcode;
     685                                _.bindAll( this, 'setHtml', 'setNode', 'fetch' );
     686                                $( this ).on( 'ready', this.setNode );
     687                        },
     688                        unbind: function() {
     689                                var self = this;
     690                                this.pauseAllPlayers();
     691                                _.each( this.players, function ( player ) {
     692                                        self.removePlayer( player );
     693                                } );
     694                                this.players = [];
     695                        },
     696                        setNode: function ( e, node ) {
     697                                this.node = node;
     698                                if ( this.parsed ) {
     699                                        this.parseMediaShortcodes();
     700                                } else {
     701                                        this.fetch();
     702                                }
     703                        },
     704                        fetch: function () {
     705                                wp.ajax.send( 'filter-content', {
     706                                        data: {
     707                                                post_ID: $( '#post_ID' ).val(),
     708                                                content: this.shortcode.string()
     709                                        }
     710                                } ).done( this.setHtml );
     711                        },
     712                        setHtml: function ( content ) {
     713                                var scripts = $( content ).find( 'script' );
     714
     715                                this.parsed = content;
     716
     717                                $( this.node ).html( this.getHtml() );
     718                                if ( scripts ) {
     719                                        _.each( scripts, function (script) {
     720                                                var element = document.createElement( 'script' );
     721                                                element.type = 'text/javascript';
     722                                                element.src = script.src;
     723                                                tinymce.activeEditor.contentDocument.getElementsByTagName( 'head' )[0].appendChild( element );
     724                                        } );
     725                                }
     726                                this.parseMediaShortcodes();
     727                        },
     728                        parseMediaShortcodes: function () {
     729                                var self = this;
     730                                $( '.wp-audio-shortcode, .wp-video-shortcode', this.node ).each( function ( i, element ) {
     731                                        self.players.push( new MediaElementPlayer( element, self.mejsSettings ) );
     732                                } );
     733                        },
     734                        getHtml: function() {
     735                                if ( ! this.parsed ) {
     736                                        return '';
     737                                }
     738                                return this.template({ content: this.parsed });
     739                        }
     740                } ),
     741                edit: function() {}
     742        };
     743
     744        _.extend( wp.mce.embed.View.prototype, wp.media.mixin );
     745
     746        wp.mce.views.register( 'embed', wp.mce.embed );
     747
    693748}(jQuery));
  • trunk/src/wp-includes/js/media-audiovideo.js

    r28182 r28358  
    132132                        var featureIndex, feature;
    133133
     134                        if ( ! t.options ) {
     135                                return;
     136                        }
     137
    134138                        // invoke features cleanup
    135139                        for ( featureIndex in t.options.features ) {
  • trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js

    r28183 r28358  
    168168                event.content = wp.mce.views.toViews( event.content );
    169169        });
     170
     171        editor.on( 'PastePreProcess', function( event ) {
     172                if ( event.content.match( /^\s*(https?:\/\/[^\s"]+)\s*$/im ) ) {
     173                        event.content = '[embed]' + event.content + '[/embed]';
     174                }
     175        } );
    170176
    171177        // When the editor's content has been updated and the DOM has been
  • trunk/src/wp-includes/media-template.php

    r28343 r28358  
    10461046        </script>
    10471047
     1048        <script type="text/html" id="tmpl-editor-embed">
     1049                <div class="toolbar">
     1050                        <div class="dashicons dashicons-no-alt remove"></div>
     1051                </div>
     1052                {{{ data.content }}}
     1053                <div class="wpview-overlay"></div>
     1054        </script>
     1055
    10481056        <?php
    10491057
Note: See TracChangeset for help on using the changeset viewer.