changeset 2348:6ef9445390d2

Move Javascript files under src/ too.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 27 Jul 2021 10:33:10 +0300
parents 4b282f4e5a35
children da0277ade8a7
files Makefile.gen old/Makefile src/tooltip.js src/util.js tooltip.js util.js world/Makefile
diffstat 7 files changed, 344 insertions(+), 344 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.gen	Tue Jul 27 10:10:06 2021 +0300
+++ b/Makefile.gen	Tue Jul 27 10:33:10 2021 +0300
@@ -79,7 +79,7 @@
 ###
 ### Map targets
 ###
-$(MISC_MAPS_PATH)%.html: $(MISC_MAPS_PATH)%.map $(MISC_MAPS_PATH)%.loc $(MISC_MAPS_PATH)%.desc $(MKCITYMAP_BIN) tooltip.js $(MISC_MAPS_PATH)misc.html
+$(MISC_MAPS_PATH)%.html: $(MISC_MAPS_PATH)%.map $(MISC_MAPS_PATH)%.loc $(MISC_MAPS_PATH)%.desc $(MKCITYMAP_BIN) src/tooltip.js $(MISC_MAPS_PATH)misc.html
 	$(MKCITYMAP_BIN) $(MKCITYMAP_OPTS) -h $(MISC_MAPS_PATH)misc.html -t "`cat $(patsubst %.map,%.desc,$<)`" $< $(patsubst %.map,%.loc,$<) `cat $(patsubst %.map,%.opts,$<)` -o "$@"
 
 
@@ -90,7 +90,7 @@
 	@hg up
 	@hg2cl
 
-upload: tooltip.js util.js $(MISC_MAPS_PATH)misc.css \
+upload: src/tooltip.js src/util.js $(MISC_MAPS_PATH)misc.css \
 	$(addprefix $(MISC_MAPS_PATH),$(addsuffix .html,$(MISC_MAPS))) \
 	$(addprefix $(MISC_MAPS_PATH),$(addsuffix .map,$(MISC_MAPS))) \
 	$(addprefix $(MISC_MAPS_PATH),$(addsuffix .loc,$(MISC_MAPS)))
--- a/old/Makefile	Tue Jul 27 10:10:06 2021 +0300
+++ b/old/Makefile	Tue Jul 27 10:33:10 2021 +0300
@@ -46,7 +46,7 @@
 #
 # Special targets
 #
