Skip to content

Commit

Permalink
Fixed errors from v2.3.1 and up + Optimizations
Browse files Browse the repository at this point in the history
- [x] Fixed errors introduced in v2.3.1 and up. #1041
- [x] Fixed the « Use accent color » feature for lights, the color was not always right. #692
- [x] Optimized some parts of the code for a more fluid/stable behavior. #1035 #1065
- [x] Optimized the pop-ups for faster opening/closing in some cases.
  • Loading branch information
Clooos authored Dec 21, 2024
1 parent a7a49c4 commit 3a162b4
Show file tree
Hide file tree
Showing 16 changed files with 691 additions and 290 deletions.
2 changes: 1 addition & 1 deletion dist/bubble-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bubble-pop-up-fix.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bubble-pop-up-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function hideElementsUntilBubbleCard() {
hideElementsUntilBubbleCard();

console.info(
`%c Bubble Card %c Pop-up fix`,
`%c Bubble Card %c Pop-up fix `,
'background-color: #555;color: #fff;padding: 3px 2px 3px 3px;border-radius: 14px 0 0 14px;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)',
'background-color: #506eac;color: #fff;padding: 3px 3px 3px 2px;border-radius: 0 14px 14px 0;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)'
);
6 changes: 4 additions & 2 deletions src/cards/button/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export function changeButton(context) {
let newOpacity = '';

if (buttonType === 'switch' && isOn) {
if (lightColor && isLight) {
const useAccentColor = context.config.use_accent_color;

if (lightColor && isLight && !useAccentColor) {
newButtonColor = getIconColor(context);
newOpacity = '.5';
} else {
Expand Down Expand Up @@ -115,7 +117,7 @@ export function changeIcon(context) {
}

export function changeName(context) {
if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
// if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
const buttonType = getButtonType(context);
const name = buttonType !== 'name' ? getName(context) : context.config.name;
if (name !== context.elements.previousName) {
Expand Down
3 changes: 1 addition & 2 deletions src/cards/button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export function handleButton(context, container = context.content, appendTo = co
}

changeIcon(context);

changeName(context);
changeState(context);
changeSubButtonState(context, container, context.elements.buttonCard);
if (context.cardType !== 'pop-up') changeStyle(context);
changeName(context);
}
2 changes: 1 addition & 1 deletion src/cards/climate/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function changeIcon(context) {
}

export function changeName(context) {
if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
//if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
const name = getName(context);
if (name !== context.previousName && context.elements.name) {
context.elements.name.innerText = name;
Expand Down
3 changes: 1 addition & 2 deletions src/cards/cover/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export function changeIcon(context) {
context.elements.buttonClose.classList.remove("disabled");
}

// Masquer le bouton stop si non supporté
if (!supportsStop) {
context.elements.buttonStop.style.display = "none";
} else {
Expand All @@ -87,7 +86,7 @@ export function changeIcon(context) {
}

export function changeName(context) {
if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
//if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
const name = getName(context);
if (name !== context.elements.previousName) {
context.elements.name.innerText = name;
Expand Down
2 changes: 1 addition & 1 deletion src/cards/media-player/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function changeBackground(context) {
}

export function changeName(context) {
if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
//if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
const name = getName(context);
if (name !== context.previousName) {
context.elements.name.innerText = name;
Expand Down
2 changes: 1 addition & 1 deletion src/cards/pop-up/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@ export function prepareStructure(context) {
} catch (e) {
console.error(e);
}
}
}
42 changes: 23 additions & 19 deletions src/cards/pop-up/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function handleTouchEnd(event, popUp) {
export function clickOutside(event, context) {
if (context.config.close_by_clicking_outside ?? true) {
const targets = event.composedPath();
const popupTarget = targets.find(target =>
const popupTarget = targets.find(target =>
target.classList?.contains('bubble-pop-up') ||
['HA-DIALOG', 'HA-MORE-INFO-DIALOG', 'HA-DIALOG-DATE-PICKER'].includes(target.nodeName)
);
Expand All @@ -48,7 +48,7 @@ export function removeHash() {
}, 50);
}

export function addHash(hash) {
export function addHash(hash) {
const newURL = hash.startsWith('#') ? window.location.href.split('#')[0] + hash : hash;
history.pushState(null, "", newURL);
window.dispatchEvent(new Event('location-changed'));
Expand Down Expand Up @@ -88,9 +88,16 @@ function toggleBackdrop(context, show) {
export function appendPopup(context, append) {
if (context.config.background_update) return;
const action = append ? 'appendChild' : 'removeChild';
requestAnimationFrame(() => {
context.verticalStack[action](context.popUp);
});

if (append) {
requestAnimationFrame(() => {
context.verticalStack.appendChild(context.popUp);
});
} else {
requestAnimationFrame(() => {
context.verticalStack.removeChild(context.popUp);
});
}
}

function updatePopupClass(popUp, open) {
Expand All @@ -101,7 +108,6 @@ function updatePopupClass(popUp, open) {
}

function updateListeners(context, add) {
// Création d'un wrapper lié au contexte
if (!context.boundClickOutside) {
context.boundClickOutside = event => clickOutside(event, context);
}
Expand All @@ -112,19 +118,18 @@ function updateListeners(context, add) {
context.listenersAdded = true;
}

if (!window.clickOutsideListenerAdded) {
if (!context.clickOutsideListenerAdded) {
window.addEventListener('click', context.boundClickOutside, { passive: true });
window.clickOutsideListenerAdded = true;
context.clickOutsideListenerAdded = true;
}
} else {
if (context.listenersAdded) {
context.popUp.removeEventListener('touchstart', context.resetCloseTimeout);
context.listenersAdded = false;

if (!location.hash && window.clickOutsideListenerAdded) {
window.removeEventListener('click', context.boundClickOutside);
window.clickOutsideListenerAdded = false;
}
context.listenersAdded = false;
}
if (context.clickOutsideListenerAdded) {
window.removeEventListener('click', context.boundClickOutside);
context.clickOutsideListenerAdded = false;
}
}
}
Expand All @@ -139,9 +144,9 @@ function clearAllTimeouts(context) {

export function openPopup(context) {
if (context.popUp.classList.contains('is-popup-opened')) return;

clearAllTimeouts(context);
appendPopup(context, true);
appendPopup(context, true); // Afficher la pop-up structure

requestAnimationFrame(() => {
toggleBackdrop(context, true);
Expand All @@ -163,8 +168,7 @@ export function openPopup(context) {
}

export function closePopup(context) {
if (!context.popUp.classList.contains('is-popup-opened')) return;

if (!context.popUp.classList.contains('is-popup-opened')) return;
clearAllTimeouts(context);
updatePopupClass(context.popUp, false);
toggleBackdrop(context, false);
Expand All @@ -186,7 +190,7 @@ export function closePopup(context) {

export function onUrlChange(context) {
return () => {
if (context.config.hash === location.hash) {
if (context.config.hash === location.hash) {
hashRecentlyAdded = true;
setTimeout(() => {
hashRecentlyAdded = false;
Expand Down
2 changes: 1 addition & 1 deletion src/cards/select/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function changeIcon(context) {
}

export function changeName(context) {
if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
//if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
const name = getName(context);
if (name !== context.elements.previousName) {
applyScrollingEffect(context, context.elements.name, name);
Expand Down
2 changes: 1 addition & 1 deletion src/cards/separator/changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function changeIcon(context) {
}
}
export function changeName(context) {
if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
//if (context.config.styles?.includes("card.querySelector('.bubble-name').innerText")) return;
const name = getName(context);
if (name !== context.elements.name.innerText) {
context.elements.name.innerText = name;
Expand Down
Loading

0 comments on commit 3a162b4

Please sign in to comment.