代码拉取完成,页面将自动刷新
///import core
///import uicore
///import ui/menu.js
///import ui/splitbutton.js
;(function() {
// todo: menu和item提成通用list
var utils = baidu.editor.utils,
uiUtils = baidu.editor.ui.uiUtils,
Menu = baidu.editor.ui.Menu,
SplitButton = baidu.editor.ui.SplitButton,
Combox = (baidu.editor.ui.Combox = function(options) {
this.initOptions(options);
this.initCombox();
});
Combox.prototype = {
uiName: "combox",
onbuttonclick: function() {
this.showPopup();
},
initCombox: function() {
var me = this;
this.items = this.items || [];
for (var i = 0; i < this.items.length; i++) {
var item = this.items[i];
item.uiName = "listitem";
item.index = i;
item.onclick = function() {
me.selectByIndex(this.index);
};
}
this.popup = new Menu({
items: this.items,
uiName: "list",
editor: this.editor,
captureWheel: true,
combox: this
});
this.initSplitButton();
},
_SplitButton_postRender: SplitButton.prototype.postRender,
postRender: function() {
this._SplitButton_postRender();
this.setLabel(this.label || "");
this.setValue(this.initValue || "");
},
showPopup: function() {
var rect = uiUtils.getClientRect(this.getDom());
rect.top += 1;
rect.bottom -= 1;
rect.height -= 2;
this.popup.showAnchorRect(rect);
},
getValue: function() {
return this.value;
},
setValue: function(value) {
var index = this.indexByValue(value);
if (index != -1) {
this.selectedIndex = index;
this.setLabel(this.items[index].label);
this.value = this.items[index].value;
} else {
this.selectedIndex = -1;
this.setLabel(this.getLabelForUnknowValue(value));
this.value = value;
}
},
setLabel: function(label) {
this.getDom("button_body").innerHTML = label;
this.label = label;
},
getLabelForUnknowValue: function(value) {
return value;
},
indexByValue: function(value) {
for (var i = 0; i < this.items.length; i++) {
if (value == this.items[i].value) {
return i;
}
}
return -1;
},
getItem: function(index) {
return this.items[index];
},
selectByIndex: function(index) {
if (
index < this.items.length &&
this.fireEvent("select", index) !== false
) {
this.selectedIndex = index;
this.value = this.items[index].value;
this.setLabel(this.items[index].label);
}
}
};
utils.inherits(Combox, SplitButton);
})();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。