MediaWiki:Common.js: различия между версиями
Kerisar (обсуждение | вклад) мНет описания правки |
Kerisar (обсуждение | вклад) мНет описания правки |
||
| Строка 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-customattributes | ||
if (customAttributesString) { | |||
const customAttributes = parseCustomAttributes(customAttributesString); | |||
for (const [key, value] of Object.entries(customAttributes)) { | |||
iframe.setAttribute( | 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-customattributes | ||
if (customAttributesString) { | |||
const customAttributes = parseCustomAttributes(customAttributesString); | |||
for (const [key, value] of Object.entries(customAttributes)) { | |||
iframe.setAttribute( | iframe.setAttribute(key, value); | ||
} | } | ||
} | } | ||
iframe.classList.add('customIframeSrcdoc'); | iframe.classList.add('customIframeSrcdoc'); | ||
| Строка 246: | Строка 262: | ||
} | } | ||
} | } | ||