Skip to content

Commit ebde535

Browse files
committed
Sync common.js.
(cherry picked from commit 1754f26)
1 parent 4af65b6 commit ebde535

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

common/common.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,29 @@ require(["core/pubsubhub"], (respecEvents) => {
145145
require(["core/pubsubhub"], (respecEvents) => {
146146
"use strict";
147147
respecEvents.sub('beforesave', (documentElement) => {
148-
$("a[href]", documentElement).each((index) => {
149-
// Don't rewrite these.
150-
if ($(this, documentElement).closest('dd').prev().text().match(/Latest editor|Test suite|Implementation report/)) return;
151-
if ($(this, documentElement).closest('section.preserve').length > 0) return;
148+
for (const anchor of document.querySelectorAll("a[href]")) {
149+
const dd = anchor.closest('dd');
150+
151+
// Don't replace specific anchors
152+
if (dd) {
153+
const dt = dd.previousElementSibling;
154+
if (dt.textContent.match(/Latest editor|Test suite|Implementation report/)) return;
155+
}
156+
if (anchor.closest('section.preserve')) return;
157+
158+
if (anchor.href === undefined) return;
152159

153-
const href = $(this, documentElement).attr("href");
154160
for (const toReplace in jsonld.conversions) {
155-
if (href.indexOf(toReplace) !== -1) {
161+
if (anchor.href.indexOf(toReplace) !== -1) {
156162
const replacement = jsonld.conversions[toReplace];
157-
const newHref = href.replace(toReplace, replacement);
158-
$(this, documentElement).attr("href", newHref);
159-
if( $(this, documentElement).text().indexOf(toReplace) !== -1 ) {
160-
$(this, documentElement).text($(this, documentElement).text().replace(toReplace, replacement));
163+
const newHref = anchor.href.replace(toReplace, replacement);
164+
anchor.setAttribute('href', newHref);
165+
if (anchor.textContent().indexOf(toReplace) !== -1) {
166+
anchor.innerText = anchor.textContent().replace(toReplace, replacement);
161167
}
162168
}
163169
}
164-
});
170+
}
165171
});
166172
});
167173

0 commit comments

Comments
 (0)