Make WordPress Core

Changeset 22102


Ignore:
Timestamp:
10/03/2012 06:40:07 AM (14 years ago)
Author:
koopersmith
Message:

MCE Views: Use default shortcode properties when the shortcode parameter is set.

Prevents devs from having to manually extend the default shortcode property object.

see #21390, #21812.

File:
1 edited

Legend:

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

    r22036 r22102  
    8383        wp.mce.view = {
    8484                // ### defaults
    85                 // The default properties used for the objects in `wp.mce.view.add()`.
    8685                defaults: {
    87                         view: Backbone.View,
    88                         text: function( instance ) {
    89                                 return instance.options.original;
     86                        // The default properties used for objects with the `pattern` key in
     87                        // `wp.mce.view.add()`.
     88                        pattern: {
     89                                view: Backbone.View,
     90                                text: function( instance ) {
     91                                        return instance.options.original;
     92                                },
     93
     94                                toView: function( content ) {
     95                                        if ( ! this.pattern )
     96                                                return;
     97
     98                                        this.pattern.lastIndex = 0;
     99                                        var match = this.pattern.exec( content );
     100
     101                                        if ( ! match )
     102                                                return;
     103
     104                                        return {
     105                                                index:   match.index,
     106                                                content: match[0],
     107                                                options: {
     108                                                        original: match[0],
     109                                                        results:  match
     110                                                }
     111                                        };
     112                                }
    90113                        },
    91114
    92                         toView: function( content ) {
    93                                 if ( ! this.pattern )
    94                                         return;
    95 
    96                                 this.pattern.lastIndex = 0;
    97                                 var match = this.pattern.exec( content );
    98 
    99                                 if ( ! match )
    100                                         return;
    101 
    102                                 return {
    103                                         index:   match.index,
    104                                         content: match[0],
    105                                         options: {
    106                                                 original: match[0],
    107                                                 results:  match
    108                                         }
    109                                 };
    110                         }
    111                 },
    112 
    113                 shortcode: {
    114                         view: Backbone.View,
    115                         text: function( instance ) {
    116                                 return instance.options.shortcode.text();
    117                         },
    118 
    119                         toView: function( content ) {
    120                                 var match = wp.shortcode.next( this.tag, content );
    121 
    122                                 if ( ! match )
    123                                         return;
    124 
    125                                 return {
    126                                         index:   match.index,
    127                                         content: match.content,
    128                                         options: {
    129                                                 shortcode: match.shortcode
    130                                         }
    131                                 };
     115                        // The default properties used for objects with the `shortcode` key in
     116                        // `wp.mce.view.add()`.
     117                        shortcode: {
     118                                view: Backbone.View,
     119                                text: function( instance ) {
     120                                        return instance.options.shortcode.text();
     121                                },
     122
     123                                toView: function( content ) {
     124                                        var match = wp.shortcode.next( this.shortcode, content );
     125
     126                                        if ( ! match )
     127                                                return;
     128
     129                                        return {
     130                                                index:   match.index,
     131                                                content: match.content,
     132                                                options: {
     133                                                        shortcode: match.shortcode
     134                                                }
     135                                        };
     136                                }
    132137                        }
    133138                },
     
    161166
    162167                        // Fetch the parent view or the default options.
    163                         parent = options.extend ? wp.mce.view.get( options.extend ) : wp.mce.view.defaults;
     168                        if ( options.extend )
     169                                parent = wp.mce.view.get( options.extend );
     170                        else if ( options.shortcode )
     171                                parent = wp.mce.view.defaults.shortcode;
     172                        else
     173                                parent = wp.mce.view.defaults.pattern;
    164174
    165175                        // Extend the `options` object with the parent's properties.
Note: See TracChangeset for help on using the changeset viewer.