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.


git-svn-id: https://develop.svn.wordpress.org/trunk@22102 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Daryl Koopersmith 2012-10-03 06:40:07 +00:00
parent 866ffeb1d5
commit 183e49c4c3
1 changed files with 52 additions and 42 deletions

View File

@ -82,8 +82,10 @@ if ( typeof wp === 'undefined' )
// custom UI, and back again.
wp.mce.view = {
// ### defaults
// The default properties used for the objects in `wp.mce.view.add()`.
defaults: {
// The default properties used for objects with the `pattern` key in
// `wp.mce.view.add()`.
pattern: {
view: Backbone.View,
text: function( instance ) {
return instance.options.original;
@ -110,6 +112,8 @@ if ( typeof wp === 'undefined' )
}
},
// The default properties used for objects with the `shortcode` key in
// `wp.mce.view.add()`.
shortcode: {
view: Backbone.View,
text: function( instance ) {
@ -117,7 +121,7 @@ if ( typeof wp === 'undefined' )
},
toView: function( content ) {
var match = wp.shortcode.next( this.tag, content );
var match = wp.shortcode.next( this.shortcode, content );
if ( ! match )
return;
@ -130,6 +134,7 @@ if ( typeof wp === 'undefined' )
}
};
}
}
},
// ### add( id, options )
@ -160,7 +165,12 @@ if ( typeof wp === 'undefined' )
var parent, remove, base, properties;
// Fetch the parent view or the default options.
parent = options.extend ? wp.mce.view.get( options.extend ) : wp.mce.view.defaults;
if ( options.extend )
parent = wp.mce.view.get( options.extend );
else if ( options.shortcode )
parent = wp.mce.view.defaults.shortcode;
else
parent = wp.mce.view.defaults.pattern;
// Extend the `options` object with the parent's properties.
_.defaults( options, parent );