Skip to content

Commit 9b1e093

Browse files
robinlejFrancoisGe
authored andcommitted
Add this.window in Plugin
1 parent 6f2d9d6 commit 9b1e093

14 files changed

+21
-29
lines changed

addons/html_builder/static/src/website_builder/plugins/customize_website_plugin.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ export class CustomizeWebsitePlugin extends Plugin {
7777
}),
7878
customizeWebsiteColor: this.withCustomHistory({
7979
getValue: ({ params: { mainParam: color, colorType, gradientColor } }) => {
80-
const style = this.document.defaultView.getComputedStyle(
81-
this.document.documentElement
82-
);
80+
const style = this.window.getComputedStyle(this.document.documentElement);
8381
if (gradientColor) {
8482
const gradientValue = this.getWebsiteVariableValue(gradientColor);
8583
if (gradientValue) {
@@ -179,9 +177,7 @@ export class CustomizeWebsitePlugin extends Plugin {
179177
if (bgImage === "none") {
180178
return "NONE";
181179
}
182-
const style = this.document.defaultView.getComputedStyle(
183-
this.document.documentElement
184-
);
180+
const style = this.window.getComputedStyle(this.document.documentElement);
185181
return getCSSVariableValue("body-image-type", style);
186182
},
187183
load: async ({ editingElement: el, params, value, historyImageSrc }) => {
@@ -265,9 +261,7 @@ export class CustomizeWebsitePlugin extends Plugin {
265261
return currentValue === value;
266262
},
267263
getValue: ({ params: { mainParam: which } }) => {
268-
const style = this.document.defaultView.getComputedStyle(
269-
this.document.documentElement
270-
);
264+
const style = this.window.getComputedStyle(this.document.documentElement);
271265
const isOutline = getCSSVariableValue(`btn-${which}-outline`, style);
272266
const isFlat = getCSSVariableValue(`btn-${which}-flat`, style);
273267
return isFlat === "true" ? "flat" : isOutline === "true" ? "outline" : "fill";
@@ -321,7 +315,7 @@ export class CustomizeWebsitePlugin extends Plugin {
321315
};
322316
}
323317
getWebsiteVariableValue(variable) {
324-
const style = this.document.defaultView.getComputedStyle(this.document.documentElement);
318+
const style = this.window.getComputedStyle(this.document.documentElement);
325319
let finalValue = getCSSVariableValue(variable, style);
326320
/* TODO dedicated action ?
327321
if (!params.colorNames) {

addons/html_builder/static/src/website_builder/plugins/options/animate_option_plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class AnimateOptionPlugin extends Plugin {
136136
setAnimateIntensity: {
137137
getValue: ({ editingElement }) => {
138138
const intensity = parseInt(
139-
this.document.defaultView
139+
this.window
140140
.getComputedStyle(editingElement)
141141
.getPropertyValue("--wanim-intensity")
142142
);
@@ -186,7 +186,7 @@ class AnimateOptionPlugin extends Plugin {
186186
// Trigger a DOM reflow.
187187
void editingElement.offsetWidth;
188188
editingElement.style.animationName = "";
189-
this.document.defaultView.dispatchEvent(new Event("resize"));
189+
this.window.dispatchEvent(new Event("resize"));
190190
} else {
191191
// Trigger a DOM reflow (Needed to prevent the animation from
192192
// being launched twice when previewing the "Intensity" option).

addons/html_builder/static/src/website_builder/plugins/options/chart_option_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class ChartOptionPlugin extends Plugin {
263263
? color
264264
: getCSSVariableValue(
265265
color,
266-
this.document.defaultView.getComputedStyle(this.document.documentElement)
266+
this.window.getComputedStyle(this.document.documentElement)
267267
);
268268
}
269269

addons/html_builder/static/src/website_builder/plugins/options/navtabs_header_buttons_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class NavTabsOptionPlugin extends Plugin {
3232
}
3333

3434
showTab(navLinkEl, paneEl) {
35-
this.document.defaultView.Tab.getOrCreateInstance(navLinkEl).show();
35+
this.window.Tab.getOrCreateInstance(navLinkEl).show();
3636
// Immediately show the pane so the history remains consistent.
3737
paneEl.classList.add("show");
3838
}

addons/html_builder/static/src/website_builder/plugins/options/popup_option_plugin.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class PopupOptionPlugin extends Plugin {
3838
};
3939

4040
setup() {
41-
this.window = this.document.defaultView;
42-
4341
this.addDomListener(this.editable, "click", (ev) => {
4442
// Note: links are excluded here so that internal modal buttons do
4543
// not close the popup as we want to allow edition of those buttons.

addons/html_builder/static/src/website_builder/plugins/theme/theme_tab_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class ThemeTabPlugin extends Plugin {
107107
const hues = [];
108108
const saturationDiffs = [];
109109
let oneHasNoSaturation = false;
110-
const style = this.document.defaultView.getComputedStyle(this.document.body);
110+
const style = this.window.getComputedStyle(this.document.body);
111111
const baseStyle = getComputedStyle(document.body);
112112
for (let id = 100; id <= 900; id += 100) {
113113
const gray = getCSSVariableValue(`${id}`, style);

addons/html_builder/static/src/website_builder/plugins/website_session_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class WebsiteSessionPlugin extends Plugin {
66
static shared = ["getSession"];
77

88
getSession() {
9-
return this.document.defaultView.odoo.loader.modules.get("@web/session").session;
9+
return this.window.odoo.loader.modules.get("@web/session").session;
1010
}
1111
}
1212

addons/html_editor/static/src/core/overlay_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class OverlayPlugin extends Plugin {
2424
overlays = [];
2525

2626
setup() {
27-
this.iframe = this.document.defaultView.frameElement;
27+
this.iframe = this.window.frameElement;
2828
this.topDocument = this.iframe?.ownerDocument || this.document;
2929
this.container = this.getScrollContainer();
3030
this.throttledUpdateContainer = throttleForAnimation(() => {

addons/html_editor/static/src/core/sanitize_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class SanitizePlugin extends Plugin {
1818
if (!window.DOMPurify) {
1919
throw new Error("DOMPurify is not available");
2020
}
21-
this.DOMPurify = DOMPurify(this.document.defaultView);
21+
this.DOMPurify = DOMPurify(this.window);
2222
}
2323
/**
2424
* Sanitizes in place an html element. Current implementation uses the

addons/html_editor/static/src/core/shortcut_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class ShortCutPlugin extends Plugin {
2828
throw new Error("ShorcutPlugin needs hotkey service to properly work");
2929
}
3030
if (document !== this.document) {
31-
hotkeyService.registerIframe({ contentWindow: this.document.defaultView });
31+
hotkeyService.registerIframe({ contentWindow: this.window });
3232
}
3333
for (const shortcut of this.getResource("shortcuts")) {
3434
const command = this.dependencies.userCommand.getCommand(shortcut.commandId);

addons/html_editor/static/src/main/list/list_plugin.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ export class ListPlugin extends Plugin {
955955
* @param {HTMLLIElement} li - LI element inside a checklist.
956956
*/
957957
isPointerInsideCheckbox(li, pointerOffsetX, pointerOffsetY) {
958-
const beforeStyle = this.document.defaultView.getComputedStyle(li, ":before");
958+
const beforeStyle = this.window.getComputedStyle(li, ":before");
959959
const checkboxPosition = {
960960
left: parseInt(beforeStyle.left),
961961
top: parseInt(beforeStyle.top),
@@ -1047,13 +1047,11 @@ export class ListPlugin extends Plugin {
10471047
return;
10481048
}
10491049
const defaultPadding =
1050-
parseFloat(
1051-
this.document.defaultView.getComputedStyle(document.documentElement).fontSize
1052-
) * 2; // 2rem
1050+
parseFloat(this.window.getComputedStyle(document.documentElement).fontSize) * 2; // 2rem
10531051
// Align the whole list based on the item that requires the largest padding.
10541052
const requiredPaddings = [...list.children].map((li) => {
10551053
const markerWidth = Math.floor(
1056-
parseFloat(this.document.defaultView.getComputedStyle(li, "::marker").width)
1054+
parseFloat(this.window.getComputedStyle(li, "::marker").width)
10571055
);
10581056
// For `UL` with large font size the marker width is so big that more padding is needed.
10591057
const paddingForMarker =

addons/html_editor/static/src/main/position_plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export class PositionPlugin extends Plugin {
2222
this.resizeObserver.observe(this.document.body);
2323
this.resizeObserver.observe(this.editable);
2424
this.addDomListener(window, "resize", this.layoutGeometryChange);
25-
if (this.document.defaultView !== window) {
26-
this.addDomListener(this.document.defaultView, "resize", this.layoutGeometryChange);
25+
if (this.window !== window) {
26+
this.addDomListener(this.window, "resize", this.layoutGeometryChange);
2727
}
2828
const scrollableElements = [this.editable, ...ancestors(this.editable)].filter((node) => {
2929
return couldBeScrollableX(node) || couldBeScrollableY(node);

addons/html_editor/static/src/others/qweb_plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class QWebPlugin extends Plugin {
9999
} else {
100100
return (
101101
child.nodeType !== Node.ELEMENT_NODE ||
102-
this.document.defaultView.getComputedStyle(child).display === "inline"
102+
this.window.getComputedStyle(child).display === "inline"
103103
);
104104
}
105105
});

addons/html_editor/static/src/plugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export class Plugin {
2121
constructor(document, editable, dependencies, config, services) {
2222
/** @type { Document } **/
2323
this.document = document;
24+
/** @type { Window } */
25+
this.window = document.defaultView;
2426
/** @type { HTMLElement } **/
2527
this.editable = editable;
2628
/** @type { EditorConfig } **/

0 commit comments

Comments
 (0)