Kri*_*esi 9 wordpress backbone.js backbone-views wordpress-3.5
我目前正在尝试使用新的WordPress 3.5媒体管理器,它使用backbone.js来创建和填充其模态窗口.
我想要做的是:用户点击上传按钮,媒体管理器弹出,用户选择图像,印刷机插入,然后图像被保存到自定义字段.
所有这些都已经有效,我唯一想改变的是用我自己的模板填充媒体上传者的边栏(用户可以添加标题,标题,选择大小等).
我已经阅读了很多关于如何使用骨干的教程,但现在有点卡住了.这是我到目前为止的一些代码:
//defined earlier:
var frame;
//on click:
if ( file_frame )
{
file_frame.open();
return;
}
else
{
// Create the media frame.
file_frame = wp.media(
{
frame: 'select',
state: 'mystate',
library: {type: 'image'},
multiple: false
});
file_frame.states.add([
new media.controller.Library({
id: 'mystate',
title: 'my title',
priority: 20,
toolbar: 'select',
filterable: 'uploaded',
library: media.query( file_frame.options.library ),
multiple: file_frame.options.multiple ? 'reset' : false,
editable: true,
displayUserSettings: false,
displaySettings: true,
allowLocalEdits: true,
//AttachmentView: ?
}),
]);
file_frame.open();
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过注册我自己的模板:
media.view.Attachment.mySidebar = media.view.Settings.AttachmentDisplay.extend(
{
className: 'attachment-display-settings',
template: media.template('avia-choose-size')
});
Run Code Online (Sandbox Code Playgroud)
但问题是:我不知道只加载这个模板而不是原始的侧边栏.将它作为AttachmentView参数传递显然不起作用,因为它取代了整个模板而不仅仅是侧边栏.
谁有一些backbone.js经验谁可以帮助?
小智 2
我不确定您是否找到了问题的答案,但我想让您知道,通过简单地修复对不带“wp”前缀的“media”对象的引用,我就得到了上述代码。所以...您的新自定义状态代码应该如下所示:
file_frame.states.add([
new wp.media.controller.Library({
id: 'mystate',
title: 'my title',
priority: 20,
toolbar: 'select',
filterable: 'uploaded',
library: wp.media.query( file_frame.options.library ),
multiple: file_frame.options.multiple ? 'reset' : false,
editable: true,
displayUserSettings: false,
displaySettings: true,
allowLocalEdits: true,
//AttachmentView: ?
}),
]);
Run Code Online (Sandbox Code Playgroud)
我个人想替换“选择”框架的初始默认状态,这是通过添加states : 'mystate'到 file_frame 选项来实现的,导致初始化返回而不创建默认的“选择”状态。然后继续创建“mystate”,正如您所演示的那样(对象语法有两个细微的变化)。
我感谢您在方法论方面的领先!它运作得很好,我之前完全迷失和沮丧。
| 归档时间: |
|
| 查看次数: |
2753 次 |
| 最近记录: |