mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
add ui
This commit is contained in:
1 parent
777a4bc927
commit
9c45527522
396 files changed
+13772
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
import delay from 'vj/utils/delay';
|
||||
import DOMAttachedObject from 'vj/components/DOMAttachedObject';
|
||||
import Marker from './Marker';
|
||||
|
||||
export default class MarkerReactive extends DOMAttachedObject {
|
||||
static DOMAttachKey = 'vjMarkerReactiveInstance';
|
||||
|
||||
static initFromDOM($dom) {
|
||||
return MarkerReactive.getOrConstruct($dom);
|
||||
}
|
||||
|
||||
static initAll() {
|
||||
$('[data-marker-enabled]').get().forEach(dom => MarkerReactive.initFromDOM($(dom)));
|
||||
}
|
||||
|
||||
constructor($target) {
|
||||
super($target);
|
||||
this._onMouseUp = this.onMouseUp.bind(this);
|
||||
this.bindEventHandlers();
|
||||
}
|
||||
|
||||
bindEventHandlers() {
|
||||
this.$dom.on('mouseup', this._onMouseUp);
|
||||
}
|
||||
|
||||
unbindEventHandlers() {
|
||||
this.$dom.off('mouseup', this._onMouseUp);
|
||||
}
|
||||
|
||||
async onMouseUp(ev) {
|
||||
await delay(1);
|
||||
if (!window.getSelection) {
|
||||
return;
|
||||
}
|
||||
const selection = window.getSelection();
|
||||
if (!selection || selection.rangeCount === 0) {
|
||||
return;
|
||||
}
|
||||
const range = selection.getRangeAt(0);
|
||||
if (range.collapsed) {
|
||||
return;
|
||||
}
|
||||
Marker.showAtPosition(this.$dom, ev.clientX, ev.clientY);
|
||||
}
|
||||
|
||||
detach() {
|
||||
if (this.detached) {
|
||||
return;
|
||||
}
|
||||
this.unbindEventHandlers();
|
||||
Marker.close();
|
||||
super.detach();
|
||||
}
|
||||
}
|
||||
|
||||
_.assign(MarkerReactive, DOMAttachedObject);
|
||||
Reference in new issue
Block a user