added 2nd breakpoint

removed sky check
not refreshing if nothing is visible
This commit is contained in:
Miodec 2023-02-28 13:15:04 +01:00
parent 54d886ea9e
commit bb8b95c4f2
2 changed files with 36 additions and 26 deletions

View file

@ -10,6 +10,9 @@ import * as PW from "./pw-ad-controller";
const breakpoint = 900;
let widerThanBreakpoint = true;
const breakpoint2 = 1330;
let widerThanBreakpoint2 = true;
let initialised = false;
export let adBlock: boolean;
@ -106,13 +109,18 @@ function updateBreakpoint(noReinstate = false): void {
}
}
function updateBreakpoint2(): void {
function updateBreakpoint2(noReinstate = false): void {
if (choice !== "pw") return;
const beforeUpdate = widerThanBreakpoint2;
if (window.innerWidth > 1330) {
PW.updateSky(true);
if (window.innerWidth > breakpoint2) {
widerThanBreakpoint2 = true;
} else {
PW.updateSky(false);
widerThanBreakpoint2 = false;
}
if (noReinstate) return;
if (beforeUpdate !== widerThanBreakpoint2) {
PW.reinstate();
}
}

View file

@ -131,14 +131,14 @@ function getUnits(): unknown {
const toReturn = [];
for (const unit of units) {
const isSky = unit.type === "sky_atf";
// const isSky = unit.type === "sky_atf";
const element = document.querySelector(`#${unit.selectorId}`);
if (
element &&
window.getComputedStyle(element).display !== "none" &&
(!isSky || (isSky && showSky))
window.getComputedStyle(element).display !== "none"
// && (!isSky || (isSky && showSky))
) {
toReturn.push(unit);
}
@ -171,6 +171,8 @@ export async function reinstate(): boolean {
export async function refreshVisible(): Promise<void> {
if (!rampReady) return;
if (getUnits().length === 0) return;
ramp.triggerRefresh();
}
@ -188,23 +190,23 @@ export function setMobile(tf: boolean): void {
ramp.setMobile(tf);
}
let showSky = false;
// let showSky = false;
export function updateSky(visible: boolean): void {
showSky = visible;
if (
showSky &&
ramp &&
!ramp.getUnits().some((u) => u.includes("pw-160x600"))
) {
ramp.addUnits(getUnits()).then(() => {
ramp.displayUnits();
});
} else if (ramp && !showSky) {
const toDestroy = [];
ramp.getUnits().map((u) => {
if (u.includes("pw-160x600")) toDestroy.push(u);
});
ramp.destroyUnits(toDestroy);
}
}
// export function updateSky(visible: boolean): void {
// showSky = visible;
// if (
// showSky &&
// ramp &&
// !ramp.getUnits().some((u) => u.includes("pw-160x600"))
// ) {
// ramp.addUnits(getUnits()).then(() => {
// ramp.displayUnits();
// });
// } else if (ramp && !showSky) {
// const toDestroy = [];
// ramp.getUnits().map((u) => {
// if (u.includes("pw-160x600")) toDestroy.push(u);
// });
// ramp.destroyUnits(toDestroy);
// }
// }