305 Star 1.5K Fork 291

GVPNotadd/Neditor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
stateful.js 3.38 KB
一键复制 编辑 原始数据 按行查看 历史
;(function() {
var browser = baidu.editor.browser,
domUtils = baidu.editor.dom.domUtils,
uiUtils = baidu.editor.ui.uiUtils;
var TPL_STATEFUL =
'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
(browser.ie
? ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
' onmouseleave="$$.Stateful_onMouseLeave(event, this);"'
: ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
' onmouseout="$$.Stateful_onMouseOut(event, this);"');
baidu.editor.ui.Stateful = {
alwalysHoverable: false,
target: null, //目标元素和this指向dom不一样
Stateful_init: function() {
this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
this.getHtmlTpl = this.Stateful_getHtmlTpl;
},
Stateful_getHtmlTpl: function() {
var tpl = this._Stateful_dGetHtmlTpl();
// 使用function避免$转义
return tpl.replace(/stateful/g, function() {
return TPL_STATEFUL;
});
},
Stateful_onMouseEnter: function(evt, el) {
this.target = el;
if (!this.isDisabled() || this.alwalysHoverable) {
this.addState("hover");
this.fireEvent("over");
}
},
Stateful_onMouseLeave: function(evt, el) {
if (!this.isDisabled() || this.alwalysHoverable) {
this.removeState("hover");
this.removeState("active");
this.fireEvent("out");
}
},
Stateful_onMouseOver: function(evt, el) {
var rel = evt.relatedTarget;
if (!uiUtils.contains(el, rel) && el !== rel) {
this.Stateful_onMouseEnter(evt, el);
}
},
Stateful_onMouseOut: function(evt, el) {
var rel = evt.relatedTarget;
if (!uiUtils.contains(el, rel) && el !== rel) {
this.Stateful_onMouseLeave(evt, el);
}
},
Stateful_onMouseDown: function(evt, el) {
if (!this.isDisabled()) {
this.addState("active");
}
},
Stateful_onMouseUp: function(evt, el) {
if (!this.isDisabled()) {
this.removeState("active");
}
},
Stateful_postRender: function() {
if (this.disabled && !this.hasState("disabled")) {
this.addState("disabled");
}
},
hasState: function(state) {
return domUtils.hasClass(this.getStateDom(), "edui-state-" + state);
},
addState: function(state) {
if (!this.hasState(state)) {
this.getStateDom().className += " edui-state-" + state;
}
},
removeState: function(state) {
if (this.hasState(state)) {
domUtils.removeClasses(this.getStateDom(), ["edui-state-" + state]);
}
},
getStateDom: function() {
return this.getDom("state");
},
isChecked: function() {
return this.hasState("checked");
},
setChecked: function(checked) {
if (!this.isDisabled() && checked) {
this.addState("checked");
} else {
this.removeState("checked");
}
},
isDisabled: function() {
return this.hasState("disabled");
},
setDisabled: function(disabled) {
if (disabled) {
this.removeState("hover");
this.removeState("checked");
this.removeState("active");
this.addState("disabled");
} else {
this.removeState("disabled");
}
}
};
})();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/notadd/neditor.git
git@gitee.com:notadd/neditor.git
notadd
neditor
Neditor
master

搜索帮助