ozdenui 0.1.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.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Tooltip - v26.10
|
|
6
|
+
|
|
7
|
+
- A hint over an object: it follows the mouse while the mouse is on its target (Tooltip({ target, hintText })).
|
|
8
|
+
- THEMES: styleName "minimal" / "minimalDark" (Tooltip.looks: on the ground of the window with a line, no shadow,
|
|
9
|
+
no arrow); Tooltip.show(target, text, Tooltip.looks.minimal) for a bubble at an object.
|
|
10
|
+
- THE BUBBLE: an optional arrow (lbl_arrow, px) that points at the mouse / the target; the
|
|
11
|
+
edge of the bubble (lbl_border) goes around the arrow too, as one line. The bubble never goes out of the screen:
|
|
12
|
+
it slides inside, or goes to the other side when there is no room (top <-> bottom, left <-> right); the arrow
|
|
13
|
+
still points at its place.
|
|
14
|
+
- Tooltip.show(target, text, look, side, content): a bubble at an object, not under the mouse (Ex: the "Click
|
|
15
|
+
again" of a SmartButton ask); it returns the bubble, bubble.remove() takes it away. look: Tooltip.BUBBLE_LOOK keys.
|
|
16
|
+
It stays at its target while a box under it scrolls, and hides while the target is out of sight. The popover does the same.
|
|
17
|
+
- CONTENT: content: function (bubble) { ... } builds its own objects in the bubble in place of the text
|
|
18
|
+
(a title and a text, a shortcut, a user card...); they are made one under the other (look.contentGap).
|
|
19
|
+
- POPOVER: trigger: "click" (or Tooltip.openPopover()): a click on the target opens the bubble and it
|
|
20
|
+
stays; its content can be clicked (buttons, fields). A click outside, Escape or a second click on the target closes
|
|
21
|
+
it. One popover at a time (Tooltip.closePopover()).
|
|
22
|
+
- SCALE: scale (the param of Tooltip(), look.scale of Tooltip.show() / openPopover()) multiplies every
|
|
23
|
+
size of the bubble: its text, padding, round corners, edge, shadow, arrow and its gaps. null (default):
|
|
24
|
+
basic.uiScale when the bubble opens (1; a page fitted with page.fit() sets 1 / page.zoom: the bubble keeps its
|
|
25
|
+
size on the screen). The objects of content(bubble) are made by the page: bubble.look.scale is their scale.
|
|
26
|
+
|
|
27
|
+
USAGE:
|
|
28
|
+
btn.tooltip = Tooltip({ target: btn, hintText: "Save the file", hintPosition: "top", lbl_arrow: 10 });
|
|
29
|
+
avatar.tooltip = Tooltip({ target: avatar, content: function (bubble) { Label({ text: "Ayşe Kaya", bold: 1 }); } });
|
|
30
|
+
btnShare.tooltip = Tooltip({ target: btnShare, trigger: "click", lbl_arrow: 12, content: function (bubble) {
|
|
31
|
+
Label({ text: "Share the link" });
|
|
32
|
+
SmartButton({ labelText: "Copy", onClick: function () { Tooltip.closePopover(); } });
|
|
33
|
+
} });
|
|
34
|
+
const bubble = Tooltip.show(button, "Click again to delete.", { color: "#E8796D", textColor: "white", arrow: 12 });
|
|
35
|
+
bubble.remove();
|
|
36
|
+
Tooltip.show(button, "Saved", { arrow: 10, scale: 1.5 }); // every size x 1.5 (default: basic.uiScale)
|
|
37
|
+
|
|
38
|
+
Started Date: June 2024
|
|
39
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
40
|
+
|
|
41
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
42
|
+
Licensed under the Apache License, Version 2.0
|
|
43
|
+
SPDX-License-Identifier: Apache-2.0
|
|
44
|
+
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
"use strict";
|
|
48
|
+
const Tooltip = function(params = {}) {
|
|
49
|
+
|
|
50
|
+
// Default values
|
|
51
|
+
const defaults = {
|
|
52
|
+
target: null,
|
|
53
|
+
hintText: "",
|
|
54
|
+
hintPosition: "top", // "top", "left", "bottom", "right"
|
|
55
|
+
lbl_fontSize: 12,
|
|
56
|
+
lbl_spaceX: 8,
|
|
57
|
+
lbl_spaceY: 3,
|
|
58
|
+
lbl_color: "rgba(255, 255, 255, 0.90)",
|
|
59
|
+
lbl_textColor: "rgba(0, 0, 0, 0.85)",
|
|
60
|
+
lbl_round: 3,
|
|
61
|
+
lbl_border: 1,
|
|
62
|
+
lbl_borderColor: "rgba(0, 0, 0, 0.9)",
|
|
63
|
+
lbl_arrow: 0, // px: the side of the arrow (0: no arrow)
|
|
64
|
+
content: null, // function (bubble): its own objects in the bubble, in place of hintText
|
|
65
|
+
trigger: "hover", // "hover": it follows the mouse; "click": a popover (it stays, its content can be clicked)
|
|
66
|
+
look: null, // Tooltip.BUBBLE_LOOK keys over the lbl_ ones (Ex: { shadow, padding: [16, 14], contentGap })
|
|
67
|
+
styleName: "", // a look of Tooltip.looks under look ("minimal", "minimalDark"). "": the lbl_ params
|
|
68
|
+
scale: null, // every size of the bubble multiplied (Ex: 1.5); null: basic.uiScale when the bubble opens
|
|
69
|
+
visible: 0,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// BOX: Component container
|
|
73
|
+
const box = startObject();
|
|
74
|
+
|
|
75
|
+
// Values ready to use
|
|
76
|
+
box.props(defaults, params);
|
|
77
|
+
|
|
78
|
+
// *** Private variables:
|
|
79
|
+
let removeMouseOver = null;
|
|
80
|
+
let removeMouseMove = null;
|
|
81
|
+
let removeMouseOut = null;
|
|
82
|
+
let removeClick = null;
|
|
83
|
+
// The room between the mouse and the bubble, for each side (under the mouse: the cursor is there)
|
|
84
|
+
const MOUSE_GAPS = { top: 12, bottom: 20, left: 25, right: 25 };
|
|
85
|
+
|
|
86
|
+
// *** Private functions:
|
|
87
|
+
|
|
88
|
+
// WHY: One hint (window.lblHint) is shared by every Tooltip: only the one under the mouse is open.
|
|
89
|
+
const removeHintLabel = function() {
|
|
90
|
+
if (!window.lblHint) return;
|
|
91
|
+
window.lblHint.remove();
|
|
92
|
+
window.lblHint = null;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const getLook = function() {
|
|
96
|
+
return Object.assign({
|
|
97
|
+
fontSize: box.lbl_fontSize,
|
|
98
|
+
padding: [box.lbl_spaceX, box.lbl_spaceY],
|
|
99
|
+
color: box.lbl_color,
|
|
100
|
+
textColor: box.lbl_textColor,
|
|
101
|
+
round: box.lbl_round,
|
|
102
|
+
border: box.lbl_border,
|
|
103
|
+
borderColor: box.lbl_borderColor,
|
|
104
|
+
arrow: box.lbl_arrow,
|
|
105
|
+
gap: MOUSE_GAPS[box.hintPosition] || MOUSE_GAPS.top,
|
|
106
|
+
scale: box.scale,
|
|
107
|
+
}, Tooltip.looks[box.styleName] || {}, box.look || {});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// The color of the bubble: the one of look wins over lbl_color (getLook)
|
|
111
|
+
const getColor = function() {
|
|
112
|
+
return getLook().color;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const refreshPosition = function(event) {
|
|
116
|
+
const point = Tooltip.toPagePoint(event.clientX, event.clientY);
|
|
117
|
+
box.mouseX = point.x;
|
|
118
|
+
box.mouseY = point.y;
|
|
119
|
+
Tooltip.place(window.lblHint, { left: point.x, top: point.y, width: 0, height: 0 }, box.hintPosition);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// *** Public functions:
|
|
123
|
+
|
|
124
|
+
// WHY: box.superRemove is overwritten by a component that extends this one, so the local copy is called below.
|
|
125
|
+
const superRemove = box.remove;
|
|
126
|
+
box.superRemove = superRemove;
|
|
127
|
+
box.remove = function() {
|
|
128
|
+
|
|
129
|
+
if (box._isRemoved) return; // WHY: remove() can be called twice (also by the parent's remove()).
|
|
130
|
+
|
|
131
|
+
// WHY: The mouse events are on the target object, box.remove() does not clean them.
|
|
132
|
+
removeMouseOver();
|
|
133
|
+
removeMouseMove();
|
|
134
|
+
removeMouseOut();
|
|
135
|
+
removeClick();
|
|
136
|
+
|
|
137
|
+
removeHintLabel();
|
|
138
|
+
if (Tooltip.isPopoverOf(box.target)) Tooltip.closePopover();
|
|
139
|
+
|
|
140
|
+
superRemove.call(box); // NOTE: basic.js remove(). It cleans all the events and the objects inside.
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
box.setHintText = function(text) {
|
|
145
|
+
box.hintText = text;
|
|
146
|
+
// WHY owner: one bubble is shared; a late call must not write on the bubble of another object.
|
|
147
|
+
if (!window.lblHint || !window.lblHint.label || window.lblHint.owner !== box) return;
|
|
148
|
+
window.lblHint.label.plainText = text;
|
|
149
|
+
if (box.mouseX === undefined) return; // The mouse did not move yet: the first mousemove places it
|
|
150
|
+
// WHY: A new text changes the width of the bubble: the bubble and its arrow must go to the mouse again.
|
|
151
|
+
Tooltip.place(window.lblHint, { left: box.mouseX, top: box.mouseY, width: 0, height: 0 }, box.hintPosition);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The bubble goes away until the mouse comes on the target again.
|
|
155
|
+
box.hideHint = function() {
|
|
156
|
+
// WHY owner: one bubble is shared; a late call must not remove the bubble of another object.
|
|
157
|
+
if (window.lblHint && window.lblHint.owner === box) removeHintLabel();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
box.setLbl_color = function(color) {
|
|
161
|
+
box.lbl_color = color;
|
|
162
|
+
if (box.look && box.look.color) box.look = Object.assign({}, box.look, { color: color });
|
|
163
|
+
if (window.lblHint) {
|
|
164
|
+
Tooltip.paintBubble(window.lblHint, color);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// *** OBJECT TEMPLATE:
|
|
169
|
+
|
|
170
|
+
const isClick = function() {
|
|
171
|
+
return box.trigger == "click";
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
removeMouseOver = box.target.on("mouseover", function() {
|
|
175
|
+
if (isClick() || window.lblHint) return;
|
|
176
|
+
window.lblHint = Tooltip.createBubble(box.hintText, getLook(), box.content);
|
|
177
|
+
window.lblHint.owner = box;
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
removeMouseMove = box.target.on("mousemove", function(self, event) {
|
|
181
|
+
if (isClick() || !window.lblHint) return;
|
|
182
|
+
window.lblHint.owner = box;
|
|
183
|
+
|
|
184
|
+
// WHY: when the mouse stays on an object that shows a tooltip, and
|
|
185
|
+
// another event changes the text and the color of the tooltip, a mouse moved without entering the object
|
|
186
|
+
// could show the text of the other event. So the text is checked.
|
|
187
|
+
// WHY plainText: the bubble is made with it (Tooltip.createBubble); text read the escaped HTML, so a hint with
|
|
188
|
+
// "&" or "<" was never the same and was written again as HTML
|
|
189
|
+
if (window.lblHint.label && window.lblHint.label.plainText != box.hintText) {
|
|
190
|
+
window.lblHint.label.plainText = box.hintText;
|
|
191
|
+
}
|
|
192
|
+
// WHY getColor(): a color of look must stay (lbl_color painted a dark bubble of a content white)
|
|
193
|
+
if (window.lblHint.look.color != getColor()) {
|
|
194
|
+
Tooltip.paintBubble(window.lblHint, getColor());
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
refreshPosition(event);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
removeMouseOut = box.target.on("mouseout", function() {
|
|
201
|
+
if (isClick()) return;
|
|
202
|
+
removeHintLabel();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// POPOVER: a click opens it, a second click closes it
|
|
206
|
+
removeClick = box.target.on("click", function() {
|
|
207
|
+
if (!isClick()) return;
|
|
208
|
+
if (Tooltip.isPopoverOf(box.target)) {
|
|
209
|
+
Tooltip.closePopover();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
Tooltip.openPopover(box.target, box.content, Object.assign(getLook(), { gap: (box.look && box.look.gap) || 6 }), box.hintPosition, box.hintText);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// *** OBJECT INIT CODE:
|
|
216
|
+
box.target.clickable = 1;
|
|
217
|
+
|
|
218
|
+
return endObject(box);
|
|
219
|
+
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// *** THE BUBBLE (static: the hint of Tooltip and Tooltip.show() use it)
|
|
223
|
+
|
|
224
|
+
// The keys of a look (Tooltip.show(target, text, look) fills the missing ones from here)
|
|
225
|
+
Tooltip.BUBBLE_LOOK = {
|
|
226
|
+
fontSize: 13,
|
|
227
|
+
bold: 0,
|
|
228
|
+
padding: [10, 6], // [left / right, top / bottom]
|
|
229
|
+
color: "rgba(255, 255, 255, 0.95)",
|
|
230
|
+
textColor: "rgba(0, 0, 0, 0.85)",
|
|
231
|
+
round: 6,
|
|
232
|
+
border: 0, // px: the edge goes around the arrow too
|
|
233
|
+
borderColor: "rgba(0, 0, 0, 0.2)",
|
|
234
|
+
shadow: "", // Ex: "0 6px 16px rgba(0, 0, 0, 0.18)"
|
|
235
|
+
arrow: 10, // px: the side of the arrow (0: no arrow)
|
|
236
|
+
contentGap: 8, // px: between the objects of a content
|
|
237
|
+
gap: 6, // px: from the target to the point of the arrow
|
|
238
|
+
edge: 8, // px: the bubble stays this far inside the screen
|
|
239
|
+
grow: 0, // 1: it grows out of the point of the arrow (not with reduced motion)
|
|
240
|
+
zIndex: 100000, // WHY: on page, over the popups (Dialog cover 4000, Modal...)
|
|
241
|
+
scale: null, // every size above multiplied (Ex: 1.5); null: basic.uiScale (a page fitted with page.fit())
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// The look with its sizes multiplied by its scale (null: basic.uiScale); with scale 1 the same look.
|
|
245
|
+
// WHY arrow, edge and shadow by name: basic.scaleStyle() multiplies only the keys named like a size (gap, round...)
|
|
246
|
+
Tooltip.scaleLook = function(look) {
|
|
247
|
+
const scale = look.scale ?? basic.uiScale;
|
|
248
|
+
const scaled = basic.scaleStyle(look, scale);
|
|
249
|
+
if (scale !== 1) {
|
|
250
|
+
scaled.arrow = basic.scaleSize(look.arrow, scale);
|
|
251
|
+
scaled.edge = basic.scaleSize(look.edge, scale);
|
|
252
|
+
scaled.shadow = basic.scaleCssText(look.shadow, scale);
|
|
253
|
+
}
|
|
254
|
+
scaled.scale = scale;
|
|
255
|
+
return scaled;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// GROUP: A bubble on the page: a text (or the objects of content(bubble)), and an arrow whose edge goes on from
|
|
259
|
+
// the edge of the bubble
|
|
260
|
+
Tooltip.createBubble = function(text, look, content) {
|
|
261
|
+
const _l = Tooltip.scaleLook(Object.assign({}, Tooltip.BUBBLE_LOOK, look || {}));
|
|
262
|
+
const hasContent = (typeof content === "function");
|
|
263
|
+
const bubble = createIn(page, function() {
|
|
264
|
+
const group = AutoLayout({
|
|
265
|
+
flow: hasContent ? "vertical" : "horizontal",
|
|
266
|
+
hug: 1,
|
|
267
|
+
align: hasContent ? "left top" : "center center",
|
|
268
|
+
gap: hasContent ? _l.contentGap : 0,
|
|
269
|
+
padding: _l.padding,
|
|
270
|
+
color: _l.color,
|
|
271
|
+
round: _l.round,
|
|
272
|
+
border: _l.border,
|
|
273
|
+
borderColor: _l.borderColor,
|
|
274
|
+
clipContent: 0,
|
|
275
|
+
zIndex: _l.zIndex,
|
|
276
|
+
role: "status",
|
|
277
|
+
});
|
|
278
|
+
group.css = { position: "absolute", boxShadow: _l.shadow || "none" };
|
|
279
|
+
group.look = _l; // (before content(): its objects can read look.scale)
|
|
280
|
+
group.label = null;
|
|
281
|
+
if (hasContent) {
|
|
282
|
+
content(group);
|
|
283
|
+
} else {
|
|
284
|
+
group.label = Label({ plainText: text, fontSize: _l.fontSize, bold: _l.bold ? 1 : 0, textColor: _l.textColor });
|
|
285
|
+
// WHY: as wide as its text (a width measured before the font came cut the end of the text)
|
|
286
|
+
group.label.css = { whiteSpace: "nowrap", width: "max-content", flexShrink: "0" };
|
|
287
|
+
}
|
|
288
|
+
// BOX: Arrow (a turned square over the edge of the bubble; two of its sides have the edge)
|
|
289
|
+
group.arrow = Box({ width: _l.arrow, height: _l.arrow, color: _l.color, visible: _l.arrow ? 1 : 0 });
|
|
290
|
+
group.arrow.css = { position: "absolute", boxSizing: "border-box" };
|
|
291
|
+
endAutoLayout();
|
|
292
|
+
return group;
|
|
293
|
+
});
|
|
294
|
+
return bubble;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
Tooltip.paintBubble = function(bubble, color) {
|
|
298
|
+
bubble.look.color = color;
|
|
299
|
+
bubble.color = color;
|
|
300
|
+
bubble.arrow.color = color;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// A point of the screen (clientX / clientY) in the pixels of the page (page.fit() zooms it with a transform)
|
|
304
|
+
Tooltip.toPagePoint = function(clientX, clientY) {
|
|
305
|
+
const pageRect = page.elem.getBoundingClientRect();
|
|
306
|
+
const scale = (pageRect.width / page.elem.offsetWidth) || 1;
|
|
307
|
+
return { x: (clientX - pageRect.left) / scale, y: (clientY - pageRect.top) / scale };
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// The place of an object in the pixels of the page
|
|
311
|
+
Tooltip.toPageRect = function(obj) {
|
|
312
|
+
const rect = obj.elem.getBoundingClientRect();
|
|
313
|
+
const topLeft = Tooltip.toPagePoint(rect.left, rect.top);
|
|
314
|
+
const bottomRight = Tooltip.toPagePoint(rect.right, rect.bottom);
|
|
315
|
+
return { left: topLeft.x, top: topLeft.y, width: bottomRight.x - topLeft.x, height: bottomRight.y - topLeft.y };
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// The screen in the pixels of the page
|
|
319
|
+
Tooltip.getScreenRect = function() {
|
|
320
|
+
const topLeft = Tooltip.toPagePoint(0, 0);
|
|
321
|
+
const bottomRight = Tooltip.toPagePoint(window.innerWidth, window.innerHeight);
|
|
322
|
+
return { left: topLeft.x, top: topLeft.y, right: bottomRight.x, bottom: bottomRight.y };
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// The bubble at a place (target: a rect in the pixels of the page; a point is a rect of 0 x 0), on its side
|
|
326
|
+
// ("top", "bottom", "left", "right"); the other side when there is no room; inside the screen.
|
|
327
|
+
// Returns the side it got.
|
|
328
|
+
Tooltip.place = function(bubble, target, side = "top") {
|
|
329
|
+
|
|
330
|
+
const _l = bubble.look;
|
|
331
|
+
const screen = Tooltip.getScreenRect();
|
|
332
|
+
const width = bubble.elem.offsetWidth;
|
|
333
|
+
const height = bubble.elem.offsetHeight;
|
|
334
|
+
// WHY 0.71: the point of a turned square is its half diagonal (side / √2) away from its middle
|
|
335
|
+
const reach = _l.gap + (_l.arrow ? _l.arrow * 0.71 : 0);
|
|
336
|
+
const centerX = target.left + target.width / 2;
|
|
337
|
+
const centerY = target.top + target.height / 2;
|
|
338
|
+
|
|
339
|
+
side = Tooltip.chooseSide(side, target, width, height, reach, screen, _l.edge);
|
|
340
|
+
|
|
341
|
+
let left = 0;
|
|
342
|
+
let top = 0;
|
|
343
|
+
if (side == "top") top = target.top - reach - height;
|
|
344
|
+
if (side == "bottom") top = target.top + target.height + reach;
|
|
345
|
+
if (side == "left") left = target.left - reach - width;
|
|
346
|
+
if (side == "right") left = target.left + target.width + reach;
|
|
347
|
+
if (side == "top" || side == "bottom") left = centerX - width / 2;
|
|
348
|
+
if (side == "left" || side == "right") top = centerY - height / 2;
|
|
349
|
+
|
|
350
|
+
// (rounded: the arrow is placed from the place the bubble really gets)
|
|
351
|
+
left = Math.round(Tooltip.clamp(left, screen.left + _l.edge, screen.right - _l.edge - width));
|
|
352
|
+
top = Math.round(Tooltip.clamp(top, screen.top + _l.edge, screen.bottom - _l.edge - height));
|
|
353
|
+
bubble.left = left;
|
|
354
|
+
bubble.top = top;
|
|
355
|
+
|
|
356
|
+
Tooltip.placeArrow(bubble, side, centerX - left, centerY - top);
|
|
357
|
+
return side;
|
|
358
|
+
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// The other side when the bubble does not fit on its side and fits there
|
|
362
|
+
Tooltip.chooseSide = function(side, target, width, height, reach, screen, edge) {
|
|
363
|
+
const room = {
|
|
364
|
+
top: target.top - screen.top - edge,
|
|
365
|
+
bottom: screen.bottom - edge - target.top - target.height,
|
|
366
|
+
left: target.left - screen.left - edge,
|
|
367
|
+
right: screen.right - edge - target.left - target.width,
|
|
368
|
+
};
|
|
369
|
+
const other = { top: "bottom", bottom: "top", left: "right", right: "left" }[side] || "bottom";
|
|
370
|
+
const need = (side == "top" || side == "bottom") ? height + reach : width + reach;
|
|
371
|
+
if (room[side] >= need || room[other] < need) return side;
|
|
372
|
+
return other;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
Tooltip.clamp = function(value, min, max) {
|
|
376
|
+
return Math.max(min, Math.min(max, value));
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// The arrow on the edge of the side that looks at the target; x / y: the target in the bubble (it stays off the
|
|
380
|
+
// round corners). WHY the middle on the edge line: the arrow covers that part of the edge, and its two sides
|
|
381
|
+
// with the edge go on from it.
|
|
382
|
+
Tooltip.placeArrow = function(bubble, side, x, y) {
|
|
383
|
+
const _l = bubble.look;
|
|
384
|
+
const arrow = bubble.arrow;
|
|
385
|
+
if (!_l.arrow) return;
|
|
386
|
+
const size = _l.arrow;
|
|
387
|
+
const line = _l.border;
|
|
388
|
+
// (the place of an absolute object starts inside the edge of the bubble)
|
|
389
|
+
const innerWidth = bubble.elem.clientWidth;
|
|
390
|
+
const innerHeight = bubble.elem.clientHeight;
|
|
391
|
+
const margin = _l.round + size * 0.71;
|
|
392
|
+
const edgeLine = line + "px solid " + _l.borderColor;
|
|
393
|
+
let left = 0;
|
|
394
|
+
let top = 0;
|
|
395
|
+
let sides = [];
|
|
396
|
+
if (side == "top" || side == "bottom") {
|
|
397
|
+
left = Tooltip.clamp(x - line, margin, innerWidth - margin) - size / 2;
|
|
398
|
+
top = (side == "top") ? innerHeight + line / 2 - size / 2 : -line / 2 - size / 2;
|
|
399
|
+
sides = (side == "top") ? ["Right", "Bottom"] : ["Left", "Top"];
|
|
400
|
+
} else {
|
|
401
|
+
top = Tooltip.clamp(y - line, margin, innerHeight - margin) - size / 2;
|
|
402
|
+
left = (side == "left") ? innerWidth + line / 2 - size / 2 : -line / 2 - size / 2;
|
|
403
|
+
sides = (side == "left") ? ["Top", "Right"] : ["Bottom", "Left"];
|
|
404
|
+
}
|
|
405
|
+
arrow.left = left;
|
|
406
|
+
arrow.top = top;
|
|
407
|
+
const css = { transform: "rotate(45deg)", borderTop: "none", borderRight: "none", borderBottom: "none", borderLeft: "none" };
|
|
408
|
+
if (line) sides.forEach(function(name) { css["border" + name] = edgeLine; });
|
|
409
|
+
arrow.css = css;
|
|
410
|
+
// (the bubble grows out of the point of the arrow)
|
|
411
|
+
bubble.css = { transformOrigin: (left + size / 2 + line) + "px " + (top + size / 2 + line) + "px" };
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// A bubble at an object (Ex: the "Click again" of an ask). Returns the bubble: bubble.remove() takes it away.
|
|
415
|
+
Tooltip.show = function(target, text, look, side = "top", content = null) {
|
|
416
|
+
const bubble = Tooltip.createBubble(text, look, content);
|
|
417
|
+
Tooltip.place(bubble, Tooltip.toPageRect(target), side);
|
|
418
|
+
// WHY: a text measured before its font came is narrower; the bubble is placed again when the fonts are ready
|
|
419
|
+
if (document.fonts && document.fonts.status != "loaded") {
|
|
420
|
+
document.fonts.ready.then(function() {
|
|
421
|
+
if (!bubble._isRemoved && !target._isRemoved) Tooltip.place(bubble, Tooltip.toPageRect(target), side);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
if (bubble.look.grow) Tooltip.grow(bubble);
|
|
425
|
+
Tooltip.followScroll(bubble, target, side);
|
|
426
|
+
return bubble;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// The bubble goes with its target when a box scrolls, once a frame (bubble.remove() cleans the event)
|
|
430
|
+
Tooltip.followScroll = function(bubble, target, side) {
|
|
431
|
+
let isPlaceWaiting = false;
|
|
432
|
+
const placeAgain = function() {
|
|
433
|
+
isPlaceWaiting = false;
|
|
434
|
+
if (bubble._isRemoved || target._isRemoved) return;
|
|
435
|
+
bubble.visible = Tooltip.isInSight(target) ? 1 : 0;
|
|
436
|
+
Tooltip.place(bubble, Tooltip.toPageRect(target), side);
|
|
437
|
+
};
|
|
438
|
+
// WHY on window in the capture phase: a scroll event does not bubble up; so it comes from every box that scrolls
|
|
439
|
+
bubble.listenTo(window, "scroll", function() {
|
|
440
|
+
if (isPlaceWaiting) return;
|
|
441
|
+
isPlaceWaiting = true;
|
|
442
|
+
requestAnimationFrame(placeAgain);
|
|
443
|
+
}, true);
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
// Is a part of the object seen: inside the screen and inside every box around it that cuts its content
|
|
447
|
+
Tooltip.isInSight = function(obj) {
|
|
448
|
+
const rect = obj.elem.getBoundingClientRect();
|
|
449
|
+
let left = Math.max(rect.left, 0);
|
|
450
|
+
let top = Math.max(rect.top, 0);
|
|
451
|
+
let right = Math.min(rect.right, window.innerWidth);
|
|
452
|
+
let bottom = Math.min(rect.bottom, window.innerHeight);
|
|
453
|
+
for (let elem = obj.elem.parentElement; elem && elem !== document.body; elem = elem.parentElement) {
|
|
454
|
+
if (getComputedStyle(elem).overflow == "visible") continue;
|
|
455
|
+
const box = elem.getBoundingClientRect();
|
|
456
|
+
left = Math.max(left, box.left);
|
|
457
|
+
top = Math.max(top, box.top);
|
|
458
|
+
right = Math.min(right, box.right);
|
|
459
|
+
bottom = Math.min(bottom, box.bottom);
|
|
460
|
+
}
|
|
461
|
+
return (right > left) && (bottom > top);
|
|
462
|
+
};
|
|
463
|
+
// USAGE: const bubble = Tooltip.show(button, "Click again to delete.", { color: "#E8796D", textColor: "white", arrow: 12, grow: 1 });
|
|
464
|
+
// USAGE: Tooltip.show(avatar, "", look, "bottom", function (bubble) { Label({ text: "Ayşe Kaya", bold: 1 }); });
|
|
465
|
+
|
|
466
|
+
// *** THE POPOVER: a bubble that stays and can be clicked; a click outside, Escape or closePopover() closes it.
|
|
467
|
+
Tooltip.openedPopover = null; // { bubble, target, close }
|
|
468
|
+
|
|
469
|
+
// options: { onClose: function () {} }. Returns the bubble.
|
|
470
|
+
Tooltip.openPopover = function(target, content, look, side = "bottom", text = "", options = {}) {
|
|
471
|
+
Tooltip.closePopover();
|
|
472
|
+
const bubble = Tooltip.show(target, text, look, side, content);
|
|
473
|
+
bubble.clickable = 1;
|
|
474
|
+
bubble.role = "dialog";
|
|
475
|
+
// WHY on window and in the capture phase: the popover is the top layer; its Escape must not reach a Dialog under it
|
|
476
|
+
const onPointerDown = function(self, event) {
|
|
477
|
+
if (bubble.elem.contains(event.target) || target.elem.contains(event.target)) return;
|
|
478
|
+
Tooltip.closePopover();
|
|
479
|
+
};
|
|
480
|
+
const onKeyDown = function(self, event) {
|
|
481
|
+
if (event.key != "Escape") return;
|
|
482
|
+
event.stopImmediatePropagation();
|
|
483
|
+
Tooltip.closePopover();
|
|
484
|
+
if (target.elem.tabIndex >= 0) target.elem.focus();
|
|
485
|
+
};
|
|
486
|
+
// WHY placed again, not closed: a phone keyboard (a field in the popover) changes the size of the screen
|
|
487
|
+
const onResize = function() {
|
|
488
|
+
if (!target._isRemoved) Tooltip.place(bubble, Tooltip.toPageRect(target), side);
|
|
489
|
+
};
|
|
490
|
+
// (bubble.remove() cleans these events)
|
|
491
|
+
bubble.listenTo(window, "pointerdown", onPointerDown, true);
|
|
492
|
+
bubble.listenTo(window, "keydown", onKeyDown, true);
|
|
493
|
+
bubble.onPageResize(onResize);
|
|
494
|
+
Tooltip.openedPopover = {
|
|
495
|
+
bubble: bubble,
|
|
496
|
+
target: target,
|
|
497
|
+
close: function() {
|
|
498
|
+
bubble.remove();
|
|
499
|
+
if (typeof options.onClose === "function") options.onClose();
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
return bubble;
|
|
503
|
+
};
|
|
504
|
+
// USAGE: Tooltip.openPopover(btnShare, function (bubble) { Label({ text: "Share" }); SmartButton({ labelText: "Copy" }); }, look, "bottom");
|
|
505
|
+
|
|
506
|
+
Tooltip.closePopover = function() {
|
|
507
|
+
const opened = Tooltip.openedPopover;
|
|
508
|
+
if (!opened) return;
|
|
509
|
+
Tooltip.openedPopover = null; // WHY first: onClose may open another one
|
|
510
|
+
opened.close();
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
Tooltip.isPopoverOf = function(target) {
|
|
514
|
+
return !!Tooltip.openedPopover && Tooltip.openedPopover.target === target;
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
Tooltip.grow = function(bubble) {
|
|
518
|
+
if (window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
|
519
|
+
bubble.opacity = 0;
|
|
520
|
+
bubble.css = { transform: "scale(0.6)" };
|
|
521
|
+
// WHY: the start look must be drawn before the motion is turned on, or it is seen at once
|
|
522
|
+
void bubble.elem.offsetHeight;
|
|
523
|
+
bubble.setMotionNow("transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s"); // a little spring at the end
|
|
524
|
+
bubble.opacity = 1;
|
|
525
|
+
bubble.css = { transform: "none" };
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// THE LOOKS OF THE THEMES (Tooltip.BUBBLE_LOOK keys): Tooltip({ styleName: "minimal" }), or the look of
|
|
529
|
+
// Tooltip.show(target, text, Tooltip.looks.minimal). minimal (_designs/minimal-theme.htm): on the ground of the window
|
|
530
|
+
// with a line, no shadow, no arrow, a 12 px text. minimalDark: the same on a dark window.
|
|
531
|
+
Tooltip.looks = {
|
|
532
|
+
minimal: { fontSize: 12, padding: [8, 4], color: "#FFFFFF", textColor: Black(0.85), round: 4, border: 1, borderColor: Black(0.2), shadow: "", arrow: 0 },
|
|
533
|
+
minimalDark: { fontSize: 12, padding: [8, 4], color: "#1A1A19", textColor: White(0.88), round: 4, border: 1, borderColor: White(0.18), shadow: "", arrow: 0 },
|
|
534
|
+
};
|