(function(){ version.extensions['timedloopMacro'] = { major: 1, minor: 0, revision: 0 }; macros['timedloop'] = { handler: function (g, e, f, b) { function tagcontents(starttag, endtag, k) { var a = b.source.slice(k); var l = 0; var c = ""; for (var i = 0; i < a.length; i++) { var w = endtag.length; if (a.substr(i, w) == endtag) { if (l == 0) { b.nextMatch = k + i + w; return c; } else { l--; c += a.charAt(i); } } else { if (a.substr(i, starttag.length) == starttag) { l++; } c += a.charAt(i); } } return ""; } var tl = "<<"+e; var etl = "<>"; var k = b.source.indexOf('>>', b.matchStart) + 2; var d = tagcontents(tl,etl,k); var tm; tm = (parseInt(f[0]) || 0) * 500; var h; if (d) { var m = insertElement(g, "span", null, "timedloop", null); new Wikifier(m,d); var s=state.history[0].passage.title; setTimeout(function to() { if (m && state.history[0].passage.title==s) { var oldm = m; oldm.classList.add("replacement-out"); setTimeout(function () { if (oldm) oldm.parentNode.removeChild(oldm); }, Math.min(tm,1000)); m = insertElement(null, "span", null, "timedloop replacement-in", null); new Wikifier(m,d); setTimeout(function () { if (m) m.classList.remove("replacement-in"); }, 1); oldm.parentNode.insertBefore(m,oldm.nextSibling); scrollWindowTo(m); setTimeout(to,tm); } }, tm); } else { throwError(g, "can't find matching end"+e); return; } } } macros['endtimedloop'] = { handler: function () {} } scrollWindowTo = function(E) { var D = window.scrollY ? window.scrollY : document.body.scrollTop; var G = J(E); if (!G) return; var C = Math.abs(D - G); var B = 0; var I = (D > G) ? -1 : 1; var F = window.setInterval(H, 25); function H() { B += 0.1; window.scrollTo(0, D + I * (C * Math.easeInOut(B))); if(B >= 1) { window.clearInterval(F) } } function J(N) { var O = A(N); var P = O + N.offsetHeight; var K = window.scrollY ? window.scrollY : document.body.scrollTop; var L = window.innerHeight ? window.innerHeight : document.body.clientHeight; var M = K + L; if(O >= K) { if(P > M) { if(N.offsetHeight < L) { return (O - (L - N.offsetHeight) + 20) } else { return O; } } } } function A(K) { var L = 0; while(K.offsetParent) { L += K.offsetTop; K = K.offsetParent; } return L } } }());