2016-08-30 17:17:37 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
urlParamsToForm();
|
|
|
|
|
|
|
|
export function getIntParameter(name: string) {
|
|
|
|
return parseInt(getStringParameter(name), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getStringParameter(name: string) {
|
2016-11-12 08:08:58 -05:00
|
|
|
const els = document.querySelectorAll(`input[name="${name}"]`);
|
|
|
|
let value: any;
|
|
|
|
let el: any;
|
2016-08-30 17:17:37 -04:00
|
|
|
|
2016-11-12 08:08:58 -05:00
|
|
|
for (let i = 0; i < els.length; i++) {
|
2016-08-30 17:17:37 -04:00
|
|
|
el = els[i];
|
2016-11-12 08:08:58 -05:00
|
|
|
const type = el.type;
|
2016-08-30 17:17:37 -04:00
|
|
|
if ((type != 'radio' && type != 'checkbox') || el.checked) {
|
|
|
|
value = el.value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value == null) {
|
|
|
|
throw new Error(`Could not find and input field with name ${name}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function bindAction(selector: string, callback: () => void) {
|
|
|
|
document.querySelector(selector).addEventListener('click', callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function profile(create: () => void, destroy: () => void, name: string) {
|
|
|
|
return function() {
|
|
|
|
window.console.profile(name + ' w GC');
|
2016-11-12 08:08:58 -05:00
|
|
|
let duration = 0;
|
|
|
|
let count = 0;
|
2016-08-30 17:17:37 -04:00
|
|
|
while (count++ < 150) {
|
|
|
|
(<any>window)['gc']();
|
2016-11-12 08:08:58 -05:00
|
|
|
const start = window.performance.now();
|
2016-08-30 17:17:37 -04:00
|
|
|
create();
|
|
|
|
duration += window.performance.now() - start;
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
window.console.profileEnd();
|
|
|
|
|
|
|
|
window.console.profile(name + ' w/o GC');
|
|
|
|
duration = 0;
|
|
|
|
count = 0;
|
|
|
|
while (count++ < 150) {
|
2016-11-12 08:08:58 -05:00
|
|
|
const start = window.performance.now();
|
2016-08-30 17:17:37 -04:00
|
|
|
create();
|
|
|
|
duration += window.performance.now() - start;
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
window.console.profileEnd();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// helper script that will read out the url parameters
|
|
|
|
// and store them in appropriate form fields on the page
|
|
|
|
function urlParamsToForm() {
|
2016-11-12 08:08:58 -05:00
|
|
|
const regex = /(\w+)=(\w+)/g;
|
|
|
|
const search = decodeURIComponent(location.search);
|
|
|
|
let match: any[];
|
2016-08-30 17:17:37 -04:00
|
|
|
while (match = regex.exec(search)) {
|
2016-11-12 08:08:58 -05:00
|
|
|
const name = match[1];
|
|
|
|
const value = match[2];
|
|
|
|
const els = document.querySelectorAll('input[name="' + name + '"]');
|
|
|
|
let el: any;
|
|
|
|
for (let i = 0; i < els.length; i++) {
|
2016-08-30 17:17:37 -04:00
|
|
|
el = els[i];
|
|
|
|
if (el.type === 'radio' || el.type === 'checkbox') {
|
|
|
|
el.checked = el.value === value;
|
|
|
|
} else {
|
|
|
|
el.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|