- From: Michael Smith via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 18 Aug 2010 12:42:51 +0000
- To: public-html-commits@w3.org
Update of /sources/public/html5/spec-author-view
In directory hutz:/tmp/cvs-serv8221
Modified Files:
dfn.js patch.anolis style.css
Log Message:
in multipage, only enable dfn pop-ups after user actually clicks a dfn the first time
Index: patch.anolis
===================================================================
RCS file: /sources/public/html5/spec-author-view/patch.anolis,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- patch.anolis 17 Aug 2010 09:52:48 -0000 1.3
+++ patch.anolis 18 Aug 2010 12:42:49 -0000 1.4
@@ -1,6 +1,6 @@
diff -r 16550726fd0d anolis
--- a/anolis Sun Aug 30 16:53:19 2009 -0500
-+++ anolis/anolis Tue Aug 17 18:29:31 2010 +0900
++++ b/anolis Wed Aug 18 21:40:56 2010 +0900
@@ -70,10 +70,10 @@
def getOptParser():
@@ -16,7 +16,7 @@
diff -r 16550726fd0d anolislib/processes/filter.py
--- a/anolislib/processes/filter.py Sun Aug 30 16:53:19 2009 -0500
-+++ anolis/anolislib/processes/filter.py Tue Aug 17 18:29:31 2010 +0900
++++ b/anolislib/processes/filter.py Wed Aug 18 21:40:56 2010 +0900
@@ -5,23 +5,4 @@
return
selector = cssselect.CSSSelector(kwargs["filter"])
@@ -44,8 +44,8 @@
+ element.drop_tree()
diff -r 16550726fd0d anolislib/processes/terms.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
-+++ anolis/anolislib/processes/terms.py Tue Aug 17 18:29:31 2010 +0900
-@@ -0,0 +1,328 @@
++++ b/anolislib/processes/terms.py Wed Aug 18 21:40:56 2010 +0900
+@@ -0,0 +1,330 @@
+# coding=UTF-8
+# Copyright (c) 2010 Michael(tm) Smith
+#
@@ -80,7 +80,7 @@
+ terms = None
+
+ def __init__(self, ElementTree, **kwargs):
-+ self.terms = etree.Element(u"div",{u"class": "index-of-terms"})
++ self.terms = etree.Element(u"div",{u"class": "index-of-terms",u"id": "index-of-terms_contents"})
+ self.buildTerms(ElementTree, **kwargs)
+ self.addTerms(ElementTree, **kwargs)
+
@@ -297,24 +297,26 @@
+ # attribute; we don't want to duplicate the id, so drop it
+ if "id" in headingLink.attrib:
+ del headingLink.attrib["id"]
-+ # some headings may contain descendants that are <a> links,
-+ # and/or that have id attributeds
-+ embeddedLinks = headingLink.xpath(".//*[@href or @id]")
++ # some headings may contain descendants that are <a> links or
++ # <dfn>s, and/or that have id attributeds
++ embeddedLinks = headingLink.xpath(".//*[self::dfn or @href or @id]")
+ # we have taken a copy of what was a heading and transformed it
+ # into a hyperlink, and because it is a hyperlink, we now do not
-+ # want it to itself contain descendant links; so, we un-linkify
-+ # any descendant elements that have @href attributes by turning
-+ # them into @href-less <span>s
++ # want it to itself contain descendant <a> links, nor any <dfn>s,
++ # so we transform those descendants into <span>s
+ for descendant in embeddedLinks:
-+ if "href" in descendant.attrib:
-+ del descendant.attrib["href"]
-+ descendant.tag = "span"
-+ # this descendant might be an <a> element that we added an
-+ # id attribute to earlier and/or may be a <dfn> that already
-+ # had an id attribute; but we don't want to duplicate the id
-+ # attributes here, so drop any id attribute we find
-+ if "id" in descendant.attrib:
-+ del descendant.attrib["id"]
++ if descendant.tag == "a" or descendant.tag == "dfn":
++ descendant.tag = "span"
++ # we need to remove any @href attributes left over in any
++ # descendants that we were <a> links
++ if "href" in descendant.attrib:
++ del descendant.attrib["href"]
++ # this descendant might be an <a> element that we added an
++ # id attribute to earlier and/or some other element with an ia
++ # attribute ; but we don't want to duplicate the id attributes
++ # here, so drop any id attribute we find
++ if "id" in descendant.attrib:
++ del descendant.attrib["id"]
+ return headingLink
+ elif node.getprevious() == None:
+ node = node.getparent()
Index: style.css
===================================================================
RCS file: /sources/public/html5/spec-author-view/style.css,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- style.css 17 Aug 2010 20:01:26 -0000 1.7
+++ style.css 18 Aug 2010 12:42:49 -0000 1.8
@@ -73,6 +73,9 @@
.index-entry ul {
margin-bottom: 0px;
}
+dfn {
+ cursor: pointer;
+}
.dfnPanel p {
margin-bottom: 3px;
}
@@ -86,3 +89,6 @@
pre .dfnPanel {
white-space: normal;
}
+html.chapter #index-filecontents {
+ display: none;
+}
Index: dfn.js
===================================================================
RCS file: /sources/public/html5/spec-author-view/dfn.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dfn.js 17 Aug 2010 20:01:26 -0000 1.1
+++ dfn.js 18 Aug 2010 12:42:49 -0000 1.2
@@ -1,30 +1,37 @@
-// dfn.js - makes <dfn> elements link back to all uses of the term.
// No copyright is asserted on this file.
-var dfnLinks;
+var dfnEnabled = false;
var dfnLinksFile = 'index-of-terms.html';
-function initDfn() {
- dfnLinks = document.implementation.createDocument(null, 'html', null);
- if (document.documentElement.className.indexOf("split") != -1) {
- var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
- request.onreadystatechange = function () {
- if (request.readyState == 4) {
- fileContents = request.responseText;
- dfnLinks.innerHTML = fileContents;
- }
- };
- try {
- request.open('GET', dfnLinksFile, true);
- request.send(null);
- } catch (e) {
- console.log(e);
- return -1;
+var fileContents = document.createElement('div');
+function initDfn(someNode, somePanelDiv) {
+ node = someNode;
+ panelDiv = somePanelDiv;
+ var loading = document.createElement("i");
+ loading.textContent = "(loading...)";
+ panelDiv.appendChild(loading);
+ var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
+ request.onreadystatechange = function () {
+ if (request.readyState == 4) {
+ fileContents.setAttribute("id","index-filecontents");
+ //fileContents.innerHTML = request.responseText;
+ // the following regex hack is for Gecko, because it seems to otherwise try
+ // to parse parts of <script> and <style> text content from XHR as markup
+ fileContents.innerHTML = request.responseText.replace(/<script(.|\s)*?\/script>/g, '').replace(/<style(.|\s)*?\/style>/g, '');
+ var targetNode = fileContents.querySelector("#"+node.id+"_index");
+ panelDiv.innerHTML = targetNode.innerHTML;
+ panelDiv.removeChild(panelDiv.firstChild);
+ document.body.appendChild(fileContents);
+ document.body.className += " dfnEnabled";
+ dfnEnabled = true;
}
- } else {
- var index = dfnLinks.importNode(document.getElementById("index-of-terms_contents"), true);
- dfnLinks.documentElement.appendChild(index);
+ };
+ try {
+ request.open('GET', dfnLinksFile, true);
+ request.send(null);
+ } catch (e) {
+ console.log(e);
+ return -1;
}
- document.body.className += " dfnEnabled";
}
var dfnPanel;
document.addEventListener('click', dfnShow, false);
@@ -42,10 +49,10 @@
dfnPanel = null;
}
var node = event.target;
- while (node && (node.nodeType != event.target.ELEMENT_NODE || node.tagName != "DFN"))
+ while (node && (node.nodeType != event.target.ELEMENT_NODE || !node.hasAttribute("id")))
node = node.parentNode;
- var panel = document.createElement('div');
- panel.className = 'dfnPanel';
+ var panel = document.createElement('div');
+ panel.className = 'dfnPanel';
if (node) {
var permalinkP = document.createElement('p');
var permalinkA = document.createElement('a');
@@ -54,12 +61,17 @@
permalinkP.appendChild(permalinkA);
panel.appendChild(permalinkP);
var introP = document.createElement('p');
- introP.textContent = "Referenced in:";
panel.appendChild(introP);
panelDiv = document.createElement('div');
- if (node.id && dfnLinks) {
- panelDiv.innerHTML = dfnLinks.getElementById(node.id+"_index").innerHTML;
- panelDiv.removeChild(panelDiv.firstChild);
+ if (node.id) {
+ introP.textContent = "Referenced in:";
+ if (!dfnEnabled) {
+ initDfn(node, panelDiv);
+ } else {
+ var targetNode = document.getElementById(node.id+"_index");
+ panelDiv.innerHTML = targetNode.innerHTML;
+ panelDiv.removeChild(panelDiv.firstChild);
+ }
panel.appendChild(panelDiv);
} else {
return -1;
@@ -68,4 +80,6 @@
dfnPanel = panel;
}
}
-initDfn();
+if (document.documentElement.className.indexOf("split") == -1) {
+ dfnEnabled = true;
+}
Received on Wednesday, 18 August 2010 12:42:52 UTC