more moving around
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
function custom_scroller_iframe (selt, iframe, debug) {
|
||||
function log () {
|
||||
if (!debug) return;
|
||||
console.log.apply(null, arguments);
|
||||
var msg = "";
|
||||
for (var i=0, l=arguments.length; i<l; i++) {
|
||||
msg += arguments[i] + " ";
|
||||
}
|
||||
debug.innerHTML += "\n"+ msg;
|
||||
}
|
||||
// console.log("selt", selt);
|
||||
// document.addEventListener("scroll", function (e) {
|
||||
// var sm = selt.scrollHeight - selt.clientHeight;
|
||||
// console.log("scroll", selt.scrollTop, sm, selt.scrollHeight);
|
||||
// })
|
||||
var dragging = false,
|
||||
drag_ref_y = 0,
|
||||
scroll_ref_y = 0,
|
||||
last_y = 0,
|
||||
starttime = null;
|
||||
|
||||
iframe.addEventListener("load", function (e) {
|
||||
var hc = iframe.contentDocument.querySelector(".header-container");
|
||||
function touchstart (e) {
|
||||
if (dragging) { return; }
|
||||
var nn = e.target.nodeName.toLowerCase(),
|
||||
touch = e;
|
||||
if (e.touches) {
|
||||
if (e.touches.length != 1) { return; }
|
||||
touch = e.touches[0];
|
||||
}
|
||||
if (nn !== "a") {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
drag_ref_y = touch.screenY;
|
||||
last_y = touch.screenY;
|
||||
scroll_ref_y = selt.scrollTop;
|
||||
dragging = true;
|
||||
starttime = new Date().getTime();
|
||||
log("start drag", drag_ref_y, starttime);
|
||||
} else {
|
||||
log("headtouch", nn);
|
||||
}
|
||||
}
|
||||
function touchmove (e) {
|
||||
if (dragging) {
|
||||
var touch = e;
|
||||
if (e.touches) {
|
||||
touch = e.touches[0];
|
||||
}
|
||||
last_y = touch.screenY;
|
||||
var dy = touch.screenY - drag_ref_y;
|
||||
selt.scrollTop = scroll_ref_y - dy;
|
||||
}
|
||||
}
|
||||
function touchend (e) {
|
||||
log("touchend", dragging);
|
||||
if (dragging) {
|
||||
dragging = false;
|
||||
var elapsed_time = new Date().getTime() - starttime;
|
||||
// log("end of drag", elapsed_time);
|
||||
if (elapsed_time <= 500) {
|
||||
var open = false,
|
||||
scrollMax = selt.scrollHeight - selt.clientHeight;
|
||||
// do a snap / throw ... direction ??
|
||||
if (last_y == drag_ref_y) {
|
||||
// console.log("no change, guessing state");
|
||||
// toggle current state
|
||||
var sp = selt.scrollTop;
|
||||
log("guess", sp/scrollMax);
|
||||
open = ((sp / scrollMax) < 0.5);
|
||||
} else {
|
||||
log("end/drag", last_y, drag_ref_y);
|
||||
open = (last_y < drag_ref_y);
|
||||
}
|
||||
log("THROW", open ? "open" : "closed");
|
||||
if (open) {
|
||||
selt.scrollTop = scrollMax;
|
||||
} else {
|
||||
selt.scrollTop = 0;
|
||||
}
|
||||
} else {
|
||||
log("long", elapsed_time);
|
||||
}
|
||||
}
|
||||
}
|
||||
hc.addEventListener("touchstart", touchstart);
|
||||
hc.addEventListener("touchmove", touchmove);
|
||||
hc.addEventListener("touchend", touchend);
|
||||
hc.addEventListener("touchcancel", touchend);
|
||||
hc.addEventListener("mousedown", touchstart);
|
||||
hc.addEventListener("mousemove", touchmove);
|
||||
hc.addEventListener("mouseup", touchend);
|
||||
hc.addEventListener("mouseleave", touchend);
|
||||
|
||||
})
|
||||
}
|
||||
911
dist/index.js
vendored
911
dist/index.js
vendored
@@ -1,788 +1,127 @@
|
||||
var index = (function (exports) {
|
||||
'use strict';
|
||||
|
||||
if (typeof document !== "undefined") {
|
||||
var element = document.documentElement;
|
||||
}
|
||||
|
||||
function tree_add(d) {
|
||||
var x = +this._x.call(null, d),
|
||||
y = +this._y.call(null, d);
|
||||
return add(this.cover(x, y), x, y, d);
|
||||
}
|
||||
|
||||
function add(tree, x, y, d) {
|
||||
if (isNaN(x) || isNaN(y)) return tree; // ignore invalid points
|
||||
|
||||
var parent,
|
||||
node = tree._root,
|
||||
leaf = {data: d},
|
||||
x0 = tree._x0,
|
||||
y0 = tree._y0,
|
||||
x1 = tree._x1,
|
||||
y1 = tree._y1,
|
||||
xm,
|
||||
ym,
|
||||
xp,
|
||||
yp,
|
||||
right,
|
||||
bottom,
|
||||
i,
|
||||
j;
|
||||
|
||||
// If the tree is empty, initialize the root as a leaf.
|
||||
if (!node) return tree._root = leaf, tree;
|
||||
|
||||
// Find the existing leaf for the new point, or add it.
|
||||
while (node.length) {
|
||||
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
||||
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
||||
if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
|
||||
}
|
||||
|
||||
// Is the new point is exactly coincident with the existing point?
|
||||
xp = +tree._x.call(null, node.data);
|
||||
yp = +tree._y.call(null, node.data);
|
||||
if (x === xp && y === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
|
||||
|
||||
// Otherwise, split the leaf node until the old and new point are separated.
|
||||
do {
|
||||
parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
|
||||
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
||||
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
||||
} while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | (xp >= xm)));
|
||||
return parent[j] = node, parent[i] = leaf, tree;
|
||||
}
|
||||
|
||||
function addAll(data) {
|
||||
var d, i, n = data.length,
|
||||
x,
|
||||
y,
|
||||
xz = new Array(n),
|
||||
yz = new Array(n),
|
||||
x0 = Infinity,
|
||||
y0 = Infinity,
|
||||
x1 = -Infinity,
|
||||
y1 = -Infinity;
|
||||
|
||||
// Compute the points and their extent.
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d))) continue;
|
||||
xz[i] = x;
|
||||
yz[i] = y;
|
||||
if (x < x0) x0 = x;
|
||||
if (x > x1) x1 = x;
|
||||
if (y < y0) y0 = y;
|
||||
if (y > y1) y1 = y;
|
||||
}
|
||||
|
||||
// If there were no (valid) points, abort.
|
||||
if (x0 > x1 || y0 > y1) return this;
|
||||
|
||||
// Expand the tree to cover the new points.
|
||||
this.cover(x0, y0).cover(x1, y1);
|
||||
|
||||
// Add the new points.
|
||||
for (i = 0; i < n; ++i) {
|
||||
add(this, xz[i], yz[i], data[i]);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
function tree_cover(x, y) {
|
||||
if (isNaN(x = +x) || isNaN(y = +y)) return this; // ignore invalid points
|
||||
|
||||
var x0 = this._x0,
|
||||
y0 = this._y0,
|
||||
x1 = this._x1,
|
||||
y1 = this._y1;
|
||||
|
||||
// If the quadtree has no extent, initialize them.
|
||||
// Integer extent are necessary so that if we later double the extent,
|
||||
// the existing quadrant boundaries don’t change due to floating point error!
|
||||
if (isNaN(x0)) {
|
||||
x1 = (x0 = Math.floor(x)) + 1;
|
||||
y1 = (y0 = Math.floor(y)) + 1;
|
||||
}
|
||||
|
||||
// Otherwise, double repeatedly to cover.
|
||||
else {
|
||||
var z = x1 - x0,
|
||||
node = this._root,
|
||||
parent,
|
||||
i;
|
||||
|
||||
while (x0 > x || x >= x1 || y0 > y || y >= y1) {
|
||||
i = (y < y0) << 1 | (x < x0);
|
||||
parent = new Array(4), parent[i] = node, node = parent, z *= 2;
|
||||
switch (i) {
|
||||
case 0: x1 = x0 + z, y1 = y0 + z; break;
|
||||
case 1: x0 = x1 - z, y1 = y0 + z; break;
|
||||
case 2: x1 = x0 + z, y0 = y1 - z; break;
|
||||
case 3: x0 = x1 - z, y0 = y1 - z; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (this._root && this._root.length) this._root = node;
|
||||
}
|
||||
|
||||
this._x0 = x0;
|
||||
this._y0 = y0;
|
||||
this._x1 = x1;
|
||||
this._y1 = y1;
|
||||
return this;
|
||||
}
|
||||
|
||||
function tree_data() {
|
||||
var data = [];
|
||||
this.visit(function(node) {
|
||||
if (!node.length) do data.push(node.data); while (node = node.next)
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
function tree_extent(_) {
|
||||
return arguments.length
|
||||
? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1])
|
||||
: isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
|
||||
}
|
||||
|
||||
function Quad(node, x0, y0, x1, y1) {
|
||||
this.node = node;
|
||||
this.x0 = x0;
|
||||
this.y0 = y0;
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
}
|
||||
|
||||
function tree_find(x, y, radius) {
|
||||
var data,
|
||||
x0 = this._x0,
|
||||
y0 = this._y0,
|
||||
x1,
|
||||
y1,
|
||||
x2,
|
||||
y2,
|
||||
x3 = this._x1,
|
||||
y3 = this._y1,
|
||||
quads = [],
|
||||
node = this._root,
|
||||
q,
|
||||
i;
|
||||
|
||||
if (node) quads.push(new Quad(node, x0, y0, x3, y3));
|
||||
if (radius == null) radius = Infinity;
|
||||
else {
|
||||
x0 = x - radius, y0 = y - radius;
|
||||
x3 = x + radius, y3 = y + radius;
|
||||
radius *= radius;
|
||||
}
|
||||
|
||||
while (q = quads.pop()) {
|
||||
|
||||
// Stop searching if this quadrant can’t contain a closer node.
|
||||
if (!(node = q.node)
|
||||
|| (x1 = q.x0) > x3
|
||||
|| (y1 = q.y0) > y3
|
||||
|| (x2 = q.x1) < x0
|
||||
|| (y2 = q.y1) < y0) continue;
|
||||
|
||||
// Bisect the current quadrant.
|
||||
if (node.length) {
|
||||
var xm = (x1 + x2) / 2,
|
||||
ym = (y1 + y2) / 2;
|
||||
|
||||
quads.push(
|
||||
new Quad(node[3], xm, ym, x2, y2),
|
||||
new Quad(node[2], x1, ym, xm, y2),
|
||||
new Quad(node[1], xm, y1, x2, ym),
|
||||
new Quad(node[0], x1, y1, xm, ym)
|
||||
);
|
||||
|
||||
// Visit the closest quadrant first.
|
||||
if (i = (y >= ym) << 1 | (x >= xm)) {
|
||||
q = quads[quads.length - 1];
|
||||
quads[quads.length - 1] = quads[quads.length - 1 - i];
|
||||
quads[quads.length - 1 - i] = q;
|
||||
}
|
||||
}
|
||||
|
||||
// Visit this point. (Visiting coincident points isn’t necessary!)
|
||||
else {
|
||||
var dx = x - +this._x.call(null, node.data),
|
||||
dy = y - +this._y.call(null, node.data),
|
||||
d2 = dx * dx + dy * dy;
|
||||
if (d2 < radius) {
|
||||
var d = Math.sqrt(radius = d2);
|
||||
x0 = x - d, y0 = y - d;
|
||||
x3 = x + d, y3 = y + d;
|
||||
data = node.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function tree_remove(d) {
|
||||
if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d))) return this; // ignore invalid points
|
||||
|
||||
var parent,
|
||||
node = this._root,
|
||||
retainer,
|
||||
previous,
|
||||
next,
|
||||
x0 = this._x0,
|
||||
y0 = this._y0,
|
||||
x1 = this._x1,
|
||||
y1 = this._y1,
|
||||
x,
|
||||
y,
|
||||
xm,
|
||||
ym,
|
||||
right,
|
||||
bottom,
|
||||
i,
|
||||
j;
|
||||
|
||||
// If the tree is empty, initialize the root as a leaf.
|
||||
if (!node) return this;
|
||||
|
||||
// Find the leaf node for the point.
|
||||
// While descending, also retain the deepest parent with a non-removed sibling.
|
||||
if (node.length) while (true) {
|
||||
if (right = x >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm;
|
||||
if (bottom = y >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym;
|
||||
if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
|
||||
if (!node.length) break;
|
||||
if (parent[(i + 1) & 3] || parent[(i + 2) & 3] || parent[(i + 3) & 3]) retainer = parent, j = i;
|
||||
}
|
||||
|
||||
// Find the point to remove.
|
||||
while (node.data !== d) if (!(previous = node, node = node.next)) return this;
|
||||
if (next = node.next) delete node.next;
|
||||
|
||||
// If there are multiple coincident points, remove just the point.
|
||||
if (previous) return (next ? previous.next = next : delete previous.next), this;
|
||||
|
||||
// If this is the root point, remove it.
|
||||
if (!parent) return this._root = next, this;
|
||||
|
||||
// Remove this leaf.
|
||||
next ? parent[i] = next : delete parent[i];
|
||||
|
||||
// If the parent now contains exactly one leaf, collapse superfluous parents.
|
||||
if ((node = parent[0] || parent[1] || parent[2] || parent[3])
|
||||
&& node === (parent[3] || parent[2] || parent[1] || parent[0])
|
||||
&& !node.length) {
|
||||
if (retainer) retainer[j] = node;
|
||||
else this._root = node;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
function removeAll(data) {
|
||||
for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
|
||||
return this;
|
||||
}
|
||||
|
||||
function tree_root() {
|
||||
return this._root;
|
||||
}
|
||||
|
||||
function tree_size() {
|
||||
var size = 0;
|
||||
this.visit(function(node) {
|
||||
if (!node.length) do ++size; while (node = node.next)
|
||||
});
|
||||
return size;
|
||||
}
|
||||
|
||||
function tree_visit(callback) {
|
||||
var quads = [], q, node = this._root, child, x0, y0, x1, y1;
|
||||
if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
|
||||
while (q = quads.pop()) {
|
||||
if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
|
||||
var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
||||
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
||||
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
||||
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
||||
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
function tree_visitAfter(callback) {
|
||||
var quads = [], next = [], q;
|
||||
if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
|
||||
while (q = quads.pop()) {
|
||||
var node = q.node;
|
||||
if (node.length) {
|
||||
var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
||||
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
||||
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
||||
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
||||
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
||||
}
|
||||
next.push(q);
|
||||
}
|
||||
while (q = next.pop()) {
|
||||
callback(q.node, q.x0, q.y0, q.x1, q.y1);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
function defaultX(d) {
|
||||
return d[0];
|
||||
}
|
||||
|
||||
function tree_x(_) {
|
||||
return arguments.length ? (this._x = _, this) : this._x;
|
||||
}
|
||||
|
||||
function defaultY(d) {
|
||||
return d[1];
|
||||
}
|
||||
|
||||
function tree_y(_) {
|
||||
return arguments.length ? (this._y = _, this) : this._y;
|
||||
}
|
||||
|
||||
function quadtree(nodes, x, y) {
|
||||
var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
|
||||
return nodes == null ? tree : tree.addAll(nodes);
|
||||
}
|
||||
|
||||
function Quadtree(x, y, x0, y0, x1, y1) {
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
this._x0 = x0;
|
||||
this._y0 = y0;
|
||||
this._x1 = x1;
|
||||
this._y1 = y1;
|
||||
this._root = undefined;
|
||||
}
|
||||
|
||||
function leaf_copy(leaf) {
|
||||
var copy = {data: leaf.data}, next = copy;
|
||||
while (leaf = leaf.next) next = next.next = {data: leaf.data};
|
||||
return copy;
|
||||
}
|
||||
|
||||
var treeProto = quadtree.prototype = Quadtree.prototype;
|
||||
|
||||
treeProto.copy = function() {
|
||||
var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1),
|
||||
node = this._root,
|
||||
nodes,
|
||||
child;
|
||||
|
||||
if (!node) return copy;
|
||||
|
||||
if (!node.length) return copy._root = leaf_copy(node), copy;
|
||||
|
||||
nodes = [{source: node, target: copy._root = new Array(4)}];
|
||||
while (node = nodes.pop()) {
|
||||
for (var i = 0; i < 4; ++i) {
|
||||
if (child = node.source[i]) {
|
||||
if (child.length) nodes.push({source: child, target: node.target[i] = new Array(4)});
|
||||
else node.target[i] = leaf_copy(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
};
|
||||
|
||||
treeProto.add = tree_add;
|
||||
treeProto.addAll = addAll;
|
||||
treeProto.cover = tree_cover;
|
||||
treeProto.data = tree_data;
|
||||
treeProto.extent = tree_extent;
|
||||
treeProto.find = tree_find;
|
||||
treeProto.remove = tree_remove;
|
||||
treeProto.removeAll = removeAll;
|
||||
treeProto.root = tree_root;
|
||||
treeProto.size = tree_size;
|
||||
treeProto.visit = tree_visit;
|
||||
treeProto.visitAfter = tree_visitAfter;
|
||||
treeProto.x = tree_x;
|
||||
treeProto.y = tree_y;
|
||||
|
||||
var noop = {value: function() {}};
|
||||
|
||||
function dispatch() {
|
||||
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
|
||||
if (!(t = arguments[i] + "") || (t in _)) throw new Error("illegal type: " + t);
|
||||
_[t] = [];
|
||||
}
|
||||
return new Dispatch(_);
|
||||
}
|
||||
|
||||
function Dispatch(_) {
|
||||
this._ = _;
|
||||
}
|
||||
|
||||
function parseTypenames(typenames, types) {
|
||||
return typenames.trim().split(/^|\s+/).map(function(t) {
|
||||
var name = "", i = t.indexOf(".");
|
||||
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
||||
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
||||
return {type: t, name: name};
|
||||
});
|
||||
}
|
||||
|
||||
Dispatch.prototype = dispatch.prototype = {
|
||||
constructor: Dispatch,
|
||||
on: function(typename, callback) {
|
||||
var _ = this._,
|
||||
T = parseTypenames(typename + "", _),
|
||||
t,
|
||||
i = -1,
|
||||
n = T.length;
|
||||
|
||||
// If no callback was specified, return the callback of the given type and name.
|
||||
if (arguments.length < 2) {
|
||||
while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
|
||||
return;
|
||||
}
|
||||
|
||||
// If a type was specified, set the callback for the given type and name.
|
||||
// Otherwise, if a null callback was specified, remove callbacks of the given name.
|
||||
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
||||
while (++i < n) {
|
||||
if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
|
||||
else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
copy: function() {
|
||||
var copy = {}, _ = this._;
|
||||
for (var t in _) copy[t] = _[t].slice();
|
||||
return new Dispatch(copy);
|
||||
},
|
||||
call: function(type, that) {
|
||||
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
|
||||
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
||||
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
||||
},
|
||||
apply: function(type, that, args) {
|
||||
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
||||
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
||||
}
|
||||
};
|
||||
|
||||
function get(type, name) {
|
||||
for (var i = 0, n = type.length, c; i < n; ++i) {
|
||||
if ((c = type[i]).name === name) {
|
||||
return c.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function set(type, name, callback) {
|
||||
for (var i = 0, n = type.length; i < n; ++i) {
|
||||
if (type[i].name === name) {
|
||||
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (callback != null) type.push({name: name, value: callback});
|
||||
return type;
|
||||
}
|
||||
|
||||
var frame = 0, // is an animation frame pending?
|
||||
timeout = 0, // is a timeout pending?
|
||||
interval = 0, // are any timers active?
|
||||
pokeDelay = 1000, // how frequently we check for clock skew
|
||||
taskHead,
|
||||
taskTail,
|
||||
clockLast = 0,
|
||||
clockNow = 0,
|
||||
clockSkew = 0,
|
||||
clock = typeof performance === "object" && performance.now ? performance : Date,
|
||||
setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); };
|
||||
|
||||
function now() {
|
||||
return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
||||
}
|
||||
|
||||
function clearNow() {
|
||||
clockNow = 0;
|
||||
}
|
||||
|
||||
function Timer() {
|
||||
this._call =
|
||||
this._time =
|
||||
this._next = null;
|
||||
}
|
||||
|
||||
Timer.prototype = timer.prototype = {
|
||||
constructor: Timer,
|
||||
restart: function(callback, delay, time) {
|
||||
if (typeof callback !== "function") throw new TypeError("callback is not a function");
|
||||
time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
||||
if (!this._next && taskTail !== this) {
|
||||
if (taskTail) taskTail._next = this;
|
||||
else taskHead = this;
|
||||
taskTail = this;
|
||||
}
|
||||
this._call = callback;
|
||||
this._time = time;
|
||||
sleep();
|
||||
},
|
||||
stop: function() {
|
||||
if (this._call) {
|
||||
this._call = null;
|
||||
this._time = Infinity;
|
||||
sleep();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function timer(callback, delay, time) {
|
||||
var t = new Timer;
|
||||
t.restart(callback, delay, time);
|
||||
return t;
|
||||
}
|
||||
|
||||
function timerFlush() {
|
||||
now(); // Get the current time, if not already set.
|
||||
++frame; // Pretend we’ve set an alarm, if we haven’t already.
|
||||
var t = taskHead, e;
|
||||
while (t) {
|
||||
if ((e = clockNow - t._time) >= 0) t._call.call(null, e);
|
||||
t = t._next;
|
||||
}
|
||||
--frame;
|
||||
}
|
||||
|
||||
function wake() {
|
||||
clockNow = (clockLast = clock.now()) + clockSkew;
|
||||
frame = timeout = 0;
|
||||
try {
|
||||
timerFlush();
|
||||
} finally {
|
||||
frame = 0;
|
||||
nap();
|
||||
clockNow = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function poke() {
|
||||
var now = clock.now(), delay = now - clockLast;
|
||||
if (delay > pokeDelay) clockSkew -= delay, clockLast = now;
|
||||
}
|
||||
|
||||
function nap() {
|
||||
var t0, t1 = taskHead, t2, time = Infinity;
|
||||
while (t1) {
|
||||
if (t1._call) {
|
||||
if (time > t1._time) time = t1._time;
|
||||
t0 = t1, t1 = t1._next;
|
||||
custom_scroller_menu(
|
||||
document.scrollingElement,
|
||||
document.getElementById("menubar"),
|
||||
document.getElementById("debug"));
|
||||
|
||||
var svg = document.querySelector("#svg"),
|
||||
iframe = document.querySelector("iframe#wikiframe"),
|
||||
cats = document.querySelector("#cats"),
|
||||
cats_contents = document.querySelector("#cats .body"),
|
||||
cats_thumb = document.querySelector("#cats .thumb"),
|
||||
allcatscb = document.querySelector("input#allcats"),
|
||||
historycb = document.querySelector("input#history"),
|
||||
current_title = null,
|
||||
loaded = false,
|
||||
wikibaseurl,
|
||||
wikibasepat;
|
||||
|
||||
|
||||
window.addEventListener("resize", resize);
|
||||
function resize() {
|
||||
var w = window,
|
||||
d = document,
|
||||
e = d.documentElement,
|
||||
g = d.getElementsByTagName('body')[0],
|
||||
x = w.innerWidth || e.clientWidth || g.clientWidth,
|
||||
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
|
||||
svg.setAttribute("width", x);
|
||||
svg.setAttribute("height", y);
|
||||
//console.log("resize", x, y);
|
||||
}
|
||||
resize();
|
||||
|
||||
// console.log("mediawikiapi", mediawikiapi);
|
||||
var symbols = {
|
||||
"Orientations": "symbols.svg#Orientations",
|
||||
"Ateliers pluridisciplinaires": "symbols.svg#Ateliers_pluridisciplinaires",
|
||||
"Cours de soutien à l'orientation": "symbols.svg#Cours_de_soutien_a_l'orientation",
|
||||
"Cours de soutien spécifique": "symbols.svg#Cours_de_soutien_specifique",
|
||||
"Cours techniques": "symbols.svg#Cours_techniques",
|
||||
"Cours théoriques": "symbols.svg#Cours_theoriques",
|
||||
"Enseignants": "symbols.svg#Enseignants",
|
||||
"default": "symbols.svg#Main"
|
||||
};
|
||||
var map = new app.Map(symbols);
|
||||
|
||||
map.init_svg("#svg");
|
||||
async function doload () {
|
||||
console.log("loading map");
|
||||
await map.load_json("sitemap.json");
|
||||
// console.log("loading categories");
|
||||
// await map.load_cats("cats.json", cats_contents);
|
||||
console.log("LOADED!");
|
||||
loaded = true;
|
||||
if (current_title) {
|
||||
map.set_active_title(current_title);
|
||||
}
|
||||
}
|
||||
|
||||
map.on("page", function (title) {
|
||||
console.log("map.page", title);
|
||||
var url = wiki_title_to_url(title);
|
||||
iframe.src = url;
|
||||
})
|
||||
// async function doload() {
|
||||
// map.set_active_node(startpage.value);
|
||||
// }
|
||||
|
||||
function strip_fragment (href) {
|
||||
var spos = href.indexOf("#");
|
||||
if (spos >= 0) {
|
||||
return href.substr(0, href.indexOf("#"))
|
||||
}
|
||||
return href;
|
||||
}
|
||||
function url_to_wiki_title (href) {
|
||||
href = strip_fragment(href);
|
||||
var m = wikibasepat.exec(href);
|
||||
if (m !== null) {
|
||||
return decodeURI(m[1]).replace(/_/g, " ");
|
||||
}
|
||||
console.log("m", m);
|
||||
}
|
||||
function wiki_title_to_url (title) {
|
||||
return wikibaseurl+encodeURI(title.replace(/ /g, "_"));
|
||||
}
|
||||
window.addEventListener("DOMContentLoaded", doload);
|
||||
function strip_title_from_wiki_url (url) {
|
||||
return url.substr(0, url.lastIndexOf("/")+1);
|
||||
}
|
||||
iframe.addEventListener("load", function () {
|
||||
var href = strip_fragment(iframe.contentWindow.location.href);
|
||||
if (!wikibaseurl) {
|
||||
wikibaseurl = strip_title_from_wiki_url(href);
|
||||
wikibasepat = new RegExp(wikibaseurl+"(.+)");
|
||||
}
|
||||
console.log("iframe loaded", href);
|
||||
var title = url_to_wiki_title(href);
|
||||
console.log("title", title);
|
||||
if (title) {
|
||||
current_title = title;
|
||||
if (loaded) {
|
||||
map.set_active_title(title);
|
||||
}
|
||||
}
|
||||
// attempt to map url to wiki page title and update the map if it is one
|
||||
|
||||
});
|
||||
|
||||
cats_thumb.addEventListener("click", function () {
|
||||
cats.classList.toggle("expanded");
|
||||
});
|
||||
// allcats checkbox
|
||||
// match current state & respond to change events
|
||||
// console.log("setting checked to", cats.classList.contains("showall"))
|
||||
allcatscb.checked = cats.classList.contains("showall");
|
||||
allcatscb.addEventListener("change", function () {
|
||||
// console.log("allcats", allcatscb);
|
||||
if (allcatscb.checked) {
|
||||
cats.classList.add("showall")
|
||||
} else {
|
||||
t2 = t1._next, t1._next = null;
|
||||
t1 = t0 ? t0._next = t2 : taskHead = t2;
|
||||
cats.classList.remove("showall")
|
||||
}
|
||||
}
|
||||
taskTail = t0;
|
||||
sleep(time);
|
||||
}
|
||||
|
||||
function sleep(time) {
|
||||
if (frame) return; // Soonest alarm already set, or will be.
|
||||
if (timeout) timeout = clearTimeout(timeout);
|
||||
var delay = time - clockNow; // Strictly less than if we recomputed clockNow.
|
||||
if (delay > 24) {
|
||||
if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
|
||||
if (interval) interval = clearInterval(interval);
|
||||
} else {
|
||||
if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
|
||||
frame = 1, setFrame(wake);
|
||||
}
|
||||
}
|
||||
|
||||
var initialRadius = 10,
|
||||
initialAngle = Math.PI * (3 - Math.sqrt(5));
|
||||
|
||||
function forceSimulation(nodes) {
|
||||
var simulation,
|
||||
alpha = 1,
|
||||
alphaMin = 0.001,
|
||||
alphaDecay = 1 - Math.pow(alphaMin, 1 / 300),
|
||||
alphaTarget = 0,
|
||||
velocityDecay = 0.6,
|
||||
forces = new Map(),
|
||||
stepper = timer(step),
|
||||
event = dispatch("tick", "end");
|
||||
|
||||
if (nodes == null) nodes = [];
|
||||
|
||||
function step() {
|
||||
tick();
|
||||
event.call("tick", simulation);
|
||||
if (alpha < alphaMin) {
|
||||
stepper.stop();
|
||||
event.call("end", simulation);
|
||||
}
|
||||
}
|
||||
|
||||
function tick(iterations) {
|
||||
var i, n = nodes.length, node;
|
||||
|
||||
if (iterations === undefined) iterations = 1;
|
||||
|
||||
for (var k = 0; k < iterations; ++k) {
|
||||
alpha += (alphaTarget - alpha) * alphaDecay;
|
||||
|
||||
forces.forEach(function(force) {
|
||||
force(alpha);
|
||||
});
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
node = nodes[i];
|
||||
if (node.fx == null) node.x += node.vx *= velocityDecay;
|
||||
else node.x = node.fx, node.vx = 0;
|
||||
if (node.fy == null) node.y += node.vy *= velocityDecay;
|
||||
else node.y = node.fy, node.vy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return simulation;
|
||||
}
|
||||
|
||||
function initializeNodes() {
|
||||
for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
||||
node = nodes[i], node.index = i;
|
||||
if (node.fx != null) node.x = node.fx;
|
||||
if (node.fy != null) node.y = node.fy;
|
||||
if (isNaN(node.x) || isNaN(node.y)) {
|
||||
var radius = initialRadius * Math.sqrt(i), angle = i * initialAngle;
|
||||
node.x = radius * Math.cos(angle);
|
||||
node.y = radius * Math.sin(angle);
|
||||
}
|
||||
if (isNaN(node.vx) || isNaN(node.vy)) {
|
||||
node.vx = node.vy = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeForce(force) {
|
||||
if (force.initialize) force.initialize(nodes);
|
||||
return force;
|
||||
}
|
||||
|
||||
initializeNodes();
|
||||
|
||||
return simulation = {
|
||||
tick: tick,
|
||||
|
||||
restart: function() {
|
||||
return stepper.restart(step), simulation;
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
return stepper.stop(), simulation;
|
||||
},
|
||||
|
||||
nodes: function(_) {
|
||||
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
|
||||
},
|
||||
|
||||
alpha: function(_) {
|
||||
return arguments.length ? (alpha = +_, simulation) : alpha;
|
||||
},
|
||||
|
||||
alphaMin: function(_) {
|
||||
return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
|
||||
},
|
||||
|
||||
alphaDecay: function(_) {
|
||||
return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
|
||||
},
|
||||
|
||||
alphaTarget: function(_) {
|
||||
return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
|
||||
},
|
||||
|
||||
velocityDecay: function(_) {
|
||||
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
|
||||
},
|
||||
|
||||
force: function(name, _) {
|
||||
return arguments.length > 1 ? ((_ == null ? forces.delete(name) : forces.set(name, initializeForce(_))), simulation) : forces.get(name);
|
||||
},
|
||||
|
||||
find: function(x, y, radius) {
|
||||
var i = 0,
|
||||
n = nodes.length,
|
||||
dx,
|
||||
dy,
|
||||
d2,
|
||||
node,
|
||||
closest;
|
||||
|
||||
if (radius == null) radius = Infinity;
|
||||
else radius *= radius;
|
||||
|
||||
for (i = 0; i < n; ++i) {
|
||||
node = nodes[i];
|
||||
dx = x - node.x;
|
||||
dy = y - node.y;
|
||||
d2 = dx * dx + dy * dy;
|
||||
if (d2 < radius) closest = node, radius = d2;
|
||||
}
|
||||
|
||||
return closest;
|
||||
},
|
||||
|
||||
on: function(name, _) {
|
||||
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// import { test } from './test.js';
|
||||
// console.log("in index.js", test);
|
||||
// test();
|
||||
console.log("in index.js");
|
||||
// import * as fetchJsonp from 'fetch-jsonp';
|
||||
// import { jsonp } from 'jsonp';
|
||||
|
||||
var jsonp = require("jsonp");
|
||||
|
||||
console.log("force", forceSimulation);
|
||||
console.log("fetchJsonp", fetchJsonp);
|
||||
|
||||
|
||||
class Map$1 {
|
||||
constructor (apiurl) {
|
||||
this.apiurl = apiurl;
|
||||
}
|
||||
load (pagetitle) {
|
||||
console.log("Map.load", pagetitle, this.apiurl);
|
||||
jsonpP (this.apiurl).then(data => {
|
||||
console.log("got data", data);
|
||||
}).catch(err => {
|
||||
console.log("ERROR", err);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// http://erg.activearchives.org/mw/api.php?action=query&prop=links&titles=Bienvenue_%C3%A0_l%E2%80%99erg
|
||||
// http://erg.activearchives.org/w/api.php?action=query&prop=info&titles=Main%20Page
|
||||
// Bienvenue_à_l’erg
|
||||
// http://erg.activearchives.org/mw/index.php/Bienvenue_%C3%A0_l%E2%80%99erg
|
||||
|
||||
exports.Map = Map$1;
|
||||
|
||||
return exports;
|
||||
|
||||
}({}));
|
||||
})
|
||||
historycb.addEventListener("change", function () {
|
||||
// console.log("history", historycb.checked);
|
||||
map.set_show_history(historycb.checked);
|
||||
})
|
||||
|
||||
3108
dist/wikimap.js
vendored
3108
dist/wikimap.js
vendored
File diff suppressed because it is too large
Load Diff
5555
dist/wikimaptotal.js
vendored
5555
dist/wikimaptotal.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,84 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="controls">
|
||||
<a href="http://localhost/mw/api.php" id="mediawikiapi"></a><input id="startpage" value="Bienvenue à l’erg" autofocus /><button id="button">ok</button>
|
||||
</div>
|
||||
<div id="content">
|
||||
<svg id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>
|
||||
</div>
|
||||
<div id="wiki">
|
||||
<iframe src="http://localhost/mw/"></iframe>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript" src="dist/wikimap.js"></script>
|
||||
<script>
|
||||
var mediawikiapi = document.querySelector("#mediawikiapi").href,
|
||||
startpage = document.querySelector("#startpage"),
|
||||
button = document.querySelector("#button"),
|
||||
svg = document.querySelector("#svg"),
|
||||
iframe = document.querySelector("iframe");
|
||||
|
||||
window.addEventListener("resize", resize);
|
||||
function resize() {
|
||||
var w = window,
|
||||
d = document,
|
||||
e = d.documentElement,
|
||||
g = d.getElementsByTagName('body')[0],
|
||||
x = w.innerWidth || e.clientWidth || g.clientWidth,
|
||||
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
|
||||
svg.setAttribute("width", x);
|
||||
svg.setAttribute("height", y);
|
||||
console.log("resize", x, y);
|
||||
}
|
||||
resize();
|
||||
// console.log("mediawikiapi", mediawikiapi);
|
||||
var map = new wikimap.Map(mediawikiapi);
|
||||
map.init_svg("#svg");
|
||||
map.on("page", function (title) {
|
||||
console.log("map.page", title);
|
||||
var url = wiki_title_to_url(title);
|
||||
iframe.src = url;
|
||||
})
|
||||
async function doload() {
|
||||
map.set_active_node(startpage.value);
|
||||
}
|
||||
var URLPAT = new RegExp("http://localhost/mw/index.php/(.+)");
|
||||
function strip_fragment (href) {
|
||||
var spos = href.indexOf("#");
|
||||
if (spos >= 0) {
|
||||
return href.substr(0, href.indexOf("#"))
|
||||
}
|
||||
return href;
|
||||
}
|
||||
function url_to_wiki_title (href) {
|
||||
href = strip_fragment(href);
|
||||
var m = URLPAT.exec(href);
|
||||
if (m !== null) {
|
||||
return decodeURI(m[1]).replace(/_/g, " ");
|
||||
}
|
||||
console.log("m", m);
|
||||
}
|
||||
function wiki_title_to_url (title) {
|
||||
return "http://localhost/mw/index.php/"+encodeURI(title.replace(/ /g, "_"));
|
||||
}
|
||||
// window.addEventListener("DOMContentLoaded", doload);
|
||||
button.addEventListener("click", doload);
|
||||
iframe.addEventListener("load", function () {
|
||||
var href = strip_fragment(iframe.contentWindow.location.href);
|
||||
console.log("iframe loaded", href);
|
||||
var title = url_to_wiki_title(href);
|
||||
console.log("title", title);
|
||||
if (title) {
|
||||
map.set_active_title(title);
|
||||
}
|
||||
// attempt to map url to wiki page title and update the map if it is one
|
||||
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
@@ -1,73 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
#page {
|
||||
position: absolute;
|
||||
left: 0; right: 0; top: 0;
|
||||
height: 160vh;
|
||||
text-align: center;
|
||||
background: gray;
|
||||
}
|
||||
#page.touched {
|
||||
background: #444;
|
||||
}
|
||||
#bottompane {
|
||||
position: absolute;
|
||||
top: 60vh;
|
||||
left: 0; right: 0;
|
||||
height: 100vh;
|
||||
z-index: 2;
|
||||
}
|
||||
#bottompane iframe {
|
||||
border: none;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
height: 100%;
|
||||
background: white;
|
||||
}
|
||||
#debug {
|
||||
font-size: 10px;
|
||||
height: 8em;
|
||||
overflow: auto;
|
||||
}
|
||||
#cats {
|
||||
display: none;
|
||||
}
|
||||
iframe#svg {
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<iframe id="svg" src="map.html"></iframe>
|
||||
<div id="bottompane">
|
||||
<iframe id="wikiframe" src="/mw"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
<div id="cats" class="expanded">
|
||||
<div class="ocontents">
|
||||
<div class="contents">
|
||||
<div class="head">Liste des catégories</div>
|
||||
<div class="body"></div>
|
||||
<div class="foot"><input id="allcats" type="checkbox"><label for="allcats">Afficher tous</label></div>
|
||||
<hr>
|
||||
<div class="history"><input id="history" type="checkbox"><label for="history">Histoire</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="botright"><div class="thumb"></div></div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="custom_scroller_iframe.js"></script>
|
||||
<script>
|
||||
custom_scroller_iframe(document.scrollingElement, document.getElementById("wikiframe"));
|
||||
</script>
|
||||
</html>
|
||||
@@ -36,7 +36,7 @@
|
||||
<div class="botright"><div class="thumb"></div></div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="custom_scroller_menu.js"></script>
|
||||
<script src="dist/custom_scroller_menu.js"></script>
|
||||
<script type="text/javascript" src="dist/app.js"></script>
|
||||
<script src="index.js"></script>
|
||||
<script src="dist/index.js"></script>
|
||||
</html>
|
||||
|
||||
127
index.js
127
index.js
@@ -1,127 +0,0 @@
|
||||
custom_scroller_menu(
|
||||
document.scrollingElement,
|
||||
document.getElementById("menubar"),
|
||||
document.getElementById("debug"));
|
||||
|
||||
var svg = document.querySelector("#svg"),
|
||||
iframe = document.querySelector("iframe#wikiframe"),
|
||||
cats = document.querySelector("#cats"),
|
||||
cats_contents = document.querySelector("#cats .body"),
|
||||
cats_thumb = document.querySelector("#cats .thumb"),
|
||||
allcatscb = document.querySelector("input#allcats"),
|
||||
historycb = document.querySelector("input#history"),
|
||||
current_title = null,
|
||||
loaded = false,
|
||||
wikibaseurl,
|
||||
wikibasepat;
|
||||
|
||||
|
||||
window.addEventListener("resize", resize);
|
||||
function resize() {
|
||||
var w = window,
|
||||
d = document,
|
||||
e = d.documentElement,
|
||||
g = d.getElementsByTagName('body')[0],
|
||||
x = w.innerWidth || e.clientWidth || g.clientWidth,
|
||||
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
|
||||
svg.setAttribute("width", x);
|
||||
svg.setAttribute("height", y);
|
||||
//console.log("resize", x, y);
|
||||
}
|
||||
resize();
|
||||
|
||||
// console.log("mediawikiapi", mediawikiapi);
|
||||
var symbols = {
|
||||
"Orientations": "symbols.svg#Orientations",
|
||||
"Ateliers pluridisciplinaires": "symbols.svg#Ateliers_pluridisciplinaires",
|
||||
"Cours de soutien à l'orientation": "symbols.svg#Cours_de_soutien_a_l'orientation",
|
||||
"Cours de soutien spécifique": "symbols.svg#Cours_de_soutien_specifique",
|
||||
"Cours techniques": "symbols.svg#Cours_techniques",
|
||||
"Cours théoriques": "symbols.svg#Cours_theoriques",
|
||||
"Enseignants": "symbols.svg#Enseignants",
|
||||
"default": "symbols.svg#Main"
|
||||
};
|
||||
var map = new app.Map(symbols);
|
||||
|
||||
map.init_svg("#svg");
|
||||
async function doload () {
|
||||
console.log("loading map");
|
||||
await map.load_json("sitemap.json");
|
||||
// console.log("loading categories");
|
||||
// await map.load_cats("cats.json", cats_contents);
|
||||
console.log("LOADED!");
|
||||
loaded = true;
|
||||
if (current_title) {
|
||||
map.set_active_title(current_title);
|
||||
}
|
||||
}
|
||||
|
||||
map.on("page", function (title) {
|
||||
console.log("map.page", title);
|
||||
var url = wiki_title_to_url(title);
|
||||
iframe.src = url;
|
||||
})
|
||||
// async function doload() {
|
||||
// map.set_active_node(startpage.value);
|
||||
// }
|
||||
|
||||
function strip_fragment (href) {
|
||||
var spos = href.indexOf("#");
|
||||
if (spos >= 0) {
|
||||
return href.substr(0, href.indexOf("#"))
|
||||
}
|
||||
return href;
|
||||
}
|
||||
function url_to_wiki_title (href) {
|
||||
href = strip_fragment(href);
|
||||
var m = wikibasepat.exec(href);
|
||||
if (m !== null) {
|
||||
return decodeURI(m[1]).replace(/_/g, " ");
|
||||
}
|
||||
console.log("m", m);
|
||||
}
|
||||
function wiki_title_to_url (title) {
|
||||
return wikibaseurl+encodeURI(title.replace(/ /g, "_"));
|
||||
}
|
||||
window.addEventListener("DOMContentLoaded", doload);
|
||||
function strip_title_from_wiki_url (url) {
|
||||
return url.substr(0, url.lastIndexOf("/")+1);
|
||||
}
|
||||
iframe.addEventListener("load", function () {
|
||||
var href = strip_fragment(iframe.contentWindow.location.href);
|
||||
if (!wikibaseurl) {
|
||||
wikibaseurl = strip_title_from_wiki_url(href);
|
||||
wikibasepat = new RegExp(wikibaseurl+"(.+)");
|
||||
}
|
||||
console.log("iframe loaded", href);
|
||||
var title = url_to_wiki_title(href);
|
||||
console.log("title", title);
|
||||
if (title) {
|
||||
current_title = title;
|
||||
if (loaded) {
|
||||
map.set_active_title(title);
|
||||
}
|
||||
}
|
||||
// attempt to map url to wiki page title and update the map if it is one
|
||||
|
||||
});
|
||||
|
||||
cats_thumb.addEventListener("click", function () {
|
||||
cats.classList.toggle("expanded");
|
||||
});
|
||||
// allcats checkbox
|
||||
// match current state & respond to change events
|
||||
// console.log("setting checked to", cats.classList.contains("showall"))
|
||||
allcatscb.checked = cats.classList.contains("showall");
|
||||
allcatscb.addEventListener("change", function () {
|
||||
// console.log("allcats", allcatscb);
|
||||
if (allcatscb.checked) {
|
||||
cats.classList.add("showall")
|
||||
} else {
|
||||
cats.classList.remove("showall")
|
||||
}
|
||||
})
|
||||
historycb.addEventListener("change", function () {
|
||||
// console.log("history", historycb.checked);
|
||||
map.set_show_history(historycb.checked);
|
||||
})
|
||||
@@ -1,54 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
#page {
|
||||
position: absolute;
|
||||
left: 0; right: 0; top: 0;
|
||||
height: 160vh;
|
||||
text-align: center;
|
||||
background: gray;
|
||||
}
|
||||
#page.touched {
|
||||
background: #444;
|
||||
}
|
||||
#bottompane {
|
||||
position: absolute;
|
||||
top: 60vh;
|
||||
left: 0; right: 0;
|
||||
height: 100vh;
|
||||
z-index: 2;
|
||||
}
|
||||
#bottompane iframe {
|
||||
border: none;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
height: 100%;
|
||||
background: white;
|
||||
}
|
||||
#debug {
|
||||
font-size: 10px;
|
||||
height: 8em;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<pre id="debug">debug:</pre>
|
||||
<div id="bottompane">
|
||||
<iframe id="wikiframe" src="/mw"></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="custom_scroller_iframe.js"></script>
|
||||
<script>
|
||||
custom_scroller_iframe(document.scrollingElement, document.getElementById("wikiframe"));
|
||||
</script>
|
||||
</html>
|
||||
140
map.html
140
map.html
@@ -1,140 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<style>
|
||||
svg {
|
||||
position: absolute;
|
||||
left: 0; top: 0;
|
||||
border: 1px solid aqua;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<svg id="svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript" src="dist/wikimaptotal.js"></script>
|
||||
<script>
|
||||
var svg = document.querySelector("#svg"),
|
||||
//iframe = document.querySelector("iframe#wikiframe"),
|
||||
// cats = document.querySelector("#cats"),
|
||||
//cats_contents = document.querySelector("#cats .body"),
|
||||
//cats_thumb = document.querySelector("#cats .thumb"),
|
||||
//allcatscb = document.querySelector("input#allcats"),
|
||||
//historycb = document.querySelector("input#history"),
|
||||
current_title = null,
|
||||
loaded = false;
|
||||
|
||||
|
||||
window.addEventListener("resize", resize);
|
||||
function resize() {
|
||||
var w = window,
|
||||
d = document,
|
||||
e = d.documentElement,
|
||||
g = d.getElementsByTagName('body')[0],
|
||||
x = w.innerWidth || e.clientWidth || g.clientWidth,
|
||||
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
|
||||
svg.setAttribute("width", x);
|
||||
svg.setAttribute("height", y);
|
||||
//console.log("resize", x, y);
|
||||
}
|
||||
resize();
|
||||
|
||||
// console.log("mediawikiapi", mediawikiapi);
|
||||
var symbols = {
|
||||
"Orientations": "symbols.svg#Orientations",
|
||||
"Ateliers pluridisciplinaires": "symbols.svg#Ateliers_pluridisciplinaires",
|
||||
"Cours de soutien à l'orientation": "symbols.svg#Cours_de_soutien_a_l'orientation",
|
||||
"Cours de soutien spécifique": "symbols.svg#Cours_de_soutien_specifique",
|
||||
"Cours techniques": "symbols.svg#Cours_techniques",
|
||||
"Cours théoriques": "symbols.svg#Cours_theoriques",
|
||||
"Enseignants": "symbols.svg#Enseignants",
|
||||
"default": "symbols.svg#Main"
|
||||
};
|
||||
var map = new wikimap.SimpleMap(symbols);
|
||||
|
||||
map.init_svg("#svg");
|
||||
async function doload () {
|
||||
console.log("loading map");
|
||||
await map.load_json("sitemap.json");
|
||||
return;
|
||||
console.log("loading categories");
|
||||
await map.load_cats("cats.json", cats_contents);
|
||||
console.log("LOADED!");
|
||||
loaded = true;
|
||||
if (current_title) {
|
||||
map.set_active_title(current_title);
|
||||
}
|
||||
}
|
||||
|
||||
map.on("page", function (title) {
|
||||
console.log("map.page", title);
|
||||
var url = wiki_title_to_url(title);
|
||||
// iframe.src = url;
|
||||
})
|
||||
// async function doload() {
|
||||
// map.set_active_node(startpage.value);
|
||||
// }
|
||||
var URLPAT = new RegExp("http://wiki.erg.be/mw/index.php/(.+)");
|
||||
function strip_fragment (href) {
|
||||
var spos = href.indexOf("#");
|
||||
if (spos >= 0) {
|
||||
return href.substr(0, href.indexOf("#"))
|
||||
}
|
||||
return href;
|
||||
}
|
||||
function url_to_wiki_title (href) {
|
||||
href = strip_fragment(href);
|
||||
var m = URLPAT.exec(href);
|
||||
if (m !== null) {
|
||||
return decodeURI(m[1]).replace(/_/g, " ");
|
||||
}
|
||||
console.log("m", m);
|
||||
}
|
||||
function wiki_title_to_url (title) {
|
||||
return "http://wiki.erg.be/mw/index.php/"+encodeURI(title.replace(/ /g, "_"));
|
||||
}
|
||||
window.addEventListener("DOMContentLoaded", doload);
|
||||
</script>
|
||||
<noscript>
|
||||
iframe.addEventListener("load", function () {
|
||||
var href = strip_fragment(iframe.contentWindow.location.href);
|
||||
console.log("iframe loaded", href);
|
||||
var title = url_to_wiki_title(href);
|
||||
console.log("title", title);
|
||||
if (title) {
|
||||
current_title = title;
|
||||
if (loaded) {
|
||||
map.set_active_title(title);
|
||||
}
|
||||
}
|
||||
// attempt to map url to wiki page title and update the map if it is one
|
||||
|
||||
});
|
||||
|
||||
cats_thumb.addEventListener("click", function () {
|
||||
cats.classList.toggle("expanded");
|
||||
});
|
||||
// allcats checkbox
|
||||
// match current state & respond to change events
|
||||
// console.log("setting checked to", cats.classList.contains("showall"))
|
||||
allcatscb.checked = cats.classList.contains("showall");
|
||||
allcatscb.addEventListener("change", function () {
|
||||
// console.log("allcats", allcatscb);
|
||||
if (allcatscb.checked) {
|
||||
cats.classList.add("showall")
|
||||
} else {
|
||||
cats.classList.remove("showall")
|
||||
}
|
||||
})
|
||||
historycb.addEventListener("change", function () {
|
||||
// console.log("history", historycb.checked);
|
||||
map.set_show_history(historycb.checked);
|
||||
})
|
||||
</noscript>
|
||||
</html>
|
||||
Reference in New Issue
Block a user