forked from fanruan/fineui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.3 KiB
117 lines
3.3 KiB
/** |
|
* 富文本编辑器 |
|
* |
|
* Created by GUY on 2017/9/15. |
|
* @class BI.RichEditor |
|
* @extends BI.Widget |
|
*/ |
|
BI.RichEditor = BI.inherit(BI.Widget, { |
|
|
|
props: { |
|
baseCls: "bi-rich-editor bi-textarea", |
|
toolbar: {}, |
|
readOnly: false |
|
}, |
|
|
|
_defaultConfig: function () { |
|
return BI.extend(BI.RichEditor.superclass._defaultConfig.apply(this, arguments), { |
|
adjustLength: 1, |
|
adjustXOffset: 0, |
|
adjustYOffset: 0 |
|
}); |
|
}, |
|
|
|
render: function () { |
|
var self = this, o = this.options; |
|
var editor = { |
|
type: "bi.nic_editor", |
|
width: o.width, |
|
height: o.height, |
|
readOnly: o.readOnly, |
|
ref: function () { |
|
self.editor = this; |
|
}, |
|
listeners: [{ |
|
eventName: BI.NicEditor.EVENT_BLUR, |
|
action: function () { |
|
self.fireEvent(BI.RichEditor.EVENT_CONFIRM); |
|
} |
|
}, { |
|
eventName: BI.NicEditor.EVENT_FOCUS, |
|
action: function () { |
|
if (!o.readOnly && !self.combo.isViewVisible()) { |
|
self.combo.showView(); |
|
} |
|
self.fireEvent(BI.RichEditor.EVENT_FOCUS); |
|
} |
|
}] |
|
}; |
|
if(o.readOnly) { |
|
return editor; |
|
} |
|
this.editor = BI.createWidget(editor); |
|
return { |
|
type: "bi.combo", |
|
container: o.container, |
|
toggle: false, |
|
trigger: "click", |
|
direction: "top,right", |
|
isNeedAdjustWidth: false, |
|
isNeedAdjustHeight: false, |
|
adjustLength: o.adjustLength, |
|
adjustXOffset: o.adjustXOffset, |
|
adjustYOffset: o.adjustYOffset, |
|
ref: function () { |
|
self.combo = this; |
|
}, |
|
el: this.editor, |
|
popup: { |
|
el: BI.extend({ |
|
type: "bi.rich_editor_text_toolbar", |
|
editor: this.editor |
|
}, o.toolbar, { |
|
ref: function (_ref) { |
|
self.editor.bindToolbar(_ref); |
|
o.toolbar.ref && o.toolbar.ref(_ref); |
|
} |
|
}), |
|
height: 34, |
|
stopPropagation: false, |
|
stopEvent: false |
|
}, |
|
listeners: [{ |
|
eventName: BI.Combo.EVENT_AFTER_HIDEVIEW, |
|
action: function () { |
|
self.fireEvent(BI.RichEditor.EVENT_AFTER_HIDEVIEW); |
|
} |
|
}] |
|
}; |
|
}, |
|
|
|
mounted: function () { |
|
var o = this.options; |
|
if(BI.isNull(o.value)) { |
|
this.editor.setValue(o.value); |
|
} |
|
}, |
|
|
|
focus: function () { |
|
this.editor.focus(); |
|
}, |
|
|
|
setValue: function (v) { |
|
this.editor.setValue(v); |
|
}, |
|
|
|
getValue: function () { |
|
return this.editor.getValue(); |
|
}, |
|
|
|
getContentHeight: function () { |
|
return this.editor.getContentHeight(); |
|
} |
|
}); |
|
BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; |
|
BI.RichEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; |
|
BI.RichEditor.EVENT_FOCUS = "EVENT_FOCUS"; |
|
BI.shortcut("bi.rich_editor", BI.RichEditor); |