forked from angular/universal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wassim Chegham
committed
Mar 7, 2016
1 parent
b63d2a7
commit 800db58
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var window = require('./dist/server/src/node/mock/window'); | ||
global.window = window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import {DOM} from 'angular2/src/platform/dom/dom_adapter'; | ||
import {provide} from 'angular2/core'; | ||
|
||
// the overloaded "window" must extend node's "global" | ||
// see: https://github.com/angular/angular/blob/master/modules/angular2/src/facade/lang.ts#L38 | ||
var win = Object.create(global); | ||
|
||
/** | ||
* Warn the developer about direct access to Window props | ||
* @param {String} prop The property being accessed | ||
*/ | ||
function beDefensive(prop){ | ||
return (<any>win).__defineGetter__(prop, () => { | ||
console.warn(`[WARNING] Property/method "${prop}" should not be called directly. Use DomAdapter instead.`); | ||
|
||
// TODO(wassim): find a generic solution to proxify DomAdapter | ||
// let doc = DOM.defaultDoc(); | ||
// return DOM.querySelector(doc, ...args); | ||
return prop; | ||
}); | ||
} | ||
|
||
let unforgeableAttributes = [ | ||
"window", | ||
"document", | ||
"location", | ||
"top" | ||
].map(beDefensive); | ||
|
||
let replaceableAttributes = [ | ||
"self", | ||
"locationbar", | ||
"menubar", | ||
"personalbar", | ||
"scrollbars", | ||
"statusbar", | ||
"toolbar", | ||
"frames", | ||
"parent", | ||
"external", | ||
"length", | ||
|
||
// CSSOM-View | ||
"screen", | ||
"scrollX", | ||
"scrollY", | ||
"pageXOffset", | ||
"pageYOffset", | ||
"innerWidth", | ||
"innerHeight", | ||
"screenX", | ||
"screenY", | ||
"outerWidth", | ||
"outerHeight", | ||
"devicePixelRatio", | ||
].map(beDefensive); | ||
|
||
let methods = [ | ||
"close", | ||
"stop", | ||
"focus", | ||
"blur", | ||
"open", | ||
"alert", | ||
"confirm", | ||
"prompt", | ||
"print", | ||
"postMessage", | ||
|
||
// WindowBase64 | ||
"btoa", | ||
"atob", | ||
|
||
// WindowTimers | ||
"setTimeout", | ||
"clearTimeout", | ||
"setInterval", | ||
"clearInterval", | ||
|
||
// HTML Editing APIs | ||
"getSelection", | ||
|
||
// CSSOM | ||
"getComputedStyle", | ||
|
||
// CSSOM-View | ||
"matchMedia", | ||
"scroll", | ||
"scrollTo", | ||
"scrollBy" | ||
].map(beDefensive); | ||
|
||
let readonlyAttributes = [ | ||
"history", | ||
"frameElement", | ||
"navigator", | ||
"applicationCache", | ||
|
||
// WindowSessionStorage | ||
"sessionStorage", | ||
|
||
// WindowLocalStorage | ||
"localStorage", | ||
].map(beDefensive); | ||
|
||
let writableAttributes = [ | ||
"name", | ||
"status", | ||
"opener", | ||
"onabort", | ||
"onafterprint", | ||
"onbeforeprint", | ||
"onbeforeunload", | ||
"onblur", | ||
"oncancel", | ||
"oncanplay", | ||
"oncanplaythrough", | ||
"onchange", | ||
"onclick", | ||
"onclose", | ||
"oncontextmenu", | ||
"oncuechange", | ||
"ondblclick", | ||
"ondrag", | ||
"ondragend", | ||
"ondragenter", | ||
"ondragleave", | ||
"ondragover", | ||
"ondragstart", | ||
"ondrop", | ||
"ondurationchange", | ||
"onemptied", | ||
"onended", | ||
"onerror", | ||
"onfocus", | ||
"onhashchange", | ||
"oninput", | ||
"oninvalid", | ||
"onkeydown", | ||
"onkeypress", | ||
"onkeyup", | ||
"onload", | ||
"onloadeddata", | ||
"onloadedmetadata", | ||
"onloadstart", | ||
"onmessage", | ||
"onmousedown", | ||
"onmousemove", | ||
"onmouseout", | ||
"onmouseover", | ||
"onmouseup", | ||
"onmousewheel", | ||
"onoffline", | ||
"ononline", | ||
"onpause", | ||
"onplay", | ||
"onplaying", | ||
"onpagehide", | ||
"onpageshow", | ||
"onpopstate", | ||
"onprogress", | ||
"onratechange", | ||
"onreset", | ||
"onresize", | ||
"onscroll", | ||
"onseeked", | ||
"onseeking", | ||
"onselect", | ||
"onshow", | ||
"onstalled", | ||
"onstorage", | ||
"onsubmit", | ||
"onsuspend", | ||
"ontimeupdate", | ||
"onunload", | ||
"onvolumechange", | ||
"onwaiting" | ||
].map(beDefensive); | ||
|
||
export var window = win; | ||
global.window = win; | ||
GLOBAL.window = win; |