4,656
edits
No edit summary |
No edit summary |
||
| (16 intermediate revisions by the same user not shown) | |||
| Line 1,360: | Line 1,360: | ||
} | } | ||
swBuildIframeAndPrint(combinedHtml, borderPref); | swBuildIframeAndPrint( | ||
combinedHtml, | |||
borderPref, | |||
null, | |||
"filtered.softwear.directory" | |||
); | |||
}) | }) | ||
.catch(function () { | .catch(function () { | ||
| Line 1,380: | Line 1,385: | ||
/* core: build iframe and print */ | /* core: build iframe and print */ | ||
function swBuildIframeAndPrint(printHtml, borderPref, $btn) { | function swBuildIframeAndPrint(printHtml, borderPref, $btn, filenameOverride) { | ||
// iframe | // iframe | ||
var iframe = document.createElement("iframe"); | var iframe = document.createElement("iframe"); | ||
| Line 1,428: | Line 1,433: | ||
// inject HTML | // inject HTML | ||
doc.body.innerHTML = printHtml; | doc.body.innerHTML = printHtml; | ||
(function () { | |||
var pres = doc.querySelectorAll(".link-pdf pre"); | |||
Array.prototype.forEach.call(pres, function (pre) { | |||
// move its children out | |||
while (pre.firstChild) { | |||
pre.parentNode.insertBefore(pre.firstChild, pre); | |||
} | |||
// remove the <pre> | |||
pre.parentNode.removeChild(pre); | |||
}); | |||
})(); | |||
// sanitize: remove inner .print-no-border if user chose WITH border | // sanitize: remove inner .print-no-border if user chose WITH border | ||
| Line 1,629: | Line 1,647: | ||
.then(function () { | .then(function () { | ||
// filename via document.title | // filename via document.title | ||
var desiredTitle; | |||
if (filenameOverride) { | |||
desiredTitle = filenameOverride; | |||
} else { | |||
var entryNum = ""; | var entryNum = ""; | ||
var numEl = doc.querySelector(".article-entry-number"); | var numEl = doc.querySelector(".article-entry-number"); | ||
if (numEl) { | if (numEl) { | ||
var m = (numEl.textContent || "").match(/\d+/); | |||
entryNum = m ? m[0] : ""; | |||
} | |||
desiredTitle = | |||
(entryNum ? entryNum + "." : "") + "softwear.directory"; | |||
} | } | ||
var oldIframeTitle = doc.title; | var oldIframeTitle = doc.title; | ||
var oldParentTitle = document.title; | var oldParentTitle = document.title; | ||
| Line 1,654: | Line 1,679: | ||
document.title = desiredTitle; | document.title = desiredTitle; | ||
window._printDoc = doc; | //window._printDoc = doc; | ||
window._printFrame = iframe; | //window._printFrame = iframe; | ||
console.log("PRINT DOC READY", doc); | //console.log("PRINT DOC READY", doc); | ||
console.log("PRINT HTML", doc.body.innerHTML); | //console.log("PRINT HTML", doc.body.innerHTML); | ||
iframe.contentWindow.focus(); | |||
iframe.contentWindow.print(); | |||
// safety cleanup | // safety cleanup | ||
| Line 1,849: | Line 1,874: | ||
// toggle filtered print options | // toggle filtered print options | ||
jQuery(document).on("click", ".print-selection-toggle", function (e) { | jQuery(document).on("click", ".print-selection-toggle", function (e) { | ||
e.preventDefault(); | |||
jQuery("#print-selection-options").toggle(); | |||
}); | |||
// run filtered batch print | // run filtered batch print | ||
| Line 1,858: | Line 1,883: | ||
".print-selection-border, .print-selection-no-border", | ".print-selection-border, .print-selection-no-border", | ||
function (e) { | function (e) { | ||
e.preventDefault(); | |||
var $btn = jQuery(this); | |||
var borderPref = $btn.hasClass("print-selection-no-border") | |||
? "without" | ? "without" | ||
: "with"; | : "with"; | ||
// disable all related buttons | |||
jQuery(".print-selection-border, .print-selection-no-border, .print-selection-toggle") | |||
.prop("disabled", true) | |||
.css("opacity", "0.5"); | |||
// change ONLY clicked button text (native feeling) | |||
var originalText = $btn.text(); | |||
$btn.text("working…"); | |||
swHandleBatchPrint(borderPref); | |||
// optional reset (if user comes back) | |||
setTimeout(function () { | |||
$btn.text(originalText); | |||
jQuery(".print-selection-border, .print-selection-no-border, .print-selection-toggle") | |||
.prop("disabled", false) | |||
.css("opacity", ""); | |||
}, 2000); | |||
} | } | ||
); | ); | ||