Implement Element.className

This commit is contained in:
Bruno de Oliveira Abinader 2014-03-13 13:48:24 -04:00
parent 3933d17262
commit 6274ecba07
6 changed files with 50 additions and 14 deletions

View file

@ -52,6 +52,7 @@ DOMInterfaces = {
'Element': { 'Element': {
'needsAbstract': [ 'needsAbstract': [
'attributes', 'attributes',
'className',
'getBoundingClientRect', 'getBoundingClientRect',
'getClientRects', 'getClientRects',
'getElementsByClassName', 'getElementsByClassName',

View file

@ -430,6 +430,16 @@ impl Element {
self.set_string_attribute(abstract_self, "id", id); self.set_string_attribute(abstract_self, "id", id);
} }
// http://dom.spec.whatwg.org/#dom-element-classname
pub fn ClassName(&self, _abstract_self: &JS<Element>) -> DOMString {
self.get_string_attribute("class")
}
// http://dom.spec.whatwg.org/#dom-element-classname
pub fn SetClassName(&mut self, abstract_self: &JS<Element>, class: DOMString) {
self.set_string_attribute(abstract_self, "class", class);
}
// http://dom.spec.whatwg.org/#dom-element-attributes // http://dom.spec.whatwg.org/#dom-element-attributes
pub fn Attributes(&mut self, abstract_self: &JS<Element>) -> JS<AttrList> { pub fn Attributes(&mut self, abstract_self: &JS<Element>) -> JS<AttrList> {
match self.attr_list { match self.attr_list {

View file

@ -140,13 +140,6 @@ impl HTMLElement {
Ok(()) Ok(())
} }
pub fn ClassName(&self) -> DOMString {
~""
}
pub fn SetClassName(&self, _class: DOMString) {
}
pub fn GetOffsetParent(&self) -> Option<JS<Element>> { pub fn GetOffsetParent(&self) -> Option<JS<Element>> {
None None
} }

View file

@ -28,10 +28,8 @@ interface Element : Node {
[Pure] [Pure]
attribute DOMString id; attribute DOMString id;
/* [Pure]
FIXME Bug 810677 Move className from HTMLElement to Element
attribute DOMString className; attribute DOMString className;
*/
/*[Constant] /*[Constant]
readonly attribute DOMTokenList? classList;*/ readonly attribute DOMTokenList? classList;*/

View file

@ -43,10 +43,6 @@ interface HTMLElement : Element {
readonly attribute boolean isContentEditable; readonly attribute boolean isContentEditable;
[SetterThrows, Pure] [SetterThrows, Pure]
attribute boolean spellcheck; attribute boolean spellcheck;
// Mozilla specific stuff
// FIXME Bug 810677 Move className from HTMLElement to Element
attribute DOMString className;
}; };
// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-htmlelement-interface // http://dev.w3.org/csswg/cssom-view/#extensions-to-the-htmlelement-interface

View file

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
let foo1 = document.getElementById("foo-1");
let foo2 = document.getElementById("foo-2");
foo1.className += " bar";
is(foo1.className, "foo bar");
let foo3 = document.createElement("div");
foo3.id = "foo-3";
foo3.className = "foo";
document.body.appendChild(foo3);
is(foo3, document.getElementById("foo-3"));
let collection = document.getElementsByClassName("foo");
is(collection.length, 2);
is(collection[0].id, foo1.id);
is(collection[1].id, foo3.id);
collection = document.getElementsByClassName("bar");
is(collection.length, 1);
is(collection[0].id, foo1.id);
collection = document.getElementsByClassName("baz");
is(collection.length, 1);
is(collection[0].id, foo2.id);
finish();
</script>
</head>
<body>
<div id="foo-1" class="foo"></div>
<div id="foo-2" class="baz"></div>
</body>
</html>