我正在尝试扩展媒体模式,但找不到有关它的任何文档/教程。我也不是骨干大师;-)
我想为附加到附件帖子类型的每个分类法添加一个选择框。目前,仅显示一个选择框。
这就是我想出的。它可以代替默认工具栏,但效果很好。
码
/**
* Extended Filters dropdown with taxonomy term selection values
*/
jQuery.each(mediaTaxonomies,function(key,label){
media.view.AttachmentFilters[key] = media.view.AttachmentFilters.extend({
className: key,
createFilters: function() {
var filters = {};
_.each( mediaTerms[key] || {}, function( term ) {
var query = {};
query[key] = {
taxonomy: key,
term_id: parseInt( term.id, 10 ),
term_slug: term.slug
};
filters[ term.slug ] = {
text: term.label,
props: query
};
});
this.filters = filters;
}
});
/**
* Replace the media-toolbar with our own
*/
media.view.AttachmentsBrowser = media.view.AttachmentsBrowser.extend({
createToolbar: function() {
media.model.Query.defaultArgs.filterSource = 'filter-media-taxonomies';
this.toolbar = new media.view.Toolbar({
controller: this.controller
});
this.views.add( this.toolbar );
this.toolbar.set( 'terms', new media.view.AttachmentFilters[key]({
controller: this.controller,
model: this.collection.props,
priority: -80
}).render() );
}
});
});