diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 045f2110872..95ac122a11c 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -5099,28 +5099,16 @@ function charsetLoadListener (event) } /* Begin Page Style Functions */ -function getStyleSheetArray(frame) -{ - var styleSheets = frame.document.styleSheets; - var styleSheetsArray = new Array(styleSheets.length); - for (var i = 0; i < styleSheets.length; i++) { - styleSheetsArray[i] = styleSheets[i]; - } - return styleSheetsArray; -} - -function getAllStyleSheets(frameset) -{ - var styleSheetsArray = getStyleSheetArray(frameset); - for (var i = 0; i < frameset.frames.length; i++) { - var frameSheets = getAllStyleSheets(frameset.frames[i]); +function getAllStyleSheets(frameset) { + var styleSheetsArray = Array.slice(frameset.document.styleSheets); + for (let i = 0; i < frameset.frames.length; i++) { + let frameSheets = getAllStyleSheets(frameset.frames[i]); styleSheetsArray = styleSheetsArray.concat(frameSheets); } return styleSheetsArray; } -function stylesheetFillPopup(menuPopup) -{ +function stylesheetFillPopup(menuPopup) { var noStyle = menuPopup.firstChild; var persistentOnly = noStyle.nextSibling; var sep = persistentOnly.nextSibling; @@ -5128,41 +5116,42 @@ function stylesheetFillPopup(menuPopup) menuPopup.removeChild(sep.nextSibling); var styleSheets = getAllStyleSheets(window.content); - var currentStyleSheets = []; + var currentStyleSheets = {}; var styleDisabled = getMarkupDocumentViewer().authorStyleDisabled; var haveAltSheets = false; var altStyleSelected = false; - for (var i = 0; i < styleSheets.length; ++i) { - var currentStyleSheet = styleSheets[i]; + for (let i = 0; i < styleSheets.length; ++i) { + let currentStyleSheet = styleSheets[i]; + + if (!currentStyleSheet.title) + continue; // Skip any stylesheets that don't match the screen media type. - var media = currentStyleSheet.media.mediaText.toLowerCase(); - if (media && (media.indexOf("screen") == -1) && (media.indexOf("all") == -1)) + let (media = currentStyleSheet.media.mediaText.toLowerCase()) { + if (media && (media.indexOf("screen") == -1) && (media.indexOf("all") == -1)) continue; + } - if (currentStyleSheet.title) { - if (!currentStyleSheet.disabled) - altStyleSelected = true; + if (!currentStyleSheet.disabled) + altStyleSelected = true; - haveAltSheets = true; + haveAltSheets = true; - var lastWithSameTitle = null; - if (currentStyleSheet.title in currentStyleSheets) - lastWithSameTitle = currentStyleSheets[currentStyleSheet.title]; + let lastWithSameTitle = null; + if (currentStyleSheet.title in currentStyleSheets) + lastWithSameTitle = currentStyleSheets[currentStyleSheet.title]; - if (!lastWithSameTitle) { - var menuItem = document.createElement("menuitem"); - menuItem.setAttribute("type", "radio"); - menuItem.setAttribute("label", currentStyleSheet.title); - menuItem.setAttribute("data", currentStyleSheet.title); - menuItem.setAttribute("checked", !currentStyleSheet.disabled && !styleDisabled); - menuPopup.appendChild(menuItem); - currentStyleSheets[currentStyleSheet.title] = menuItem; - } else { - if (currentStyleSheet.disabled) - lastWithSameTitle.removeAttribute("checked"); - } + if (!lastWithSameTitle) { + let menuItem = document.createElement("menuitem"); + menuItem.setAttribute("type", "radio"); + menuItem.setAttribute("label", currentStyleSheet.title); + menuItem.setAttribute("data", currentStyleSheet.title); + menuItem.setAttribute("checked", !currentStyleSheet.disabled && !styleDisabled); + menuPopup.appendChild(menuItem); + currentStyleSheets[currentStyleSheet.title] = menuItem; + } else if (currentStyleSheet.disabled) { + lastWithSameTitle.removeAttribute("checked"); } } @@ -5174,20 +5163,15 @@ function stylesheetFillPopup(menuPopup) } function stylesheetInFrame(frame, title) { - var docStyleSheets = frame.document.styleSheets; - - for (var i = 0; i < docStyleSheets.length; ++i) { - if (docStyleSheets[i].title == title) - return true; - } - return false; + return Array.some(frame.document.styleSheets, + function (stylesheet) stylesheet.title == title); } function stylesheetSwitchFrame(frame, title) { var docStyleSheets = frame.document.styleSheets; - for (var i = 0; i < docStyleSheets.length; ++i) { - var docStyleSheet = docStyleSheets[i]; + for (let i = 0; i < docStyleSheets.length; ++i) { + let docStyleSheet = docStyleSheets[i]; if (title == "_nostyle") docStyleSheet.disabled = true; @@ -5199,18 +5183,16 @@ function stylesheetSwitchFrame(frame, title) { } function stylesheetSwitchAll(frameset, title) { - if (!title || title == "_nostyle" || stylesheetInFrame(frameset, title)) { + if (!title || title == "_nostyle" || stylesheetInFrame(frameset, title)) stylesheetSwitchFrame(frameset, title); - } - for (var i = 0; i < frameset.frames.length; i++) { + + for (let i = 0; i < frameset.frames.length; i++) stylesheetSwitchAll(frameset.frames[i], title); - } } function setStyleDisabled(disabled) { getMarkupDocumentViewer().authorStyleDisabled = disabled; } - /* End of the Page Style functions */ var BrowserOffline = {