0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed global variable leak for new card scripts

no issue

- wraps the card js scripts into an IIFE to avoid polluting global variables on the site
- also any fixes errors caused by `swup` and its scripts-plugin that trips over already created global variables
This commit is contained in:
Rishabh 2021-12-08 22:58:22 +05:30
parent b7c17ca439
commit 2d43c12276
3 changed files with 159 additions and 154 deletions

View file

@ -1,3 +1,4 @@
(function() {
const handleAudioPlayer = function (audioElementContainer) {
const audioPlayerContainer = audioElementContainer.querySelector('.kg-player-container');
const playIconContainer = audioElementContainer.querySelector('.kg-audio-play-icon');
@ -144,4 +145,4 @@ const audioCardElements = document.querySelectorAll('.kg-audio-card');
for (let i = 0; i < audioCardElements.length; i++) {
handleAudioPlayer(audioCardElements[i]);
}
})();

View file

@ -1,8 +1,10 @@
var images = document.querySelectorAll('.kg-gallery-image img');
(function() {
const images = document.querySelectorAll('.kg-gallery-image img');
images.forEach(function (image) {
var container = image.closest('.kg-gallery-image');
var width = image.attributes.width.value;
var height = image.attributes.height.value;
var ratio = width / height;
const container = image.closest('.kg-gallery-image');
const width = image.attributes.width.value;
const height = image.attributes.height.value;
const ratio = width / height;
container.style.flex = ratio + ' 1 0%';
})
})();

View file

@ -1,3 +1,4 @@
(function() {
const toggleHeadingElements = document.getElementsByClassName("kg-toggle-heading");
const toggleFn = function(event) {
@ -14,3 +15,4 @@ const toggleFn = function(event) {
for (let i = 0; i < toggleHeadingElements.length; i++) {
toggleHeadingElements[i].addEventListener('click', toggleFn, false);
}
})();