Переглянути джерело

LibWeb: Added HTMLLinkElement.as

Hexeption 1 рік тому
батько
коміт
2f4668edce

+ 21 - 0
Base/res/html/misc/linkas.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Link AS test</title>
+</head>
+<body>
+<script>
+    var link = document.createElement('link');
+    link.rel = 'stylesheet';
+    link.href = 'https://fonts.googleapis.com/css?family=Roboto:400,700';
+    link.as = 'style';
+
+    console.log("Link.as: " + link.as); // should be 'style'
+
+    link.as = 'uwu';
+
+    console.log("Link.as: " + link.as); // should be ''
+</script>
+</body>
+</html>

+ 1 - 0
Userland/Libraries/LibWeb/HTML/AttributeNames.h

@@ -25,6 +25,7 @@ namespace AttributeNames {
     __ENUMERATE_HTML_ATTRIBUTE(alt)                        \
     __ENUMERATE_HTML_ATTRIBUTE(archive)                    \
     __ENUMERATE_HTML_ATTRIBUTE(async)                      \
+    __ENUMERATE_HTML_ATTRIBUTE(as)                         \
     __ENUMERATE_HTML_ATTRIBUTE(autocomplete)               \
     __ENUMERATE_HTML_ATTRIBUTE(autofocus)                  \
     __ENUMERATE_HTML_ATTRIBUTE(autoplay)                   \

+ 23 - 0
Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp

@@ -90,6 +90,29 @@ void HTMLLinkElement::inserted()
     }
 }
 
+// https://html.spec.whatwg.org/multipage/semantics.html#dom-link-as
+String HTMLLinkElement::as() const
+{
+    String attribute_value = get_attribute_value(HTML::AttributeNames::as);
+
+    if (attribute_value.equals_ignoring_ascii_case("fetch"sv) ||
+        attribute_value.equals_ignoring_ascii_case("image"sv) ||
+        attribute_value.equals_ignoring_ascii_case("script"sv) ||
+        attribute_value.equals_ignoring_ascii_case("style"sv) ||
+        attribute_value.equals_ignoring_ascii_case("video"sv) ||
+        attribute_value.equals_ignoring_ascii_case("audio"sv) ||
+        attribute_value.equals_ignoring_ascii_case("track"sv) ||
+        attribute_value.equals_ignoring_ascii_case("font"sv))
+        return attribute_value.to_lowercase().release_value();
+
+    return String {};
+}
+
+WebIDL::ExceptionOr<void> HTMLLinkElement::set_as(String const& value)
+{
+    return set_attribute(HTML::AttributeNames::as, move(value));
+}
+
 // https://html.spec.whatwg.org/multipage/semantics.html#dom-link-rellist
 JS::NonnullGCPtr<DOM::DOMTokenList> HTMLLinkElement::rel_list()
 {

+ 2 - 0
Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h

@@ -33,6 +33,8 @@ public:
     String rel() const { return get_attribute_value(HTML::AttributeNames::rel); }
     String type() const { return get_attribute_value(HTML::AttributeNames::type); }
     String href() const { return get_attribute_value(HTML::AttributeNames::href); }
+    String as() const;
+    WebIDL::ExceptionOr<void> set_as(String const&);
 
     JS::NonnullGCPtr<DOM::DOMTokenList> rel_list();
 

+ 1 - 1
Userland/Libraries/LibWeb/HTML/HTMLLinkElement.idl

@@ -12,7 +12,7 @@ interface HTMLLinkElement : HTMLElement {
     [CEReactions, Reflect] attribute DOMString href;
     [CEReactions, Reflect=crossorigin, Enumerated=CORSSettingsAttribute] attribute DOMString? crossOrigin;
     [CEReactions, Reflect] attribute DOMString rel;
-    [FIXME, CEReactions] attribute DOMString as;
+    [CEReactions] attribute DOMString as;
     [SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
     [CEReactions, Reflect] attribute DOMString media;
     [CEReactions, Reflect] attribute DOMString integrity;