Skip to content

Instantly share code, notes, and snippets.

@darobin
Created April 9, 2013 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darobin/5346591 to your computer and use it in GitHub Desktop.
Save darobin/5346591 to your computer and use it in GitHub Desktop.
Just a very quick and dirty stab at using JS for IDL (more at https://github.com/darobin/ideal/)
var ideal = require("../ideal")
, dom = exports
;
dom.Phase = ideal.legacyEnum("NONE", "CAPTURING_PHASE", "AT_TARGET", "BUBBLING_PHASE");
dom.Event = ideal.class
.importLegacyEnum(dom.Phase)
.constructor
.param(String, "type")
.param({ bubbles: false, cancelable: false }, "options")
.nonwritable
.property(String, "type")
.property(dom.EventTarget, "target").nullable
.property(dom.EventTarget, "currentTarget").nullable
.property(dom.Phase, "eventPhase")
.property(Boolean, "bubbles")
.property(Boolean, "cancelable")
.property(Boolean, "defaultPrevented")
.property(Boolean, "isTrusted").nonconfigurable
.property(Date, "timeStamp")
.method(null, "preventDefault")
.method(null, "initEvent")
.param(String, "type")
.param(Boolean, "bubbles")
.param(Boolean, "cancelable")
;
dom.CustomEvent = ideal.class
.extends(dom.Event)
.constructor
.param(String, "type")
.param({bubbles: false, cancelable: false, detail: null}, "options")
.method(null, "initCustomEvent")
.param(String, "type")
.param(Boolean, "bubbles")
.param(Boolean, "cancelable")
.param(ideal.any, "details")
;
dom.EventTarget = ideal.interface
.method(null, "addEventListener")
.param(String, "type")
.param(dom.EventListener, "callback").nullable
.param(Boolean, "capture").default(false)
.method(null, "removeEventListener")
.param(String, "type")
.param(dom.EventListener, "callback").nullable
.param(Boolean, "capture").default(false)
.method(Boolean, "dispatchEvent")
.param(dom.Event, "event")
;
// TODO: Deal with this craziness
dom.EventListener = ideal.interface;
dom.Content = ideal.union(dom.Node, String);
dom.ParentNode = ideal.interface
.nonwritable
.property(dom.HTMLCollection, "children")
.property(dom.Element, "firstElementChild").nullable
.property(dom.Element, "lastElementChild").nullable
.property(Number, "childElementCount")
.method(null, "prepend")
.param(dom.Content, "nodes").variadic
;
dom.ChildNode = ideal.interface
.nonwritable
.property(dom.Element, "previousElementSibling").nullable
.property(dom.Element, "nextElementSibling").nullable
.method(null, "before")
.param(dom.Content, "nodes").variadic
.method(null, "after")
.param(dom.Content, "nodes").variadic
.method(null, "replace")
.param(dom.Content, "nodes").variadic
.method(null, "remove")
;
dom.MutationCallback = ideal.callback(null)
.param([dom.MutationCallback], "mutations")
.param(dom.MutationObserver, "observer")
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment