4,554
edits
No edit summary |
No edit summary |
||
Line 1,734: | Line 1,734: | ||
"#print-button, #print-chooser, #print-options", | "#print-button, #print-chooser, #print-options", | ||
function (e) { | function (e) { | ||
// click on the main [print] | |||
// click on the main [print] | // click on the main [print] | ||
if (jQuery(e.target).closest("#print-button").length) { | if (jQuery(e.target).closest("#print-button").length) { | ||
Line 1,739: | Line 1,740: | ||
var $chooser = swEnsurePrintChooser(); | var $chooser = swEnsurePrintChooser(); | ||
$chooser.toggle(); | $chooser.toggle(); | ||
jQuery("#show-article").toggleClass( | var visible = $chooser.is(":visible"); | ||
jQuery("#show-article").toggleClass("print-opts-open", visible); | |||
) | // --- DEBUG + one-time direct binding on the freshly inserted anchors | ||
try { | |||
var aWith = document.getElementById("print-with-border"); | |||
var aNo = document.getElementById("print-no-border"); | |||
console.log("[swprint] chooser toggled; visible=", visible, { | |||
withExists: !!aWith, | |||
noExists: !!aNo, | |||
withCount: document.querySelectorAll("#print-with-border").length, | |||
noCount: document.querySelectorAll("#print-no-border").length, | |||
}); | |||
// Bind native onclicks (idempotent) | |||
[aWith, aNo].forEach(function (a) { | |||
if (!a) return; | |||
if (!a.__swprintBound) { | |||
a.__swprintBound = true; | |||
a.onclick = function (ev) { | |||
ev.preventDefault(); | |||
ev.stopPropagation(); | |||
if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | |||
console.log("[swprint] NATIVE anchor onclick ->", this.id); | |||
if (window.jQuery) { | |||
swHandlePrintChoice(this.id, jQuery(this)); | |||
} else { | |||
swHandlePrintChoice(this.id, null); | |||
} | |||
return false; | |||
}; | |||
} | |||
}); | |||
} catch (err) {} | |||
return; | return; | ||
} | } | ||
Line 1,785: | Line 1,817: | ||
); | ); | ||
// - | // ===== Ultra-hard native catcher (capture), no 'closest' dependency ===== | ||
(function () { | (function () { | ||
if (window. | if (window.__swprintUltraCatcher) return; | ||
window. | window.__swprintUltraCatcher = true; | ||
document.addEventListener( | document.addEventListener( | ||
Line 1,796: | Line 1,826: | ||
function (ev) { | function (ev) { | ||
try { | try { | ||
var | var node = ev.target; | ||
var | var foundId = ""; | ||
// manual ancestor walk (ES5-safe) | |||
while (node && node !== document) { | |||
if (node.nodeType === 1 && node.id) { | |||
if ( | |||
node.id === "print-with-border" || | |||
node.id === "print-no-border" | |||
) { | |||
foundId = node.id; | |||
break; | |||
} | |||
} | |||
node = node.parentNode; | |||
} | |||
if (!foundId) return; | |||
// beat anything that tries to swallow the event | |||
ev.preventDefault(); | |||
ev.stopPropagation(); | |||
if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | |||
console.log("[swprint] ULTRA catcher routed:", foundId); | |||
var $btn = window.jQuery && node ? jQuery(node) : null; | |||
swHandlePrintChoice(foundId, $btn); | |||
} catch (e) { | } catch (e) {} | ||
}, | }, | ||
true | true // capture | ||
); | ); | ||
})(); | })(); | ||