From 22b9565c52ab926ca1bd0b611ccf7fbfd72f8167 Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Tue, 22 May 2018 14:57:45 -0700 Subject: [PATCH 01/10] short header for devtools --- .../report/html/renderer/report-renderer.js | 31 +++++++- .../html/renderer/report-ui-features.js | 3 + lighthouse-core/report/html/report-styles.css | 1 - lighthouse-core/report/html/templates.html | 79 +++++++++++-------- 4 files changed, 78 insertions(+), 36 deletions(-) diff --git a/lighthouse-core/report/html/renderer/report-renderer.js b/lighthouse-core/report/html/renderer/report-renderer.js index 23edaaaa7019..3b60f14a8b76 100644 --- a/lighthouse-core/report/html/renderer/report-renderer.js +++ b/lighthouse-core/report/html/renderer/report-renderer.js @@ -61,18 +61,33 @@ class ReportRenderer { */ _renderReportHeader(report) { const header = this._dom.cloneTemplate('#tmpl-lh-heading', this._templateContext); + const scoreContainer = this._dom.cloneTemplate('#tmpl-lh-score-container', this._templateContext); + const toolbarEl = this._dom.find('.lh-toolbar', header); + /** @type {HTMLDivElement} */ (toolbarEl.parentNode).insertBefore(scoreContainer, toolbarEl); + this._dom.find('.lh-config__timestamp', header).textContent = Util.formatDateTime(report.fetchTime); this._dom.find('.lh-product-info__version', header).textContent = report.lighthouseVersion; - const url = /** @type {HTMLAnchorElement} */ (this._dom.find('.lh-metadata__url', header)); + const metadataUrl = /** @type {HTMLAnchorElement} */ (this._dom.find('.lh-metadata__url', header)); const toolbarUrl = /** @type {HTMLAnchorElement}*/ (this._dom.find('.lh-toolbar__url', header)); - url.href = url.textContent = toolbarUrl.href = toolbarUrl.textContent = report.finalUrl; + metadataUrl.href = metadataUrl.textContent = toolbarUrl.href = toolbarUrl.textContent = report.finalUrl; const emulationDescriptions = Util.getEmulationDescriptions(report.configSettings || {}); this._dom.find('.lh-config__emulation', header).textContent = emulationDescriptions.summary; return header; } + /** + * @return {Element} + */ + _renderReportShortHeader() { + const shortHeaderContainer = this._dom.createElement('div', 'lh-header-container'); + const scoreContainer = this._dom.cloneTemplate('#tmpl-lh-score-container', this._templateContext); + shortHeaderContainer.appendChild(scoreContainer); + return shortHeaderContainer; + } + + /** * @param {ReportJSON} report * @return {DocumentFragment} @@ -124,10 +139,18 @@ class ReportRenderer { * @return {DocumentFragment} */ _renderReport(report) { - const headerStickyContainer = this._dom.createElement('div', 'lh-header-sticky'); - headerStickyContainer.appendChild(this._renderReportHeader(report)); + let headerStickyContainer; + // No header if it's devtools + if (this._dom.document().querySelector('.lh-devtools')) { + headerStickyContainer = this._dom.createElement('div', 'lh-header-nonsticky'); + headerStickyContainer.appendChild(this._renderReportShortHeader()); + } else { + headerStickyContainer = this._dom.createElement('div', 'lh-header-sticky'); + headerStickyContainer.appendChild(this._renderReportHeader(report)); + } const scoreContainer = this._dom.find('.lh-scores-container', headerStickyContainer); + const container = this._dom.createElement('div', 'lh-container'); const reportSection = container.appendChild(this._dom.createElement('div', 'lh-report')); diff --git a/lighthouse-core/report/html/renderer/report-ui-features.js b/lighthouse-core/report/html/renderer/report-ui-features.js index 3f849dba494e..28d6d0a8b974 100644 --- a/lighthouse-core/report/html/renderer/report-ui-features.js +++ b/lighthouse-core/report/html/renderer/report-ui-features.js @@ -71,6 +71,9 @@ class ReportUIFeatures { * @param {ReportJSON} report */ initFeatures(report) { + // Quit if it's a devtools report. + if (this._dom.document().querySelector('.lh-devtools')) return; + this.json = report; this._setupMediaQueryListeners(); this._setupExportButton(); diff --git a/lighthouse-core/report/html/report-styles.css b/lighthouse-core/report/html/report-styles.css index 614755a6ad14..c069e10984dd 100644 --- a/lighthouse-core/report/html/report-styles.css +++ b/lighthouse-core/report/html/report-styles.css @@ -105,7 +105,6 @@ --lh-section-vpadding: 8px; } - @keyframes fadeIn { 0% { opacity: 0;} 100% { opacity: 0.6;} diff --git a/lighthouse-core/report/html/templates.html b/lighthouse-core/report/html/templates.html index 95bd0434516c..c12d0531329a 100644 --- a/lighthouse-core/report/html/templates.html +++ b/lighthouse-core/report/html/templates.html @@ -99,6 +99,39 @@ + + + + +