+// the letters of the "Show" checkboxes, in the order they appear in the URL
+// fragment; each one designates the checkbox of id "sh_" plus that letter.
+var show_boxes = "bnuwyo";
+
+// Reflects the current view (the shown categories and the first line to
+// review) into the URL fragment, so that the address bar always holds a link
+// reproducing exactly what is displayed and which can be sent to a coworker
+// as-is. The history entry is replaced and never pushed: nothing is reloaded
+// nor scrolled, the listing does not even blink, and leaving the page still
+// takes a single click on "back".
+function updt_url() {
+ var show = "";
+ var i;
+
+ if (!window.history || !history.replaceState)
+ return;
+
+ for (i = 0; i < show_boxes.length; i++)
+ if (document.getElementById("sh_" + show_boxes.charAt(i)).checked)
+ show += show_boxes.charAt(i);
+
+ // browsers may refuse to touch the history of a page loaded from a local
+ // file (opaque origin). The fragment is then just not maintained, which
+ // affects nothing else, hence the silent catch.
+ try {
+ history.replaceState(null, "", "#show=" + show +
+ "&start=" + (review ? review : "all"));
+ } catch (e) {
+ }
+}
+
+// Applies the view settings possibly passed in the URL fragment: "show" holds
+// the letters of the categories to display, the missing ones being hidden,
+// and "start" is the first line to review, either "all" or a line number.
+// Both are optional and anything not understood is ignored, so that an old or
+// hand-edited link degrades to the page's defaults instead of breaking. A
+// fragment element without "=" is left alone as well, which preserves the
+// ability to point at a commit id. Only the state is set here, the caller
+// redraws.
+function apply_url() {
+ var args = location.hash.substring(1).split("&");
+ var i, j, eq, key, val, num, el;
+
+ for (i = 0; i < args.length; i++) {
+ eq = args[i].indexOf("=");
+ if (eq < 0)
+ continue;
+ key = args[i].substring(0, eq);
+ val = args[i].substring(eq + 1);
+ if (key == "show") {
+ for (j = 0; j < show_boxes.length; j++)
+ document.getElementById("sh_" + show_boxes.charAt(j)).checked =
+ val.indexOf(show_boxes.charAt(j)) >= 0;
+ }
+ else if (key == "start") {
+ if (val == "all") {
+ document.getElementById("show_all").checked = true;
+ review = 0;
+ }
+ else {
+ num = parseInt(val, 10);
+ el = document.getElementById("rv_" + num);
+ if (el) {
+ el.checked = true;
+ review = num;
+ }
+ }
+ }
+ }
+}
+
+// Pasting a link into a tab which already shows the page only changes the
+// fragment, and the browser reloads nothing: apply it by hand or nothing
+// would happen at all. replaceState() does not trigger this event, so the
+// updates emitted above cannot loop back here.
+window.addEventListener("hashchange", function() {
+ apply_url();
+ updt_table(0);
+ updt_output();
+});
+