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