2015-02-27 17:50:06 -05:00
|
|
|
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
|
2015-03-27 13:37:02 -04:00
|
|
|
import {document, window} from 'angular2/src/facade/browser';
|
2015-02-05 16:08:05 -05:00
|
|
|
import {NumberWrapper, BaseException, isBlank} from 'angular2/src/facade/lang';
|
2015-01-09 21:00:04 -05:00
|
|
|
|
2015-02-27 17:50:06 -05:00
|
|
|
var DOM = new BrowserDomAdapter();
|
|
|
|
|
2015-01-09 21:00:04 -05:00
|
|
|
export function getIntParameter(name:string) {
|
2015-01-15 13:51:47 -05:00
|
|
|
return NumberWrapper.parseInt(getStringParameter(name), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getStringParameter(name:string) {
|
|
|
|
var els = DOM.querySelectorAll(document, `input[name="${name}"]`)
|
|
|
|
var value;
|
|
|
|
var el;
|
|
|
|
|
|
|
|
for (var i=0; i<els.length; i++) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export function bindAction(selector:string, callback:Function) {
|
|
|
|
var el = DOM.querySelector(document, selector);
|
|
|
|
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);
|
|
|
|
}
|