MediaWiki:Common.js: различия между версиями

мНет описания правки
мНет описания правки
Строка 207: Строка 207:
//console.log(textCSS);
//console.log(textCSS);
document.head.appendChild(styleSheet);
document.head.appendChild(styleSheet);
}
function parseCustomAttributes(attributesString) {
  const attributes = {};
  const regex = /(\w+)="([^&]+)"/g;
  let match;
  while ((match = regex.exec(attributesString)) !== null) {
    attributes[match[1]] = match[2];
  }
  return attributes;
}
}


function createIframeFromSrc(element) {
function createIframeFromSrc(element) {
   var src = element.getAttribute('data-customIframeSrc');
   var src = element.getAttribute('data-customIframeSrc');
  var customAttributesString = element.getAttribute('data-customattributes');
   if (src) {
   if (src) {
     var iframe = document.createElement('iframe');
     var iframe = document.createElement('iframe');
     iframe.src = src;
     iframe.src = src;


     // Копируем все атрибуты из исходного элемента, кроме data-атрибутов
     // Добавляем атрибуты из data-customattributes
     Array.prototype.forEach.call(element.attributes, function(attr) {
     if (customAttributesString) {
       if (!attr.name.startsWith('data-')) {
       const customAttributes = parseCustomAttributes(customAttributesString);
      console.log(attr.name, attr.value);
      for (const [key, value] of Object.entries(customAttributes)) {
         iframe.setAttribute(attr.name, attr.value);
         iframe.setAttribute(key, value);
       }
       }
     });
     }


     iframe.classList.add('customIframe');
     iframe.classList.add('customIframe');
Строка 230: Строка 244:
function createIframeFromSrcdoc(element) {
function createIframeFromSrcdoc(element) {
   var srcdoc = element.getAttribute('data-customIframeSrcdoc');
   var srcdoc = element.getAttribute('data-customIframeSrcdoc');
  var customAttributesString = element.getAttribute('data-customattributes');
   if (srcdoc) {
   if (srcdoc) {
     var iframe = document.createElement('iframe');
     var iframe = document.createElement('iframe');
     iframe.srcdoc = srcdoc;
     iframe.srcdoc = srcdoc;


     // Копируем все атрибуты из исходного элемента, кроме data-атрибутов
     // Добавляем атрибуты из data-customattributes
     Array.prototype.forEach.call(element.attributes, function(attr) {
     if (customAttributesString) {
       if (!attr.name.startsWith('data-')) {
       const customAttributes = parseCustomAttributes(customAttributesString);
      console.log(attr.name, attr.value);
      for (const [key, value] of Object.entries(customAttributes)) {
         iframe.setAttribute(attr.name, attr.value);
         iframe.setAttribute(key, value);
       }
       }
     });
     }


     iframe.classList.add('customIframeSrcdoc');
     iframe.classList.add('customIframeSrcdoc');
Строка 246: Строка 262:
   }
   }
}
}