|
1 |
| -/* globals omitTerms, respecConfig, $, require */ |
| 1 | +/* globals require */ |
2 | 2 | /* JSON-LD Working Group common spec JavaScript */
|
3 |
| -// We should be able to remove terms that are not actually |
4 |
| -// referenced from the common definitions |
5 |
| -// |
6 |
| -// Add class "preserve" to a definition to ensure it is not removed. |
7 |
| -// |
8 |
| -// the termlist is in a block of class "termlist". |
9 |
| -const termNames = [] ; |
10 |
| -const termsReferencedByTerms = [] ; |
11 |
| - |
12 |
| -function restrictReferences(utils, content) { |
13 |
| - const base = document.createElement("div"); |
14 |
| - base.innerHTML = content; |
15 |
| - |
16 |
| - // New new logic: |
17 |
| - // |
18 |
| - // 1. build a list of all term-internal references |
19 |
| - // 2. When ready to process, for each reference INTO the terms, |
20 |
| - // remove any terms they reference from the termNames array too. |
21 |
| - const noPreserve = base.querySelectorAll("dfn:not(.preserve)"); |
22 |
| - for (const item of noPreserve) { |
23 |
| - const $t = $(item); |
24 |
| - const titles = $t.getDfnTitles(); |
25 |
| - const n = $t.makeID("dfn", titles[0]); |
26 |
| - if (n) { |
27 |
| - termNames[n] = $t.parent(); |
28 |
| - } |
29 |
| - } |
30 |
| - |
31 |
| - const $container = $(".termlist", base) ; |
32 |
| - const containerID = $container.makeID("", "terms") ; |
33 |
| - return (base.innerHTML); |
34 |
| -} |
35 | 3 |
|
| 4 | +/* |
| 5 | +* Implement tabbed examples. |
| 6 | +*/ |
36 | 7 | require(["core/pubsubhub"], (respecEvents) => {
|
37 | 8 | "use strict";
|
38 | 9 |
|
39 |
| - respecEvents.sub('end', (message) => { |
| 10 | + respecEvents.sub('end-all', (documentElement) => { |
40 | 11 | // remove data-cite on where the citation is to ourselves.
|
41 |
| - const selfDfns = document.querySelectorAll("dfn[data-cite^='" + respecConfig.shortName.toUpperCase() + "#']"); |
| 12 | + const selfDfns = document.querySelectorAll("dfn[data-cite^='__SPEC__#']"); |
42 | 13 | for (const dfn of selfDfns) {
|
| 14 | + const anchor = dfn.querySelector('a'); |
| 15 | + if (anchor) { |
| 16 | + const anchorContent = anchor.textContent; |
| 17 | + dfn.removeChild(anchor); |
| 18 | + dfn.textContent = anchorContent; |
| 19 | + } |
43 | 20 | delete dfn.dataset.cite;
|
44 | 21 | }
|
45 | 22 |
|
46 | 23 | // Update data-cite references to ourselves.
|
47 |
| - const selfRefs = document.querySelectorAll("a[data-cite^='" + respecConfig.shortName.toUpperCase() + "#']"); |
| 24 | + const selfRefs = document.querySelectorAll("a[data-cite^='__SPEC__#']"); |
48 | 25 | for (const anchor of selfRefs) {
|
49 | 26 | anchor.href= anchor.dataset.cite.replace(/^.*#/,"#");
|
50 | 27 | delete anchor.dataset.cite;
|
51 | 28 | }
|
52 |
| - }); |
53 | 29 |
|
54 |
| - // add a handler to come in after all the definitions are resolved |
55 |
| - // |
56 |
| - // New logic: If the reference is within a 'dl' element of |
57 |
| - // class 'termlist', and if the target of that reference is |
58 |
| - // also within a 'dl' element of class 'termlist', then |
59 |
| - // consider it an internal reference and ignore it. |
60 |
| - respecEvents.sub('end', (message) => { |
61 |
| - if (message === 'core/link-to-dfn') { |
62 |
| - // all definitions are linked; find any internal references |
63 |
| - const internalTerms = document.querySelectorAll(".termlist a.internalDFN"); |
64 |
| - for (const item of internalTerms) { |
65 |
| - const idref = item.getAttribute('href').replace(/^#/,"") ; |
66 |
| - if (termNames[idref]) { |
67 |
| - // this is a reference to another term |
68 |
| - // what is the idref of THIS term? |
69 |
| - const def = item.closest('dd'); |
70 |
| - if (def) { |
71 |
| - const tid = def.previousElementSibling |
72 |
| - .querySelector('dfn') |
73 |
| - .getAttribute('id'); |
74 |
| - if (tid) { |
75 |
| - if (termsReferencedByTerms[tid] === undefined) termsReferencedByTerms[tid] = []; |
76 |
| - termsReferencedByTerms[tid].push(idref); |
77 |
| - } |
78 |
| - } |
79 |
| - } |
80 |
| - } |
81 |
| - |
82 |
| - // clearRefs is recursive. Walk down the tree of |
83 |
| - // references to ensure that all references are resolved. |
84 |
| - const clearRefs = (theTerm) => { |
85 |
| - if (termsReferencedByTerms[theTerm] ) { |
86 |
| - for (const item of termsReferencedByTerms[theTerm]) { |
87 |
| - if (termNames[item]) { |
88 |
| - delete termNames[item]; |
89 |
| - clearRefs(item); |
90 |
| - } |
91 |
| - } |
92 |
| - }; |
93 |
| - // make sure this term doesn't get removed |
94 |
| - if (termNames[theTerm]) { |
95 |
| - delete termNames[theTerm]; |
96 |
| - } |
97 |
| - }; |
98 |
| - |
99 |
| - // now termsReferencedByTerms has ALL terms that |
100 |
| - // reference other terms, and a list of the |
101 |
| - // terms that they reference |
102 |
| - const internalRefs = document.querySelectorAll("a[data-link-type='dfn']"); |
103 |
| - for (const item of internalRefs) { |
104 |
| - const idref = item.getAttribute('href').replace(/^.*#/,"") ; |
105 |
| - // if the item is outside the term list |
106 |
| - if (!item.closest('dl.termlist')) { |
107 |
| - clearRefs(idref); |
108 |
| - } |
109 |
| - } |
110 |
| - |
111 |
| - // delete any terms that were not referenced. |
112 |
| - for (const term in termNames) { |
113 |
| - const $p = $("#"+term); |
114 |
| - // Remove term definitions inside a dt, where data-cite does not start with shortname |
115 |
| - if ($p === undefined) { continue; } |
116 |
| - if (!$p.parent().is("dt")) { continue; } |
117 |
| - if (($p.data("cite") || "").toLowerCase().startsWith(respecConfig.shortName)) { continue; } |
118 |
| - |
119 |
| - const $dt = $p.parent(); |
120 |
| - const $dd = $dt.next(); |
121 |
| - |
122 |
| - // If the associated dd contains a dfn which is _not_ in termNames, warn |
123 |
| - if ($dd.children("dfn").length > 0) { |
124 |
| - console.log(term + " definition contains definitions " + $dd.children("dfn").attr("id")) |
125 |
| - } |
126 |
| - console.log("drop term " + term); |
127 |
| - const tList = $p.getDfnTitles(); |
128 |
| - $dd.remove(); // remove dd |
129 |
| - $dt.remove(); // remove dt |
130 |
| - // FIXME: this depended on an undocumented internal structure |
131 |
| - //for (const item of tList) { |
132 |
| - // if (respecConfig.definitionMap[item]) { |
133 |
| - // delete respecConfig.definitionMap[item]; |
134 |
| - // } |
135 |
| - //} |
136 |
| - } |
137 |
| - } |
138 |
| - }); |
139 |
| -}); |
140 |
| - |
141 |
| -/* |
142 |
| -* Implement tabbed examples. |
143 |
| -*/ |
144 |
| -require(["core/pubsubhub"], (respecEvents) => { |
145 |
| - "use strict"; |
146 |
| - respecEvents.sub('end-all', (documentElement) => { |
147 | 30 | // Add playground links
|
148 | 31 | for (const link of document.querySelectorAll("a.playground")) {
|
149 | 32 | let pre;
|
|
0 commit comments