4,656
edits
No edit summary |
No edit summary |
||
| Line 1,316: | Line 1,316: | ||
function hidePrintSelectionOptions() { | function hidePrintSelectionOptions() { | ||
jQuery("#print-selection-options").hide(); | |||
} | |||
function swHandleBatchPrint(borderPref) { | |||
swPrintPreloadFont(); | |||
var $cards = jQuery(".card:visible").not(".event"); | |||
if (!$cards.length) { | |||
alert("No entries to print."); | |||
return; | |||
} | |||
var requests = []; | |||
$cards.each(function () { | |||
var $card = jQuery(this); | |||
var title = $card.data("page"); | |||
if (!title) return; | |||
var url = | |||
window.mw && mw.util && mw.util.getUrl | |||
? swPrintCacheBust(mw.util.getUrl(title)) | |||
: swPrintCacheBust("/wiki/" + String(title)); | |||
requests.push( | |||
jQuery.get(url).then(function (html) { | |||
var $tmp = jQuery("<div>").html(html); | |||
var $print = $tmp.find(".print-only").first(); | |||
return $print.length ? $print.prop("outerHTML") : ""; | |||
}) | |||
); | |||
}); | |||
Promise.all(requests) | |||
.then(function (results) { | |||
var combinedHtml = results.join(""); | |||
if (!combinedHtml.trim()) { | |||
alert("Could not generate print content."); | |||
return; | |||
} | |||
swBuildIframeAndPrint(combinedHtml, borderPref); | |||
}) | |||
.catch(function () { | |||
alert("There was a problem preparing the print selection."); | |||
}); | |||
} | } | ||
| Line 1,799: | Line 1,847: | ||
jQuery("#print-selection-options").toggle(); | jQuery("#print-selection-options").toggle(); | ||
}); | }); | ||
// run filtered batch print | |||
jQuery(document).on( | |||
"click", | |||
".print-selection-border, .print-selection-no-border", | |||
function (e) { | |||
e.preventDefault(); | |||
var borderPref = jQuery(this).hasClass("print-selection-no-border") | |||
? "without" | |||
: "with"; | |||
hidePrintSelectionOptions(); | |||
swHandleBatchPrint(borderPref); | |||
} | |||
); | |||
/* ---------- /Softwear PRINT ---------- */ | /* ---------- /Softwear PRINT ---------- */ | ||