@stackoverflow/stacks 0.74.0 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/index.d.ts +7 -0
- package/dist/controllers/s-expandable-control.d.ts +17 -0
- package/dist/controllers/s-modal.d.ts +97 -0
- package/dist/controllers/s-navigation-tablist.d.ts +36 -0
- package/dist/controllers/s-popover.d.ts +155 -0
- package/dist/controllers/s-table.d.ts +8 -0
- package/dist/controllers/s-tooltip.d.ts +82 -0
- package/dist/controllers/s-uploader.d.ts +48 -0
- package/dist/css/stacks.css +4633 -2703
- package/dist/css/stacks.min.css +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/js/stacks.js +6026 -5403
- package/dist/js/stacks.min.js +1 -1
- package/dist/stacks.d.ts +21 -0
- package/lib/css/atomic/{_stacks-borders.less → borders.less} +30 -30
- package/lib/css/atomic/{_stacks-colors.less → colors.less} +0 -0
- package/lib/css/atomic/{_stacks-flex.less → flex.less} +14 -13
- package/lib/css/atomic/{_stacks-grid.less → grid.less} +12 -11
- package/lib/css/atomic/{_stacks-misc.less → misc.less} +23 -22
- package/lib/css/atomic/spacing.less +314 -0
- package/lib/css/atomic/{_stacks-typography.less → typography.less} +29 -29
- package/lib/css/atomic/width-height.less +194 -0
- package/lib/css/base/{_stacks-body.less → body.less} +3 -5
- package/lib/css/base/{_stacks-configuration-static.less → configuration-static.less} +3 -1
- package/lib/css/base/{_stacks-icons.less → icons.less} +0 -0
- package/lib/css/base/{_stacks-internals.less → internals.less} +0 -10
- package/lib/css/base/{_stacks-reset-meyer.less → reset-meyer.less} +0 -0
- package/lib/css/base/{_stacks-reset-normalize.less → reset-normalize.less} +0 -0
- package/lib/css/base/{_stacks-reset.less → reset.less} +2 -2
- package/lib/css/components/{_stacks-activity-indicator.less → activity-indicator.less} +9 -9
- package/lib/css/components/{_stacks-avatars.less → avatars.less} +40 -40
- package/lib/css/components/{_stacks-badges.less → badges.less} +11 -11
- package/lib/css/components/{_stacks-banners.less → banners.less} +5 -6
- package/lib/css/components/{_stacks-blank-states.less → blank-states.less} +2 -2
- package/lib/css/components/{_stacks-breadcrumbs.less → breadcrumbs.less} +7 -7
- package/lib/css/components/{_stacks-button-groups.less → button-groups.less} +2 -2
- package/lib/css/components/{_stacks-buttons.less → buttons.less} +77 -72
- package/lib/css/components/{_stacks-cards.less → cards.less} +2 -2
- package/lib/css/components/{_stacks-code-blocks.less → code-blocks.less} +8 -8
- package/lib/css/components/{_stacks-collapsible.less → collapsible.less} +0 -0
- package/lib/css/components/{_stacks-inputs.less → inputs.less} +41 -41
- package/lib/css/components/{_stacks-link-previews.less → link-previews.less} +17 -17
- package/lib/css/components/{_stacks-links.less → links.less} +4 -4
- package/lib/css/components/{_stacks-menu.less → menu.less} +5 -5
- package/lib/css/components/{_stacks-modals.less → modals.less} +20 -20
- package/lib/css/components/{_stacks-navigation.less → navigation.less} +12 -12
- package/lib/css/components/{_stacks-notices.less → notices.less} +12 -12
- package/lib/css/components/{_stacks-page-titles.less → page-titles.less} +9 -9
- package/lib/css/components/{_stacks-pagination.less → pagination.less} +8 -8
- package/lib/css/components/{_stacks-popovers.less → popovers.less} +17 -17
- package/lib/css/components/{_stacks-post-summary.less → post-summary.less} +155 -60
- package/lib/css/components/{_stacks-progress-bars.less → progress-bars.less} +29 -30
- package/lib/css/components/{_stacks-prose.less → prose.less} +31 -31
- package/lib/css/components/{_stacks-spinner.less → spinner.less} +14 -14
- package/lib/css/components/{_stacks-tables.less → tables.less} +10 -10
- package/lib/css/components/{_stacks-tags.less → tags.less} +33 -41
- package/lib/css/components/{_stacks-toggle-switches.less → toggle-switches.less} +5 -5
- package/lib/css/components/{_stacks-topbar.less → topbar.less} +27 -40
- package/lib/css/components/{_stacks-uploader.less → uploader.less} +18 -18
- package/lib/css/components/{_stacks-user-cards.less → user-cards.less} +14 -14
- package/lib/css/components/{_stacks-widget-dynamic.less → widget-dynamic.less} +1 -1
- package/lib/css/components/{_stacks-widget-static.less → widget-static.less} +39 -38
- package/lib/css/exports/{_stacks-constants-colors.less → constants-colors.less} +21 -29
- package/lib/css/exports/constants-helpers.less +108 -0
- package/lib/css/exports/constants-type.less +153 -0
- package/lib/css/exports/{_stacks-exports.less → exports.less} +4 -4
- package/lib/css/exports/{_stacks-mixins.less → mixins.less} +18 -1
- package/lib/css/stacks-dynamic.less +12 -13
- package/lib/css/stacks-static.less +38 -38
- package/lib/ts/controllers/index.ts +8 -0
- package/lib/ts/controllers/s-expandable-control.ts +163 -164
- package/lib/ts/controllers/s-modal.ts +259 -261
- package/lib/ts/controllers/s-navigation-tablist.ts +96 -97
- package/lib/ts/controllers/s-popover.ts +438 -440
- package/lib/ts/controllers/s-table.ts +203 -203
- package/lib/ts/controllers/s-tooltip.ts +195 -196
- package/lib/ts/controllers/s-uploader.ts +162 -164
- package/lib/ts/index.ts +20 -0
- package/lib/ts/stacks.ts +73 -68
- package/lib/tsconfig.json +8 -6
- package/package.json +43 -27
- package/dist/css/stacks-flexgrid-shim.min.css +0 -1
- package/lib/css/atomic/_stacks-spacing.less +0 -162
- package/lib/css/atomic/_stacks-width-height.less +0 -189
- package/lib/css/base/_stacks-configuration-dynamic.less +0 -106
- package/lib/css/exports/_stacks-constants-helpers.less +0 -139
- package/lib/css/exports/_stacks-constants-type.less +0 -91
- package/lib/ts/finalize.ts +0 -1
- package/lib/ts/stimulus.d.ts +0 -4
|
@@ -1,247 +1,246 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
placement: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export class TooltipController extends BasePopoverController {
|
|
7
|
-
static targets = [];
|
|
1
|
+
import * as Stacks from "../stacks";
|
|
2
|
+
import { BasePopoverController, PopoverController } from "./s-popover";
|
|
8
3
|
|
|
9
|
-
|
|
4
|
+
export interface TooltipOptions {
|
|
5
|
+
placement: string;
|
|
6
|
+
}
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
private boundHideIfWithin!: any;
|
|
14
|
-
private activeTimeout!: any;
|
|
8
|
+
export class TooltipController extends BasePopoverController {
|
|
9
|
+
static targets = [];
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
* Binds mouseover and mouseout events in addition to BasePopoverController.connect
|
|
18
|
-
*/
|
|
19
|
-
connect() {
|
|
20
|
-
super.connect();
|
|
11
|
+
protected popoverSelectorAttribute = "aria-describedby";
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.bindMouseEvents();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
13
|
+
private boundScheduleShow!: any;
|
|
14
|
+
private boundHide!: any;
|
|
15
|
+
private boundHideIfWithin!: any;
|
|
16
|
+
private activeTimeout!: any;
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Binds mouseover and mouseout events in addition to BasePopoverController.connect
|
|
20
|
+
*/
|
|
21
|
+
connect() {
|
|
22
|
+
super.connect();
|
|
23
|
+
|
|
24
|
+
// Only bind to mouse events if the pointer device supports hover behavior.
|
|
25
|
+
// Otherwise we run into issues with mobile browser showing popovers for
|
|
26
|
+
// click events and not being able to hide them.
|
|
27
|
+
if (window.matchMedia("(hover: hover)").matches) {
|
|
28
|
+
this.bindMouseEvents();
|
|
36
29
|
}
|
|
30
|
+
}
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// if the controller exists and already has a visible popover, don't show the tooltip
|
|
47
|
-
if (controller && (<PopoverController>controller).isVisible) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
32
|
+
/**
|
|
33
|
+
* Unbinds mouse events in addition to BasePopoverController.disconnect
|
|
34
|
+
*/
|
|
35
|
+
disconnect() {
|
|
36
|
+
this.unbindMouseEvents();
|
|
37
|
+
super.disconnect();
|
|
38
|
+
}
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Attempts to show the tooltip popover so long as no other Stacks-managed popover is
|
|
42
|
+
* present on the page.
|
|
43
|
+
*/
|
|
44
|
+
show(dispatcher: Event|Element|null = null) {
|
|
45
|
+
// check and see if this controller coexists with a popover
|
|
46
|
+
var controller = Stacks.application.getControllerForElementAndIdentifier(this.element, "s-popover");
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
scheduleShow(dispatcher: Event | Element | null = null) {
|
|
58
|
-
window.clearTimeout(this.activeTimeout);
|
|
59
|
-
this.activeTimeout = window.setTimeout(() => this.show(dispatcher), 300);
|
|
48
|
+
// if the controller exists and already has a visible popover, don't show the tooltip
|
|
49
|
+
if (controller && (<PopoverController>controller).isVisible) {
|
|
50
|
+
return;
|
|
60
51
|
}
|
|
61
52
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*/
|
|
65
|
-
hide(dispatcher: Event | Element | null = null) {
|
|
66
|
-
window.clearTimeout(this.activeTimeout);
|
|
67
|
-
this.activeTimeout = null;
|
|
68
|
-
|
|
69
|
-
super.hide(dispatcher);
|
|
70
|
-
}
|
|
53
|
+
super.show(dispatcher);
|
|
54
|
+
}
|
|
71
55
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Sets up a tooltip popover show after a delay.
|
|
58
|
+
*/
|
|
59
|
+
scheduleShow(dispatcher: Event | Element | null = null) {
|
|
60
|
+
window.clearTimeout(this.activeTimeout);
|
|
61
|
+
this.activeTimeout = window.setTimeout(() => this.show(dispatcher), 300);
|
|
62
|
+
}
|
|
76
63
|
|
|
77
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Cancels the scheduled tooltip popover display and hides it if already displayed
|
|
66
|
+
*/
|
|
67
|
+
hide(dispatcher: Event | Element | null = null) {
|
|
68
|
+
window.clearTimeout(this.activeTimeout);
|
|
69
|
+
this.activeTimeout = null;
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
content = document.createRange().createContextualFragment(htmlTitle);
|
|
82
|
-
} else {
|
|
83
|
-
var plainTitle = this.element.getAttribute("title");
|
|
84
|
-
if (plainTitle) {
|
|
85
|
-
content = document.createTextNode(plainTitle);
|
|
86
|
-
} else {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
71
|
+
super.hide(dispatcher);
|
|
72
|
+
}
|
|
90
73
|
|
|
91
|
-
|
|
92
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Applies data-s-tooltip-html-title and title attributes.
|
|
76
|
+
*/
|
|
77
|
+
applyTitleAttributes() {
|
|
93
78
|
|
|
94
|
-
|
|
95
|
-
if (!popoverId) {
|
|
96
|
-
popoverId = TooltipController.generateId();
|
|
97
|
-
this.element.setAttribute("aria-describedby", popoverId);
|
|
98
|
-
}
|
|
79
|
+
var content: Node;
|
|
99
80
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (parentNode) {
|
|
110
|
-
// insertBefore inserts at end if element.nextSibling is null.
|
|
111
|
-
parentNode.insertBefore(popover, this.element.nextSibling);
|
|
112
|
-
} else {
|
|
113
|
-
document.body.appendChild(popover);
|
|
114
|
-
}
|
|
81
|
+
var htmlTitle = this.data.get("html-title");
|
|
82
|
+
if (htmlTitle) {
|
|
83
|
+
content = document.createRange().createContextualFragment(htmlTitle);
|
|
84
|
+
} else {
|
|
85
|
+
var plainTitle = this.element.getAttribute("title");
|
|
86
|
+
if (plainTitle) {
|
|
87
|
+
content = document.createTextNode(plainTitle);
|
|
88
|
+
} else {
|
|
89
|
+
return null;
|
|
115
90
|
}
|
|
91
|
+
}
|
|
116
92
|
|
|
117
|
-
|
|
93
|
+
this.data.delete("html-title");
|
|
94
|
+
this.element.removeAttribute("title");
|
|
118
95
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
96
|
+
var popoverId = this.element.getAttribute("aria-describedby");
|
|
97
|
+
if (!popoverId) {
|
|
98
|
+
popoverId = TooltipController.generateId();
|
|
99
|
+
this.element.setAttribute("aria-describedby", popoverId);
|
|
100
|
+
}
|
|
122
101
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
102
|
+
var popover = document.getElementById(popoverId);
|
|
103
|
+
if (!popover) {
|
|
104
|
+
popover = document.createElement("div");
|
|
105
|
+
popover.id = popoverId;
|
|
106
|
+
popover.className = "s-popover s-popover__tooltip pe-none";
|
|
107
|
+
popover.setAttribute("aria-hidden", "true");
|
|
108
|
+
popover.setAttribute("role", "tooltip");
|
|
109
|
+
|
|
110
|
+
var parentNode = this.element.parentNode;
|
|
111
|
+
if (parentNode) {
|
|
112
|
+
// insertBefore inserts at end if element.nextSibling is null.
|
|
113
|
+
parentNode.insertBefore(popover, this.element.nextSibling);
|
|
126
114
|
} else {
|
|
127
|
-
|
|
115
|
+
document.body.appendChild(popover);
|
|
128
116
|
}
|
|
129
|
-
|
|
130
|
-
this.scheduleUpdate();
|
|
131
|
-
|
|
132
|
-
return popover;
|
|
133
117
|
}
|
|
134
118
|
|
|
135
|
-
|
|
136
|
-
* Automatically hides the tooltip popover when a Stacks popover is shown anywhere on
|
|
137
|
-
* the page.
|
|
138
|
-
*/
|
|
139
|
-
protected bindDocumentEvents() {
|
|
140
|
-
this.boundHideIfWithin = this.boundHideIfWithin || this.hideIfWithin.bind(this);
|
|
119
|
+
const arrow = popover.querySelector(".s-popover--arrow");
|
|
141
120
|
|
|
142
|
-
|
|
143
|
-
|
|
121
|
+
// clear and set the content of the popover
|
|
122
|
+
popover.innerHTML = "";
|
|
123
|
+
popover.appendChild(content);
|
|
144
124
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
125
|
+
// create the arrow if necessary
|
|
126
|
+
if (arrow) {
|
|
127
|
+
popover.appendChild(arrow);
|
|
128
|
+
} else {
|
|
129
|
+
popover.insertAdjacentHTML("beforeend", `<div class="s-popover--arrow"></div>`);
|
|
150
130
|
}
|
|
151
131
|
|
|
152
|
-
|
|
153
|
-
* Attempts to generate a new tooltip popover from the title attribute if no popover
|
|
154
|
-
* was present when requested, otherwise throws an error.
|
|
155
|
-
*/
|
|
156
|
-
protected generatePopover(): HTMLElement | null {
|
|
157
|
-
return this.applyTitleAttributes();
|
|
158
|
-
}
|
|
132
|
+
this.scheduleUpdate();
|
|
159
133
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* @param event An event object from s-popover:shown
|
|
163
|
-
*/
|
|
164
|
-
private hideIfWithin(event: Event) {
|
|
165
|
-
if ((<Element>event.target!).contains(this.referenceElement)) {
|
|
166
|
-
this.hide();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
134
|
+
return popover;
|
|
135
|
+
}
|
|
169
136
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.referenceElement.addEventListener("mouseover", this.boundScheduleShow);
|
|
178
|
-
this.referenceElement.addEventListener("mouseout", this.boundHide);
|
|
179
|
-
this.referenceElement.addEventListener("focus", this.boundScheduleShow);
|
|
180
|
-
this.referenceElement.addEventListener("blur", this.boundHide);
|
|
181
|
-
}
|
|
137
|
+
/**
|
|
138
|
+
* Automatically hides the tooltip popover when a Stacks popover is shown anywhere on
|
|
139
|
+
* the page.
|
|
140
|
+
*/
|
|
141
|
+
protected bindDocumentEvents() {
|
|
142
|
+
this.boundHideIfWithin = this.boundHideIfWithin || this.hideIfWithin.bind(this);
|
|
182
143
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
144
|
+
document.addEventListener("s-popover:shown", this.boundHideIfWithin);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Unbinds all mouse events
|
|
149
|
+
*/
|
|
150
|
+
protected unbindDocumentEvents() {
|
|
151
|
+
document.removeEventListener("s-popover:shown", this.boundHideIfWithin);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Attempts to generate a new tooltip popover from the title attribute if no popover
|
|
156
|
+
* was present when requested, otherwise throws an error.
|
|
157
|
+
*/
|
|
158
|
+
protected generatePopover(): HTMLElement | null {
|
|
159
|
+
return this.applyTitleAttributes();
|
|
160
|
+
}
|
|
192
161
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Hides the tooltip if is or is within the event's target.
|
|
164
|
+
* @param event An event object from s-popover:shown
|
|
165
|
+
*/
|
|
166
|
+
private hideIfWithin(event: Event) {
|
|
167
|
+
if ((<Element>event.target!).contains(this.referenceElement)) {
|
|
168
|
+
this.hide();
|
|
199
169
|
}
|
|
200
170
|
}
|
|
201
171
|
|
|
202
172
|
/**
|
|
203
|
-
*
|
|
204
|
-
* @param element The element to add a tooltip to.
|
|
205
|
-
* @param html An HTML string to populate the tooltip with.
|
|
206
|
-
* @param options Options for rendering the tooltip.
|
|
173
|
+
* Binds mouse events to show/hide on reference element hover
|
|
207
174
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
175
|
+
private bindMouseEvents() {
|
|
176
|
+
this.boundScheduleShow = this.boundScheduleShow || this.scheduleShow.bind(this);
|
|
177
|
+
this.boundHide = this.boundHide || this.hide.bind(this);
|
|
178
|
+
|
|
179
|
+
this.referenceElement.addEventListener("mouseover", this.boundScheduleShow);
|
|
180
|
+
this.referenceElement.addEventListener("mouseout", this.boundHide);
|
|
181
|
+
this.referenceElement.addEventListener("focus", this.boundScheduleShow);
|
|
182
|
+
this.referenceElement.addEventListener("blur", this.boundHide);
|
|
212
183
|
}
|
|
213
184
|
|
|
214
185
|
/**
|
|
215
|
-
*
|
|
216
|
-
* @param element The element to add a tooltip to.
|
|
217
|
-
* @param text A plain text string to populate the tooltip with.
|
|
218
|
-
* @param options Options for rendering the tooltip.
|
|
186
|
+
* Unbinds all mouse events
|
|
219
187
|
*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
188
|
+
private unbindMouseEvents() {
|
|
189
|
+
this.referenceElement.removeEventListener("mouseover", this.boundScheduleShow);
|
|
190
|
+
this.referenceElement.removeEventListener("mouseout", this.boundHide);
|
|
191
|
+
this.referenceElement.removeEventListener("focus", this.boundScheduleShow);
|
|
192
|
+
this.referenceElement.removeEventListener("blur", this.boundHide);
|
|
224
193
|
}
|
|
225
194
|
|
|
226
195
|
/**
|
|
227
|
-
*
|
|
228
|
-
* @param element The element to add a tooltip to.
|
|
229
|
-
* @param options Options for rendering the tooltip.
|
|
196
|
+
* Generates an ID for tooltips created with setTooltip.
|
|
230
197
|
*/
|
|
231
|
-
|
|
198
|
+
private static generateId() {
|
|
199
|
+
// generate a random number, then convert to a well formatted string
|
|
200
|
+
return "--stacks-s-tooltip-" + Math.random().toString(36).substring(2, 10);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
232
203
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Adds or updates a Stacks tooltip on a given element, initializing the controller if necessary
|
|
206
|
+
* @param element The element to add a tooltip to.
|
|
207
|
+
* @param html An HTML string to populate the tooltip with.
|
|
208
|
+
* @param options Options for rendering the tooltip.
|
|
209
|
+
*/
|
|
210
|
+
export function setTooltipHtml(element: Element, html: string, options?: TooltipOptions) {
|
|
211
|
+
element.setAttribute("data-s-tooltip-html-title", html);
|
|
212
|
+
element.removeAttribute("title");
|
|
213
|
+
applyOptionsAndTitleAttributes(element, options);
|
|
214
|
+
}
|
|
236
215
|
|
|
237
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Adds or updates a Stacks tooltip on a given element, initializing the controller if necessary
|
|
218
|
+
* @param element The element to add a tooltip to.
|
|
219
|
+
* @param text A plain text string to populate the tooltip with.
|
|
220
|
+
* @param options Options for rendering the tooltip.
|
|
221
|
+
*/
|
|
222
|
+
export function setTooltipText(element: Element, text: string, options?: TooltipOptions) {
|
|
223
|
+
element.setAttribute("title", text);
|
|
224
|
+
element.removeAttribute("data-s-tooltip-html-title");
|
|
225
|
+
applyOptionsAndTitleAttributes(element, options);
|
|
226
|
+
}
|
|
238
227
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Shared helper for setTooltip* to initialize and set tooltip content
|
|
230
|
+
* @param element The element to add a tooltip to.
|
|
231
|
+
* @param options Options for rendering the tooltip.
|
|
232
|
+
*/
|
|
233
|
+
function applyOptionsAndTitleAttributes(element: Element, options?: TooltipOptions) {
|
|
234
|
+
|
|
235
|
+
if (options && options.placement) {
|
|
236
|
+
element.setAttribute("data-s-tooltip-placement", options.placement);
|
|
244
237
|
}
|
|
245
|
-
}
|
|
246
238
|
|
|
247
|
-
Stacks.application.
|
|
239
|
+
var controller = <TooltipController>Stacks.application.getControllerForElementAndIdentifier(element, "s-tooltip");
|
|
240
|
+
|
|
241
|
+
if (controller) {
|
|
242
|
+
controller.applyTitleAttributes();
|
|
243
|
+
} else {
|
|
244
|
+
element.setAttribute("data-controller", element.getAttribute("data-controller") + " s-tooltip");
|
|
245
|
+
}
|
|
246
|
+
}
|