Revision of Twine: Jonah: Disable all links after leaving a passage from Thu, 05/09/2013 - 05:02

If you're using Jonah, and you're not using single-passage, then you may find this useful. It causes all internal links to behave like the slightly cumbersome <<choice>> macro.

(function () {
  var d2 = History.prototype.display;
  function closeLinks() {
    var ret = [];
    var l = document.getElementById("passages").getElementsByClassName("internalLink");
    for(var i = l.length-1; i >= 0; i--) {
      var D = insertElement(null, "span", null, "disabled");
      D.innerHTML = l[i].innerHTML;
      l[i].parentNode.insertBefore(D, l[i].nextSibling);
      ret.push(l[i]);
    }
    return ret;
  }
  History.prototype.display = function (E, C, A) {
    var l = closeLinks();
    var r = d2.call(this, E, C, A);
    l.forEach(function (e) {
      e.parentNode.removeChild(e);
    });
    return r;
  }
}());

This is designed to also work with approximately all of my link macros (<<cyclinglink>>, <<revise>>, <<replace>> etc.)

Version history:

  1. 9-5-13: Initial.

Feel free to report any bugs to @webbedspace.