- From: Michael Smith via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 04 Mar 2010 17:25:08 +0000
- To: public-html-commits@w3.org
Update of /sources/public/html5/markup/images/js In directory hutz:/tmp/cvs-serv14032/js Added Files: dfn.js Log Message: new --- NEW FILE: dfn.js --- // 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; } }, 0, i); } 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'; var p = document.createElement('p'); panel.appendChild(p); if (node.id in dfnMap || node.parentNode.id in dfnMap) { p.textContent = 'Referenced in:'; 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; a.appendChild(document.createTextNode('(' + n + ')')); 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.getAttribute('class')!= "section") { node = node.parentNode; if (node.tagName == "DIV" && node.getAttribute('class') == "section") { return node.childNodes[1]; } } }
Received on Thursday, 4 March 2010 17:25:12 UTC