4,554
edits
No edit summary |
No edit summary |
||
Line 1,743: | Line 1,743: | ||
jQuery("#show-article").toggleClass("print-opts-open", visible); | jQuery("#show-article").toggleClass("print-opts-open", visible); | ||
// | // Bind native handlers to ALL matching nodes (ids are duplicated on Entry pages) | ||
try { | try { | ||
var | var nodes = Array.prototype.slice.call( | ||
document.querySelectorAll( | |||
'[id="print-with-border"], [id="print-no-border"]' | |||
) | |||
); | |||
console.log("[swprint] chooser toggled; visible=", visible, { | console.log("[swprint] chooser toggled; visible=", visible, { | ||
withCount: document.querySelectorAll('[id="print-with-border"]') | |||
.length, | |||
withCount: document.querySelectorAll(" | noCount: document.querySelectorAll('[id="print-no-border"]').length, | ||
noCount: document.querySelectorAll(" | |||
}); | }); | ||
nodes.forEach(function (el) { | |||
if (el.__swprintBound) return; // idempotent | |||
if ( | el.__swprintBound = true; | ||
var handler = function (ev) { | |||
ev.preventDefault(); | |||
ev.stopPropagation(); | |||
if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | |||
var id = el.getAttribute("id") || ""; | |||
console.log("[swprint] NATIVE anchor fired ->", id); | |||
if (window.jQuery) { | |||
swHandlePrintChoice(id, jQuery(el)); | |||
} else { | |||
swHandlePrintChoice(id, null); | |||
} | |||
return false; | |||
}; | |||
// bind early in the chain | |||
el.addEventListener("click", handler, true); // capture | |||
el.addEventListener("pointerup", handler, true); // extra safety for widgets | |||
}); | }); | ||
} catch (err) {} | } catch (err) {} | ||
return; | return; // don't start printing yet | ||
} | } | ||
// click on a choice link | // click on a choice link | ||
var $choice = jQuery(e.target).closest( | var $choice = jQuery(e.target).closest( | ||
Line 1,854: | Line 1,860: | ||
}, | }, | ||
true // capture | true // capture | ||
); | |||
})(); | |||
// ===== Window-level ultra catcher (earliest in the path) ===== | |||
(function () { | |||
if (window.__swprintWindowCatcher) return; | |||
window.__swprintWindowCatcher = true; | |||
var route = function (node) { | |||
while (node && node !== document) { | |||
if (node.nodeType === 1) { | |||
var id = node.getAttribute && node.getAttribute("id"); | |||
if (id === "print-with-border" || id === "print-no-border") return id; | |||
} | |||
node = node.parentNode; | |||
} | |||
return ""; | |||
}; | |||
window.addEventListener( | |||
"click", | |||
function (ev) { | |||
try { | |||
var id = route(ev.target); | |||
if (!id) return; | |||
ev.preventDefault(); | |||
ev.stopPropagation(); | |||
if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | |||
console.log("[swprint] WINDOW catcher routed:", id); | |||
var $btn = | |||
(window.jQuery && jQuery(ev.target).closest('[id="' + id + '"]')) || | |||
null; | |||
swHandlePrintChoice(id, $btn); | |||
} catch (e) {} | |||
}, | |||
true // capture on window (earliest) | |||
); | ); | ||
})(); | })(); |