Make WordPress Core

Ticket #28532: 28532.diff

File 28532.diff, 4.8 KB (added by wonderboymusic, 11 years ago)
  • wp-includes/js/mce-view.js

     
    687687                                return this.template({ content: this.parsed });
    688688                        }
    689689                } ),
    690                 edit: function() {}
     690
     691                edit: function( node ) {
     692                        var embed = media.embed,
     693                                self = this,
     694                                frame, data;
     695
     696                        $( document ).trigger( 'media:edit' );
     697
     698                        data = window.decodeURIComponent( $( node ).attr('data-wpview-text') );
     699                        frame = embed.edit( data );
     700                        frame.on( 'close', function() {
     701                                frame.detach();
     702                        } );
     703                        frame.state( 'embed' ).props.on( 'change:url', function (model, url) {
     704                                if ( ! url ) {
     705                                        return;
     706                                }
     707                                frame.state( 'embed' ).metadata = model.toJSON();
     708                        } );
     709                        frame.state( 'embed' ).on( 'select', function() {
     710                                var shortcode = embed.shortcode( frame.state( 'embed' ).metadata ).string();
     711                                $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) );
     712                                wp.mce.views.refreshView( self, shortcode );
     713                                frame.detach();
     714                        } );
     715                        frame.open();
     716                }
    691717        } );
    692718
    693719}(jQuery));
  • wp-includes/js/media-editor.js

     
    298298                }
    299299        };
    300300
     301        wp.media.embed = {
     302                coerce : wp.media.coerce,
     303
     304                defaults : {
     305                        url : '',
     306                        width: '',
     307                        height: ''
     308                },
     309
     310                edit : function( data ) {
     311                        var frame, props = {},
     312                                shortcode = wp.shortcode.next( 'embed', data ).shortcode;
     313
     314                        props = _.defaults( shortcode.attrs.named, this.defaults );
     315                        if ( shortcode.content ) {
     316                                props.url = shortcode.content;
     317                        }
     318
     319                        frame = wp.media({
     320                                frame: 'post',
     321                                state: 'embed',
     322                                metadata: props
     323                        });
     324
     325                        return frame;
     326                },
     327
     328                shortcode : function( model ) {
     329                        var self = this, content;
     330
     331                        _.each( this.defaults, function( value, key ) {
     332                                model[ key ] = self.coerce( model, key );
     333
     334                                if ( value === model[ key ] ) {
     335                                        delete model[ key ];
     336                                }
     337                        });
     338
     339                        content = model.url;
     340                        delete model.url;
     341
     342                        return new wp.shortcode({
     343                                tag: 'embed',
     344                                attrs: model,
     345                                content: content
     346                        });
     347                }
     348        };
     349
    301350        wp.media.collection = function(attributes) {
    302351                var collections = {};
    303352
  • wp-includes/js/media-views.js

     
    14021402
    14031403                        priority: 120,
    14041404                        type:     'link',
    1405                         url:      ''
     1405                        url:      '',
     1406                        metadata: {}
    14061407                },
    14071408
    14081409                // The amount of time used when debouncing the scan.
    14091410                sensitivity: 200,
    14101411
    1411                 initialize: function() {
     1412                initialize: function(options) {
     1413                        this.metadata = options.metadata;
    14121414                        this.debouncedScan = _.debounce( _.bind( this.scan, this ), this.sensitivity );
    1413                         this.props = new Backbone.Model({ url: '' });
     1415                        this.props = new Backbone.Model( this.metadata || { url: '' });
    14141416                        this.props.on( 'change:url', this.debouncedScan, this );
    14151417                        this.props.on( 'change:url', this.refresh, this );
    14161418                        this.on( 'scan', this.scanImage, this );
     
    22782280                        _.defaults( this.options, {
    22792281                                multiple:  true,
    22802282                                editing:   false,
    2281                                 state:    'insert'
     2283                                state:    'insert',
     2284                                metadata:  {}
    22822285                        });
    22832286                        /**
    22842287                         * call 'initialize' directly on the parent class
     
    23302333                                }),
    23312334
    23322335                                // Embed states.
    2333                                 new media.controller.Embed(),
     2336                                new media.controller.Embed( { metadata: options.metadata } ),
    23342337
    23352338                                new media.controller.EditImage( { model: options.editImage } ),
    23362339
     
    64406443                },
    64416444
    64426445                initialize: function() {
    6443                         this.$input = $('<input id="embed-url-field" />').attr( 'type', 'text' ).val( this.model.get('url') );
     6446                        var self = this;
     6447
     6448                        this.$input = $('<input id="embed-url-field" type="text" />').val( this.model.get('url') );
    64446449                        this.input = this.$input[0];
    64456450
    64466451                        this.spinner = $('<span class="spinner" />')[0];
     
    64476452                        this.$el.append([ this.input, this.spinner ]);
    64486453
    64496454                        this.model.on( 'change:url', this.render, this );
     6455
     6456                        if ( this.model.get( 'url' ) ) {
     6457                                _.delay( function () {
     6458                                        self.model.trigger( 'change:url' );
     6459                                }, 500 );
     6460                        }
    64506461                },
    64516462                /**
    64526463                 * @returns {wp.media.view.EmbedUrl} Returns itself to allow chaining
  • wp-includes/media-template.php

     
    10771077
    10781078        <script type="text/html" id="tmpl-editor-embed">
    10791079                <div class="toolbar">
     1080                        <div class="dashicons dashicons-edit edit"></div>
    10801081                        <div class="dashicons dashicons-no-alt remove"></div>
    10811082                </div>
    10821083                {{{ data.content }}}