mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Merge pull request #3095 from ChrisParis/HTMLScriptElement.text
Implement HTMLScriptElement.text; r=Ms2ger
This commit is contained in:
commit
4cc08bde00
2 changed files with 26 additions and 3 deletions
|
@ -4,15 +4,17 @@
|
|||
|
||||
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding;
|
||||
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods;
|
||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use dom::bindings::codegen::InheritTypes::HTMLScriptElementDerived;
|
||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast, TextCast};
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
use dom::document::Document;
|
||||
use dom::element::{HTMLScriptElementTypeId, Element, AttributeHandlers};
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, ElementNodeTypeId};
|
||||
use dom::node::{Node, NodeHelpers, ElementNodeTypeId};
|
||||
use dom::text::Text;
|
||||
use servo_util::str::DOMString;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
|
@ -44,6 +46,26 @@ impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> {
|
|||
let element: &JSRef<Element> = ElementCast::from_ref(self);
|
||||
element.get_url_attribute("src")
|
||||
}
|
||||
|
||||
// http://www.whatwg.org/html/#dom-script-text
|
||||
fn Text(&self) -> DOMString {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let mut content = String::new();
|
||||
for child in node.children() {
|
||||
let text: Option<&JSRef<Text>> = TextCast::to_ref(&child);
|
||||
match text {
|
||||
Some(text) => content.push_str(text.characterdata.data.borrow().as_slice()),
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
content
|
||||
}
|
||||
|
||||
// http://www.whatwg.org/html/#dom-script-text
|
||||
fn SetText(&self, value: DOMString) {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
node.SetTextContent(Some(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl Reflectable for HTMLScriptElement {
|
||||
|
|
|
@ -12,7 +12,8 @@ interface HTMLScriptElement : HTMLElement {
|
|||
// attribute boolean async;
|
||||
// attribute boolean defer;
|
||||
// attribute DOMString crossOrigin;
|
||||
// attribute DOMString text;
|
||||
[Pure]
|
||||
attribute DOMString text;
|
||||
|
||||
// also has obsolete members
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue