4,351
edits
No edit summary |
No edit summary |
||
Line 1,045: | Line 1,045: | ||
setShowArticleRotationEffect(); | setShowArticleRotationEffect(); | ||
}); | }); | ||
function cacheBust(url) { | |||
return url + (url.indexOf('?') > -1 ? '&' : '?') + '_=' + Date.now(); | |||
} | |||
// Kill any previous print handlers | // Kill any previous print handlers | ||
$(document).off('click.print', '#print-button'); | $(document).off('click.print', '#print-button'); | ||
$(document).on('click.print', '#print-button', function () { | $(document).on('click.print', '#print-button', function () { | ||
var title = window.currentEntryTitle; // e.g. "090" | var title = window.currentEntryTitle; // e.g. "090" | ||
if (!title) { console.warn('[print] no currentEntryTitle'); window.print(); return; } | if (!title) { console.warn('[print] no currentEntryTitle'); window.print(); return; } | ||
var pageUrl = mw.util.getUrl(title); // | var pageUrl = mw.util.getUrl(title); | ||
console.log('[print] fetching page HTML:', | var pageUrlFresh = cacheBust(pageUrl); // ⬅ cache bust | ||
console.log('[print] fetching page HTML:', pageUrlFresh); | |||
$.get( | $.get(pageUrlFresh).done(function (html) { | ||
var $tmp = $('<div>').html(html); | var $tmp = $('<div>').html(html); | ||
var $print = $tmp.find('.print-only').first(); | var $print = $tmp.find('.print-only').first(); | ||
console.log('[print] .print-only found:', $print.length); | console.log('[print] .print-only found:', $print.length); | ||
if (!$print.length) { console.warn('[print] no .print-only found; fallback print'); window.print(); return; } | if (!$print.length) { console.warn('[print] no .print-only found; fallback print'); window.print(); return; } | ||
Line 1,074: | Line 1,077: | ||
var doc = iframe.contentDocument || iframe.contentWindow.document; | var doc = iframe.contentDocument || iframe.contentWindow.document; | ||
var printCssUrl = '/index.php?title=MediaWiki:Print.css&action=raw&ctype=text/css'; | var printCssUrl = '/index.php?title=MediaWiki:Print.css&action=raw&ctype=text/css'; | ||
var printCssFresh = cacheBust(printCssUrl); // ⬅ cache bust | |||
doc.open(); | doc.open(); | ||
Line 1,080: | Line 1,085: | ||
'<!doctype html><html><head><meta charset="utf-8">' + | '<!doctype html><html><head><meta charset="utf-8">' + | ||
'<title>Print</title>' + | '<title>Print</title>' + | ||
'<link rel="stylesheet" href="' + | '<link rel="stylesheet" href="' + printCssFresh + '">' + | ||
'</head><body>' + $print.prop('outerHTML') + '</body></html>' | '</head><body>' + $print.prop('outerHTML') + '</body></html>' | ||
); | ); | ||
Line 1,094: | Line 1,099: | ||
}); | }); | ||
}); | }); | ||