4,554
edits
| No edit summary | No edit summary | ||
| Line 1,293: | Line 1,293: | ||
|      // Bind ONCE, on the chooser itself (robust to nested elements) |      // Bind ONCE, on the chooser itself (robust to nested elements) | ||
|      if (!$chooser.data("swBound")) { |      if (!$chooser.data("swBound")) { | ||
|        function chooserFire(ev, where) { | |||
|          var a =  |          var a = | ||
|          if (!a) return;  |           ev.target && ev.target.closest ? ev.target.closest("a[id]") : null; | ||
|          if (!a) return; | |||
|          var id = a.getAttribute("id"); |          var id = a.getAttribute("id"); | ||
|          if (id !== "print-with-border" && id !== "print-no-border") return; |          if (id !== "print-with-border" && id !== "print-no-border") return; | ||
|          try { |          try { | ||
|            console.log("[swprint] chooser  |            console.log("[swprint] chooser " + where + " ->", id); | ||
|          } catch (e2) {} |          } catch (e2) {} | ||
|         ev.preventDefault && ev.preventDefault(); | |||
|         ev.stopImmediatePropagation && ev.stopImmediatePropagation(); | |||
|         ev.stopPropagation && ev.stopPropagation(); | |||
|          swHandlePrintChoice(id, jQuery(a)); |          swHandlePrintChoice(id, jQuery(a)); | ||
|        }); |         return false; | ||
|        } | |||
|       $chooser.on( | |||
|         "pointerdown", | |||
|         chooserFire.bind(null, /*ev*/ null, "pointerdown") | |||
|       ); // jQuery will pass ev | |||
|       $chooser.on("touchstart", chooserFire.bind(null, null, "touchstart")); | |||
|       $chooser.on("mousedown", chooserFire.bind(null, null, "mousedown")); | |||
|       $chooser.on("click", chooserFire.bind(null, null, "click")); | |||
|        $chooser.data("swBound", true); |        $chooser.data("swBound", true); | ||
|        try { |        try { | ||
| Line 1,783: | Line 1,794: | ||
|          // bind multiple phases/types to dodge libraries that swallow 'click' |          // bind multiple phases/types to dodge libraries that swallow 'click' | ||
|         // add these lines among the other addEventListener calls: | |||
|         el.addEventListener( | |||
|           "pointerdown", | |||
|           function (e) { | |||
|             fire(e, "pointerdown(capture)"); | |||
|           }, | |||
|           true | |||
|         ); | |||
|         el.addEventListener( | |||
|           "touchstart", | |||
|           function (e) { | |||
|             fire(e, "touchstart(capture)"); | |||
|           }, | |||
|           true | |||
|         ); | |||
|         el.addEventListener( | |||
|           "mousedown", | |||
|           function (e) { | |||
|             fire(e, "mousedown(capture)"); | |||
|           }, | |||
|           true | |||
|         ); | |||
|          el.addEventListener( |          el.addEventListener( | ||
|            "pointerup", |            "pointerup", | ||
| Line 1,841: | Line 1,874: | ||
|      } |      } | ||
|    } |    } | ||
|   (function () { | |||
|     if (window.__swprintEarlyCatcher) return; | |||
|     window.__swprintEarlyCatcher = true; | |||
|     function routeEarly(ev, where) { | |||
|       var t = ev.target; | |||
|       if (!t) return; | |||
|       var a = t.closest | |||
|         ? t.closest("a#print-with-border, a#print-no-border") | |||
|         : null; | |||
|       if (!a) return; | |||
|       try { | |||
|         console.log("[swprint] EARLY-CAPTURE " + where + " ->", a.id); | |||
|       } catch (e) {} | |||
|       ev.preventDefault && ev.preventDefault(); | |||
|       ev.stopImmediatePropagation && ev.stopImmediatePropagation(); | |||
|       ev.stopPropagation && ev.stopPropagation(); | |||
|       swHandlePrintChoice(a.id, (window.jQuery && jQuery(a)) || null); | |||
|       return false; | |||
|     } | |||
|     // Catch before anything else can mutate DOM or swallow events | |||
|     window.addEventListener( | |||
|       "pointerdown", | |||
|       function (e) { | |||
|         routeEarly(e, "window:pointerdown"); | |||
|       }, | |||
|       true | |||
|     ); | |||
|     window.addEventListener( | |||
|       "touchstart", | |||
|       function (e) { | |||
|         routeEarly(e, "window:touchstart"); | |||
|       }, | |||
|       true | |||
|     ); | |||
|     window.addEventListener( | |||
|       "mousedown", | |||
|       function (e) { | |||
|         routeEarly(e, "window:mousedown"); | |||
|       }, | |||
|       true | |||
|     ); | |||
|   })(); | |||
|    (function () { |    (function () { | ||