- From: Michael Smith via cvs-syncmail <cvsmail@w3.org>
- Date: Mon, 09 Aug 2010 01:03:44 +0000
- To: public-html-commits@w3.org
Update of /sources/public/html5/markup/js In directory hutz:/tmp/cvs-serv32670/js Modified Files: dfn.js Log Message: make dfn pop-ups work in multipage version Index: dfn.js =================================================================== RCS file: /sources/public/html5/markup/js/dfn.js,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- dfn.js 8 Aug 2010 09:49:19 -0000 1.8 +++ dfn.js 9 Aug 2010 01:03:42 -0000 1.9 @@ -1,128 +1,51 @@ // dfn.js - makes <dfn> elements link back to all uses of the term. -// Modified from source at: -// http://www.whatwg.org/specs/web-apps/current-work/dfn.js // No copyright is asserted on that file nor on this modified version. -var dfnMapTarget = -1; -var dfnMapDone = 0; -var dfnMap = {}; -document.addEventListener('DOMContentLoaded', function (event) { - var links = []; - dfnMapTarget = document.links.length; - for (var i = 0; i < dfnMapTarget; i += 1) - links[i] = document.links[i]; - var inc = 100; - for (var i = 0; i < dfnMapTarget; i += inc) { - setTimeout(function (j) { - for (var k = j; k < j+inc && k < dfnMapTarget; k += 1) { - if (links[k].href.indexOf('#') >= 0) { - if (links[k].className != "no-backref" && - links[k].parentNode.className != "no-backref") { - var s = links[k].href.substr(links[k].href.indexOf('#') + 1); - if (!(s in dfnMap)) - dfnMap[s] = []; - dfnMap[s].push(links[k]); - } - } - dfnMapDone += 1; +var dfnLinks; +var dfnLinksFile = 'index.xhtml'; +function initDfn() { + if (document.body.className.indexOf("chunk") != -1) { + var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); + request.onreadystatechange = function () { + if (request.readyState == 4) { + dfnLinks = request.responseXML; } - }, 0, i); + }; + request.open('GET', dfnLinksFile, true); + request.send(null); + } else { + dfnLinks = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null); + var index = dfnLinks.importNode(document.getElementById("index"), true); + dfnLinks.documentElement.appendChild(index); } document.body.className += " dfnEnabled"; -}, false); +} var dfnPanel; -var dfnUniqueId = 0; -var dfnTimeout; document.addEventListener('click', dfnShow, false); function dfnShow(event) { - if (dfnTimeout) { - clearTimeout(dfnTimeout); - dfnTimeout = null; - } if (dfnPanel) { dfnPanel.parentNode.removeChild(dfnPanel); dfnPanel = null; } - if (dfnMapDone == dfnMapTarget) { - var node = event.target; - while (node && (node.nodeType != event.target.ELEMENT_NODE || node.tagName != "DFN")) - node = node.parentNode; - if (node) { - var panel = document.createElement('div'); - panel.className = 'dfnPanel'; - if (node.id) { - var permalinkP = document.createElement('p'); - var permalinkA = document.createElement('a'); - permalinkA.href = '#' + node.id; - permalinkA.textContent = '#' + node.id; - permalinkP.appendChild(permalinkA); - panel.appendChild(permalinkP); - } - var p = document.createElement('p'); - panel.appendChild(p); - if (node.id in dfnMap || node.parentNode.id in dfnMap) { - var ul = document.createElement('ul'); - var lastHeader; - var lastLi; - var n; - var sourceLinks = []; - if (node.id in dfnMap) - for (var i = 0; i < dfnMap[node.id].length; i += 1) { - if (dfnMap[node.id][i].textContent != "#") { - sourceLinks.push(dfnMap[node.id][i]); - } - } - if (sourceLinks.length == 0) - p.textContent = 'No references in this file.'; - if (node.parentNode.id in dfnMap) - for (var i = 0; i < dfnMap[node.parentNode.id].length; i += 1) - sourceLinks.push(dfnMap[node.parentNode.id][i]); - for (var i = 0; i < sourceLinks.length; i += 1) { - var link = sourceLinks[i]; - var header = dfnGetCaption(link); - var a = document.createElement('a'); - if (!link.id) - link.id = 'DYNAMICALLY_GENERATED_FRAGMENT_ID_DO_NOT_BOOKMARK-' + dfnUniqueId++; - a.href = '#' + link.id; - if (header != lastHeader) { - lastHeader = header; - n = 1; - var li = document.createElement('li'); - var cloneHeader = header.cloneNode(true); - while (cloneHeader.hasChildNodes()) - a.appendChild(cloneHeader.firstChild); - lastLi = li; - li.appendChild(a); - ul.appendChild(li); - } else { - n += 1; - var span = document.createElement('span'); - span.appendChild(document.createTextNode('[' + n + ']')); - span.className = "index-counter"; - a.appendChild(span); - lastLi.appendChild(document.createTextNode(' ')); - lastLi.appendChild(a); - } - } - panel.appendChild(ul); - } else { - p.textContent = 'No references in this file.'; - } - node.appendChild(panel); - dfnPanel = panel; - } - } else { - dfnTimeout = setTimeout(dfnShow, 250, event); - } -} - -function dfnGetCaption(link) { - var node = link; - while (node && (!node.className || node.className.indexOf("section") == -1)) { + var node = event.target; + while (node && (node.nodeType != event.target.ELEMENT_NODE || node.tagName != "DFN")) node = node.parentNode; - if (node.tagName == "DIV" && (node.className && node.className.indexOf("section") != -1)) { - return node.childNodes[1]; + var panel = document.createElement('div'); + panel.className = 'dfnPanel'; + if (node) { + var permalinkP = document.createElement('p'); + var permalinkA = document.createElement('a'); + permalinkA.href = '#' + node.id; + permalinkA.textContent = '#' + node.id; + permalinkP.appendChild(permalinkA); + panel.appendChild(permalinkP); + panelDiv = document.createElement('div'); + if (node.id) { + panelDiv.innerHTML = dfnLinks.getElementById(node.id+"_index_items").innerHTML; + panel.appendChild(panelDiv); } + node.appendChild(panel); + dfnPanel = panel; } }
Received on Monday, 9 August 2010 01:03:47 UTC