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,53 +82,58 @@ 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: {
view: Backbone.View,
text: function( instance ) {
return instance.options.original;
// 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;
},
toView: function( content ) {
if ( ! this.pattern )
return;
this.pattern.lastIndex = 0;
var match = this.pattern.exec( content );
if ( ! match )
return;
return {
index: match.index,
content: match[0],
options: {
original: match[0],
results: match
}
};
}
},
toView: function( content ) {
if ( ! this.pattern )
return;
// The default properties used for objects with the `shortcode` key in
// `wp.mce.view.add()`.
shortcode: {
view: Backbone.View,
text: function( instance ) {
return instance.options.shortcode.text();
},
this.pattern.lastIndex = 0;
var match = this.pattern.exec( content );
toView: function( content ) {
var match = wp.shortcode.next( this.shortcode, content );
if ( ! match )
return;
if ( ! match )
return;
return {
index: match.index,
content: match[0],
options: {
original: match[0],
results: match
}
};
}
},
shortcode: {
view: Backbone.View,
text: function( instance ) {
return instance.options.shortcode.text();
},
toView: function( content ) {
var match = wp.shortcode.next( this.tag, content );
if ( ! match )
return;
return {
index: match.index,
content: match.content,
options: {
shortcode: match.shortcode
}
};
return {
index: match.index,
content: match.content,
options: {
shortcode: match.shortcode
}
};
}
}
},
@ -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 );