Skip to content

Commit

Permalink
Migrate lang attributes to iframe documents
Browse files Browse the repository at this point in the history
Also detect and use both lang and xml:lang
  • Loading branch information
austinmatherne-wk committed Nov 20, 2024
1 parent 36b6910 commit 0c10844
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions iXBRLViewerPlugin/viewer/src/js/ixbrlviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ export class iXBRLViewer {
else {
docTitle = "Inline Viewer";
}
if ($('html').attr("lang") === undefined) {
$('html').attr("lang", "en-US");
}

$('head').children().not("script").not("style#ixv-style").not("link#ixv-favicon").appendTo($(iframe).contents().find('head'));

Expand Down Expand Up @@ -235,7 +232,7 @@ export class iXBRLViewer {

if (!stubViewer) {
iframes = $(iv._reparentDocument());
}
}
const ds = reportSet.reportFiles();
let hasExternalIframe = false;
for (let i = stubViewer ? 0 : 1; i < ds.length; i++) {
Expand All @@ -252,15 +249,31 @@ export class iXBRLViewer {
/* Poll for iframe load completing - there doesn't seem to be a reliable event that we can use */
let timer = setInterval(function () {
let complete = true;
iframes.each(function (n) {
const iframe = this;
iframes.each((n, iframe) => {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
if ((iframeDoc.readyState != 'complete' && iframeDoc.readyState != 'interactive') || $(iframe).contents().find("body").children().length == 0) {
complete = false;
}
});
if (complete) {
clearInterval(timer);
const html = $('html');
const lang = html.attr('lang') || html.attr('xml:lang');
// Remove any report language from the application html node.
html.removeAttr('lang');
html.removeAttr('xml:lang');
iframes.each((n, iframe) => {
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
const iframeHtml = $(iframeDoc).find('html');
let frameLang = iframeHtml.attr('lang') || iframeHtml.attr('xml:lang');
if (frameLang === undefined) {
frameLang = lang;
}
if (frameLang !== undefined) {
// Try to set the language of the iframe to the language of the report.
iframeHtml.attr({'lang': frameLang, 'xml:lang': frameLang});
}
});

const viewer = iv.viewer = new Viewer(iv, iframes, reportSet);

Expand Down

0 comments on commit 0c10844

Please sign in to comment.