-%.js: ../%.js
+%.js:: ../src/%.js
 	@ln -s $< $@
 
 misc.css: ../misc/misc.css
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tooltip.js	Tue Jul 27 10:33:10 2021 +0300
@@ -0,0 +1,142 @@
+//
+// Tooltip and other utility functions in JavaScript for BatMUD maps
+// Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
+// (C) Copyright 2006-2019 Tecnic Software productions (TNSP)
+//
+var myprev = null;
+var mytt = null;
+var myx = 0;
+var myy = 0;
+
+
+// Add or remove given CSS class to specified element
+function mapSetStyle(uid, ustyle, uset)
+{
+  var uelem = document.getElementById(uid);
+  if (uelem)
+  {
+    if (uset)
+      uelem.classList.add(ustyle);
+    else
+      uelem.classList.remove(ustyle);
+  }
+}
+
+
+// Set or unset active element style
+function mapSetActive(uid, uset)
+{
+  mapSetStyle('maploc'+uid, "locactive", uset);
+  mapSetStyle('listloc'+uid, "locactive", uset);
+}
+
+
+// Hilite map and list elements of given id
+function qh(uid)
+{
+  if (myprev != null) mapSetActive(myprev, false);
+  mapSetActive(uid, true);
+  myprev = uid;
+}
+
+
+function qn()
+{
+  if (myprev != null) mapSetActive(myprev, false);
+  myprev = null;
+  htt();
+}
+
+
+function sttq(uid)
+{
+  qh(uid);
+  stt(uid);
+}
+
+
+// Update the tooltip box
+function mapUpdateTooltip(e)
+{
+  var x = document.all ? (window.event.x + document.body.scrollLeft) : e.pageX;
+  var y = document.all ? (window.event.y + document.body.scrollTop)  : e.pageY;
+  if (mytt != null)
+  {
+    var winW = 0, winH = 0;
+    var boxW = mytt.clientWidth + 25, boxH = mytt.clientHeight + 25;
+
+    if (typeof(window.innerWidth) == 'number')
+    {
+      // Non-MSIE
+      winW = window.innerWidth;
+      winH = window.innerHeight;
+    } else
+    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
+    {
+      // MSIE 6+ in 'standards compliant mode'
+      winW = document.documentElement.clientWidth;
+      winH = document.documentElement.clientHeight;
+    } else
+    if (document.body && (document.body.clientWidth || document.body.clientHeight))
+    {
+      // MSIE 4 compatible
+      winW = document.body.clientWidth;
+      winH = document.body.clientHeight;
+    }
+
+    if (x + boxW + 15 >= winW)
+      x -= boxW;
+    else
+      x += 15;
+
+    if (y + boxH + 15 >= winH)
+      y -= boxH;
+    else
+      y += 15;
+
+    myx = x;
+    myy = y;
+
+    mytt.style.left = x + "px";
+    mytt.style.top  = y + "px";
+  }
+}
+
+
+// Show tooltip
+function stt(id)
+{
+  htt();
+
+  mytt = document.getElementById("tt"+ id);
+  
+  mytt.style.left    = myx + "px";
+  mytt.style.top     = myy + "px";
+  mytt.style.display = "block";
+}
+
+
+// Hide tooltip
+function htt()
+{
+  if (mytt)
+  {
+    mytt.style.display = "none";
+  }
+}
+
+
+// Highlight one location (by index number) during page load
+function mapOnLoad()
+{
+  document.onmousemove = mapUpdateTooltip;
+
+  var hstr = window.location.href;
+  if (hstr.indexOf("?") >= 0)
+  {
+    var uid = unescape(hstr.substr(hstr.indexOf("?") + 1).toLowerCase());
+
+    mapSetStyle('maploc'+uid, "lochilite", true);
+    mapSetStyle('listloc'+uid, "lochilite", true);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/util.js	Tue Jul 27 10:33:10 2021 +0300
@@ -0,0 +1,198 @@
+//
+// Positioning utility functions in JavaScript for BatMUD maps
+// Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
+// (C) Copyright 2007-2019 Tecnic Software productions (TNSP)
+//
+
+var currLoc = null;
+var scrollTimerID = -1;
+var scrollPos0, scrollPos1;
+var scrollIndex = 0.0;
+
+
+function mapFindElemCoords(elem)
+{
+  var xc = yc = 0;
+  if (elem.offsetParent)
+  {
+    xc = elem.offsetLeft;
+    yc = elem.offsetTop;
+    while (elem = elem.offsetParent)
+    {
+      xc += elem.offsetLeft;
+      yc += elem.offsetTop;
+    }
+  }
+
+  return [xc, yc];
+}
+
+
+function mapGetWindowSize()
+{
+  var winW = 0, winH = 0;
+  if (typeof(window.innerWidth) == 'number')
+  {
+    // Non-MSIE
+    winW = window.innerWidth;
+    winH = window.innerHeight;
+  }
+  else
+  if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
+  {
+    // MSIE 6+ in 'standards compliant mode'
+    winW = document.documentElement.clientWidth;
+    winH = document.documentElement.clientHeight;
+  }
+  else
+  if (document.body && (document.body.clientWidth || document.body.clientHeight))
+  {
+    // MSIE 4 compatible
+    winW = document.body.clientWidth;
+    winH = document.body.clientHeight;
+  }
+
+  return [winW, winH];
+}
+
+
+function mapClamp10(a)
+{
+  return (a < 0.0 ? 0.0 : (a > 1.0 ? 1.0 : a));
+}
+
+
+function mapSCurve(t)
+{
+  return (t * t * (3.0 - 2.0 * t));
+}
+
+
+function mapLerp(t, a, b)
+{
+  return (a + t * (b - a));
+}
+
+
+function mapScrollToPos()
+{
+  if (scrollIndex <= 1.0)
+  {
+    var dim = mapGetWindowSize();
+    var n = mapSCurve(mapClamp10(scrollIndex));
+    var px = mapLerp(n, scrollPos0[0], scrollPos1[0]);
+    var py = mapLerp(n, scrollPos0[1], scrollPos1[1]);
+
+    window.scrollTo(px - (dim[0] / 2), py - (dim[1] / 2));
+    scrollIndex += 0.01;
+  }
+  else
+    clearInterval(scrollTimerID);
+}
+
+
+function mapSetActiveLocation(newLoc)
+{
+  // Change CSS class state for prev/curr/new selected element
+  if (currLoc != null)
+  {
+    var celem = document.getElementById(currLoc);
+    var mcelem = document.getElementById("m"+ currLoc);
+    if (celem && mcelem)
+    {
+      celem.classList.remove("nactive");
+      mcelem.classList.remove("nactive");
+    }
+  }
+
+  var celem = document.getElementById(newLoc);
+  var mcelem = document.getElementById("m"+ newLoc);
+  if (celem && mcelem)
+  {
+    celem.classList.add("nactive");
+    mcelem.classList.add("nactive");
+  }
+
+  // Set the active item in the location dropdown
+  var ssel = document.getElementById("slocation");
+  if (ssel)
+  {
+    var found = false;
+    for (var opt, i = 0; opt = ssel.options[i]; i++)
+    {
+      if (opt.value == newLoc)
+      {
+        ssel.selectedIndex = i;
+        found = true;
+        break;
+      }
+    }
+
+    if (!found)
+      ssel.selectedIndex = 0;
+  }
+}
+
+
+function mapSetPosToElem(nelem)
+{
+  var pos = mapFindElemCoords(nelem);
+  var dim = mapGetWindowSize();
+  window.scrollTo(pos[0] - (dim[0] / 2), pos[1] - (dim[1] / 2));
+}
+
+
+function mapGotoPos()
+{
+  var newLoc = document.getElementById("slocation").value;
+  if (currLoc != newLoc)
+  {
+    var nelem = document.getElementById(newLoc);
+    if (nelem)
+    {
+      var sscroll = document.getElementById("sscroll").checked;
+      var celem = currLoc != null ? document.getElementById(currLoc) : null;
+      if (sscroll && celem)
+      {
+        if (scrollTimerID != -1)
+          clearInterval(scrollTimerID);
+
+        scrollPos0 = mapFindElemCoords(celem);
+        scrollPos1 = mapFindElemCoords(nelem);
+        scrollIndex = 0.0;
+
+        scrollTimerID = setInterval(mapScrollToPos, 10);
+      }
+      else
+        mapSetPosToElem(nelem);
+
+      mapSetActiveLocation(newLoc);
+      currLoc = newLoc;
+    }
+  }
+}
+
+
+function mapToggleLabels()
+{
+  var vcl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0];
+  vcl.style.visibility = document.getElementById("shide").checked ? "visible" : "hidden";
+}
+
+
+function mapOnLoad()
+{
+  var slink = window.location.href;
+  var spos;
+  if ((spos = slink.indexOf("#")) >= 0)
+  {
+    var eid = unescape(slink.substr(spos + 1).toLowerCase()).trim();
+    var nelem = document.getElementById(eid);
+    if (nelem)
+    {
+      mapSetPosToElem(nelem);
+      mapSetActiveLocation(eid);
+      currLoc = eid;
+    }
+  }
+}
--- a/tooltip.js	Tue Jul 27 10:10:06 2021 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-//
-// Tooltip and other utility functions in JavaScript for BatMUD maps
-// Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
-// (C) Copyright 2006-2019 Tecnic Software productions (TNSP)
-//
-var myprev = null;
-var mytt = null;
-var myx = 0;
-var myy = 0;
-
-
-// Add or remove given CSS class to specified element
-function mapSetStyle(uid, ustyle, uset)
-{
-  var uelem = document.getElementById(uid);
-  if (uelem)
-  {
-    if (uset)
-      uelem.classList.add(ustyle);
-    else
-      uelem.classList.remove(ustyle);
-  }
-}
-
-
-// Set or unset active element style
-function mapSetActive(uid, uset)
-{
-  mapSetStyle('maploc'+uid, "locactive", uset);
-  mapSetStyle('listloc'+uid, "locactive", uset);
-}
-
-
-// Hilite map and list elements of given id
-function qh(uid)
-{
-  if (myprev != null) mapSetActive(myprev, false);
-  mapSetActive(uid, true);
-  myprev = uid;
-}
-
-
-function qn()
-{
-  if (myprev != null) mapSetActive(myprev, false);
-  myprev = null;
-  htt();
-}
-
-
-function sttq(uid)
-{
-  qh(uid);
-  stt(uid);
-}
-
-
-// Update the tooltip box
-function mapUpdateTooltip(e)
-{
-  var x = document.all ? (window.event.x + document.body.scrollLeft) : e.pageX;
-  var y = document.all ? (window.event.y + document.body.scrollTop)  : e.pageY;
-  if (mytt != null)
-  {
-    var winW = 0, winH = 0;
-    var boxW = mytt.clientWidth + 25, boxH = mytt.clientHeight + 25;
-
-    if (typeof(window.innerWidth) == 'number')
-    {
-      // Non-MSIE
-      winW = window.innerWidth;
-      winH = window.innerHeight;
-    } else
-    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
-    {
-      // MSIE 6+ in 'standards compliant mode'
-      winW = document.documentElement.clientWidth;
-      winH = document.documentElement.clientHeight;
-    } else
-    if (document.body && (document.body.clientWidth || document.body.clientHeight))
-    {
-      // MSIE 4 compatible
-      winW = document.body.clientWidth;
-      winH = document.body.clientHeight;
-    }
-
-    if (x + boxW + 15 >= winW)
-      x -= boxW;
-    else
-      x += 15;
-
-    if (y + boxH + 15 >= winH)
-      y -= boxH;
-    else
-      y += 15;
-
-    myx = x;
-    myy = y;
-
-    mytt.style.left = x + "px";
-    mytt.style.top  = y + "px";
-  }
-}
-
-
-// Show tooltip
-function stt(id)
-{
-  htt();
-
-  mytt = document.getElementById("tt"+ id);
-  
-  mytt.style.left    = myx + "px";
-  mytt.style.top     = myy + "px";
-  mytt.style.display = "block";
-}
-
-
-// Hide tooltip
-function htt()
-{
-  if (mytt)
-  {
-    mytt.style.display = "none";
-  }
-}
-
-
-// Highlight one location (by index number) during page load
-function mapOnLoad()
-{
-  document.onmousemove = mapUpdateTooltip;
-
-  var hstr = window.location.href;
-  if (hstr.indexOf("?") >= 0)
-  {
-    var uid = unescape(hstr.substr(hstr.indexOf("?") + 1).toLowerCase());
-
-    mapSetStyle('maploc'+uid, "lochilite", true);
-    mapSetStyle('listloc'+uid, "lochilite", true);
-  }
-}
--- a/util.js	Tue Jul 27 10:10:06 2021 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,198 +0,0 @@
-//
-// Positioning utility functions in JavaScript for BatMUD maps
-// Programmed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
-// (C) Copyright 2007-2019 Tecnic Software productions (TNSP)
-//
-
-var currLoc = null;
-var scrollTimerID = -1;
-var scrollPos0, scrollPos1;
-var scrollIndex = 0.0;
-
-
-function mapFindElemCoords(elem)
-{
-  var xc = yc = 0;
-  if (elem.offsetParent)
-  {
-    xc = elem.offsetLeft;
-    yc = elem.offsetTop;
-    while (elem = elem.offsetParent)
-    {
-      xc += elem.offsetLeft;
-      yc += elem.offsetTop;
-    }
-  }
-
-  return [xc, yc];
-}
-
-
-function mapGetWindowSize()
-{
-  var winW = 0, winH = 0;
-  if (typeof(window.innerWidth) == 'number')
-  {
-    // Non-MSIE
-    winW = window.innerWidth;
-    winH = window.innerHeight;
-  }
-  else
-  if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
-  {
-    // MSIE 6+ in 'standards compliant mode'
-    winW = document.documentElement.clientWidth;
-    winH = document.documentElement.clientHeight;
-  }
-  else
-  if (document.body && (document.body.clientWidth || document.body.clientHeight))
-  {
-    // MSIE 4 compatible
-    winW = document.body.clientWidth;
-    winH = document.body.clientHeight;
-  }
-
-  return [winW, winH];
-}
-
-
-function mapClamp10(a)
-{
-  return (a < 0.0 ? 0.0 : (a > 1.0 ? 1.0 : a));
-}
-
-
-function mapSCurve(t)
-{
-  return (t * t * (3.0 - 2.0 * t));
-}
-
-
-function mapLerp(t, a, b)
-{
-  return (a + t * (b - a));
-}
-
-
-function mapScrollToPos()
-{
-  if (scrollIndex <= 1.0)
-  {
-    var dim = mapGetWindowSize();
-    var n = mapSCurve(mapClamp10(scrollIndex));
-    var px = mapLerp(n, scrollPos0[0], scrollPos1[0]);
-    var py = mapLerp(n, scrollPos0[1], scrollPos1[1]);
-
-    window.scrollTo(px - (dim[0] / 2), py - (dim[1] / 2));
-    scrollIndex += 0.01;
-  }
-  else
-    clearInterval(scrollTimerID);
-}
-
-
-function mapSetActiveLocation(newLoc)
-{
-  // Change CSS class state for prev/curr/new selected element
-  if (currLoc != null)
-  {
-    var celem = document.getElementById(currLoc);
-    var mcelem = document.getElementById("m"+ currLoc);
-    if (celem && mcelem)
-    {
-      celem.classList.remove("nactive");
-      mcelem.classList.remove("nactive");
-    }
-  }
-
-  var celem = document.getElementById(newLoc);
-  var mcelem = document.getElementById("m"+ newLoc);
-  if (celem && mcelem)
-  {
-    celem.classList.add("nactive");
-    mcelem.classList.add("nactive");
-  }
-
-  // Set the active item in the location dropdown
-  var ssel = document.getElementById("slocation");
-  if (ssel)
-  {
-    var found = false;
-    for (var opt, i = 0; opt = ssel.options[i]; i++)
-    {
-      if (opt.value == newLoc)
-      {
-        ssel.selectedIndex = i;
-        found = true;
-        break;
-      }
-    }
-
-    if (!found)
-      ssel.selectedIndex = 0;
-  }
-}
-
-
-function mapSetPosToElem(nelem)
-{
-  var pos = mapFindElemCoords(nelem);
-  var dim = mapGetWindowSize();
-  window.scrollTo(pos[0] - (dim[0] / 2), pos[1] - (dim[1] / 2));
-}
-
-
-function mapGotoPos()
-{
-  var newLoc = document.getElementById("slocation").value;
-  if (currLoc != newLoc)
-  {
-    var nelem = document.getElementById(newLoc);
-    if (nelem)
-    {
-      var sscroll = document.getElementById("sscroll").checked;
-      var celem = currLoc != null ? document.getElementById(currLoc) : null;
-      if (sscroll && celem)
-      {
-        if (scrollTimerID != -1)
-          clearInterval(scrollTimerID);
-
-        scrollPos0 = mapFindElemCoords(celem);
-        scrollPos1 = mapFindElemCoords(nelem);
-        scrollIndex = 0.0;
-
-        scrollTimerID = setInterval(mapScrollToPos, 10);
-      }
-      else
-        mapSetPosToElem(nelem);
-
-      mapSetActiveLocation(newLoc);
-      currLoc = newLoc;
-    }
-  }
-}
-
-
-function mapToggleLabels()
-{
-  var vcl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0];
-  vcl.style.visibility = document.getElementById("shide").checked ? "visible" : "hidden";
-}
-
-
-function mapOnLoad()
-{
-  var slink = window.location.href;
-  var spos;
-  if ((spos = slink.indexOf("#")) >= 0)
-  {
-    var eid = unescape(slink.substr(spos + 1).toLowerCase()).trim();
-    var nelem = document.getElementById(eid);
-    if (nelem)
-    {
-      mapSetPosToElem(nelem);
-      mapSetActiveLocation(eid);
-      currLoc = eid;
-    }
-  }
-}
--- a/world/Makefile	Tue Jul 27 10:10:06 2021 +0300
+++ b/world/Makefile	Tue Jul 27 10:33:10 2021 +0300
@@ -98,7 +98,7 @@
 diff: cleardiff $(addsuffix .diff,$(CONT_MAPS))
 	@hg diff .
 
-%.js: ../%.js
+%.js:: ../src/%.js
 	@ln -s $< $@
 
 # Clean temporary and generated targets