Facebook
From tes, 2 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 105
  1. document.addEventListener('DOMContentLoaded', function() {
  2.     // English Language
  3.     setupLanguage('english', 'tab-call-to-action-english', 'CTA_ctaTranslationEn');
  4.  
  5.     // German Language
  6.     setupLanguage('german', 'tab-call-to-action-german', 'CTA_ctaTranslationDe');
  7. });
  8.  
  9. function setupLanguage(language, mainDivId, prefix) {
  10.     var mainDiv = document.getElementById(mainDivId);
  11.     if (!mainDiv) return;
  12.  
  13.     var rowDiv = mainDiv.querySelector('.row');
  14.     if (!rowDiv) return;
  15.  
  16.     var secondChild = rowDiv.children[1];
  17.     if (!secondChild) return;
  18.  
  19.     secondChild.classList.add('col-md-5');
  20.     secondChild.style.backgroundColor = 'white';
  21.     secondChild.style.borderRadius = '20px';
  22.  
  23.     var imageInput = document.getElementById(`${prefix}_image_file`);
  24.     var titleLabel = document.getElementById(`${prefix}_title`);
  25.     var descriptionLabel = document.getElementById(`${prefix}_description`);
  26.     var buttonLabel = document.getElementById(`${prefix}_button_label`);
  27.     var buttonLink = document.getElementById(`${prefix}_button_link`);
  28.  
  29.     if (imageInput) {
  30.         var outputImage = document.createElement('img');
  31.         imageInput.onchange = function(evt) {
  32.             const [file] = imageInput.files;
  33.             outputImage.src = URL.createObjectURL(file);
  34.             outputImage.style.height = '300px';
  35.             outputImage.style.width = '600px';
  36.         };
  37.         secondChild.appendChild(outputImage);
  38.     }
  39.  
  40.     if (titleLabel) {
  41.         var titleResult = createAndAppendElement(secondChild, 'h4');
  42.         titleResult.style.color = 'black';
  43.         titleResult.style.textAlign = 'center';
  44.         titleLabel.addEventListener('input', function(e) {
  45.             titleResult.innerText = e.target.value;
  46.         });
  47.         if (titleLabel.value) {
  48.             titleResult.innerText = titleLabel.value;
  49.         }
  50.     }
  51.  
  52.     if (descriptionLabel) {
  53.         var descriptionResult = createAndAppendElement(secondChild, 'p');
  54.         descriptionResult.style.color = 'black';
  55.         descriptionLabel.addEventListener('input', function(e) {
  56.             descriptionResult.innerText = e.target.value;
  57.         });
  58.         if (descriptionLabel.value) {
  59.             descriptionResult.innerText = descriptionLabel.value;
  60.         }
  61.     }
  62.  
  63.     if (buttonLabel && buttonLink) {
  64.         var buttonResult = createAndAppendElement(secondChild, 'a');
  65.         buttonLabel.addEventListener('input', function(e) {
  66.             buttonResult.innerText = e.target.value;
  67.             applyButtonStyles(buttonResult);
  68.         });
  69.         buttonLink.addEventListener('input', function(e) {
  70.             buttonResult.href = e.target.value;
  71.         });
  72.         if (buttonLabel.value) {
  73.             buttonResult.innerText = buttonLabel.value;
  74.             applyButtonStyles(buttonResult);
  75.         }
  76.         if (buttonLink.value) {
  77.             buttonResult.href = buttonLink.value;
  78.         }
  79.     }
  80. }
  81.  
  82. function createAndAppendElement(parent, tagName) {
  83.     var element = document.createElement(tagName);
  84.     parent.appendChild(element);
  85.     return element;
  86. }
  87.  
  88. function applyButtonStyles(button) {
  89.     button.style.display = 'inline-block';
  90.     button.style.color = 'white';
  91.     button.style.width = '200px';
  92.     button.style.height = '50px';
  93.     button.style.textAlign = 'center';
  94.     button.style.backgroundColor = 'black';
  95. }
  96.