coupdoeil 1.0.0.pre.alpha.1 → 1.0.0.pre.alpha.3
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 +4 -4
- data/CHANGELOG.md +11 -0
- data/app/assets/javascripts/coupdoeil.js +251 -249
- data/app/assets/javascripts/coupdoeil.min.js +1 -1
- data/app/assets/javascripts/coupdoeil.min.js.map +1 -1
- data/app/javascript/coupdoeil/elements/coupdoeil_element.js +1 -1
- data/app/javascript/coupdoeil/events/onclick.js +1 -2
- data/app/javascript/coupdoeil/events/onmouseover.js +8 -5
- data/app/javascript/coupdoeil/events.js +3 -1
- data/app/javascript/coupdoeil/hovercard/actions.js +0 -60
- data/app/javascript/coupdoeil/hovercard/cache.js +5 -1
- data/app/javascript/coupdoeil/hovercard/closing.js +52 -8
- data/app/javascript/coupdoeil/hovercard/controller.js +0 -2
- data/app/javascript/coupdoeil/hovercard/current.js +13 -0
- data/app/javascript/coupdoeil/hovercard/opening.js +90 -87
- data/app/javascript/coupdoeil/hovercard/optionsParser.js +3 -2
- data/app/javascript/coupdoeil/hovercard/positioning.js +5 -5
- data/app/javascript/coupdoeil/hovercard/state_check.js +2 -1
- data/app/models/coupdoeil/hovercard/options_set.rb +1 -3
- data/lib/coupdoeil/engine.rb +9 -1
- data/lib/coupdoeil/version.rb +1 -1
- data/lib/generators/coupdoeil/install/templates/layout.html.erb.tt +0 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0871a9b627344de4a1fe232f327a356ae872276aad53fe80f02484f597c1f2e2'
|
4
|
+
data.tar.gz: ab0f944bd59bc7459f4e8dd12f3bdfbbbf28d52a7687434db49cffa2e364bd86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6c7fe4cdf5617157b0262055890657092d907decb2c73f7873d6a2ffd9664218740a8369615207945dea2e2570a2616aba025d8be39abe8b3bf690b47fa083a
|
7
|
+
data.tar.gz: 98f0fd4ed2eaca581be298319d4de20465490f08dbba2223ab712dcd5be51c3a946d19176a079074451b0d290bf7385f3e5fb22387c86f19ba4d9c5efd22401a
|
data/CHANGELOG.md
CHANGED
@@ -1 +1,12 @@
|
|
1
1
|
# CHANGELOG
|
2
|
+
|
3
|
+
### ???
|
4
|
+
- update getting-started docs
|
5
|
+
- remove JS console logs
|
6
|
+
- remove width: max-content from layout template
|
7
|
+
- update docs
|
8
|
+
- fix Coupdoeil::Hovercard::OptionSet#preload?
|
9
|
+
|
10
|
+
### 1.0.0-alpha.2
|
11
|
+
- refactor `opening.js`
|
12
|
+
- fix the load of Coupdoeil::Engine
|
@@ -5,8 +5,6 @@ class HovercardController {
|
|
5
5
|
this.children = new Set;
|
6
6
|
this.parent = null;
|
7
7
|
this.closingRequest = null;
|
8
|
-
this.openingDelay = null;
|
9
|
-
this.fetchDelay = null;
|
10
8
|
}
|
11
9
|
get isOpen() {
|
12
10
|
return !!this.coupdoeilElement.dataset.hovercardOpen;
|
@@ -57,7 +55,7 @@ const ANIMATIONS = [ false, "slide-in", "fade-in", "slide-out", "custom" ];
|
|
57
55
|
|
58
56
|
const PLACEMENTS = [ "auto", "top", "top-start", "top-end", "right", "right-start", "right-end", "bottom", "bottom-start", "bottom-end", "left", "left-start", "left-end" ];
|
59
57
|
|
60
|
-
const LOADINGS = [ "
|
58
|
+
const LOADINGS = [ "async", "preload", "lazy" ];
|
61
59
|
|
62
60
|
function parseCSSSize(value) {
|
63
61
|
if (typeof value === "number") {
|
@@ -103,7 +101,7 @@ function getCache(optionsInt) {
|
|
103
101
|
}
|
104
102
|
|
105
103
|
function getLoading(optionsInt) {
|
106
|
-
return LOADINGS[optionsInt & 3
|
104
|
+
return LOADINGS[optionsInt >> 1 & 3];
|
107
105
|
}
|
108
106
|
|
109
107
|
function getTrigger$1(optionsInt) {
|
@@ -187,180 +185,10 @@ function setHovercardContentHTML(controller, value) {
|
|
187
185
|
hovercardContentHTMLMap.set(cacheMapKey(controller), value);
|
188
186
|
}
|
189
187
|
|
190
|
-
async function enter(element, transitionName = null) {
|
191
|
-
element.classList.remove("hidden");
|
192
|
-
await transition("enter", element, transitionName);
|
193
|
-
}
|
194
|
-
|
195
|
-
async function leave(element, transitionName = null) {
|
196
|
-
await transition("leave", element, transitionName);
|
197
|
-
element.classList.add("hidden");
|
198
|
-
}
|
199
|
-
|
200
|
-
async function transition(direction, element, animation) {
|
201
|
-
const dataset = element.dataset;
|
202
|
-
const animationClass = animation ? `${animation}-${direction}` : direction;
|
203
|
-
let transition = `transition${direction.charAt(0).toUpperCase() + direction.slice(1)}`;
|
204
|
-
const genesis = dataset[transition] ? dataset[transition].split(" ") : [ animationClass ];
|
205
|
-
const start = dataset[`${transition}Start`] ? dataset[`${transition}Start`].split(" ") : [ `${animationClass}-start` ];
|
206
|
-
const end = dataset[`${transition}End`] ? dataset[`${transition}End`].split(" ") : [ `${animationClass}-end` ];
|
207
|
-
addClasses(element, genesis);
|
208
|
-
addClasses(element, start);
|
209
|
-
await nextFrame();
|
210
|
-
removeClasses(element, start);
|
211
|
-
addClasses(element, end);
|
212
|
-
await afterTransition(element);
|
213
|
-
removeClasses(element, end);
|
214
|
-
removeClasses(element, genesis);
|
215
|
-
}
|
216
|
-
|
217
|
-
function addClasses(element, classes) {
|
218
|
-
element.classList.add(...classes);
|
219
|
-
}
|
220
|
-
|
221
|
-
function removeClasses(element, classes) {
|
222
|
-
element.classList.remove(...classes);
|
223
|
-
}
|
224
|
-
|
225
|
-
function nextFrame() {
|
226
|
-
return new Promise((resolve => {
|
227
|
-
requestAnimationFrame((() => {
|
228
|
-
requestAnimationFrame(resolve);
|
229
|
-
}));
|
230
|
-
}));
|
231
|
-
}
|
232
|
-
|
233
|
-
function afterTransition(element) {
|
234
|
-
return new Promise((resolve => {
|
235
|
-
const computedDuration = getComputedStyle(element).transitionDuration.split(",")[0];
|
236
|
-
const duration = Number(computedDuration.replace("s", "")) * 1e3;
|
237
|
-
setTimeout((() => {
|
238
|
-
resolve();
|
239
|
-
}), duration);
|
240
|
-
}));
|
241
|
-
}
|
242
|
-
|
243
|
-
function detachFromParent(controller) {
|
244
|
-
if (controller.parent) {
|
245
|
-
controller.parent.children.delete(controller);
|
246
|
-
controller.parent = null;
|
247
|
-
}
|
248
|
-
}
|
249
|
-
|
250
|
-
function cancelCloseRequest(controller) {
|
251
|
-
clearTimeout(controller.closingRequest);
|
252
|
-
controller.closingRequest = null;
|
253
|
-
}
|
254
|
-
|
255
|
-
function closeNow(controller, allowAnimation = true) {
|
256
|
-
if (controller.closing || controller.isClosed) return;
|
257
|
-
controller.closing = true;
|
258
|
-
cancelOpenCloseActions(controller);
|
259
|
-
controller.children.forEach((childController => {
|
260
|
-
closeNow(childController);
|
261
|
-
}));
|
262
|
-
detachFromParent(controller);
|
263
|
-
if (allowAnimation && controller.card.dataset.animation) {
|
264
|
-
closeWithAnimation(controller);
|
265
|
-
} else {
|
266
|
-
closeWithoutAnimation(controller);
|
267
|
-
}
|
268
|
-
}
|
269
|
-
|
270
|
-
async function closeWithAnimation(controller) {
|
271
|
-
await leave(controller.card, "hovercard");
|
272
|
-
closeWithoutAnimation(controller);
|
273
|
-
}
|
274
|
-
|
275
|
-
function closeWithoutAnimation(controller) {
|
276
|
-
controller.card.remove();
|
277
|
-
controller.card = null;
|
278
|
-
delete controller.closing;
|
279
|
-
delete controller.coupdoeilElement.dataset.hovercardOpen;
|
280
|
-
}
|
281
|
-
|
282
|
-
function clear(controller) {
|
283
|
-
closeNow(controller, false);
|
284
|
-
}
|
285
|
-
|
286
|
-
function closeLater(controller) {
|
287
|
-
cancelOpenCloseActions(controller);
|
288
|
-
controller.closingRequest = setTimeout((() => {
|
289
|
-
closeNow(controller);
|
290
|
-
}), defaultConfig.closingDelay);
|
291
|
-
}
|
292
|
-
|
293
|
-
function closeChildrenNow(controller) {
|
294
|
-
controller.children.forEach((childController => {
|
295
|
-
closeNow(childController);
|
296
|
-
}));
|
297
|
-
}
|
298
|
-
|
299
|
-
function closeOnHoverChildrenLater(controller) {
|
300
|
-
controller.children.forEach((childController => {
|
301
|
-
if (triggeredOnHover(childController)) {
|
302
|
-
closeLater(childController);
|
303
|
-
}
|
304
|
-
}));
|
305
|
-
}
|
306
|
-
|
307
|
-
const CURRENT_HOVERCARDS_BY_ID = new Map;
|
308
|
-
|
309
|
-
window.hovercads = CURRENT_HOVERCARDS_BY_ID;
|
310
|
-
|
311
188
|
function clearHovercardContentCache() {
|
312
189
|
hovercardContentHTMLMap.clear();
|
313
190
|
}
|
314
191
|
|
315
|
-
function currentHovercardsById() {
|
316
|
-
return CURRENT_HOVERCARDS_BY_ID;
|
317
|
-
}
|
318
|
-
|
319
|
-
function addToCurrents(coupdoeilElement) {
|
320
|
-
CURRENT_HOVERCARDS_BY_ID.set(coupdoeilElement.uniqueId, coupdoeilElement);
|
321
|
-
}
|
322
|
-
|
323
|
-
function closeAllNow() {
|
324
|
-
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
325
|
-
closeNow(coupdoeilElement.hovercardController);
|
326
|
-
removeFromCurrents(coupdoeilElement);
|
327
|
-
}
|
328
|
-
}
|
329
|
-
|
330
|
-
function clearAll() {
|
331
|
-
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
332
|
-
clear(coupdoeilElement.hovercardController);
|
333
|
-
removeFromCurrents(coupdoeilElement);
|
334
|
-
}
|
335
|
-
}
|
336
|
-
|
337
|
-
function closeTriggeredOnHoverNow() {
|
338
|
-
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
339
|
-
if (triggeredOnHover(coupdoeilElement.hovercardController)) {
|
340
|
-
closeNow(coupdoeilElement.hovercardController);
|
341
|
-
removeFromCurrents(coupdoeilElement);
|
342
|
-
}
|
343
|
-
}
|
344
|
-
}
|
345
|
-
|
346
|
-
function closeTriggeredOnHoverLater() {
|
347
|
-
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
348
|
-
if (triggeredOnHover(coupdoeilElement.hovercardController)) {
|
349
|
-
closeLater(coupdoeilElement.hovercardController);
|
350
|
-
removeFromCurrents(coupdoeilElement);
|
351
|
-
}
|
352
|
-
}
|
353
|
-
}
|
354
|
-
|
355
|
-
function removeFromCurrents(coupdoeilElement) {
|
356
|
-
CURRENT_HOVERCARDS_BY_ID.delete(coupdoeilElement.uniqueId);
|
357
|
-
}
|
358
|
-
|
359
|
-
function cancelOpenCloseActions(controller) {
|
360
|
-
cancelOpening(controller);
|
361
|
-
cancelCloseRequest(controller);
|
362
|
-
}
|
363
|
-
|
364
192
|
const sides = [ "top", "right", "bottom", "left" ];
|
365
193
|
|
366
194
|
const alignments = [ "start", "end" ];
|
@@ -1935,10 +1763,10 @@ const computePosition = (reference, floating, options) => {
|
|
1935
1763
|
});
|
1936
1764
|
};
|
1937
1765
|
|
1938
|
-
async function positionHovercard(
|
1766
|
+
async function positionHovercard(target, card, options) {
|
1939
1767
|
let {placement: placements, offset: offsetValue} = options;
|
1940
1768
|
const placement = placements[0];
|
1941
|
-
const arrowElement =
|
1769
|
+
const arrowElement = card.querySelector("[data-hovercard-arrow]");
|
1942
1770
|
const middleware = [ AutoPositioningWithFallbacks(placements) ];
|
1943
1771
|
if (arrowElement) {
|
1944
1772
|
const arrowSize = arrowElement.clientWidth;
|
@@ -1948,7 +1776,7 @@ async function positionHovercard(controller, options) {
|
|
1948
1776
|
}));
|
1949
1777
|
}
|
1950
1778
|
middleware.push(offset(offsetValue));
|
1951
|
-
const computedPosition = await computePosition(
|
1779
|
+
const computedPosition = await computePosition(target, card, {
|
1952
1780
|
placement: placement,
|
1953
1781
|
middleware: middleware
|
1954
1782
|
});
|
@@ -1956,8 +1784,8 @@ async function positionHovercard(controller, options) {
|
|
1956
1784
|
if (arrowElement) {
|
1957
1785
|
positionArrow(arrowElement, computedPosition);
|
1958
1786
|
}
|
1959
|
-
|
1960
|
-
Object.assign(
|
1787
|
+
card.dataset.placement = actualPlacement;
|
1788
|
+
Object.assign(card.style, {
|
1961
1789
|
left: `${x}px`,
|
1962
1790
|
top: `${y}px`
|
1963
1791
|
});
|
@@ -2009,91 +1837,179 @@ function positionArrow(arrowElement, computedData) {
|
|
2009
1837
|
});
|
2010
1838
|
}
|
2011
1839
|
|
1840
|
+
async function enter(element, transitionName = null) {
|
1841
|
+
element.classList.remove("hidden");
|
1842
|
+
await transition("enter", element, transitionName);
|
1843
|
+
}
|
1844
|
+
|
1845
|
+
async function leave(element, transitionName = null) {
|
1846
|
+
await transition("leave", element, transitionName);
|
1847
|
+
element.classList.add("hidden");
|
1848
|
+
}
|
1849
|
+
|
1850
|
+
async function transition(direction, element, animation) {
|
1851
|
+
const dataset = element.dataset;
|
1852
|
+
const animationClass = animation ? `${animation}-${direction}` : direction;
|
1853
|
+
let transition = `transition${direction.charAt(0).toUpperCase() + direction.slice(1)}`;
|
1854
|
+
const genesis = dataset[transition] ? dataset[transition].split(" ") : [ animationClass ];
|
1855
|
+
const start = dataset[`${transition}Start`] ? dataset[`${transition}Start`].split(" ") : [ `${animationClass}-start` ];
|
1856
|
+
const end = dataset[`${transition}End`] ? dataset[`${transition}End`].split(" ") : [ `${animationClass}-end` ];
|
1857
|
+
addClasses(element, genesis);
|
1858
|
+
addClasses(element, start);
|
1859
|
+
await nextFrame();
|
1860
|
+
removeClasses(element, start);
|
1861
|
+
addClasses(element, end);
|
1862
|
+
await afterTransition(element);
|
1863
|
+
removeClasses(element, end);
|
1864
|
+
removeClasses(element, genesis);
|
1865
|
+
}
|
1866
|
+
|
1867
|
+
function addClasses(element, classes) {
|
1868
|
+
element.classList.add(...classes);
|
1869
|
+
}
|
1870
|
+
|
1871
|
+
function removeClasses(element, classes) {
|
1872
|
+
element.classList.remove(...classes);
|
1873
|
+
}
|
1874
|
+
|
1875
|
+
function nextFrame() {
|
1876
|
+
return new Promise((resolve => {
|
1877
|
+
requestAnimationFrame((() => {
|
1878
|
+
requestAnimationFrame(resolve);
|
1879
|
+
}));
|
1880
|
+
}));
|
1881
|
+
}
|
1882
|
+
|
1883
|
+
function afterTransition(element) {
|
1884
|
+
return new Promise((resolve => {
|
1885
|
+
const computedDuration = getComputedStyle(element).transitionDuration.split(",")[0];
|
1886
|
+
const duration = Number(computedDuration.replace("s", "")) * 1e3;
|
1887
|
+
setTimeout((() => {
|
1888
|
+
resolve();
|
1889
|
+
}), duration);
|
1890
|
+
}));
|
1891
|
+
}
|
1892
|
+
|
1893
|
+
const CURRENT_HOVERCARDS_BY_ID = new Map;
|
1894
|
+
|
1895
|
+
function currentHovercardsById() {
|
1896
|
+
return CURRENT_HOVERCARDS_BY_ID;
|
1897
|
+
}
|
1898
|
+
|
1899
|
+
function addToCurrents(coupdoeilElement) {
|
1900
|
+
CURRENT_HOVERCARDS_BY_ID.set(coupdoeilElement.uniqueId, coupdoeilElement);
|
1901
|
+
}
|
1902
|
+
|
1903
|
+
function removeFromCurrents(coupdoeilElement) {
|
1904
|
+
CURRENT_HOVERCARDS_BY_ID.delete(coupdoeilElement.uniqueId);
|
1905
|
+
}
|
1906
|
+
|
1907
|
+
function detachFromParent(controller) {
|
1908
|
+
if (controller.parent) {
|
1909
|
+
controller.parent.children.delete(controller);
|
1910
|
+
controller.parent = null;
|
1911
|
+
}
|
1912
|
+
}
|
1913
|
+
|
1914
|
+
function cancelOpenCloseActions(controller) {
|
1915
|
+
cancelOpening(controller);
|
1916
|
+
cancelCloseRequest(controller);
|
1917
|
+
}
|
1918
|
+
|
2012
1919
|
function cancelOpening(controller) {
|
2013
|
-
clearTimeout(controller.openingDelay);
|
2014
|
-
controller.openingDelay = null;
|
2015
|
-
clearTimeout(controller.fetchDelay);
|
2016
|
-
controller.fetchDelay = null;
|
2017
1920
|
delete controller.coupdoeilElement.openingHovercard;
|
2018
1921
|
}
|
2019
1922
|
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
1923
|
+
function cancelCloseRequest(controller) {
|
1924
|
+
clearTimeout(controller.closingRequest);
|
1925
|
+
controller.closingRequest = null;
|
1926
|
+
addToCurrents(controller.coupdoeilElement);
|
1927
|
+
}
|
1928
|
+
|
1929
|
+
function closeNow(controller, allowAnimation = true) {
|
1930
|
+
if (controller.closing || controller.isClosed && !controller.coupdoeilElement.openingHovercard) return;
|
1931
|
+
controller.closing = true;
|
1932
|
+
cancelOpenCloseActions(controller);
|
1933
|
+
controller.children.forEach((childController => {
|
1934
|
+
closeNow(childController);
|
1935
|
+
}));
|
1936
|
+
detachFromParent(controller);
|
1937
|
+
if (allowAnimation && controller.card && controller.card.dataset.animation) {
|
1938
|
+
closeWithAnimation(controller);
|
1939
|
+
} else {
|
1940
|
+
closeWithoutAnimation(controller);
|
2024
1941
|
}
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
1942
|
+
}
|
1943
|
+
|
1944
|
+
async function closeWithAnimation(controller) {
|
1945
|
+
await leave(controller.card, "hovercard");
|
1946
|
+
closeWithoutAnimation(controller);
|
1947
|
+
}
|
1948
|
+
|
1949
|
+
function closeWithoutAnimation(controller) {
|
1950
|
+
if (controller.card) {
|
1951
|
+
controller.card.remove();
|
1952
|
+
controller.card = null;
|
2028
1953
|
}
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
1954
|
+
delete controller.closing;
|
1955
|
+
delete controller.coupdoeilElement.dataset.hovercardOpen;
|
1956
|
+
}
|
1957
|
+
|
1958
|
+
function clear(controller) {
|
1959
|
+
closeNow(controller, false);
|
1960
|
+
}
|
1961
|
+
|
1962
|
+
function closeLater(controller) {
|
1963
|
+
cancelOpenCloseActions(controller);
|
1964
|
+
controller.closingRequest = setTimeout((() => {
|
1965
|
+
closeNow(controller);
|
1966
|
+
}), defaultConfig.closingDelay);
|
1967
|
+
}
|
1968
|
+
|
1969
|
+
function closeChildrenNow(controller) {
|
1970
|
+
controller.children.forEach((childController => {
|
1971
|
+
closeNow(childController);
|
2038
1972
|
}));
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
return;
|
1973
|
+
}
|
1974
|
+
|
1975
|
+
function closeOnHoverChildrenLater(controller) {
|
1976
|
+
controller.children.forEach((childController => {
|
1977
|
+
if (triggeredOnHover(childController)) {
|
1978
|
+
closeLater(childController);
|
2046
1979
|
}
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
1980
|
+
}));
|
1981
|
+
}
|
1982
|
+
|
1983
|
+
function closeAllNow() {
|
1984
|
+
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
1985
|
+
closeNow(coupdoeilElement.hovercardController);
|
1986
|
+
removeFromCurrents(coupdoeilElement);
|
2050
1987
|
}
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
1988
|
+
}
|
1989
|
+
|
1990
|
+
function clearAll() {
|
1991
|
+
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
1992
|
+
clearHovercard(coupdoeilElement.hovercardController);
|
1993
|
+
removeFromCurrents(coupdoeilElement);
|
2056
1994
|
}
|
2057
1995
|
}
|
2058
1996
|
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
controller.card.dataset.animation = options.animation;
|
1997
|
+
function closeTriggeredOnHoverNow() {
|
1998
|
+
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
1999
|
+
if (triggeredOnHover(coupdoeilElement.hovercardController)) {
|
2000
|
+
closeNow(coupdoeilElement.hovercardController);
|
2001
|
+
removeFromCurrents(coupdoeilElement);
|
2002
|
+
}
|
2066
2003
|
}
|
2067
|
-
requestAnimationFrame((async () => {
|
2068
|
-
controller.card.style.opacity = "0";
|
2069
|
-
controller.card.classList.remove("hidden");
|
2070
|
-
requestAnimationFrame((async () => {
|
2071
|
-
await positionHovercard(controller, options);
|
2072
|
-
controller.card.classList.add("hidden");
|
2073
|
-
controller.card.style.removeProperty("opacity");
|
2074
|
-
requestAnimationFrame((async () => {
|
2075
|
-
addToCurrents(controller.coupdoeilElement);
|
2076
|
-
delete controller.coupdoeilElement.openingHovercard;
|
2077
|
-
controller.coupdoeilElement.dataset.hovercardOpen = true;
|
2078
|
-
await enter(controller.card, "hovercard");
|
2079
|
-
}));
|
2080
|
-
}));
|
2081
|
-
}));
|
2082
2004
|
}
|
2083
2005
|
|
2084
|
-
function
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
};
|
2006
|
+
function closeTriggeredOnHoverLater() {
|
2007
|
+
for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
|
2008
|
+
if (triggeredOnHover(coupdoeilElement.hovercardController)) {
|
2009
|
+
closeLater(coupdoeilElement.hovercardController);
|
2010
|
+
removeFromCurrents(coupdoeilElement);
|
2011
|
+
}
|
2091
2012
|
}
|
2092
|
-
return {
|
2093
|
-
fetch: defaultConfig.fetchDelay,
|
2094
|
-
reOpening: defaultConfig.fetchDelay + defaultConfig.openingDelay,
|
2095
|
-
actualOpening: defaultConfig.openingDelay - defaultConfig.fetchDelay
|
2096
|
-
};
|
2097
2013
|
}
|
2098
2014
|
|
2099
2015
|
function fetchHovercardContent(controller) {
|
@@ -2120,14 +2036,100 @@ function fetchHovercardContent(controller) {
|
|
2120
2036
|
}));
|
2121
2037
|
}
|
2122
2038
|
|
2039
|
+
async function loadHovercardContentHTML(controller, options, delayOptions) {
|
2040
|
+
return new Promise((resolve => {
|
2041
|
+
setTimeout((async () => {
|
2042
|
+
if (!controller.coupdoeilElement.openingHovercard) return;
|
2043
|
+
if (options.cache === false || options.cache && !getHovercardContentHTML(controller)) {
|
2044
|
+
let html;
|
2045
|
+
if (options.loading === "preload") {
|
2046
|
+
html = preloadedContentElement(controller).innerHTML;
|
2047
|
+
} else {
|
2048
|
+
html = await fetchHovercardContent(controller);
|
2049
|
+
}
|
2050
|
+
setHovercardContentHTML(controller, html);
|
2051
|
+
}
|
2052
|
+
resolve();
|
2053
|
+
}), delayOptions.fetch);
|
2054
|
+
}));
|
2055
|
+
}
|
2056
|
+
|
2057
|
+
async function openHovercard(controller, {parent: parent}) {
|
2058
|
+
if (controller.isOpen) {
|
2059
|
+
return cancelCloseRequest(controller);
|
2060
|
+
}
|
2061
|
+
if (parent) {
|
2062
|
+
controller.parent = parent;
|
2063
|
+
parent.children.add(controller);
|
2064
|
+
}
|
2065
|
+
const delays = getDelayOptionsForController(controller);
|
2066
|
+
const options = extractOptionsFromElement(controller.coupdoeilElement);
|
2067
|
+
const openingDelay = new Promise((resolve => setTimeout(resolve, delays.opening)));
|
2068
|
+
const fetchDelay = loadHovercardContentHTML(controller, options, delays);
|
2069
|
+
await Promise.all([ fetchDelay, openingDelay ]);
|
2070
|
+
const parentIsClosedOrClosing = controller.parent && (controller.parent.isClosed || controller.parent.closingRequest);
|
2071
|
+
if (controller.coupdoeilElement.openingHovercard && !parentIsClosedOrClosing) {
|
2072
|
+
await display(controller, options);
|
2073
|
+
}
|
2074
|
+
}
|
2075
|
+
|
2076
|
+
async function display(controller, options) {
|
2077
|
+
if (controller.isOpen) return;
|
2078
|
+
cancelCloseRequest(controller);
|
2079
|
+
controller.card = buildHovercardElement(controller, options);
|
2080
|
+
document.body.appendChild(controller.card);
|
2081
|
+
if (options.animation) {
|
2082
|
+
controller.card.dataset.animation = options.animation;
|
2083
|
+
}
|
2084
|
+
executeNextFrameIfStillOpening(controller, (async () => {
|
2085
|
+
await positionHovercard(controller.coupdoeilElement, controller.card, options);
|
2086
|
+
controller.card.classList.add("hidden");
|
2087
|
+
controller.card.style.removeProperty("visibility");
|
2088
|
+
executeNextFrameIfStillOpening(controller, (async () => {
|
2089
|
+
addToCurrents(controller.coupdoeilElement);
|
2090
|
+
delete controller.coupdoeilElement.openingHovercard;
|
2091
|
+
controller.coupdoeilElement.dataset.hovercardOpen = true;
|
2092
|
+
await enter(controller.card, "hovercard");
|
2093
|
+
}));
|
2094
|
+
}));
|
2095
|
+
}
|
2096
|
+
|
2097
|
+
function executeNextFrameIfStillOpening(controller, callback) {
|
2098
|
+
requestAnimationFrame((() => {
|
2099
|
+
if (controller.coupdoeilElement.openingHovercard) {
|
2100
|
+
callback.call();
|
2101
|
+
} else {
|
2102
|
+
clear(controller);
|
2103
|
+
}
|
2104
|
+
}));
|
2105
|
+
}
|
2106
|
+
|
2107
|
+
function getDelayOptionsForController(controller) {
|
2108
|
+
if (triggeredOnClick(controller)) {
|
2109
|
+
return {
|
2110
|
+
fetch: 0,
|
2111
|
+
opening: 0
|
2112
|
+
};
|
2113
|
+
}
|
2114
|
+
let fetchDelay;
|
2115
|
+
{
|
2116
|
+
fetchDelay = defaultConfig.openingDelay / 2;
|
2117
|
+
}
|
2118
|
+
return {
|
2119
|
+
fetch: fetchDelay,
|
2120
|
+
opening: defaultConfig.openingDelay
|
2121
|
+
};
|
2122
|
+
}
|
2123
|
+
|
2123
2124
|
function buildHovercardElement(controller, options) {
|
2124
2125
|
const el = document.createElement("div");
|
2125
2126
|
el.setAttribute("role", "dialog");
|
2126
|
-
el.classList.add(HOVERCARD_CLASS_NAME
|
2127
|
+
el.classList.add(HOVERCARD_CLASS_NAME);
|
2127
2128
|
el.style.cssText = "position: absolute; left: 0; top: 0;";
|
2128
2129
|
el.innerHTML = getHovercardContentHTML(controller);
|
2129
2130
|
el.controller = controller;
|
2130
2131
|
el.dataset.placement = options.placement;
|
2132
|
+
el.style.visibility = "hidden";
|
2131
2133
|
return el;
|
2132
2134
|
}
|
2133
2135
|
|