2015-11-17 18:24:36 -05:00
|
|
|
import {BrowserDomAdapter} from 'angular2/src/platform/browser/browser_adapter';
|
2015-11-06 20:34:07 -05:00
|
|
|
import {document, window} from 'angular2/src/facade/browser';
|
|
|
|
import {NumberWrapper, isBlank} from 'angular2/src/facade/lang';
|
|
|
|
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
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}"]`);
|
2015-01-15 13:51:47 -05:00
|
|
|
var value;
|
|
|
|
var el;
|
|
|
|
|
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);
|
2015-05-20 20:19:46 -04:00
|
|
|
DOM.on(el, 'click', function(_) { callback(); });
|
2015-03-27 13:37:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function microBenchmark(name, iterationCount, callback) {
|
|
|
|
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);
|
|
|
|
}
|