Permalink
Browse files

lots of new DOM functionality

  • Loading branch information...
2 parents 7d3dbf9 + 63d5b42 commit b4bc6f0fee8dc93c71190b079d439a7060a6d767 John A. De Goes committed Aug 19, 2010
View
@@ -2,10 +2,26 @@
<html>
<head>
<title>Stax JavaScript Demo</title>
+ <script type="text/javascript">
+ var expandIframe = function() {
+ var iframe = document.getElementById('test-iframe');
+
+ iframe.style.position = 'fixed';
+ iframe.style.left = '50%';
+ iframe.style.top = '50%';
+ iframe.style.marginLeft = '-150px';
+ iframe.style.marginTop = '-100px';
+ }
+ </script>
</head>
<body>
<div id="haxe:trace"></div>
+ <!--
+ <iframe id="test-iframe" src="http://www.yahoo.com" width="300" height="250"></iframe>
+ <input type="button" value="Fix" onclick="javascript:expandIframe();"/>
+ -->
+
<script type="text/javascript" src="demo.js"></script>
</body>
</html>
View
@@ -5,6 +5,7 @@ import js.Env;
import js.io.IFrameIO;
import js.dom.Elements;
import js.dom.Quirks;
+import js.detect.BrowserSupport;
import haxe.framework.Injector;
import haxe.time.ScheduledExecutor;
@@ -28,7 +29,7 @@ class Demo {
var iframeIO1: IFrameIO;
var iframeIO2: IFrameIO;
- var d = Env.documentHtml;
+ var d = Env.document;
var body = d.getElementsByTagName('body')[0];
@@ -85,11 +86,37 @@ class Demo {
};
}
+ public static function browserSupportDemo() {
+ Env.document.createElement('div').withEffect(function(div) {
+ div.innerHTML += '<table>' +
+ '<tr><td>positionFixed:</td><td>' + BrowserSupport.positionFixed() + '</td></tr>' +
+ '<tr><td>boxModel:</td><td>' + BrowserSupport.boxModel() + '</td></tr>' +
+ '<tr><td>getAttributeStyle:</td><td>' + BrowserSupport.getAttributeStyle() + '</td></tr>' +
+ '<tr><td>opacity:</td><td>' + BrowserSupport.opacity() + '</td></tr>' +
+ '<tr><td>cssFloat:</td><td>' + BrowserSupport.cssFloat() + '</td></tr>' +
+ '<tr><td>checkboxValueDefaultsToOn:</td><td>' + BrowserSupport.checkboxValueDefaultsToOn() + '</td></tr>' +
+ '<tr><td>defaultSelectedHasSelectProperty:</td><td>' + BrowserSupport.defaultSelectedHasSelectProperty() + '</td></tr>' +
+ '<tr><td>offsetAddsBorderForTableAndCells:</td><td>' + BrowserSupport.offsetAddsBorderForTableAndCells() + '</td></tr>' +
+ '<tr><td>offsetDoesNotIncludeMarginInBodyOffset:</td><td>' + BrowserSupport.offsetDoesNotIncludeMarginInBodyOffset() + '</td></tr>' +
+ '<tr><td>offsetDoesNotAddBorder:</td><td>' + BrowserSupport.offsetDoesNotAddBorder() + '</td></tr>' +
+ '<tr><td>offsetSubtractsBorderForOverflowNotVisible:</td><td>' + BrowserSupport.offsetSubtractsBorderForOverflowNotVisible() + '</td></tr>' +
+ '<tr><td>spuriousTbodyInsertedBug:</td><td>' + BrowserSupport.spuriousTbodyInsertedBug() + '</td></tr>' +
+ '<tr><td>whitespaceDroppedWithInnerHTMLBug:</td><td>' + BrowserSupport.whitespaceDroppedWithInnerHTMLBug() + '</td></tr>' +
+ '<tr><td>linksDroppedWithInnerHTMLBug:</td><td>' + BrowserSupport.linksDroppedWithInnerHTMLBug() + '</td></tr>' +
+ '<tr><td>hrefIsNormalizedBug:</td><td>' + BrowserSupport.hrefIsNormalizedBug() + '</td></tr>' +
+ '</table>';
+
+ Env.document.body.appendChild(div);
+ });
+ }
+
public static function main() {
Injector.enter(function(c) {
c.bind(ScheduledExecutor, ScheduledExecutorSystem);
iframeDemo();
+
+ browserSupportDemo();
});
}
}
View
@@ -219,8 +219,7 @@ extern interface Attr implements Node {
public var schemaTypeInfo (default,null): TypeInfo;
public var isID (default,null): Bool;
}
-//Tested
-extern interface Element implements Node {
+extern interface AbstractElement<E: Node> implements Node {
public var schemaTypeInfo (default,null): TypeInfo;
public var tagName (default, null): DOMString;
public var scrollTop: Int;
@@ -245,7 +244,7 @@ extern interface Element implements Node {
public function removeAttributeNode(oldAttr: Attr): Attr;
- public function getElementsByTagName(name: DOMString): DomCollection<Node>;
+ public function getElementsByTagName(name: DOMString): DomCollection<E>;
public function getAttributeNS(namespaceURI: DOMString, localName: DOMString): DOMString;
@@ -257,7 +256,7 @@ extern interface Element implements Node {
public function setAttributeNodeNS(newAttr: Attr): Attr;
- public function getElementsByTagNameNS(namespaceURI: DOMString, localName: DOMString): DomCollection<Node>;
+ public function getElementsByTagNameNS(namespaceURI: DOMString, localName: DOMString): DomCollection<E>;
public function hasAttribute(name: DOMString): Bool;
@@ -274,6 +273,9 @@ extern interface Element implements Node {
public function getBoundingClientRect(): ClientRect;
}
//Tested
+extern interface Element implements AbstractElement<Element> {
+}
+//Tested
extern interface Text implements CharacterData {
public function splitText(offset: Int): Text;
@@ -374,7 +376,7 @@ extern interface DocumentFragment implements Node {
}
//Tested
-extern interface Document implements Node {
+extern interface AbstractDocument<E> implements Node {
public var doctype (default, null): DocumentType;
public var implementation (default, null): DOMImplementation;
public var documentElement (default, null): Element;
@@ -397,7 +399,7 @@ extern interface Document implements Node {
public var defaultView (default, null): Window;
- public function createElement(tagName: DOMString): Element;
+ public function createElement(tagName: DOMString): E;
public function createDocumentFragment(): DocumentFragment;
@@ -413,25 +415,28 @@ extern interface Document implements Node {
public function createEntityReference(name: DOMString): EntityReference;
- public function getElementsByTagName(tagname: DOMString): DomCollection<Node>;
+ public function getElementsByTagName(tagname: DOMString): DomCollection<E>;
public function importNode(importedNode: Node, deep: Bool): Node;
- public function createElementNS(namespaceURI: DOMString, qualifiedName: DOMString): Element;
+ public function createElementNS(namespaceURI: DOMString, qualifiedName: DOMString): E;
public function createAttributeNS(nameSpaceURI: DOMString, qualifiedName: DOMString): Attr;
- public function getElementsByTagNameNS(namespaceURI: DOMString, localName: DOMString): DomCollection<Node>;
+ public function getElementsByTagNameNS(namespaceURI: DOMString, localName: DOMString): DomCollection<E>;
- public function getElementById(elementId: DOMString): HTMLElement;
+ public function getElementById(elementId: DOMString): E;
public function adoptNode(source: Node): Node;
public function normalizeDocument(): Void;
public function renameNode(n: Node, namespaceURI: DOMString, qualifiedName: DOMString): Node;
- public function getOverrideStyle(elt: Element, pseudoElt: DOMString): CSSStyleDeclaration;
+ public function getOverrideStyle(elt: HTMLElement, pseudoElt: DOMString): CSSStyleDeclaration;
+}
+
+extern interface Document implements AbstractDocument<Element> {
}
extern interface Storage {
@@ -592,7 +597,7 @@ interface Selection {
public function stringifier(): DOMString;
}
-extern interface HTMLDocument implements Document {
+extern interface HTMLDocument implements HTMLElement, implements AbstractDocument<HTMLElement> {
public var title: DOMString;
public var referrer (default, null): DOMString;
public var domain (default, null): DOMString;
@@ -605,7 +610,7 @@ extern interface HTMLDocument implements Document {
public var anchors (default, null): HTMLCollection;
public var cookie: DOMString;
- public function getElementsByName(elementName: DOMString): DomCollection<Node>;
+ public function getElementsByName(elementName: DOMString): DomCollection<HTMLElement>;
public var location (default, null): Location;
public var lastModified (default, null): DOMString;
@@ -625,7 +630,7 @@ extern interface HTMLDocument implements Document {
public function getter(name: DOMString): Dynamic;
- public function getElementsByClassName(classNames: DOMString): DomCollection<Node>;
+ public function getElementsByClassName(classNames: DOMString): DomCollection<HTMLElement>;
// dynamic markup insertion
public var innerHTML : DOMString;
@@ -639,7 +644,7 @@ extern interface HTMLDocument implements Document {
public function writeln(text: DOMString): Void;
// user interaction
- public var activeElement (default, null): Element;
+ public var activeElement (default, null): HTMLElement;
public var designMode :DOMString;
public var commands :HTMLCollection;
@@ -712,15 +717,13 @@ extern interface HTMLDocument implements Document {
public var ontimeupdate: EventListener<Event>;
public var onvolumechange: EventListener<Event>;
public var onwaiting: EventListener<Event>;
-
}
extern interface HTMLUnknownElement implements HTMLElement {
-
}
//Tested
-extern interface HTMLElement implements Element {
+extern interface HTMLElement implements AbstractElement<HTMLElement> {
public var id: DOMString;
public var title: DOMString;
public var lang: DOMString;
@@ -749,9 +752,8 @@ extern interface HTMLElement implements Element {
public var outerHTML: DOMString;
public function insertAdjacentHTML(position: DOMString, text: DOMString): Void;
-
- public var offsetLeft (default,null): Int;
+ public var offsetLeft (default,null): Int;
public var offsetTop (default,null): Int;
public var offsetWidth (default,null): Int;
public var offsetHeight (default,null): Int;
@@ -769,7 +771,7 @@ extern interface HTMLElement implements Element {
public var oncanplay: EventListener<Event>;
public var oncanplaythrough: EventListener<Event>;
public var onchange: EventListener<Event>;
- public var onclick: EventListener<Event>;
+ public var onclick: EventListener<MouseEvent>;
public var oncontextmenu: EventListener<Event>;
public var ondblclick: EventListener<MouseEvent>;
public var ondrag: EventListener<MouseEvent>;
@@ -1445,6 +1447,20 @@ extern interface Media {
* <----------------- Events level 2 Port ------------------>
* *** Unable to Automate testing for all Events ***
*/
+// FIXME!!!!!!!!!
+typedef MessagePortArray = {}
+
+extern interface MessageEvent implements Event {
+ public var data (default, null): Dynamic;
+ public var origin (default, null): DOMString;
+ public var lastEventId (default, null): DOMString;
+ public var source (default, null): WindowProxy;
+ public var ports (default, null): MessagePortArray;
+
+ public function initMessageEvent(typeArg: DOMString, canBubbleArg: Bool, cancelableArg: Bool, dataArg: Dynamic, originArg: DOMString, lastEventIdArg: DOMString, sourceArg: WindowProxy, portsArg: MessagePortArray): Void;
+
+ public function initMessageEventNS(namespaceURI: DOMString, typeArg: DOMString, canBubbleArg: Bool, cancelableArg: Bool, dataArg: Dynamic, originArg: DOMString, lastEventIdArg: DOMString, sourceArg: WindowProxy, portsArg: MessagePortArray): Void;
+}
extern interface StorageEvent implements Event {
public var key (default, null): DOMString;
@@ -2101,7 +2117,7 @@ extern interface CSSCharsetRule implements CSSRule {
extern interface CSSUnknownRule implements CSSRule {
}
//UnableToTest
-extern interface CSS2Properties ArrayAccess<DOMString> {
+extern interface CSS2Properties {
public var azimuth: DOMString;
public var background: DOMString;
public var backgroundAttachment: DOMString;
@@ -2175,6 +2191,7 @@ extern interface CSS2Properties ArrayAccess<DOMString> {
public var maxWidth: DOMString;
public var minHeight: DOMString;
public var minWidth: DOMString;
+ public var opacity: DOMString;
public var orphans: DOMString;
public var outline: DOMString;
public var outlineColor: DOMString;
@@ -2306,7 +2323,7 @@ extern interface CSSStyleSheet implements StyleSheet {
}
//Unable to Test
extern interface ViewCSS implements AbstractView {
- public function getComputedStyle(elt: Element, pseudoElt: DOMString): CSSStyleDeclaration;
+ public function getComputedStyle(elt: HTMLElement, pseudoElt: DOMString): CSSStyleDeclaration;
}
//Unable to Test
extern interface DOMImplementationCSS implements DOMImplementation {
@@ -2553,9 +2570,9 @@ extern interface Window implements ArrayAccess<WindowProxy>, implements EventTar
public function btoa(unencodedString: DOMString): DOMString;
- public var getComputedStyle (default, null): Element -> DOMString -> CSSStyleDeclaration;
+ public function getComputedStyle(e: HTMLElement, s: DOMString): CSSStyleDeclaration;
- public var postMessage (default, null): DOMString -> DOMString -> Void;
+ public function postMessage(s1: DOMString, s2: DOMString): Void;
public function getSelection(): Selection;
@@ -217,9 +217,23 @@ class FloatExtensions {
}
}
class StringExtensions {
- public static function toBool(v: String): Bool { return if (v.toLowerCase() == "false" || v == "0") false else true; }
- public static function toInt(v: String): Int { return Std.parseInt(v); }
- public static function toFloat(v: String): Float { return Std.parseFloat(v); }
+ public static function toBool(v: String, ?d: Bool): Bool {
+ if (v == null) return d;
+
+ var vLower = v.toLowerCase();
+
+ return (if (vLower == 'false' || v == '0') Some(false) else if (vLower == 'true' || v == '1') Some(true) else None).getOrElseC(d);
+ }
+ public static function toInt(v: String, ?d: Null<Int>): Int {
+ if (v == null) return d;
+
+ return Std.parseInt(v).toOption().filter(function(i) return !Math.isNaN(i)).getOrElseC(d);
+ }
+ public static function toFloat(v: String, ?d: Null<Float>): Float {
+ if (v == null) return d;
+
+ return Std.parseFloat(v).toOption().filter(function(i) return !Math.isNaN(i)).getOrElseC(d);
+ }
public static function startsWith(v: String, frag: String): Bool {
return if (v.length >= frag.length && frag == v.substr(0, frag.length)) true else false;
}
@@ -352,7 +366,7 @@ class ArrayExtensions {
public static function ShowT<T>(c: Class<Array<Dynamic>>, show: Show<T>): Show<Array<T>> {
return ShowTypeclass.create({
show: function(v: Array<T>) {
- return "[" + v.map(function(e) { return show.show(e); }).join(", ") + "]";
+ return "[" + v.map(function(e) return show.show(e)).join(", ") + "]";
}
});
}
@@ -492,6 +506,13 @@ class Function0Extensions {
}
}
+ public static function thenDo(f1: Void -> Void, f2: Void -> Void): Void -> Void {
+ return function() {
+ f1();
+ f2();
+ }
+ }
+
public static function promote<A, Z>(f: Void -> Z): A -> Z {
return function(a: A): Z {
return f();
@@ -503,6 +524,16 @@ class Function0Extensions {
f();
}
}
+
+ public static function stage<Z, T>(f: Void -> Z, before: Void -> T, after: T -> Void): Z {
+ var state = before();
+
+ var result = f();
+
+ after(state);
+
+ return result;
+ }
}
class Function1Extensions {
public static function swallow<A>(f: Function<A, Void>): Function<A, Void> {
Oops, something went wrong.

0 comments on commit b4bc6f0

Please sign in to comment.