4,554
edits
No edit summary |
No edit summary |
||
Line 1,739: | Line 1,739: | ||
e.preventDefault(); | e.preventDefault(); | ||
var $chooser = swEnsurePrintChooser(); | var $chooser = swEnsurePrintChooser(); | ||
// make sure it sits on top & accepts clicks (diagnostic-safe) | |||
$chooser.css({ | |||
position: "absolute", | |||
zIndex: 99999, | |||
background: "#fff", | |||
padding: "4px 6px", | |||
border: "1px solid #ddd", | |||
}); | |||
$chooser.toggle(); | $chooser.toggle(); | ||
var visible = $chooser.is(":visible"); | var visible = $chooser.is(":visible"); | ||
jQuery("#show-article").toggleClass("print-opts-open", visible); | jQuery("#show-article").toggleClass("print-opts-open", visible); | ||
// Bind native handlers to ALL | // Bind native handlers to ALL nodes that currently exist with those IDs | ||
try { | try { | ||
var nodes = Array.prototype.slice.call( | var nodes = Array.prototype.slice.call( | ||
Line 1,757: | Line 1,767: | ||
nodes.forEach(function (el) { | nodes.forEach(function (el) { | ||
if (el.__swprintBound) return; | if (el.__swprintBound) return; | ||
el.__swprintBound = true; | el.__swprintBound = true; | ||
Line 1,765: | Line 1,775: | ||
if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | ||
var id = el.getAttribute("id") || ""; | var id = el.getAttribute("id") || ""; | ||
console.log("[swprint] NATIVE | console.log("[swprint] NATIVE choice fired ->", id); | ||
swHandlePrintChoice(id, (window.jQuery && jQuery(el)) || null); | |||
return false; | return false; | ||
}; | }; | ||
// | // capture = see it before anything else | ||
el.addEventListener("click", handler, true); | el.addEventListener("click", handler, true); | ||
el.addEventListener("pointerup", handler, true); | el.addEventListener("pointerup", handler, true); | ||
}); | }); | ||
} catch (err) {} | } catch (err) {} | ||
// run visibility diagnostics on the two buttons | |||
(function swprintDebugChoices() { | |||
function dump(id) { | |||
var list = document.querySelectorAll('[id="' + id + '"]'); | |||
for (var i = 0; i < list.length; i++) { | |||
var el = list[i]; | |||
var cs = window.getComputedStyle(el); | |||
var r = el.getBoundingClientRect(); | |||
console.log("[swprint][diag]", id, i, { | |||
tag: el.tagName, | |||
display: cs.display, | |||
visibility: cs.visibility, | |||
opacity: cs.opacity, | |||
pointerEvents: cs.pointerEvents, | |||
rect: { | |||
x: Math.round(r.x), | |||
y: Math.round(r.y), | |||
w: Math.round(r.width), | |||
h: Math.round(r.height), | |||
}, | |||
zIndex: cs.zIndex, | |||
}); | |||
} | |||
} | |||
dump("print-with-border"); | |||
dump("print-no-border"); | |||
})(); | |||
return; | |||
} | } | ||
Line 1,863: | Line 1,897: | ||
})(); | })(); | ||
// | // Window-level chooser catcher: any click inside #print-chooser is routed. | ||
(function () { | (function () { | ||
if (window. | if (window.__swprintWindowChooserCatch) return; | ||
window. | window.__swprintWindowChooserCatch = true; | ||
window.addEventListener( | window.addEventListener( | ||
Line 1,883: | Line 1,906: | ||
function (ev) { | function (ev) { | ||
try { | try { | ||
var | var chooser = document.getElementById("print-chooser"); | ||
if (! | if (!chooser || chooser.style.display === "none") return; | ||
// Did we click a WITH / NO element (or inside it)? | |||
var btn = ev.target.closest | |||
? ev.target.closest( | |||
'#print-with-border, #print-no-border, [id="print-with-border"], [id="print-no-border"]' | |||
) | |||
: null; | |||
if (!btn || !chooser.contains(btn)) return; | |||
ev.preventDefault(); | ev.preventDefault(); | ||
ev.stopPropagation(); | ev.stopPropagation(); | ||
if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | if (ev.stopImmediatePropagation) ev.stopImmediatePropagation(); | ||
console.log("[swprint] WINDOW catcher | |||
var $btn = | var id = btn.getAttribute("id") || ""; | ||
console.log("[swprint] WINDOW chooser catcher ->", id); | |||
var $btn = (window.jQuery && jQuery(btn)) || null; | |||
swHandlePrintChoice(id, $btn); | swHandlePrintChoice(id, $btn); | ||
} catch (e) {} | } catch (e) {} | ||
}, | }, | ||
true | true | ||
); | ); // capture | ||
})(); | })(); | ||
// If a widget uses <button> inside the chooser, map it to the nearest id node | |||
jQuery(document).on( | |||
"click.swprintChoiceBtn2", | |||
"#print-chooser button", | |||
function (e) { | |||
var host = this.closest( | |||
'[id="print-with-border"], [id="print-no-border"]' | |||
); | |||
if (!host) return; | |||
e.preventDefault(); | |||
console.log("[swprint] BUTTON inside chooser ->", host.id); | |||
swHandlePrintChoice(host.id, (window.jQuery && jQuery(host)) || null); | |||
} | |||
); | |||
// also hide choices on ESC; your close-button handler already hides them | // also hide choices on ESC; your close-button handler already hides them |