-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Report: header, footer, leftnav, share, oh my #2000
Changes from 32 commits
45b289e
9f8014d
fef3a99
8b4d2e7
7d9e20c
6887af7
2b84229
b138885
c9633af
ee7fcb1
3b7e90f
c717870
85d6b8e
2ff34f7
e9751c7
2918469
2a60c3a
121fda3
a445a6e
703043a
c237657
d7f3c29
aa93acc
3899e47
33021e5
31a7385
d33cc21
4bbba21
a30c86e
d8ce09f
777adfe
a1ffbf5
e542539
8bf076f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2015 The Closure Compiler Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Externs for the Google Universal Analytics API (analytics.js). | ||
* | ||
* The analytics.js API allows the user to choose a name of Google Analytics | ||
* object. This externs file assumes that the name is ‘ga’. If you include | ||
* analytics.js snippet and use a different name, this externs file will not | ||
* be useful to you (unless you change the name ‘ga’ to whatever name you’ve | ||
* chosen). | ||
* | ||
* @see https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference | ||
* @externs | ||
*/ | ||
|
||
|
||
/** | ||
* @param {string} methodName | ||
* @param {...?} var_args | ||
* @return {?} | ||
*/ | ||
function ga(methodName, var_args) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think putting functions on this function will actually work. Is the rest of this file needed right now? Definitely should avoid unknown type and do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took this entire thing from closure's common externs. |
||
|
||
/** | ||
* @param {string} trackingId | ||
* @param {!Object=} opt_configObject | ||
* @return {!_GATracker} | ||
*/ | ||
ga.create = function(trackingId, opt_configObject) {}; | ||
|
||
/** | ||
* @param {string} name | ||
* @return {?_GATracker} | ||
*/ | ||
ga.getByName = function(name) {}; | ||
|
||
/** @return {!Array<!_GATracker>} */ | ||
ga.getAll = function() {}; | ||
|
||
|
||
/** @type {string|undefined} */ | ||
var GoogleAnalyticsObject; | ||
|
||
|
||
/** @interface */ | ||
function _GATracker() {} | ||
|
||
/** | ||
* @param {string} hitType | ||
* @param {!Object=} opt_fieldObject | ||
* @return {*} | ||
*/ | ||
_GATracker.prototype.send = function(hitType, opt_fieldObject) {}; | ||
|
||
/** | ||
* @param {string|!Object} nameOrFieldObject | ||
* @param {string|number|!Object|boolean=} opt_value (required if | ||
* nameOrFieldObject is a string) | ||
*/ | ||
_GATracker.prototype.set = function(nameOrFieldObject, opt_value) {}; | ||
|
||
/** | ||
* @param {string} name | ||
* @return {string|number|?Object|boolean} | ||
*/ | ||
_GATracker.prototype.get = function(name) {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,37 +15,7 @@ | |
*/ | ||
'use strict'; | ||
|
||
/* globals self */ | ||
|
||
const RATINGS = { | ||
PASS: {label: 'pass', minScore: 75}, | ||
AVERAGE: {label: 'average', minScore: 45}, | ||
FAIL: {label: 'fail'} | ||
}; | ||
|
||
/** | ||
* Convert a score to a rating label. | ||
* @param {number} score | ||
* @return {string} | ||
*/ | ||
function calculateRating(score) { | ||
let rating = RATINGS.FAIL.label; | ||
if (score >= RATINGS.PASS.minScore) { | ||
rating = RATINGS.PASS.label; | ||
} else if (score >= RATINGS.AVERAGE.minScore) { | ||
rating = RATINGS.AVERAGE.label; | ||
} | ||
return rating; | ||
} | ||
|
||
/** | ||
* Format number. | ||
* @param {number} number | ||
* @return {string} | ||
*/ | ||
function formatNumber(number) { | ||
return number.toLocaleString(undefined, {maximumFractionDigits: 1}); | ||
} | ||
/* globals self, formatNumber, calculateRating */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this global/ |
||
|
||
class CategoryRenderer { | ||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ class DOM { | |
|
||
/** | ||
* @param {string} selector | ||
* @param {!Document|!Element} context | ||
* @param {!Document|!DocumentFragment|!Element} context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we just switch this to |
||
* @return {!DocumentFragment} A clone of the template content. | ||
* @throws {Error} | ||
*/ | ||
|
@@ -113,7 +113,7 @@ class DOM { | |
* Guaranteed context.querySelector. Always returns an element or throws if | ||
* nothing matches query. | ||
* @param {string} query | ||
* @param {!DocumentFragment|!Element} context | ||
* @param {!Document|!DocumentFragment|!Element} context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would |
||
* @return {!Element} | ||
*/ | ||
find(query, context) { | ||
|
@@ -127,7 +127,7 @@ class DOM { | |
/** | ||
* Helper for context.querySelectorAll. Returns an Array instead of a NodeList. | ||
* @param {string} query | ||
* @param {!DocumentFragment|!Element} context | ||
* @param {!Document|!DocumentFragment|!Element} context | ||
* @return {!Array<Element>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should return |
||
*/ | ||
findAll(query, context) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
const RATINGS = { | ||
PASS: {label: 'pass', minScore: 75}, | ||
AVERAGE: {label: 'average', minScore: 45}, | ||
FAIL: {label: 'fail'} | ||
}; | ||
|
||
/** | ||
* Convert a score to a rating label. | ||
* @param {number} score | ||
* @return {string} | ||
*/ | ||
function calculateRating(score) { | ||
let rating = RATINGS.FAIL.label; | ||
if (score >= RATINGS.PASS.minScore) { | ||
rating = RATINGS.PASS.label; | ||
} else if (score >= RATINGS.AVERAGE.minScore) { | ||
rating = RATINGS.AVERAGE.label; | ||
} | ||
return rating; | ||
} | ||
|
||
/** | ||
* Format number. | ||
* @param {number} number | ||
* @return {string} | ||
*/ | ||
function formatNumber(number) { | ||
return number.toLocaleString(undefined, {maximumFractionDigits: 1}); | ||
} | ||
|
||
/** | ||
* Format time. | ||
* @param {string} date | ||
* @return {string} | ||
*/ | ||
function formatDateTime(date) { | ||
const options = { | ||
month: 'short', day: 'numeric', year: 'numeric', | ||
hour: 'numeric', minute: 'numeric', timeZoneName: 'short' | ||
}; | ||
let formatter = new Intl.DateTimeFormat('en-US', options); | ||
|
||
// Force UTC if runtime timezone could not be detected. | ||
// See https://github.com/GoogleChrome/lighthouse/issues/1056 | ||
const tz = formatter.resolvedOptions().timeZone; | ||
if (!tz || tz.toLowerCase() === 'etc/unknown') { | ||
options.timeZone = 'UTC'; | ||
formatter = new Intl.DateTimeFormat('en-US', options); | ||
} | ||
return formatter.format(new Date(date)); | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to get #2050 landed to get this automatically checked, but I believe this breaks @paulirish's build script. Unless that was reverted? I forget where that landed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also we need to update the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, even when I uncomment that line the compilation succeeds. Although I don't seem to get a closure-output.js file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
er, you're right. I guess ignore this :) not sure what changed
you have to set |
||
calculateRating, | ||
formatNumber, | ||
formatDateTime, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does devtools want a logger? This PR might need to adjust to the model in #2002 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDK. I'm just porting :) Knowing the separation of LH proper and integrations of LH is still unclear. Right now the operating assumption is that we're keeping everything we currently have b/c #1937 doesn't capture these types of details. For me, the dream is that there will be all sorts of existing tools that adopt a LH report. It's impossible to foresee all those integration touch points. Rather than designing our system around a particular integration , it might be easier to flip it. IOW, the integration (e.g. devtools) decides what parts of LH it wants to throw away or replace. Removing handlebars, adding For the features stuff, I've updated it to take the approach in b12f2ea. Devtools can decide not to load the feature (including logger). Some open thoughts/questions for everyone. "Integration X" can be substituted for "devtools".
|
||
* @license | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Logs messages via a UI butter. | ||
* @class | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need |
||
*/ | ||
class Logger { | ||
/** | ||
* @param {!Element} element | ||
*/ | ||
constructor(element) { | ||
this.el = element; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should type this until we get NTI: |
||
/** @private {?number} */ | ||
this._id = null; | ||
} | ||
|
||
/** | ||
* Shows a butter bar. | ||
* @param {!string} msg The message to show. | ||
* @param {boolean=} optAutoHide True to hide the message after a duration. | ||
* Default is true. | ||
*/ | ||
log(msg, optAutoHide) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we use default params elsewhere already...want to use one here? |
||
const autoHide = typeof optAutoHide === 'undefined' ? true : optAutoHide; | ||
|
||
clearTimeout(this._id); | ||
|
||
this.el.textContent = msg; | ||
this.el.classList.add('show'); | ||
if (autoHide) { | ||
this._id = setTimeout(_ => { | ||
this.el.classList.remove('show'); | ||
}, 7000); | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} msg | ||
*/ | ||
warn(msg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need jsdoc on these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
this.log('Warning: ' + msg); | ||
} | ||
|
||
/** | ||
* @param {string} msg | ||
*/ | ||
error(msg) { | ||
this.log(msg); | ||
} | ||
|
||
/** | ||
* Explicitly hides the butter bar. | ||
*/ | ||
hide() { | ||
clearTimeout(this._id); | ||
this.el.classList.remove('show'); | ||
} | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = Logger; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2015?