-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel-view.ts
52 lines (42 loc) · 1.35 KB
/
label-view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { ViewOptions as BaseOpt } from 'backbone';
import { extend } from 'lodash';
import View from '../core/view';
import { rdfs, skos } from '../common-rdf/ns';
import FlatItem from '../common-adapters/flat-item-model';
import attachTooltip from '../tooltip/tooltip-view';
type TooltipSetting = false | 'top' | 'bottom' | 'left' | 'right';
export interface ViewOptions extends BaseOpt<FlatItem> {
toolTipSetting?: TooltipSetting;
}
export default class LabelView extends View<FlatItem> {
toolTipSetting: TooltipSetting;
constructor(options?: ViewOptions) {
super(options);
this.toolTipSetting = 'right';
if (options && options.toolTipSetting !== undefined) {
this.toolTipSetting = options.toolTipSetting;
}
this.model.when('classLabel', this.processClass, this);
}
processClass() {
this.addTooltip();
this.render();
}
render(): this {
this.$el.text(this.model.get('classLabel'));
this.$el.addClass(this.model.get('cssClass'));
return this;
}
addTooltip(): void {
if (typeof this.toolTipSetting === 'string') {
attachTooltip(this, {
direction: this.toolTipSetting,
model: this.model,
});
}
}
}
extend(LabelView.prototype, {
tagName: 'span',
className: 'tag',
});