4,396
edits
No edit summary |
No edit summary |
||
Line 774: | Line 774: | ||
if (!pageTitle) return; | if (!pageTitle) return; | ||
var api = mw.util.wikiScript('api'); | |||
// remove any previous print block so we don't duplicate | // remove any previous print block so we don't duplicate | ||
$('#show-article .print-only').remove(); | $('#show-article .print-only').remove(); | ||
Line 782: | Line 783: | ||
page: pageTitle, | page: pageTitle, | ||
prop: 'text', | prop: 'text', | ||
format: 'json' | format: 'json' | ||
}).done(function (res) { | }).done(function (res) { | ||
var html = res && res.parse && res.parse.text && res.parse.text['*']; | |||
if (!html) return; | if (!html) return; | ||
var $tmp = $('<div>').html(html); | |||
var $printBlock = $tmp.find('.print-only').first(); | |||
if ($printBlock.length) { | if ($printBlock.length) { | ||
$('#show-article').append($printBlock); | $('#show-article').append($printBlock); | ||
} | } | ||
}); | }); | ||
} | } | ||
function openModal(cardElement, event) { | function openModal(cardElement, event) { | ||
event.stopPropagation(); | event.stopPropagation(); | ||
// ⬇️ NEW: detect the entry page title from the clicked card and fetch print layout | // ⬇️ NEW: detect the entry page title from the clicked card and fetch print layout | ||
var pageTitle = $(cardElement).data('page'); // set by ShowEntries | var pageTitle = $(cardElement).data('page'); // set by ShowEntries | ||
Line 1,085: | Line 1,081: | ||
$('#print-button').on('click', function () { | $('#print-button').on('click', function () { | ||
$('body').addClass('print-entry-only'); | $('body').addClass('print-entry-only'); | ||
requestAnimationFrame(() | requestAnimationFrame(function () { | ||
requestAnimationFrame(() | requestAnimationFrame(function () { | ||
window.print(); | |||
}); | |||
}); | }); | ||
}); | }); |