mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui-default: init
将ui-default合并至主存储库便于维护
This commit is contained in:
1 parent
6317c9057f
commit
5faa54c7ca
564 files changed
+23083
-14
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