]> gitweb.michael.orlitzky.com - charm-bypass.git/blobdiff - index.html.in
index.html.in: replace the hint with a link to my introduction
[charm-bypass.git] / index.html.in
index 763e2694220eae446b6e19c65551ca1600f1f2f6..a8bb47dedf0d40c46884887f6c31ac3440975a5a 100644 (file)
@@ -8,7 +8,7 @@
           href="data:image/svg+xml;base64,@FAVICON@" />
 
     <title>
-      CharmBypass: it's transit equity y'all
+      CharmBypass: got that transit equity
     </title>
 
     <style>
         font-weight: bold;
       }
 
+      /* Display form errors for the one browser that doesn't support
+       * them natively, mobile Firefox. We use "visibility" to toggle
+       * it on and off, but "display" to hide it completely in non-
+       * stupid web browsers. */
+      #marc-form-errors {
+        color: #a00;
+        visibility: hidden;
+        display: none;
+      }
+
       svg {
         /* Set the height to 100% of the screen, which we'll keep; and the
          * initial position to (0,0), which we're going to change
   <body>
     <div id="menu">
       <h1>CharmBypass</h1>
-      <h2>it's transit equity y'all</h2>
+      <p><strong>got that <em>transit equity</em></strong></p>
 
-      <p>
-        <em>Hint:</em> If they start checking it, the daily security
-        code stays the same all day and is the same on a $2 bus ticket
-        as it is on a $9 MARC ticket. It's also the same on every phone.
-      </p>
+      <ol>
+        <li>
+          <a href="https://michael.orlitzky.com/articles/charmbypass_pt._1%3A_introducing_charmbypass.xhtml">
+            Introduction
+          </a>
+        </li>
+      </ol>
 
       <form>
         <fieldset>
                    pattern="[a-zA-Z0-9]*" />
           </div>
 
-          <p>Zone:</p>
+          <p>
+            Zone<sup>&dagger;</sup>:
+          </p>
           <div>
             <input type="radio" required
                    name="zone"
           </div>
 
           <input type="submit" name="go" value="Generate Ticket" />
+
+          <p>
+            <sup>&dagger;</sup>
+            On the MTA's PDF schedule for your route
+          </p>
         </fieldset>
       </form>
       <form>
             <label for="destination8">West Baltimore (Penn Line)</label>
           </div>
 
+          <p id="marc-form-errors">OK</p>
+
           <input type="hidden" name="serviceid" value="R" />
           <input type="hidden" name="servicename" value="MARC Train" />
-          <input type="submit" name="go" value="Generate Ticket" />
+          <input type="submit"
+                 name="go"
+                 id="marc-submit"
+                 value="Generate Ticket" />
         </fieldset>
       </form>
     </div>
        */
       function compute_marc_zone(src, dest) {
 
-        /* Sorted on the first component, then the second */
+        /* Sorted on the first component, then the second.
+         *
+         * Key:
+         *
+         *   $6.00 => 1
+         *   $7.00 => 2
+         *   $8.00 => 3
+         *   $9.00 => 4
+         */
         const zone_map = {
           BAL_BWE: 2,
           BAL_BWI: 1,
           BWE_SEB: 1,
           BWE_WAS: 2,
           BWE_WBL: 2,
+          BWI_SEB: 2,
           BWI_WAS: 3,
-          BWI_WBL: 1
+          BWI_WBL: 1,
+          SEB_WAS: 1,
+          SEB_WBL: 3,
+          WAS_WBL: 4
         };
 
         /* Forward direction key for zone_map */
         menu.style.display = "none";
       }
 
+      /**
+       * Determine if the user agent is mobile Firefox.
+       */
+      function ua_is_mobile_ff() {
+        const ua = navigator.userAgent.toLowerCase();
+        return (ua.includes("firefox") && ua.includes("mobile"));
+      }
+
       /**
        * Validate the MARC form's origin/destination.
        *
        * zone information for the (origin,destination) pair, that indicates
        * that it's probably not a valid choice; otherwise I would have
        * filled in the information from the CharmPass app already.
+       *
+       * All browsers except mobile Firefox let us call setCustomValidity()
+       * to provide an error message that is displayed if the user tries
+       * to submit invalid choices. But amazingly, mobile Firefox does not:
+       *
+       *   https://bugzilla.mozilla.org/show_bug.cgi?id=1510450
+       *
+       * Instead we have to work around it (in that one browser) by
+       * showing/hiding a paragraph that we fill with the errors.
        */
       function validate_origin_destination(event) {
         const origins = document.getElementsByName("origin");
         const destinations = document.getElementsByName("destination");
+        const mfe = document.getElementById("marc-form-errors");
+        const marcsubmit = document.getElementById("marc-submit");
+
+        if (ua_is_mobile_ff()) {
+          /* Even though this is only for one browser, empty paragraphs
+           * are handled inconsistently and should be avoided as a rule.
+           * So, we make it say "OK" before we hide it. */
+          mfe.textContent = "OK";
+          mfe.style.visibility = "hidden";
+          marcsubmit.disabled = false;
+        }
 
         let src = null;
         let dest = null;
         })
 
         if (src.value === dest.value) {
-          let err = "Origin and destination are the same!";
+          let err = "Origin and destination are the same";
           dest.setCustomValidity(err);
+
+          if (ua_is_mobile_ff()) {
+            mfe.textContent = err;
+            mfe.style.visibility = "visible";
+            marcsubmit.disabled = true;
+          }
         }
         else if (compute_marc_zone(src.value, dest.value) === null) {
-          let err = "Origin and destination are on different lines!";
+          let err = "Origin and destination are on different lines";
           dest.setCustomValidity(err);
+
+          if (ua_is_mobile_ff()) {
+            mfe.textContent = err;
+            mfe.style.visibility = "visible";
+            marcsubmit.disabled = true;
+          }
         }
       }
 
          (x) => x.addEventListener("change", validate_origin_destination)
         );
 
-       /* Also do it when the page loads, because firefox likes to
-        * remember your selection even after the page reloads. */
+        /* Also do it when the page loads, because firefox likes to
+         * remember your selection even after the page reloads. */
         window.addEventListener("load", validate_origin_destination);
+
+        /* Finally, we have to babysit mobile Firefox, who doesn't
+         * support HTML5 form validation going into 2024. Turn on
+         * the little form errors paragraph so we can toggle its
+         * visibility (and make it display the error) when the user
+         * makes an invalid selection. */
+        window.addEventListener("load", () => {
+          if (ua_is_mobile_ff()) {
+            const mfe = document.getElementById("marc-form-errors");
+            mfe.style.display = "block";
+          }
+        });
       }
 
     </script>