Add cross-linking to external specs in editor's draft.
authortravil
Thu, 03 Apr 2014 12:16:31 -0700
changeset 54 2d082ea2c1ab
parent 53 619b91c88dc8
child 55 49c41bbec2b4
Add cross-linking to external specs in editor's draft.
index.html
--- a/index.html	Thu Apr 03 11:49:13 2014 -0700
+++ b/index.html	Thu Apr 03 12:16:31 2014 -0700
@@ -1553,5 +1553,23 @@
     [[HTML5]] and his useful comments.
 </section>
 
+   <script>
+      try {
+        var urlMap = { 
+            "DOM4": "http://www.w3.org/TR/dom/#",
+            "HTML5": "http://www.w3.org/TR/html5/single-page.html#",
+        };
+        [].forEach.call(document.querySelectorAll("[class=externalDFN]"), function (el) {
+            var key = el.getAttribute("data-spec");
+            if (!key) throw Error("Missed a 'data-spec' attribute on an class='externalDFN' reference for title='" + el.title + "'");
+            if (typeof urlMap[key] == "undefined") throw Error("Unknown 'data-spec' attribute value '" + key + "'");
+            var link = el.title;
+            if (link == "") throw Error("title value not provided on external reference for 'data-spec' attribute value '" + key + "'");
+            if (el.localName != "a") throw Error("Reference used on a non-anchor element: '" + el.localName + "'");
+            el.removeAttribute("data-spec");
+            el.href = urlMap[key] + link;
+        });
+      } catch (ex) { alert(ex); }
+   </script>
 </body>
 </html>
\ No newline at end of file