2016-06-23 09:47:54 -07: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
|
|
|
|
*/
|
|
|
|
|
2016-08-10 15:55:18 -07:00
|
|
|
import {BaseException} from '@angular/core';
|
|
|
|
|
2016-04-28 17:50:03 -07:00
|
|
|
import {BrowserDomAdapter} from '../src/browser/browser_adapter';
|
|
|
|
import {document, window} from '../src/facade/browser';
|
2016-06-08 16:38:52 -07:00
|
|
|
import {NumberWrapper, isBlank} from '../src/facade/lang';
|
2015-01-09 18:00:04 -08:00
|
|
|
|
2015-02-27 14:50:06 -08:00
|
|
|
var DOM = new BrowserDomAdapter();
|
|
|
|
|
2015-05-20 17:19:46 -07:00
|
|
|
export function getIntParameter(name: string) {
|
2015-01-15 10:51:47 -08:00
|
|
|
return NumberWrapper.parseInt(getStringParameter(name), 10);
|
|
|
|
}
|
|
|
|
|
2015-05-20 17:19:46 -07:00
|
|
|
export function getStringParameter(name: string) {
|
|
|
|
var els = DOM.querySelectorAll(document, `input[name="${name}"]`);
|
2016-06-08 15:45:15 -07:00
|
|
|
var value: any /** TODO #9100 */;
|
|
|
|
var el: any /** TODO #9100 */;
|
2015-01-15 10:51:47 -08:00
|
|
|
|
2015-05-20 17:19:46 -07:00
|
|
|
for (var i = 0; i < els.length; i++) {
|
2015-01-15 10:51:47 -08:00
|
|
|
el = els[i];
|
2015-02-19 11:18:23 +01:00
|
|
|
var type = DOM.type(el);
|
2015-03-26 15:49:41 -07:00
|
|
|
if ((type != 'radio' && type != 'checkbox') || DOM.getChecked(el)) {
|
2015-02-19 11:18:23 +01:00
|
|
|
value = DOM.getValue(el);
|
2015-01-15 10:51:47 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isBlank(value)) {
|
2015-01-09 18:00:04 -08:00
|
|
|
throw new BaseException(`Could not find and input field with name ${name}`);
|
|
|
|
}
|
2015-01-15 10:51:47 -08:00
|
|
|
|
|
|
|
return value;
|
2015-01-09 18:00:04 -08:00
|
|
|
}
|
|
|
|
|
2015-05-20 17:19:46 -07:00
|
|
|
export function bindAction(selector: string, callback: Function) {
|
2015-01-09 18:00:04 -08:00
|
|
|
var el = DOM.querySelector(document, selector);
|
2016-06-08 15:45:15 -07:00
|
|
|
DOM.on(el, 'click', function(_: any /** TODO #9100 */) { callback(); });
|
2015-03-27 10:37:02 -07:00
|
|
|
}
|
|
|
|
|
2016-06-08 16:38:52 -07:00
|
|
|
export function microBenchmark(
|
|
|
|
name: any /** TODO #9100 */, iterationCount: any /** TODO #9100 */,
|
|
|
|
callback: any /** TODO #9100 */) {
|
2015-03-27 10:37:02 -07:00
|
|
|
var durationName = `${name}/${iterationCount}`;
|
|
|
|
window.console.time(durationName);
|
|
|
|
callback();
|
|
|
|
window.console.timeEnd(durationName);
|
|
|
|
}
|
2015-06-01 17:33:51 -07:00
|
|
|
|
|
|
|
export function windowProfile(name: string): void {
|
|
|
|
(<any>window.console).profile(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function windowProfileEnd(name: string): void {
|
|
|
|
(<any>window.console).profileEnd(name);
|
|
|
|
}
|