4,554
edits
No edit summary |
No edit summary |
||
Line 1,282: | Line 1,282: | ||
if ($chooser.length) return $chooser; | if ($chooser.length) return $chooser; | ||
// Keep your existing IDs (print-with-border / print-no-border) | |||
$chooser = jQuery( | $chooser = jQuery( | ||
'<div id="print-chooser" class="print-chooser" style="display:none;">' + | '<div id="print-chooser" class="print-chooser" style="display:none;">' + | ||
'<a href="#" id=" | '<a href="#" id="print-with-border" class="print-choice">border</a> ' + | ||
'<a href="#" id=" | '<a href="#" id="print-no-border" class="print-choice">no border</a>' + | ||
"</div>" | "</div>" | ||
); | ); | ||
jQuery("#print-button").after($chooser); | jQuery("#print-button").after($chooser); | ||
// Bind | // Bind ONCE, on the chooser itself (robust to nested elements) | ||
if (!$chooser.data("swBound")) { | if (!$chooser.data("swBound")) { | ||
$chooser.on("click | $chooser.on("click", function (e) { | ||
e. | var a = e.target && e.target.closest ? e.target.closest("a[id]") : null; | ||
var id = | if (!a) return; // clicked outside a link in the chooser | ||
var id = a.getAttribute("id"); | |||
if (id !== "print-with-border" && id !== "print-no-border") return; | |||
e.preventDefault(); // stop navigation | |||
try { | try { | ||
console.log("[swprint] chooser click - | console.log("[swprint] chooser click ->", id); | ||
} catch (e2) {} | } catch (e2) {} | ||
swHandlePrintChoice(id, jQuery( | swHandlePrintChoice(id, jQuery(a)); | ||
}); | }); | ||
$chooser.data("swBound", true); | $chooser.data("swBound", true); | ||
try { | |||
console.log("[swprint] chooser handler bound"); | |||
} catch (e) {} | |||
} | } | ||