305 Star 1.5K Fork 291

GVPNotadd/Neditor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
splitbutton.js 3.23 KB
一键复制 编辑 原始数据 按行查看 历史
///import core
///import uicore
///import ui/stateful.js
;(function() {
var utils = baidu.editor.utils,
uiUtils = baidu.editor.ui.uiUtils,
domUtils = baidu.editor.dom.domUtils,
UIBase = baidu.editor.ui.UIBase,
Stateful = baidu.editor.ui.Stateful,
SplitButton = (baidu.editor.ui.SplitButton = function(options) {
this.initOptions(options);
this.initSplitButton();
});
SplitButton.prototype = {
popup: null,
uiName: "splitbutton",
title: "",
initSplitButton: function() {
this.initUIBase();
this.Stateful_init();
var me = this;
if (this.popup != null) {
var popup = this.popup;
this.popup = null;
this.setPopup(popup);
}
},
_UIBase_postRender: UIBase.prototype.postRender,
postRender: function() {
this.Stateful_postRender();
this._UIBase_postRender();
},
setPopup: function(popup) {
if (this.popup === popup) return;
if (this.popup != null) {
this.popup.dispose();
}
popup.addListener("show", utils.bind(this._onPopupShow, this));
popup.addListener("hide", utils.bind(this._onPopupHide, this));
popup.addListener(
"postrender",
utils.bind(function() {
popup
.getDom("body")
.appendChild(
uiUtils.createElementByHtml(
'<div id="' +
this.popup.id +
'_bordereraser" class="edui-bordereraser edui-background" style="width:' +
(uiUtils.getClientRect(this.getDom()).width + 20) +
'px"></div>'
)
);
popup.getDom().className += " " + this.className;
}, this)
);
this.popup = popup;
},
_onPopupShow: function() {
this.addState("opened");
},
_onPopupHide: function() {
this.removeState("opened");
},
getHtmlTpl: function() {
return (
'<div id="##" class="edui-box %%">' +
"<div " +
(this.title ? 'title="' + this.title + '"' : "") +
' id="##_state" stateful><div class="%%-body">' +
'<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
'<div class="edui-box edui-icon"><svg class="edui-iconfont"><use xlink:href="#' + this.className + '"></use></svg></div>' +
"</div>" +
'<div class="edui-box edui-splitborder"></div>' +
'<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
"</div></div></div>"
);
},
showPopup: function() {
// 当popup往上弹出的时候,做特殊处理
var rect = uiUtils.getClientRect(this.getDom());
rect.top -= this.popup.SHADOW_RADIUS;
rect.height += this.popup.SHADOW_RADIUS;
this.popup.showAnchorRect(rect);
},
_onArrowClick: function(event, el) {
if (!this.isDisabled()) {
this.showPopup();
}
},
_onButtonClick: function() {
if (!this.isDisabled()) {
this.fireEvent("buttonclick");
}
}
};
utils.inherits(SplitButton, UIBase);
utils.extend(SplitButton.prototype, Stateful, true);
})();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/notadd/neditor.git
git@gitee.com:notadd/neditor.git
notadd
neditor
Neditor
master

搜索帮助