Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
扩展的UI组件需要配置toolbars参数才可显示
Browse files Browse the repository at this point in the history
  • Loading branch information
campaign committed Jul 18, 2014
1 parent e4d12e6 commit 69f4737
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions _examples/customizeToolbarUIDemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ <h1>二次开发demo</h1>
//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
UE.getEditor('editor',{
//清空了工具栏
toolbars:[[]]
})
toolbars:[['combox','bold','button','dialog']]
});

</script>
</html>
46 changes: 25 additions & 21 deletions _src/adapter/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
var editor = this.editor;
var toolbars = this.toolbars || [];
var toolbarUis = [];
var extraUIs = [];
for (var i = 0; i < toolbars.length; i++) {
var toolbar = toolbars[i];
var toolbarUi = new baidu.editor.ui.Toolbar({theme:editor.options.theme});
Expand All @@ -342,21 +343,36 @@
if(toolbarItem == '||'){
toolbarItem = 'Breakline';
}
if (baidu.editor.ui[toolbarItem]) {
toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
var ui = baidu.editor.ui[toolbarItem];
if (ui) {
if(utils.isFunction(ui)){
toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
}else{
if(ui.id && ui.id != editor.key){
continue;
}
var itemUI = ui.execFn.call(editor,editor,toolbarItem);
if(itemUI){
if(ui.index === undefined){
toolbarUi.add(itemUI);
continue;
}else{
extraUIs.push({
index:ui.index,
itemUI:itemUI
})
}
}
}
}

//fullscreen这里单独处理一下,放到首行去
if (toolbarItem == 'fullscreen') {
if (toolbarUis && toolbarUis[0]) {
toolbarUis[0].items.splice(0, 0, toolbarItemUi);
} else {
toolbarItemUi && toolbarUi.items.splice(0, 0, toolbarItemUi);
}

continue;


}
} else {
toolbarItemUi = toolbarItem;
Expand All @@ -371,21 +387,9 @@

//接受外部定制的UI

utils.each(UE._customizeUI,function(obj,key){
var itemUI,index;
if(obj.id && obj.id != editor.key){
return false;
}
itemUI = obj.execFn.call(editor,editor,key);
if(itemUI){
index = obj.index;
if(index === undefined){
index = toolbarUi.items.length;
}
toolbarUi.add(itemUI,index)
}
utils.each(extraUIs,function(obj){
toolbarUi.add(obj.itemUI,obj.index)
});

this.toolbars = toolbarUis;
},
getHtmlTpl:function () {
Expand Down Expand Up @@ -846,7 +850,7 @@

UE.registerUI = function(uiName,fn,index,editorId){
utils.each(uiName.split(/\s+/), function (name) {
UE._customizeUI[name] = {
baidu.editor.ui[name] = {
id : editorId,
execFn:fn,
index:index
Expand Down

1 comment on commit 69f4737

@tonyzheng121
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个commit为什么仅在dev-1.5.0分支上

Please sign in to comment.