coupdoeil 1.0.0.pre.beta.1 → 1.0.0.pre.beta.2
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 +3 -0
- data/README.md +21 -21
- data/app/assets/javascripts/coupdoeil.js +132 -132
- data/app/assets/javascripts/coupdoeil.min.js +1 -1
- data/app/assets/javascripts/coupdoeil.min.js.map +1 -1
- data/app/assets/stylesheets/coupdoeil/popover-animation.css +44 -0
- data/app/assets/stylesheets/coupdoeil/popover-arrow.css +39 -0
- data/app/assets/stylesheets/coupdoeil/popover.css +84 -0
- data/app/controllers/coupdoeil/{hovercards_controller.rb → popovers_controller.rb} +13 -13
- data/app/helpers/coupdoeil/application_helper.rb +4 -4
- data/app/javascript/coupdoeil/elements/coupdoeil_element.js +13 -13
- data/app/javascript/coupdoeil/events/onclick.js +36 -36
- data/app/javascript/coupdoeil/events/onmouseover.js +52 -52
- data/app/javascript/coupdoeil/events.js +4 -4
- data/app/javascript/coupdoeil/index.js +1 -1
- data/app/javascript/coupdoeil/{hovercard → popover}/attributes.js +3 -3
- data/app/javascript/coupdoeil/popover/cache.js +22 -0
- data/app/javascript/coupdoeil/{hovercard → popover}/closing.js +18 -18
- data/app/javascript/coupdoeil/{hovercard → popover}/config.js +6 -6
- data/app/javascript/coupdoeil/popover/controller.js +20 -0
- data/app/javascript/coupdoeil/popover/current.js +13 -0
- data/app/javascript/coupdoeil/{hovercard → popover}/opening.js +26 -26
- data/app/javascript/coupdoeil/{hovercard → popover}/optionsParser.js +5 -5
- data/app/javascript/coupdoeil/{hovercard → popover}/positioning.js +2 -2
- data/app/javascript/coupdoeil/popover/state_check.js +12 -0
- data/app/models/coupdoeil/params.rb +4 -4
- data/app/models/coupdoeil/{hovercard → popover}/option/animation.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/option/cache.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/option/loading.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/option/offset.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/option/opening_delay.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/option/placement.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/option/trigger.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/option.rb +1 -1
- data/app/models/coupdoeil/{hovercard → popover}/options_set.rb +1 -1
- data/app/models/coupdoeil/{hovercard → popover}/registry.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/setup.rb +2 -2
- data/app/models/coupdoeil/{hovercard → popover}/view_context_delegation.rb +3 -3
- data/app/models/coupdoeil/{hovercard.rb → popover.rb} +8 -8
- data/app/models/coupdoeil/tag.rb +15 -15
- data/app/style/{hovercard-animation.scss → popover-animation.scss} +7 -7
- data/app/style/popover-arrow.scss +40 -0
- data/app/style/popover.scss +2 -0
- data/config/routes.rb +1 -1
- data/lib/coupdoeil/engine.rb +8 -8
- data/lib/coupdoeil/version.rb +1 -1
- data/lib/generators/coupdoeil/install/install_generator.rb +8 -8
- data/lib/generators/coupdoeil/install/templates/layout.html.erb.tt +1 -1
- data/lib/generators/coupdoeil/popover/USAGE +15 -0
- data/lib/generators/coupdoeil/popover/popover_generator.rb +22 -0
- data/lib/generators/coupdoeil/{hovercard/templates/hovercard.rb.tt → popover/templates/popover.rb.tt} +1 -1
- metadata +39 -39
- data/app/assets/stylesheets/coupdoeil/hovercard-animation.css +0 -44
- data/app/assets/stylesheets/coupdoeil/hovercard-arrow.css +0 -39
- data/app/assets/stylesheets/coupdoeil/hovercard.css +0 -84
- data/app/javascript/coupdoeil/hovercard/cache.js +0 -22
- data/app/javascript/coupdoeil/hovercard/controller.js +0 -20
- data/app/javascript/coupdoeil/hovercard/current.js +0 -13
- data/app/javascript/coupdoeil/hovercard/state_check.js +0 -12
- data/app/style/hovercard-arrow.scss +0 -40
- data/app/style/hovercard.scss +0 -2
- data/lib/generators/coupdoeil/hovercard/USAGE +0 -15
- data/lib/generators/coupdoeil/hovercard/hovercard_generator.rb +0 -22
- /data/app/javascript/coupdoeil/{hovercard → popover}/actions.js +0 -0
- /data/app/javascript/coupdoeil/{hovercard.js → popover.js} +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class PopoverController {
|
2
2
|
constructor(coupdoeilElement) {
|
3
3
|
this.coupdoeilElement = coupdoeilElement;
|
4
4
|
this.card = null;
|
@@ -7,18 +7,18 @@ class HovercardController {
|
|
7
7
|
this.closingRequest = null;
|
8
8
|
}
|
9
9
|
get isOpen() {
|
10
|
-
return !!this.coupdoeilElement.dataset.
|
10
|
+
return !!this.coupdoeilElement.dataset.popoverOpen;
|
11
11
|
}
|
12
12
|
get isClosed() {
|
13
13
|
return !this.isOpen;
|
14
14
|
}
|
15
15
|
}
|
16
16
|
|
17
|
-
const
|
17
|
+
const POPOVER_CLASS_NAME = "coupdoeil--popover";
|
18
18
|
|
19
|
-
const
|
19
|
+
const POPOVER_SELECTOR = `.${POPOVER_CLASS_NAME}`;
|
20
20
|
|
21
|
-
const
|
21
|
+
const POPOVER_CLOSE_BTN_SELECTOR = "[data-popover-close]";
|
22
22
|
|
23
23
|
const CLOSING_DELAY_MS = 75;
|
24
24
|
|
@@ -115,7 +115,7 @@ function getTrigger$1(optionsInt) {
|
|
115
115
|
return TRIGGERS[optionsInt & 1];
|
116
116
|
}
|
117
117
|
|
118
|
-
const
|
118
|
+
const popoverOptions = {
|
119
119
|
animation: undefined,
|
120
120
|
cache: undefined,
|
121
121
|
loading: undefined,
|
@@ -126,8 +126,8 @@ const HovercardOptions = {
|
|
126
126
|
};
|
127
127
|
|
128
128
|
function extractOptionsFromElement(coupdoeilElement) {
|
129
|
-
const optionsInt = coupdoeilElement.
|
130
|
-
const options = Object.create(
|
129
|
+
const optionsInt = coupdoeilElement.popoverController.optionsInt ||= parseOtionsInt(coupdoeilElement);
|
130
|
+
const options = Object.create(popoverOptions);
|
131
131
|
for (const option of ORDERED_OPTIONS) {
|
132
132
|
options[option] = OPTIONS[option].getter(optionsInt);
|
133
133
|
}
|
@@ -135,21 +135,21 @@ function extractOptionsFromElement(coupdoeilElement) {
|
|
135
135
|
}
|
136
136
|
|
137
137
|
function parseOtionsInt(coupdoeilElement) {
|
138
|
-
const optionsString = coupdoeilElement.getAttribute("
|
138
|
+
const optionsString = coupdoeilElement.getAttribute("popover-options");
|
139
139
|
return parseInt(optionsString, 36);
|
140
140
|
}
|
141
141
|
|
142
142
|
function extractOptionFromElement(coupdoeilElement, optionName) {
|
143
|
-
const optionsInt = coupdoeilElement.
|
143
|
+
const optionsInt = coupdoeilElement.popoverController.optionsInt ||= parseOtionsInt(coupdoeilElement);
|
144
144
|
return OPTIONS[optionName].getter(optionsInt);
|
145
145
|
}
|
146
146
|
|
147
147
|
function getType(controller) {
|
148
|
-
return controller.coupdoeilElement.getAttribute("
|
148
|
+
return controller.coupdoeilElement.getAttribute("popover-type");
|
149
149
|
}
|
150
150
|
|
151
151
|
function getParams(controller) {
|
152
|
-
return controller.coupdoeilElement.getAttribute("
|
152
|
+
return controller.coupdoeilElement.getAttribute("popover-params");
|
153
153
|
}
|
154
154
|
|
155
155
|
function getTrigger(controller) {
|
@@ -173,10 +173,10 @@ function notTriggeredOnHover(controller) {
|
|
173
173
|
}
|
174
174
|
|
175
175
|
function preloadedContentElement(controller) {
|
176
|
-
return controller.coupdoeilElement.querySelector(".
|
176
|
+
return controller.coupdoeilElement.querySelector(".popover-content");
|
177
177
|
}
|
178
178
|
|
179
|
-
const
|
179
|
+
const popoverContentHTMLMap = new Map;
|
180
180
|
|
181
181
|
function cacheMapKey(controller) {
|
182
182
|
if (preloadedContentElement(controller)) {
|
@@ -185,16 +185,16 @@ function cacheMapKey(controller) {
|
|
185
185
|
return getType(controller) + getParams(controller);
|
186
186
|
}
|
187
187
|
|
188
|
-
function
|
189
|
-
return
|
188
|
+
function getPopoverContentHTML(controller) {
|
189
|
+
return popoverContentHTMLMap.get(cacheMapKey(controller));
|
190
190
|
}
|
191
191
|
|
192
|
-
function
|
193
|
-
|
192
|
+
function setPopoverContentHTML(controller, value) {
|
193
|
+
popoverContentHTMLMap.set(cacheMapKey(controller), value);
|
194
194
|
}
|
195
195
|
|
196
|
-
function
|
197
|
-
|
196
|
+
function clearPopoverContentCache() {
|
197
|
+
popoverContentHTMLMap.clear();
|
198
198
|
}
|
199
199
|
|
200
200
|
const sides = [ "top", "right", "bottom", "left" ];
|
@@ -1771,10 +1771,10 @@ const computePosition = (reference, floating, options) => {
|
|
1771
1771
|
});
|
1772
1772
|
};
|
1773
1773
|
|
1774
|
-
async function
|
1774
|
+
async function positionPopover(target, card, options) {
|
1775
1775
|
let {placement: placements, offset: offsetValue} = options;
|
1776
1776
|
const placement = placements[0];
|
1777
|
-
const arrowElement = card.querySelector("[data-
|
1777
|
+
const arrowElement = card.querySelector("[data-popover-arrow]");
|
1778
1778
|
const middleware = [ AutoPositioningWithFallbacks(placements) ];
|
1779
1779
|
if (arrowElement) {
|
1780
1780
|
const arrowSize = arrowElement.clientWidth;
|
@@ -1898,18 +1898,18 @@ function afterTransition(element) {
|
|
1898
1898
|
}));
|
1899
1899
|
}
|
1900
1900
|
|
1901
|
-
const
|
1901
|
+
const CURRENT_POPOVERS_BY_ID = new Map;
|
1902
1902
|
|
1903
|
-
function
|
1904
|
-
return
|
1903
|
+
function currentPopoversById() {
|
1904
|
+
return CURRENT_POPOVERS_BY_ID;
|
1905
1905
|
}
|
1906
1906
|
|
1907
1907
|
function addToCurrents(coupdoeilElement) {
|
1908
|
-
|
1908
|
+
CURRENT_POPOVERS_BY_ID.set(coupdoeilElement.uniqueId, coupdoeilElement);
|
1909
1909
|
}
|
1910
1910
|
|
1911
1911
|
function removeFromCurrents(coupdoeilElement) {
|
1912
|
-
|
1912
|
+
CURRENT_POPOVERS_BY_ID.delete(coupdoeilElement.uniqueId);
|
1913
1913
|
}
|
1914
1914
|
|
1915
1915
|
function detachFromParent(controller) {
|
@@ -1925,7 +1925,7 @@ function cancelOpenCloseActions(controller) {
|
|
1925
1925
|
}
|
1926
1926
|
|
1927
1927
|
function cancelOpening(controller) {
|
1928
|
-
delete controller.coupdoeilElement.
|
1928
|
+
delete controller.coupdoeilElement.openingPopover;
|
1929
1929
|
}
|
1930
1930
|
|
1931
1931
|
function cancelCloseRequest(controller) {
|
@@ -1935,7 +1935,7 @@ function cancelCloseRequest(controller) {
|
|
1935
1935
|
}
|
1936
1936
|
|
1937
1937
|
function closeNow(controller, allowAnimation = true) {
|
1938
|
-
if (controller.closing || controller.isClosed && !controller.coupdoeilElement.
|
1938
|
+
if (controller.closing || controller.isClosed && !controller.coupdoeilElement.openingPopover) return;
|
1939
1939
|
controller.closing = true;
|
1940
1940
|
cancelOpenCloseActions(controller);
|
1941
1941
|
controller.children.forEach((childController => {
|
@@ -1950,7 +1950,7 @@ function closeNow(controller, allowAnimation = true) {
|
|
1950
1950
|
}
|
1951
1951
|
|
1952
1952
|
async function closeWithAnimation(controller) {
|
1953
|
-
await leave(controller.card, "
|
1953
|
+
await leave(controller.card, "popover");
|
1954
1954
|
closeWithoutAnimation(controller);
|
1955
1955
|
}
|
1956
1956
|
|
@@ -1960,7 +1960,7 @@ function closeWithoutAnimation(controller) {
|
|
1960
1960
|
controller.card = null;
|
1961
1961
|
}
|
1962
1962
|
delete controller.closing;
|
1963
|
-
delete controller.coupdoeilElement.dataset.
|
1963
|
+
delete controller.coupdoeilElement.dataset.popoverOpen;
|
1964
1964
|
}
|
1965
1965
|
|
1966
1966
|
function clear(controller) {
|
@@ -1989,23 +1989,23 @@ function closeOnHoverChildrenLater(controller) {
|
|
1989
1989
|
}
|
1990
1990
|
|
1991
1991
|
function closeAllNow() {
|
1992
|
-
for (const coupdoeilElement of
|
1993
|
-
closeNow(coupdoeilElement.
|
1992
|
+
for (const coupdoeilElement of CURRENT_POPOVERS_BY_ID.values()) {
|
1993
|
+
closeNow(coupdoeilElement.popoverController);
|
1994
1994
|
removeFromCurrents(coupdoeilElement);
|
1995
1995
|
}
|
1996
1996
|
}
|
1997
1997
|
|
1998
1998
|
function clearAll() {
|
1999
|
-
for (const coupdoeilElement of
|
2000
|
-
clear(coupdoeilElement.
|
1999
|
+
for (const coupdoeilElement of CURRENT_POPOVERS_BY_ID.values()) {
|
2000
|
+
clear(coupdoeilElement.popoverController);
|
2001
2001
|
removeFromCurrents(coupdoeilElement);
|
2002
2002
|
}
|
2003
2003
|
}
|
2004
2004
|
|
2005
2005
|
function closeTriggeredOnHoverLater() {
|
2006
|
-
for (const coupdoeilElement of
|
2007
|
-
if (triggeredOnHover(coupdoeilElement.
|
2008
|
-
closeLater(coupdoeilElement.
|
2006
|
+
for (const coupdoeilElement of CURRENT_POPOVERS_BY_ID.values()) {
|
2007
|
+
if (triggeredOnHover(coupdoeilElement.popoverController)) {
|
2008
|
+
closeLater(coupdoeilElement.popoverController);
|
2009
2009
|
removeFromCurrents(coupdoeilElement);
|
2010
2010
|
}
|
2011
2011
|
}
|
@@ -2017,19 +2017,19 @@ function closeTriggeredOnHoverNowUnlessAncestor(controller) {
|
|
2017
2017
|
topMostParent = topMostParent.parent;
|
2018
2018
|
}
|
2019
2019
|
const idToSkip = topMostParent.coupdoeilElement.uniqueId;
|
2020
|
-
for (const coupdoeilElement of
|
2021
|
-
if (coupdoeilElement.uniqueId !== idToSkip && triggeredOnHover(coupdoeilElement.
|
2022
|
-
closeNow(coupdoeilElement.
|
2020
|
+
for (const coupdoeilElement of CURRENT_POPOVERS_BY_ID.values()) {
|
2021
|
+
if (coupdoeilElement.uniqueId !== idToSkip && triggeredOnHover(coupdoeilElement.popoverController)) {
|
2022
|
+
closeNow(coupdoeilElement.popoverController);
|
2023
2023
|
removeFromCurrents(coupdoeilElement);
|
2024
2024
|
}
|
2025
2025
|
}
|
2026
2026
|
}
|
2027
2027
|
|
2028
|
-
function
|
2028
|
+
function fetchPopoverContent(controller) {
|
2029
2029
|
const type = getType(controller);
|
2030
2030
|
const params = getParams(controller);
|
2031
2031
|
const authenticityToken = document.querySelector("meta[name=csrf-token]").content;
|
2032
|
-
let url = `/coupdoeil/
|
2032
|
+
let url = `/coupdoeil/popover`;
|
2033
2033
|
const opts = {
|
2034
2034
|
method: "POST",
|
2035
2035
|
headers: {
|
@@ -2043,31 +2043,31 @@ function fetchHovercardContent(controller) {
|
|
2043
2043
|
};
|
2044
2044
|
return fetch(url, opts).then((response => {
|
2045
2045
|
if (response.status >= 400) {
|
2046
|
-
throw "error while fetching
|
2046
|
+
throw "error while fetching popover content";
|
2047
2047
|
}
|
2048
2048
|
return response.text();
|
2049
2049
|
}));
|
2050
2050
|
}
|
2051
2051
|
|
2052
|
-
async function
|
2052
|
+
async function loadPopoverContentHTML(controller, options, delayOptions) {
|
2053
2053
|
return new Promise((resolve => {
|
2054
2054
|
setTimeout((async () => {
|
2055
|
-
if (!controller.coupdoeilElement.
|
2056
|
-
if (options.cache === false || options.cache && !
|
2055
|
+
if (!controller.coupdoeilElement.openingPopover) return;
|
2056
|
+
if (options.cache === false || options.cache && !getPopoverContentHTML(controller)) {
|
2057
2057
|
let html;
|
2058
2058
|
if (options.loading === "preload") {
|
2059
2059
|
html = preloadedContentElement(controller).innerHTML;
|
2060
2060
|
} else {
|
2061
|
-
html = await
|
2061
|
+
html = await fetchPopoverContent(controller);
|
2062
2062
|
}
|
2063
|
-
|
2063
|
+
setPopoverContentHTML(controller, html);
|
2064
2064
|
}
|
2065
2065
|
resolve();
|
2066
2066
|
}), delayOptions.fetch);
|
2067
2067
|
}));
|
2068
2068
|
}
|
2069
2069
|
|
2070
|
-
async function
|
2070
|
+
async function openPopover(controller, {parent: parent, beforeDisplay: beforeDisplay}) {
|
2071
2071
|
if (controller.isOpen) {
|
2072
2072
|
return cancelCloseRequest(controller);
|
2073
2073
|
}
|
@@ -2078,10 +2078,10 @@ async function openHovercard(controller, {parent: parent, beforeDisplay: beforeD
|
|
2078
2078
|
const options = extractOptionsFromElement(controller.coupdoeilElement);
|
2079
2079
|
const delays = getDelayOptionsForController(controller, options);
|
2080
2080
|
const openingDelay = new Promise((resolve => setTimeout(resolve, delays.opening)));
|
2081
|
-
const fetchDelay =
|
2081
|
+
const fetchDelay = loadPopoverContentHTML(controller, options, delays);
|
2082
2082
|
await Promise.all([ fetchDelay, openingDelay ]);
|
2083
2083
|
const parentIsClosedOrClosing = controller.parent && (controller.parent.isClosed || controller.parent.closingRequest);
|
2084
|
-
if (controller.coupdoeilElement.
|
2084
|
+
if (controller.coupdoeilElement.openingPopover && !parentIsClosedOrClosing) {
|
2085
2085
|
await display(controller, options, beforeDisplay);
|
2086
2086
|
}
|
2087
2087
|
}
|
@@ -2089,13 +2089,13 @@ async function openHovercard(controller, {parent: parent, beforeDisplay: beforeD
|
|
2089
2089
|
async function display(controller, options, beforeDisplay) {
|
2090
2090
|
if (controller.isOpen) return;
|
2091
2091
|
cancelCloseRequest(controller);
|
2092
|
-
controller.card =
|
2092
|
+
controller.card = buildPopoverElement(controller, options);
|
2093
2093
|
document.body.appendChild(controller.card);
|
2094
2094
|
if (options.animation) {
|
2095
2095
|
controller.card.dataset.animation = options.animation;
|
2096
2096
|
}
|
2097
2097
|
executeNextFrameIfStillOpening(controller, (async () => {
|
2098
|
-
await
|
2098
|
+
await positionPopover(controller.coupdoeilElement, controller.card, options);
|
2099
2099
|
controller.card.classList.add("hidden");
|
2100
2100
|
controller.card.style.removeProperty("visibility");
|
2101
2101
|
executeNextFrameIfStillOpening(controller, (async () => {
|
@@ -2103,16 +2103,16 @@ async function display(controller, options, beforeDisplay) {
|
|
2103
2103
|
beforeDisplay(controller);
|
2104
2104
|
}
|
2105
2105
|
addToCurrents(controller.coupdoeilElement);
|
2106
|
-
delete controller.coupdoeilElement.
|
2107
|
-
controller.coupdoeilElement.dataset.
|
2108
|
-
await enter(controller.card, "
|
2106
|
+
delete controller.coupdoeilElement.openingPopover;
|
2107
|
+
controller.coupdoeilElement.dataset.popoverOpen = true;
|
2108
|
+
await enter(controller.card, "popover");
|
2109
2109
|
}));
|
2110
2110
|
}));
|
2111
2111
|
}
|
2112
2112
|
|
2113
2113
|
function executeNextFrameIfStillOpening(controller, callback) {
|
2114
2114
|
requestAnimationFrame((() => {
|
2115
|
-
if (controller.coupdoeilElement.
|
2115
|
+
if (controller.coupdoeilElement.openingPopover) {
|
2116
2116
|
callback.call();
|
2117
2117
|
} else {
|
2118
2118
|
clear(controller);
|
@@ -2133,12 +2133,12 @@ function getDelayOptionsForController(controller, options) {
|
|
2133
2133
|
};
|
2134
2134
|
}
|
2135
2135
|
|
2136
|
-
function
|
2136
|
+
function buildPopoverElement(controller, options) {
|
2137
2137
|
const el = document.createElement("div");
|
2138
2138
|
el.setAttribute("role", "dialog");
|
2139
|
-
el.classList.add(
|
2139
|
+
el.classList.add(POPOVER_CLASS_NAME);
|
2140
2140
|
el.style.cssText = "position: absolute; left: 0; top: 0;";
|
2141
|
-
el.innerHTML =
|
2141
|
+
el.innerHTML = getPopoverContentHTML(controller);
|
2142
2142
|
el.controller = controller;
|
2143
2143
|
el.dataset.placement = options.placement;
|
2144
2144
|
el.style.visibility = "hidden";
|
@@ -2155,20 +2155,20 @@ class CoupdoeilElement extends HTMLElement {
|
|
2155
2155
|
constructor() {
|
2156
2156
|
super();
|
2157
2157
|
this.uniqueId = generateUniqueId();
|
2158
|
-
this.
|
2158
|
+
this.popoverController = new PopoverController(this);
|
2159
2159
|
}
|
2160
|
-
|
2161
|
-
if (this.
|
2162
|
-
this.
|
2163
|
-
const parent = this.closest(
|
2160
|
+
openPopover(triggerElement = null, callbacks) {
|
2161
|
+
if (this.openingPopover || this.popoverController.isOpen || this.disabled || triggerElement === this) return;
|
2162
|
+
this.openingPopover = true;
|
2163
|
+
const parent = this.closest(POPOVER_SELECTOR)?.controller;
|
2164
2164
|
addToCurrents(this);
|
2165
|
-
return
|
2165
|
+
return openPopover(this.popoverController, {
|
2166
2166
|
parent: parent,
|
2167
2167
|
...callbacks
|
2168
2168
|
});
|
2169
2169
|
}
|
2170
|
-
|
2171
|
-
closeNow(this.
|
2170
|
+
closePopover() {
|
2171
|
+
closeNow(this.popoverController);
|
2172
2172
|
}
|
2173
2173
|
get disabled() {
|
2174
2174
|
return !!this.getAttribute("disabled");
|
@@ -2182,119 +2182,119 @@ class CoupdoeilElement extends HTMLElement {
|
|
2182
2182
|
}
|
2183
2183
|
}
|
2184
2184
|
|
2185
|
-
function
|
2186
|
-
return element.closest(
|
2185
|
+
function isElementClosePopoverButton(element) {
|
2186
|
+
return element.closest(POPOVER_CLOSE_BTN_SELECTOR) || element.dataset.hasOwnProperty("popoverClose");
|
2187
2187
|
}
|
2188
2188
|
|
2189
|
-
function
|
2190
|
-
return
|
2189
|
+
function isAnyPopoverOpened() {
|
2190
|
+
return currentPopoversById().size > 0;
|
2191
2191
|
}
|
2192
2192
|
|
2193
2193
|
const coupdoeilOnClickEvent = ({target: clickedElement}) => {
|
2194
2194
|
const coupdoeilElement = clickedElement.closest("coup-doeil");
|
2195
|
-
const
|
2196
|
-
if (coupdoeilElement &&
|
2197
|
-
|
2195
|
+
const popoverElement = clickedElement.closest(POPOVER_SELECTOR);
|
2196
|
+
if (coupdoeilElement && popoverElement) {
|
2197
|
+
handleClickedCoupdoeilWithinPopover(coupdoeilElement, popoverElement, clickedElement);
|
2198
2198
|
} else if (coupdoeilElement) {
|
2199
|
-
|
2200
|
-
} else if (
|
2201
|
-
|
2199
|
+
handleClickedCoupdoeilOutsidePopover(coupdoeilElement, clickedElement);
|
2200
|
+
} else if (popoverElement) {
|
2201
|
+
handleClickOutsideCoupdoeilButWithinPopover(popoverElement, clickedElement);
|
2202
2202
|
} else {
|
2203
|
-
|
2203
|
+
handleClickOutsideCoupdoeilAndPopover();
|
2204
2204
|
}
|
2205
2205
|
};
|
2206
2206
|
|
2207
|
-
function
|
2208
|
-
const
|
2209
|
-
if (noTriggeredOnClick(
|
2210
|
-
if (
|
2211
|
-
closeNow(
|
2207
|
+
function handleClickedCoupdoeilWithinPopover(coupdoeilElement, _popoverElement, clickedElement) {
|
2208
|
+
const popover = coupdoeilElement.popoverController;
|
2209
|
+
if (noTriggeredOnClick(popover)) return;
|
2210
|
+
if (popover.isOpen) {
|
2211
|
+
closeNow(popover);
|
2212
2212
|
} else {
|
2213
|
-
coupdoeilElement.
|
2213
|
+
coupdoeilElement.openPopover(clickedElement);
|
2214
2214
|
}
|
2215
2215
|
}
|
2216
2216
|
|
2217
|
-
function
|
2218
|
-
const
|
2219
|
-
if (noTriggeredOnClick(
|
2220
|
-
if (
|
2221
|
-
closeNow(
|
2217
|
+
function handleClickedCoupdoeilOutsidePopover(coupdoeilElement, clickedElement) {
|
2218
|
+
const popover = coupdoeilElement.popoverController;
|
2219
|
+
if (noTriggeredOnClick(popover)) return;
|
2220
|
+
if (popover.isOpen) {
|
2221
|
+
closeNow(popover);
|
2222
2222
|
} else {
|
2223
2223
|
closeAllNow();
|
2224
|
-
coupdoeilElement.
|
2224
|
+
coupdoeilElement.openPopover(clickedElement);
|
2225
2225
|
}
|
2226
2226
|
}
|
2227
2227
|
|
2228
|
-
function
|
2229
|
-
const
|
2230
|
-
if (
|
2231
|
-
closeNow(
|
2232
|
-
} else if (
|
2233
|
-
closeChildrenNow(
|
2228
|
+
function handleClickOutsideCoupdoeilButWithinPopover(popoverElement, clickedElement) {
|
2229
|
+
const popover = popoverElement.controller;
|
2230
|
+
if (isElementClosePopoverButton(clickedElement)) {
|
2231
|
+
closeNow(popover);
|
2232
|
+
} else if (popover.children.size > 0) {
|
2233
|
+
closeChildrenNow(popover);
|
2234
2234
|
}
|
2235
2235
|
}
|
2236
2236
|
|
2237
|
-
function
|
2237
|
+
function handleClickOutsideCoupdoeilAndPopover() {
|
2238
2238
|
closeAllNow();
|
2239
2239
|
}
|
2240
2240
|
|
2241
2241
|
const onMouseOver = ({target: hoveredElement}) => {
|
2242
2242
|
const coupdoeilElement = hoveredElement.closest("coup-doeil");
|
2243
|
-
const
|
2244
|
-
if (coupdoeilElement &&
|
2245
|
-
|
2243
|
+
const popoverElement = hoveredElement.closest(POPOVER_SELECTOR);
|
2244
|
+
if (coupdoeilElement && popoverElement) {
|
2245
|
+
handleMouseOverCoupdoeilWithinPopover(coupdoeilElement, popoverElement, hoveredElement);
|
2246
2246
|
} else if (coupdoeilElement) {
|
2247
|
-
|
2248
|
-
} else if (
|
2249
|
-
|
2247
|
+
handleMouseOverCoupdoeilOutsidePopover(coupdoeilElement, hoveredElement);
|
2248
|
+
} else if (popoverElement) {
|
2249
|
+
handleOverOutsideCoupdoeilButWithinPopover(popoverElement);
|
2250
2250
|
} else {
|
2251
|
-
|
2251
|
+
handleOverOutsideCoupdoeilAndPopover();
|
2252
2252
|
}
|
2253
2253
|
};
|
2254
2254
|
|
2255
|
-
function
|
2256
|
-
const
|
2257
|
-
const
|
2258
|
-
if (notTriggeredOnHover(
|
2259
|
-
if (
|
2260
|
-
closeChildrenNow(
|
2255
|
+
function handleMouseOverCoupdoeilWithinPopover(coupdoeilElement, popoverElement, hoveredElement) {
|
2256
|
+
const childPopover = coupdoeilElement.popoverController;
|
2257
|
+
const parentPopover = popoverElement.controller;
|
2258
|
+
if (notTriggeredOnHover(childPopover)) return;
|
2259
|
+
if (childPopover.isOpen) {
|
2260
|
+
closeChildrenNow(childPopover);
|
2261
2261
|
} else {
|
2262
|
-
closeChildrenNow(
|
2263
|
-
coupdoeilElement.
|
2262
|
+
closeChildrenNow(parentPopover);
|
2263
|
+
coupdoeilElement.openPopover(hoveredElement);
|
2264
2264
|
}
|
2265
2265
|
}
|
2266
2266
|
|
2267
|
-
function
|
2268
|
-
const
|
2269
|
-
if (notTriggeredOnHover(
|
2270
|
-
if (
|
2271
|
-
coupdoeilElement.
|
2267
|
+
function handleMouseOverCoupdoeilOutsidePopover(coupdoeilElement, hoveredElement) {
|
2268
|
+
const popover = coupdoeilElement.popoverController;
|
2269
|
+
if (notTriggeredOnHover(popover)) return;
|
2270
|
+
if (popover.isClosed) {
|
2271
|
+
coupdoeilElement.openPopover(hoveredElement, {
|
2272
2272
|
beforeDisplay: closeTriggeredOnHoverNowUnlessAncestor
|
2273
2273
|
});
|
2274
|
-
} else if (
|
2275
|
-
cancelCloseRequest(
|
2274
|
+
} else if (popover.closingRequest) {
|
2275
|
+
cancelCloseRequest(popover);
|
2276
2276
|
addToCurrents(coupdoeilElement);
|
2277
2277
|
}
|
2278
2278
|
}
|
2279
2279
|
|
2280
|
-
function
|
2281
|
-
if (
|
2280
|
+
function handleOverOutsideCoupdoeilAndPopover() {
|
2281
|
+
if (isAnyPopoverOpened()) {
|
2282
2282
|
closeTriggeredOnHoverLater();
|
2283
2283
|
}
|
2284
2284
|
}
|
2285
2285
|
|
2286
|
-
function
|
2287
|
-
const
|
2288
|
-
if (
|
2289
|
-
cancelCloseRequest(
|
2290
|
-
addToCurrents(
|
2291
|
-
} else if (
|
2292
|
-
closeOnHoverChildrenLater(
|
2286
|
+
function handleOverOutsideCoupdoeilButWithinPopover(popoverElement) {
|
2287
|
+
const popover = popoverElement.controller;
|
2288
|
+
if (popover.closingRequest) {
|
2289
|
+
cancelCloseRequest(popover);
|
2290
|
+
addToCurrents(popover.coupdoeilElement);
|
2291
|
+
} else if (popover.children.size > 0) {
|
2292
|
+
closeOnHoverChildrenLater(popover);
|
2293
2293
|
}
|
2294
2294
|
}
|
2295
2295
|
|
2296
2296
|
document.addEventListener("DOMContentLoaded", (() => {
|
2297
|
-
|
2297
|
+
clearPopoverContentCache();
|
2298
2298
|
document.addEventListener("click", coupdoeilOnClickEvent);
|
2299
2299
|
document.documentElement.addEventListener("mouseover", onMouseOver, {
|
2300
2300
|
passive: true
|
@@ -2305,7 +2305,7 @@ document.addEventListener("DOMContentLoaded", (() => {
|
|
2305
2305
|
}));
|
2306
2306
|
document.addEventListener("turbo:load", (_event => {
|
2307
2307
|
clearAll();
|
2308
|
-
|
2308
|
+
clearPopoverContentCache();
|
2309
2309
|
}));
|
2310
2310
|
}
|
2311
2311
|
}));
|