feat(dom): add setData()
method.
This commit is contained in:
parent
cdf791f0c5
commit
6f3368ef16
@ -5,6 +5,7 @@ import 'dart:js' show JsObject;
|
||||
import 'dom_adapter.dart' show setRootDomAdapter;
|
||||
import 'generic_browser_adapter.dart' show GenericBrowserDomAdapter;
|
||||
import '../facade/browser.dart';
|
||||
import 'dart:js' as js;
|
||||
|
||||
// WARNING: Do not expose outside this class. Parsing HTML using this
|
||||
// sanitizer is a security risk.
|
||||
@ -100,6 +101,7 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||
setRootDomAdapter(new BrowserDomAdapter());
|
||||
}
|
||||
|
||||
// TODO(tbosch): move this into a separate environment class once we have it
|
||||
logError(error) {
|
||||
window.console.error(error);
|
||||
}
|
||||
@ -329,4 +331,14 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||
String getUserAgent() {
|
||||
return window.navigator.userAgent;
|
||||
}
|
||||
void setData(Element element, String name, String value) {
|
||||
element.dataset[name] = value;
|
||||
}
|
||||
String getData(Element element, String name) {
|
||||
return element.dataset[name];
|
||||
}
|
||||
// TODO(tbosch): move this into a separate environment class once we have it
|
||||
setGlobalVar(String name, value) {
|
||||
js.context[name] = value;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {isBlank, isPresent} from 'angular2/src/facade/lang';
|
||||
import {isBlank, isPresent, global} from 'angular2/src/facade/lang';
|
||||
import {setRootDomAdapter} from './dom_adapter';
|
||||
import {GenericBrowserDomAdapter} from './generic_browser_adapter';
|
||||
|
||||
@ -51,6 +51,7 @@ var _chromeNumKeyPadMap = {
|
||||
export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||
static makeCurrent() { setRootDomAdapter(new BrowserDomAdapter()); }
|
||||
|
||||
// TODO(tbosch): move this into a separate environment class once we have it
|
||||
logError(error) { window.console.error(error); }
|
||||
|
||||
get attrToPropMap(): any { return _attrToPropMap; }
|
||||
@ -254,6 +255,12 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
||||
getLocation() { return window.location; }
|
||||
getBaseHref() { return relativePath(document.baseURI); }
|
||||
getUserAgent(): string { return window.navigator.userAgent; }
|
||||
setData(element, name: string, value: string) { element.dataset[name] = value; }
|
||||
getData(element, name: string): string { return element.dataset[name]; }
|
||||
// TODO(tbosch): move this into a separate environment class once we have it
|
||||
setGlobalVar(name: string, value: any) {
|
||||
global[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// based on urlUtils.js in AngularJS 1
|
||||
|
@ -115,4 +115,7 @@ export class DomAdapter {
|
||||
getLocation() { throw _abstract(); }
|
||||
getBaseHref() { throw _abstract(); }
|
||||
getUserAgent(): string { throw _abstract(); }
|
||||
setData(element, name: string, value: string) { throw _abstract(); }
|
||||
getData(element, name: string): string { throw _abstract(); }
|
||||
setGlobalVar(name: string, value: any) { throw _abstract(); }
|
||||
}
|
||||
|
@ -306,4 +306,14 @@ class Html5LibDomAdapter implements DomAdapter {
|
||||
String getUserAgent() {
|
||||
throw 'not implemented';
|
||||
}
|
||||
void setData(Element element, String name, String value) {
|
||||
this.setAttribute(element, 'data-${name}', value);
|
||||
}
|
||||
String getData(Element element, String name) {
|
||||
return this.getAttribute(element, 'data-${name}');
|
||||
}
|
||||
// TODO(tbosch): move this into a separate environment class once we have it
|
||||
setGlobalVar(String name, value) {
|
||||
// noop on the server
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ var url = require('url');
|
||||
|
||||
import {List, MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
import {DomAdapter, setRootDomAdapter} from './dom_adapter';
|
||||
import {BaseException, isPresent, isBlank} from 'angular2/src/facade/lang';
|
||||
import {BaseException, isPresent, isBlank, global} from 'angular2/src/facade/lang';
|
||||
import {SelectorMatcher, CssSelector} from 'angular2/src/render/dom/compiler/selector';
|
||||
|
||||
var _attrToPropMap = {
|
||||
@ -543,6 +543,16 @@ export class Parse5DomAdapter extends DomAdapter {
|
||||
getUserAgent() {
|
||||
return "Fake user agent";
|
||||
}
|
||||
getData(el, name:string):string {
|
||||
return this.getAttribute(el, 'data-'+name);
|
||||
}
|
||||
setData(el, name:string, value:string) {
|
||||
this.setAttribute(el, 'data-'+name, value);
|
||||
}
|
||||
// TODO(tbosch): move this into a separate environment class once we have it
|
||||
setGlobalVar(name: string, value: any) {
|
||||
global[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: build a proper list, this one is all the keys of a HTMLInputElement
|
||||
|
@ -1,15 +0,0 @@
|
||||
library angular2.src.facade.js_interop;
|
||||
|
||||
import 'dart:js' as js;
|
||||
|
||||
setGlobalVar(String name, value) {
|
||||
js.context[name] = value;
|
||||
}
|
||||
|
||||
getGlobalVar(String name) {
|
||||
return js.context[name];
|
||||
}
|
||||
|
||||
invokeJsFunction(js.JsFunction fn, self, args) {
|
||||
return fn.apply(args, thisArg: self);
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
import {global} from './lang';
|
||||
|
||||
export function setGlobalVar(name: string, value: any) {
|
||||
global[name] = value;
|
||||
}
|
||||
|
||||
export function getGlobalVar(name: string) {
|
||||
return global[name];
|
||||
}
|
||||
|
||||
export function invokeJsFunction(fn: Function, self: any, args: List<any>) {
|
||||
return fn.apply(self, args);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user