MediaWiki:Gadget-GrAnnotations.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 15: | Line 15: | ||
var currentUserEmail = ''; | var currentUserEmail = ''; | ||
// FIXED: was `new mw.Api()` called directly and synchronously here — | |||
// at this point in MediaWiki:Common.js's own load lifecycle, | |||
// mediawiki.api (the module that provides the REAL mw.Api | |||
// constructor) is not guaranteed to have finished loading yet, and | |||
// calling the constructor before it has throws "mw.Api is not a | |||
// constructor" synchronously. Confirmed directly via the real error | |||
// trace, and confirmed this is pre-existing code, not anything | |||
// introduced by the more recent Ullekha/tab changes. Uncaught here | |||
// (the .catch below only ever handled promise rejections, never a | |||
// synchronous throw from the constructor call itself), this would | |||
// halt the REST of this script's own execution — meaning later code | |||
// in this same file (the tab-building logic) may never run at all on | |||
// whatever page load hits this race. mw.loader.using() guarantees the | |||
// module is actually ready before mw.Api is ever touched, regardless | |||
// of load timing. Verified the exact failure mode and the fix | |||
// directly before applying here. | |||
if ( currentUser && window.mw ) { | if ( currentUser && window.mw ) { | ||
new mw.Api().get({ action: 'query', meta: 'userinfo', uiprop: 'email', formatversion: 2 }) | mw.loader.using( 'mediawiki.api' ).then( function () { | ||
return new mw.Api().get({ action: 'query', meta: 'userinfo', uiprop: 'email', formatversion: 2 }); | |||
} ).then( function (data) { | |||
var info = data && data.query && data.query.userinfo; | |||
if ( info && info.email ) currentUserEmail = info.email; | |||
} ).catch( function () {} ); | |||
} | } | ||
| Line 60: | Line 77: | ||
var $fbComposer, $fbIssueType, $fbText, $fbEmail, $fbSubmit, $fbQuote; | var $fbComposer, $fbIssueType, $fbText, $fbEmail, $fbSubmit, $fbQuote; | ||
// CHANGED: added $tabFootnotes / $paneFootnotes alongside the existing | // CHANGED: added $tabFootnotes / $paneFootnotes alongside the existing | ||
// Notes/Bookmarks tab+pane refs, for the Footnotes tab. | // Notes/Bookmarks tab+pane refs, for the Footnotes tab. REMOVED: the | ||
// $tabSandarbha / $paneSandarbha, | // earlier $tabSandarbha/$paneSandarbha — that feature was replaced by | ||
var $tabNotes, $tabBookmarks, $tabFootnotes | // the real Ullekha citation-index mechanism (see quickedit.js), which | ||
// works entirely through common.js's own site-wide logic and needs no | |||
// panel integration here at all. | |||
var $tabNotes, $tabBookmarks, $tabFootnotes, $paneNotes, $paneBookmarks, $paneFootnotes; | |||
function buildDom() { | function buildDom() { | ||
| Line 169: | Line 189: | ||
' <button class="gra-tab" id="gra-tab-footnotes">', | ' <button class="gra-tab" id="gra-tab-footnotes">', | ||
' <span class="gra-icon gra-icon-footnote" aria-hidden="true"></span> Footnotes', | ' <span class="gra-icon gra-icon-footnote" aria-hidden="true"></span> Footnotes', | ||
' </button>', | ' </button>', | ||
' </div>', | ' </div>', | ||
| Line 178: | Line 195: | ||
' <div class="gra-pane" id="gra-pane-bookmarks"></div>', | ' <div class="gra-pane" id="gra-pane-bookmarks"></div>', | ||
' <div class="gra-pane" id="gra-pane-footnotes"></div>', | ' <div class="gra-pane" id="gra-pane-footnotes"></div>', | ||
' </div>', | ' </div>', | ||
'</div>', | '</div>', | ||
| Line 202: | Line 218: | ||
$tabBookmarks = $('#gra-tab-bookmarks'); | $tabBookmarks = $('#gra-tab-bookmarks'); | ||
$tabFootnotes = $('#gra-tab-footnotes'); | $tabFootnotes = $('#gra-tab-footnotes'); | ||
$paneNotes = $('#gra-pane-notes'); | $paneNotes = $('#gra-pane-notes'); | ||
$paneBookmarks= $('#gra-pane-bookmarks'); | $paneBookmarks= $('#gra-pane-bookmarks'); | ||
$paneFootnotes= $('#gra-pane-footnotes'); | $paneFootnotes= $('#gra-pane-footnotes'); | ||
$ntInput = $('#gra-nt-input'); | $ntInput = $('#gra-nt-input'); | ||
$ntSubmit = $('#gra-nt-submit'); | $ntSubmit = $('#gra-nt-submit'); | ||
| Line 471: | Line 485: | ||
$tabBookmarks.toggleClass('gra-tab-active', tab==='bookmarks'); | $tabBookmarks.toggleClass('gra-tab-active', tab==='bookmarks'); | ||
$tabFootnotes.toggleClass('gra-tab-active', tab==='footnotes'); | $tabFootnotes.toggleClass('gra-tab-active', tab==='footnotes'); | ||
$paneNotes.toggleClass('gra-pane-active', tab==='notes'); | $paneNotes.toggleClass('gra-pane-active', tab==='notes'); | ||
$paneBookmarks.toggleClass('gra-pane-active', tab==='bookmarks'); | $paneBookmarks.toggleClass('gra-pane-active', tab==='bookmarks'); | ||
$paneFootnotes.toggleClass('gra-pane-active', tab==='footnotes'); | $paneFootnotes.toggleClass('gra-pane-active', tab==='footnotes'); | ||
if (tab==='notes') renderNoteCards(); | if (tab==='notes') renderNoteCards(); | ||
else if (tab==='bookmarks') renderBookmarkCards(); | else if (tab==='bookmarks') renderBookmarkCards(); | ||
else | else renderFootnoteCards(); | ||
} | } | ||
| Line 580: | Line 591: | ||
}); | }); | ||
$paneFootnotes.html(html); | $paneFootnotes.html(html); | ||
} | } | ||
| Line 796: | Line 772: | ||
// NEW: third tab. | // NEW: third tab. | ||
$tabFootnotes.on('click', function(){ switchTab('footnotes'); }); | $tabFootnotes.on('click', function(){ switchTab('footnotes'); }); | ||
$paneNotes.on('click', '.gra-note-card', function(e){ | $paneNotes.on('click', '.gra-note-card', function(e){ | ||
| Line 825: | Line 799: | ||
// that broke every time the marker format changed. | // 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 (id) { closePanel(); scrollToHighlight(id); } | if (id) { closePanel(); scrollToHighlight(id); } | ||
| Line 864: | Line 832: | ||
setTimeout(function(){ | setTimeout(function(){ | ||
var $card = $paneFootnotes.find('[data-gra-id="'+id+'"]'); | var $card = $paneFootnotes.find('[data-gra-id="'+id+'"]'); | ||
if ($card.length) { | if ($card.length) { | ||
$card.addClass('gra-card-active'); | $card.addClass('gra-card-active'); | ||