MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 544: | Line 544: | ||
Array.prototype.forEach.call(items, function (li) { | Array.prototype.forEach.call(items, function (li) { | ||
var numEl = li.querySelector('.gra-qe-footnote-num'); | var numEl = li.querySelector('.gra-qe-footnote-num'); | ||
var textEl = li.querySelector(' | var quoteEl = li.querySelector('.gra-qe-footnote-quote'); | ||
var textEl = li.querySelector('.gra-qe-footnote-text'); | |||
var num = numEl ? numEl.textContent.trim() : ''; | var num = numEl ? numEl.textContent.trim() : ''; | ||
var text = textEl ? textEl.textContent : li.textContent; | // CHANGED: was showing the NUMBER as the card's primary line and the | ||
html += '<div class="gra-footnote-card" data-gra-id="'+esc( | // footnote's own note text as secondary — nowhere did it show WHICH | ||
// text in the document the footnote actually belongs to, which was | |||
// the whole point of being able to identify one footnote from | |||
// another. Now shows the referenced quote as primary (matching how | |||
// Notes/Bookmarks already identify themselves by quote, not by an | |||
// arbitrary id), with the number as a small prefix and the | |||
// footnote's own note text as secondary. Falls back to the note | |||
// text alone if a footnote predates this change and has no quote | |||
// span at all, rather than showing nothing. | |||
var quote = quoteEl ? quoteEl.textContent : ''; | |||
var text = textEl ? textEl.textContent : (quoteEl ? '' : li.textContent); | |||
var primary = quote ? (num + ' ' + quote) : (num + ' ' + text); | |||
var id = li.getAttribute('data-gra-id') || ''; | |||
html += '<div class="gra-bookmark-card gra-footnote-card" data-gra-id="'+esc(id)+'">' | |||
+ '<span class="gra-icon gra-icon-footnote" aria-hidden="true"></span>' | + '<span class="gra-icon gra-icon-footnote" aria-hidden="true"></span>' | ||
+ '<div class="gra- | + '<div class="gra-bookmark-info">' | ||
+ '<div class="gra- | + '<div class="gra-bookmark-name">'+esc(primary)+'</div>' | ||
+ '<div class="gra- | + (quote ? '<div class="gra-bookmark-quote">'+esc(text)+'</div>' : '') | ||
+ '</div>' | + '</div>' | ||
+ '</div>'; | + '</div>'; | ||
| Line 758: | Line 772: | ||
if (id) deleteBookmark(id); | if (id) deleteBookmark(id); | ||
}); | }); | ||
// | // CHANGED: footnote highlights now carry data-gra-id (see quickedit.js's | ||
// | // redesign — plain highlight span, no href/marker element anymore), so | ||
// | // this can reuse the EXACT same scrollToHighlight(id) helper Notes/ | ||
// Bookmarks already use below, instead of custom href-parsing logic | |||
// that broke every time the marker format changed. | |||
$paneFootnotes.on('click', '.gra-footnote-card', function(){ | $paneFootnotes.on('click', '.gra-footnote-card', function(){ | ||
var id = $(this).attr('data-gra-id'); | var id = $(this).attr('data-gra-id'); | ||
if ( | if (id) { closePanel(); scrollToHighlight(id); } | ||
}); | }); | ||
| Line 794: | Line 802: | ||
}, 100); | }, 100); | ||
}); | }); | ||
// | // CHANGED: was .gra-qe-footnote-ref a with e.preventDefault() (it used | ||
// | // to be a real link). Now a plain highlight span, same as notes/ | ||
// | // bookmarks — no href to prevent, id read directly via data-gra-id, | ||
// | // and the handler is now identical in shape to the two right above it. | ||
$(CONTENT_SEL).on('click', '.gra-qe-footnote- | $(CONTENT_SEL).on('click', '.gra-qe-footnote-highlight', function(){ | ||
var id = $(this).attr('data-gra-id'); | |||
var id = $(this).attr(' | |||
openPanel('footnotes'); | openPanel('footnotes'); | ||
setTimeout(function(){ | setTimeout(function(){ | ||