From 8e63663f8854f17bcafc358510e697c9552e6453 Mon Sep 17 00:00:00 2001
From: David Thompson
Date: Fri, 20 Mar 2015 17:52:06 -0400
Subject: [PATCH] Add crazy streaming JS at the last minute! holy crap!
---
2015/assets/js/mithril.js | 1024 +++++++++++++++++++++++++
2015/assets/js/mithril.min.js | 8 +
2015/assets/js/mithril.min.js.map | 1 +
2015/assets/js/stream.js | 270 +++++--
2015/live/index.html | 23 +-
server/2015/footer.html | 13 +-
server/staging/lp15/live_sidebar.html | 5 +-
server/staging/lp15/weblabels.html | 26 +-
8 files changed, 1292 insertions(+), 78 deletions(-)
create mode 100644 2015/assets/js/mithril.js
create mode 100644 2015/assets/js/mithril.min.js
create mode 100644 2015/assets/js/mithril.min.js.map
diff --git a/2015/assets/js/mithril.js b/2015/assets/js/mithril.js
new file mode 100644
index 00000000..29082ca9
--- /dev/null
+++ b/2015/assets/js/mithril.js
@@ -0,0 +1,1024 @@
+var m = (function app(window, undefined) {
+ var OBJECT = "[object Object]", ARRAY = "[object Array]", STRING = "[object String]", FUNCTION = "function";
+ var type = {}.toString;
+ var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/;
+ var voidElements = /^(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR)$/;
+
+ // caching commonly used variables
+ var $document, $location, $requestAnimationFrame, $cancelAnimationFrame;
+
+ // self invoking function needed because of the way mocks work
+ function initialize(window){
+ $document = window.document;
+ $location = window.location;
+ $cancelAnimationFrame = window.cancelAnimationFrame || window.clearTimeout;
+ $requestAnimationFrame = window.requestAnimationFrame || window.setTimeout;
+ }
+
+ initialize(window);
+
+
+ /**
+ * @typedef {String} Tag
+ * A string that looks like -> div.classname#id[param=one][param2=two]
+ * Which describes a DOM node
+ */
+
+ /**
+ *
+ * @param {Tag} The DOM node tag
+ * @param {Object=[]} optional key-value pairs to be mapped to DOM attrs
+ * @param {...mNode=[]} Zero or more Mithril child nodes. Can be an array, or splat (optional)
+ *
+ */
+ function m() {
+ var args = [].slice.call(arguments);
+ var hasAttrs = args[1] != null && type.call(args[1]) === OBJECT && !("tag" in args[1]) && !("subtree" in args[1]);
+ var attrs = hasAttrs ? args[1] : {};
+ var classAttrName = "class" in attrs ? "class" : "className";
+ var cell = {tag: "div", attrs: {}};
+ var match, classes = [];
+ if (type.call(args[0]) != STRING) throw new Error("selector in m(selector, attrs, children) should be a string")
+ while (match = parser.exec(args[0])) {
+ if (match[1] === "" && match[2]) cell.tag = match[2];
+ else if (match[1] === "#") cell.attrs.id = match[2];
+ else if (match[1] === ".") classes.push(match[2]);
+ else if (match[3][0] === "[") {
+ var pair = attrParser.exec(match[3]);
+ cell.attrs[pair[1]] = pair[3] || (pair[2] ? "" :true)
+ }
+ }
+ if (classes.length > 0) cell.attrs[classAttrName] = classes.join(" ");
+
+
+ var children = hasAttrs ? args[2] : args[1];
+ if (type.call(children) === ARRAY) {
+ cell.children = children
+ }
+ else {
+ cell.children = hasAttrs ? args.slice(2) : args.slice(1)
+ }
+
+ for (var attrName in attrs) {
+ if (attrName === classAttrName) {
+ if (attrs[attrName] !== "") cell.attrs[attrName] = (cell.attrs[attrName] || "") + " " + attrs[attrName];
+ }
+ else cell.attrs[attrName] = attrs[attrName]
+ }
+ return cell
+ }
+ function build(parentElement, parentTag, parentCache, parentIndex, data, cached, shouldReattach, index, editable, namespace, configs) {
+ //`build` is a recursive function that manages creation/diffing/removal of DOM elements based on comparison between `data` and `cached`
+ //the diff algorithm can be summarized as this:
+ //1 - compare `data` and `cached`
+ //2 - if they are different, copy `data` to `cached` and update the DOM based on what the difference is
+ //3 - recursively apply this algorithm for every array and for the children of every virtual element
+
+ //the `cached` data structure is essentially the same as the previous redraw's `data` data structure, with a few additions:
+ //- `cached` always has a property called `nodes`, which is a list of DOM elements that correspond to the data represented by the respective virtual element
+ //- in order to support attaching `nodes` as a property of `cached`, `cached` is *always* a non-primitive object, i.e. if the data was a string, then cached is a String instance. If data was `null` or `undefined`, cached is `new String("")`
+ //- `cached also has a `configContext` property, which is the state storage object exposed by config(element, isInitialized, context)
+ //- when `cached` is an Object, it represents a virtual element; when it's an Array, it represents a list of elements; when it's a String, Number or Boolean, it represents a text node
+
+ //`parentElement` is a DOM element used for W3C DOM API calls
+ //`parentTag` is only used for handling a corner case for textarea values
+ //`parentCache` is used to remove nodes in some multi-node cases
+ //`parentIndex` and `index` are used to figure out the offset of nodes. They're artifacts from before arrays started being flattened and are likely refactorable
+ //`data` and `cached` are, respectively, the new and old nodes being diffed
+ //`shouldReattach` is a flag indicating whether a parent node was recreated (if so, and if this node is reused, then this node must reattach itself to the new parent)
+ //`editable` is a flag that indicates whether an ancestor is contenteditable
+ //`namespace` indicates the closest HTML namespace as it cascades down from an ancestor
+ //`configs` is a list of config functions to run after the topmost `build` call finishes running
+
+ //there's logic that relies on the assumption that null and undefined data are equivalent to empty strings
+ //- this prevents lifecycle surprises from procedural helpers that mix implicit and explicit return statements (e.g. function foo() {if (cond) return m("div")}
+ //- it simplifies diffing code
+ //data.toString() is null if data is the return value of Console.log in Firefox
+ if (data == null || data.toString() == null) data = "";
+ if (data.subtree === "retain") return cached;
+ var cachedType = type.call(cached), dataType = type.call(data);
+ if (cached == null || cachedType !== dataType) {
+ if (cached != null) {
+ if (parentCache && parentCache.nodes) {
+ var offset = index - parentIndex;
+ var end = offset + (dataType === ARRAY ? data : cached.nodes).length;
+ clear(parentCache.nodes.slice(offset, end), parentCache.slice(offset, end))
+ }
+ else if (cached.nodes) clear(cached.nodes, cached)
+ }
+ cached = new data.constructor;
+ if (cached.tag) cached = {}; //if constructor creates a virtual dom element, use a blank object as the base cached node instead of copying the virtual el (#277)
+ cached.nodes = []
+ }
+
+ if (dataType === ARRAY) {
+ //recursively flatten array
+ for (var i = 0, len = data.length; i < len; i++) {
+ if (type.call(data[i]) === ARRAY) {
+ data = data.concat.apply([], data);
+ i-- //check current index again and flatten until there are no more nested arrays at that index
+ }
+ }
+
+ var nodes = [], intact = cached.length === data.length, subArrayCount = 0;
+
+ //keys algorithm: sort elements without recreating them if keys are present
+ //1) create a map of all existing keys, and mark all for deletion
+ //2) add new keys to map and mark them for addition
+ //3) if key exists in new list, change action from deletion to a move
+ //4) for each key, handle its corresponding action as marked in previous steps
+ //5) copy unkeyed items into their respective gaps
+ var DELETION = 1, INSERTION = 2 , MOVE = 3;
+ var existing = {}, unkeyed = [], shouldMaintainIdentities = false;
+ for (var i = 0; i < cached.length; i++) {
+ if (cached[i] && cached[i].attrs && cached[i].attrs.key != null) {
+ shouldMaintainIdentities = true;
+ existing[cached[i].attrs.key] = {action: DELETION, index: i}
+ }
+ }
+ if (shouldMaintainIdentities) {
+ if (data.indexOf(null) > -1) data = data.filter(function(x) {return x != null})
+
+ var keysDiffer = false
+ if (data.length != cached.length) keysDiffer = true
+ else for (var i = 0, cachedCell, dataCell; cachedCell = cached[i], dataCell = data[i]; i++) {
+ if (cachedCell.attrs && dataCell.attrs && cachedCell.attrs.key != dataCell.attrs.key) {
+ keysDiffer = true
+ break
+ }
+ }
+
+ if (keysDiffer) {
+ for (var i = 0, len = data.length; i < len; i++) {
+ if (data[i] && data[i].attrs) {
+ if (data[i].attrs.key != null) {
+ var key = data[i].attrs.key;
+ if (!existing[key]) existing[key] = {action: INSERTION, index: i};
+ else existing[key] = {
+ action: MOVE,
+ index: i,
+ from: existing[key].index,
+ element: cached.nodes[existing[key].index] || $document.createElement("div")
+ }
+ }
+ else unkeyed.push({index: i, element: parentElement.childNodes[i] || $document.createElement("div")})
+ }
+ }
+ var actions = []
+ for (var prop in existing) actions.push(existing[prop])
+ var changes = actions.sort(sortChanges);
+ var newCached = new Array(cached.length)
+
+ for (var i = 0, change; change = changes[i]; i++) {
+ if (change.action === DELETION) {
+ clear(cached[change.index].nodes, cached[change.index]);
+ newCached.splice(change.index, 1)
+ }
+ if (change.action === INSERTION) {
+ var dummy = $document.createElement("div");
+ dummy.key = data[change.index].attrs.key;
+ parentElement.insertBefore(dummy, parentElement.childNodes[change.index] || null);
+ newCached.splice(change.index, 0, {attrs: {key: data[change.index].attrs.key}, nodes: [dummy]})
+ }
+
+ if (change.action === MOVE) {
+ if (parentElement.childNodes[change.index] !== change.element && change.element !== null) {
+ parentElement.insertBefore(change.element, parentElement.childNodes[change.index] || null)
+ }
+ newCached[change.index] = cached[change.from]
+ }
+ }
+ for (var i = 0, len = unkeyed.length; i < len; i++) {
+ var change = unkeyed[i];
+ parentElement.insertBefore(change.element, parentElement.childNodes[change.index] || null);
+ newCached[change.index] = cached[change.index]
+ }
+ cached = newCached;
+ cached.nodes = new Array(parentElement.childNodes.length);
+ for (var i = 0, child; child = parentElement.childNodes[i]; i++) cached.nodes[i] = child
+ }
+ }
+ //end key algorithm
+
+ for (var i = 0, cacheCount = 0, len = data.length; i < len; i++) {
+ //diff each item in the array
+ var item = build(parentElement, parentTag, cached, index, data[i], cached[cacheCount], shouldReattach, index + subArrayCount || subArrayCount, editable, namespace, configs);
+ if (item === undefined) continue;
+ if (!item.nodes.intact) intact = false;
+ if (item.$trusted) {
+ //fix offset of next element if item was a trusted string w/ more than one html element
+ //the first clause in the regexp matches elements
+ //the second clause (after the pipe) matches text nodes
+ subArrayCount += (item.match(/<[^\/]|\>\s*[^<]/g) || []).length
+ }
+ else subArrayCount += type.call(item) === ARRAY ? item.length : 1;
+ cached[cacheCount++] = item
+ }
+ if (!intact) {
+ //diff the array itself
+
+ //update the list of DOM nodes by collecting the nodes from each item
+ for (var i = 0, len = data.length; i < len; i++) {
+ if (cached[i] != null) nodes.push.apply(nodes, cached[i].nodes)
+ }
+ //remove items from the end of the array if the new array is shorter than the old one
+ //if errors ever happen here, the issue is most likely a bug in the construction of the `cached` data structure somewhere earlier in the program
+ for (var i = 0, node; node = cached.nodes[i]; i++) {
+ if (node.parentNode != null && nodes.indexOf(node) < 0) clear([node], [cached[i]])
+ }
+ if (data.length < cached.length) cached.length = data.length;
+ cached.nodes = nodes
+ }
+ }
+ else if (data != null && dataType === OBJECT) {
+ if (!data.attrs) data.attrs = {};
+ if (!cached.attrs) cached.attrs = {};
+
+ var dataAttrKeys = Object.keys(data.attrs)
+ var hasKeys = dataAttrKeys.length > ("key" in data.attrs ? 1 : 0)
+ //if an element is different enough from the one in cache, recreate it
+ if (data.tag != cached.tag || dataAttrKeys.join() != Object.keys(cached.attrs).join() || data.attrs.id != cached.attrs.id) {
+ if (cached.nodes.length) clear(cached.nodes);
+ if (cached.configContext && typeof cached.configContext.onunload === FUNCTION) cached.configContext.onunload()
+ }
+ if (type.call(data.tag) != STRING) return;
+
+ var node, isNew = cached.nodes.length === 0;
+ if (data.attrs.xmlns) namespace = data.attrs.xmlns;
+ else if (data.tag === "svg") namespace = "http://www.w3.org/2000/svg";
+ else if (data.tag === "math") namespace = "http://www.w3.org/1998/Math/MathML";
+ if (isNew) {
+ if (data.attrs.is) node = namespace === undefined ? $document.createElement(data.tag, data.attrs.is) : $document.createElementNS(namespace, data.tag, data.attrs.is);
+ else node = namespace === undefined ? $document.createElement(data.tag) : $document.createElementNS(namespace, data.tag);
+ cached = {
+ tag: data.tag,
+ //set attributes first, then create children
+ attrs: hasKeys ? setAttributes(node, data.tag, data.attrs, {}, namespace) : data.attrs,
+ children: data.children != null && data.children.length > 0 ?
+ build(node, data.tag, undefined, undefined, data.children, cached.children, true, 0, data.attrs.contenteditable ? node : editable, namespace, configs) :
+ data.children,
+ nodes: [node]
+ };
+ if (cached.children && !cached.children.nodes) cached.children.nodes = [];
+ //edge case: setting value on doesn't work before children exist, so set it again after children have been created
+ if (data.tag === "select" && data.attrs.value) setAttributes(node, data.tag, {value: data.attrs.value}, {}, namespace);
+ parentElement.insertBefore(node, parentElement.childNodes[index] || null)
+ }
+ else {
+ node = cached.nodes[0];
+ if (hasKeys) setAttributes(node, data.tag, data.attrs, cached.attrs, namespace);
+ cached.children = build(node, data.tag, undefined, undefined, data.children, cached.children, false, 0, data.attrs.contenteditable ? node : editable, namespace, configs);
+ cached.nodes.intact = true;
+ if (shouldReattach === true && node != null) parentElement.insertBefore(node, parentElement.childNodes[index] || null)
+ }
+ //schedule configs to be called. They are called after `build` finishes running
+ if (typeof data.attrs["config"] === FUNCTION) {
+ var context = cached.configContext = cached.configContext || {};
+
+ // bind
+ var callback = function(data, args) {
+ return function() {
+ return data.attrs["config"].apply(data, args)
+ }
+ };
+ configs.push(callback(data, [node, !isNew, context, cached]))
+ }
+ }
+ else if (typeof dataType != FUNCTION) {
+ //handle text nodes
+ var nodes;
+ if (cached.nodes.length === 0) {
+ if (data.$trusted) {
+ nodes = injectHTML(parentElement, index, data)
+ }
+ else {
+ nodes = [$document.createTextNode(data)];
+ if (!parentElement.nodeName.match(voidElements)) parentElement.insertBefore(nodes[0], parentElement.childNodes[index] || null)
+ }
+ cached = "string number boolean".indexOf(typeof data) > -1 ? new data.constructor(data) : data;
+ cached.nodes = nodes
+ }
+ else if (cached.valueOf() !== data.valueOf() || shouldReattach === true) {
+ nodes = cached.nodes;
+ if (!editable || editable !== $document.activeElement) {
+ if (data.$trusted) {
+ clear(nodes, cached);
+ nodes = injectHTML(parentElement, index, data)
+ }
+ else {
+ //corner case: replacing the nodeValue of a text node that is a child of a textarea/contenteditable doesn't work
+ //we need to update the value property of the parent textarea or the innerHTML of the contenteditable element instead
+ if (parentTag === "textarea") parentElement.value = data;
+ else if (editable) editable.innerHTML = data;
+ else {
+ if (nodes[0].nodeType === 1 || nodes.length > 1) { //was a trusted string
+ clear(cached.nodes, cached);
+ nodes = [$document.createTextNode(data)]
+ }
+ parentElement.insertBefore(nodes[0], parentElement.childNodes[index] || null);
+ nodes[0].nodeValue = data
+ }
+ }
+ }
+ cached = new data.constructor(data);
+ cached.nodes = nodes
+ }
+ else cached.nodes.intact = true
+ }
+
+ return cached
+ }
+ function sortChanges(a, b) {return a.action - b.action || a.index - b.index}
+ function setAttributes(node, tag, dataAttrs, cachedAttrs, namespace) {
+ for (var attrName in dataAttrs) {
+ var dataAttr = dataAttrs[attrName];
+ var cachedAttr = cachedAttrs[attrName];
+ if (!(attrName in cachedAttrs) || (cachedAttr !== dataAttr)) {
+ cachedAttrs[attrName] = dataAttr;
+ try {
+ //`config` isn't a real attributes, so ignore it
+ if (attrName === "config" || attrName == "key") continue;
+ //hook event handlers to the auto-redrawing system
+ else if (typeof dataAttr === FUNCTION && attrName.indexOf("on") === 0) {
+ node[attrName] = autoredraw(dataAttr, node)
+ }
+ //handle `style: {...}`
+ else if (attrName === "style" && dataAttr != null && type.call(dataAttr) === OBJECT) {
+ for (var rule in dataAttr) {
+ if (cachedAttr == null || cachedAttr[rule] !== dataAttr[rule]) node.style[rule] = dataAttr[rule]
+ }
+ for (var rule in cachedAttr) {
+ if (!(rule in dataAttr)) node.style[rule] = ""
+ }
+ }
+ //handle SVG
+ else if (namespace != null) {
+ if (attrName === "href") node.setAttributeNS("http://www.w3.org/1999/xlink", "href", dataAttr);
+ else if (attrName === "className") node.setAttribute("class", dataAttr);
+ else node.setAttribute(attrName, dataAttr)
+ }
+ //handle cases that are properties (but ignore cases where we should use setAttribute instead)
+ //- list and form are typically used as strings, but are DOM element references in js
+ //- when using CSS selectors (e.g. `m("[style='']")`), style is used as a string, but it's an object in js
+ else if (attrName in node && !(attrName === "list" || attrName === "style" || attrName === "form" || attrName === "type")) {
+ //#348 don't set the value if not needed otherwise cursor placement breaks in Chrome
+ if (tag !== "input" || node[attrName] !== dataAttr) node[attrName] = dataAttr
+ }
+ else node.setAttribute(attrName, dataAttr)
+ }
+ catch (e) {
+ //swallow IE's invalid argument errors to mimic HTML's fallback-to-doing-nothing-on-invalid-attributes behavior
+ if (e.message.indexOf("Invalid argument") < 0) throw e
+ }
+ }
+ //#348 dataAttr may not be a string, so use loose comparison (double equal) instead of strict (triple equal)
+ else if (attrName === "value" && tag === "input" && node.value != dataAttr) {
+ node.value = dataAttr
+ }
+ }
+ return cachedAttrs
+ }
+ function clear(nodes, cached) {
+ for (var i = nodes.length - 1; i > -1; i--) {
+ if (nodes[i] && nodes[i].parentNode) {
+ try {nodes[i].parentNode.removeChild(nodes[i])}
+ catch (e) {} //ignore if this fails due to order of events (see http://stackoverflow.com/questions/21926083/failed-to-execute-removechild-on-node)
+ cached = [].concat(cached);
+ if (cached[i]) unload(cached[i])
+ }
+ }
+ if (nodes.length != 0) nodes.length = 0
+ }
+ function unload(cached) {
+ if (cached.configContext && typeof cached.configContext.onunload === FUNCTION) cached.configContext.onunload();
+ if (cached.children) {
+ if (type.call(cached.children) === ARRAY) {
+ for (var i = 0, child; child = cached.children[i]; i++) unload(child)
+ }
+ else if (cached.children.tag) unload(cached.children)
+ }
+ }
+ function injectHTML(parentElement, index, data) {
+ var nextSibling = parentElement.childNodes[index];
+ if (nextSibling) {
+ var isElement = nextSibling.nodeType != 1;
+ var placeholder = $document.createElement("span");
+ if (isElement) {
+ parentElement.insertBefore(placeholder, nextSibling || null);
+ placeholder.insertAdjacentHTML("beforebegin", data);
+ parentElement.removeChild(placeholder)
+ }
+ else nextSibling.insertAdjacentHTML("beforebegin", data)
+ }
+ else parentElement.insertAdjacentHTML("beforeend", data);
+ var nodes = [];
+ while (parentElement.childNodes[index] !== nextSibling) {
+ nodes.push(parentElement.childNodes[index]);
+ index++
+ }
+ return nodes
+ }
+ function autoredraw(callback, object) {
+ return function(e) {
+ e = e || event;
+ m.redraw.strategy("diff");
+ m.startComputation();
+ try {return callback.call(object, e)}
+ finally {
+ endFirstComputation()
+ }
+ }
+ }
+
+ var html;
+ var documentNode = {
+ appendChild: function(node) {
+ if (html === undefined) html = $document.createElement("html");
+ if ($document.documentElement && $document.documentElement !== node) {
+ $document.replaceChild(node, $document.documentElement)
+ }
+ else $document.appendChild(node);
+ this.childNodes = $document.childNodes
+ },
+ insertBefore: function(node) {
+ this.appendChild(node)
+ },
+ childNodes: []
+ };
+ var nodeCache = [], cellCache = {};
+ m.render = function(root, cell, forceRecreation) {
+ var configs = [];
+ if (!root) throw new Error("Please ensure the DOM element exists before rendering a template into it.");
+ var id = getCellCacheKey(root);
+ var isDocumentRoot = root === $document;
+ var node = isDocumentRoot || root === $document.documentElement ? documentNode : root;
+ if (isDocumentRoot && cell.tag != "html") cell = {tag: "html", attrs: {}, children: cell};
+ if (cellCache[id] === undefined) clear(node.childNodes);
+ if (forceRecreation === true) reset(root);
+ cellCache[id] = build(node, null, undefined, undefined, cell, cellCache[id], false, 0, null, undefined, configs);
+ for (var i = 0, len = configs.length; i < len; i++) configs[i]()
+ };
+ function getCellCacheKey(element) {
+ var index = nodeCache.indexOf(element);
+ return index < 0 ? nodeCache.push(element) - 1 : index
+ }
+
+ m.trust = function(value) {
+ value = new String(value);
+ value.$trusted = true;
+ return value
+ };
+
+ function gettersetter(store) {
+ var prop = function() {
+ if (arguments.length) store = arguments[0];
+ return store
+ };
+
+ prop.toJSON = function() {
+ return store
+ };
+
+ return prop
+ }
+
+ m.prop = function (store) {
+ //note: using non-strict equality check here because we're checking if store is null OR undefined
+ if (((store != null && type.call(store) === OBJECT) || typeof store === FUNCTION) && typeof store.then === FUNCTION) {
+ return propify(store)
+ }
+
+ return gettersetter(store)
+ };
+
+ var roots = [], modules = [], controllers = [], lastRedrawId = null, lastRedrawCallTime = 0, computePostRedrawHook = null, prevented = false, topModule;
+ var FRAME_BUDGET = 16; //60 frames per second = 1 call per 16 ms
+ m.module = function(root, module) {
+ if (!root) throw new Error("Please ensure the DOM element exists before rendering a template into it.");
+ var index = roots.indexOf(root);
+ if (index < 0) index = roots.length;
+ var isPrevented = false;
+ if (controllers[index] && typeof controllers[index].onunload === FUNCTION) {
+ var event = {
+ preventDefault: function() {isPrevented = true}
+ };
+ controllers[index].onunload(event)
+ }
+ if (!isPrevented) {
+ m.redraw.strategy("all");
+ m.startComputation();
+ roots[index] = root;
+ var currentModule = topModule = module = module || {};
+ var controller = new (module.controller || function() {});
+ //controllers may call m.module recursively (via m.route redirects, for example)
+ //this conditional ensures only the last recursive m.module call is applied
+ if (currentModule === topModule) {
+ controllers[index] = controller;
+ modules[index] = module
+ }
+ endFirstComputation();
+ return controllers[index]
+ }
+ };
+ m.redraw = function(force) {
+ //lastRedrawId is a positive number if a second redraw is requested before the next animation frame
+ //lastRedrawID is null if it's the first redraw and not an event handler
+ if (lastRedrawId && force !== true) {
+ //when setTimeout: only reschedule redraw if time between now and previous redraw is bigger than a frame, otherwise keep currently scheduled timeout
+ //when rAF: always reschedule redraw
+ if (new Date - lastRedrawCallTime > FRAME_BUDGET || $requestAnimationFrame === window.requestAnimationFrame) {
+ if (lastRedrawId > 0) $cancelAnimationFrame(lastRedrawId);
+ lastRedrawId = $requestAnimationFrame(redraw, FRAME_BUDGET)
+ }
+ }
+ else {
+ redraw();
+ lastRedrawId = $requestAnimationFrame(function() {lastRedrawId = null}, FRAME_BUDGET)
+ }
+ };
+ m.redraw.strategy = m.prop();
+ var blank = function() {return ""}
+ function redraw() {
+ var forceRedraw = m.redraw.strategy() === "all";
+ for (var i = 0, root; root = roots[i]; i++) {
+ if (controllers[i]) {
+ m.render(root, modules[i].view ? modules[i].view(controllers[i]) : blank(), forceRedraw)
+ }
+ }
+ //after rendering within a routed context, we need to scroll back to the top, and fetch the document title for history.pushState
+ if (computePostRedrawHook) {
+ computePostRedrawHook();
+ computePostRedrawHook = null
+ }
+ lastRedrawId = null;
+ lastRedrawCallTime = new Date;
+ m.redraw.strategy("diff")
+ }
+
+ var pendingRequests = 0;
+ m.startComputation = function() {pendingRequests++};
+ m.endComputation = function() {
+ pendingRequests = Math.max(pendingRequests - 1, 0);
+ if (pendingRequests === 0) m.redraw()
+ };
+ var endFirstComputation = function() {
+ if (m.redraw.strategy() == "none") {
+ pendingRequests--
+ m.redraw.strategy("diff")
+ }
+ else m.endComputation();
+ }
+
+ m.withAttr = function(prop, withAttrCallback) {
+ return function(e) {
+ e = e || event;
+ var currentTarget = e.currentTarget || this;
+ withAttrCallback(prop in currentTarget ? currentTarget[prop] : currentTarget.getAttribute(prop))
+ }
+ };
+
+ //routing
+ var modes = {pathname: "", hash: "#", search: "?"};
+ var redirect = function() {}, routeParams, currentRoute;
+ m.route = function() {
+ //m.route()
+ if (arguments.length === 0) return currentRoute;
+ //m.route(el, defaultRoute, routes)
+ else if (arguments.length === 3 && type.call(arguments[1]) === STRING) {
+ var root = arguments[0], defaultRoute = arguments[1], router = arguments[2];
+ redirect = function(source) {
+ var path = currentRoute = normalizeRoute(source);
+ if (!routeByValue(root, router, path)) {
+ m.route(defaultRoute, true)
+ }
+ };
+ var listener = m.route.mode === "hash" ? "onhashchange" : "onpopstate";
+ window[listener] = function() {
+ var path = $location[m.route.mode]
+ if (m.route.mode === "pathname") path += $location.search
+ if (currentRoute != normalizeRoute(path)) {
+ redirect(path)
+ }
+ };
+ computePostRedrawHook = setScroll;
+ window[listener]()
+ }
+ //config: m.route
+ else if (arguments[0].addEventListener) {
+ var element = arguments[0];
+ var isInitialized = arguments[1];
+ var context = arguments[2];
+ element.href = (m.route.mode !== 'pathname' ? $location.pathname : '') + modes[m.route.mode] + this.attrs.href;
+ element.removeEventListener("click", routeUnobtrusive);
+ element.addEventListener("click", routeUnobtrusive)
+ }
+ //m.route(route, params)
+ else if (type.call(arguments[0]) === STRING) {
+ var oldRoute = currentRoute;
+ currentRoute = arguments[0];
+ var args = arguments[1] || {}
+ var queryIndex = currentRoute.indexOf("?")
+ var params = queryIndex > -1 ? parseQueryString(currentRoute.slice(queryIndex + 1)) : {}
+ for (var i in args) params[i] = args[i]
+ var querystring = buildQueryString(params)
+ var currentPath = queryIndex > -1 ? currentRoute.slice(0, queryIndex) : currentRoute
+ if (querystring) currentRoute = currentPath + (currentPath.indexOf("?") === -1 ? "?" : "&") + querystring;
+
+ var shouldReplaceHistoryEntry = (arguments.length === 3 ? arguments[2] : arguments[1]) === true || oldRoute === arguments[0];
+
+ if (window.history.pushState) {
+ computePostRedrawHook = function() {
+ window.history[shouldReplaceHistoryEntry ? "replaceState" : "pushState"](null, $document.title, modes[m.route.mode] + currentRoute);
+ setScroll()
+ };
+ redirect(modes[m.route.mode] + currentRoute)
+ }
+ else $location[m.route.mode] = currentRoute
+ }
+ };
+ m.route.param = function(key) {
+ if (!routeParams) throw new Error("You must call m.route(element, defaultRoute, routes) before calling m.route.param()")
+ return routeParams[key]
+ };
+ m.route.mode = "search";
+ function normalizeRoute(route) {
+ return route.slice(modes[m.route.mode].length)
+ }
+ function routeByValue(root, router, path) {
+ routeParams = {};
+
+ var queryStart = path.indexOf("?");
+ if (queryStart !== -1) {
+ routeParams = parseQueryString(path.substr(queryStart + 1, path.length));
+ path = path.substr(0, queryStart)
+ }
+
+ for (var route in router) {
+ if (route === path) {
+ m.module(root, router[route]);
+ return true
+ }
+
+ var matcher = new RegExp("^" + route.replace(/:[^\/]+?\.{3}/g, "(.*?)").replace(/:[^\/]+/g, "([^\\/]+)") + "\/?$");
+
+ if (matcher.test(path)) {
+ path.replace(matcher, function() {
+ var keys = route.match(/:[^\/]+/g) || [];
+ var values = [].slice.call(arguments, 1, -2);
+ for (var i = 0, len = keys.length; i < len; i++) routeParams[keys[i].replace(/:|\./g, "")] = decodeURIComponent(values[i])
+ m.module(root, router[route])
+ });
+ return true
+ }
+ }
+ }
+ function routeUnobtrusive(e) {
+ e = e || event;
+ if (e.ctrlKey || e.metaKey || e.which === 2) return;
+ if (e.preventDefault) e.preventDefault();
+ else e.returnValue = false;
+ var currentTarget = e.currentTarget || this;
+ var args = m.route.mode === "pathname" && currentTarget.search ? parseQueryString(currentTarget.search.slice(1)) : {};
+ m.route(currentTarget[m.route.mode].slice(modes[m.route.mode].length), args)
+ }
+ function setScroll() {
+ if (m.route.mode != "hash" && $location.hash) $location.hash = $location.hash;
+ else window.scrollTo(0, 0)
+ }
+ function buildQueryString(object, prefix) {
+ var str = [];
+ for(var prop in object) {
+ var key = prefix ? prefix + "[" + prop + "]" : prop, value = object[prop];
+ var valueType = type.call(value)
+ var pair = value != null && (valueType === OBJECT) ?
+ buildQueryString(value, key) :
+ valueType === ARRAY ?
+ value.map(function(item) {return encodeURIComponent(key + "[]") + "=" + encodeURIComponent(item)}).join("&") :
+ encodeURIComponent(key) + "=" + encodeURIComponent(value)
+ str.push(pair)
+ }
+ return str.join("&")
+ }
+
+ function parseQueryString(str) {
+ var pairs = str.split("&"), params = {};
+ for (var i = 0, len = pairs.length; i < len; i++) {
+ var pair = pairs[i].split("=");
+ params[decodeURIComponent(pair[0])] = pair[1] ? decodeURIComponent(pair[1]) : ""
+ }
+ return params
+ }
+ function reset(root) {
+ var cacheKey = getCellCacheKey(root);
+ clear(root.childNodes, cellCache[cacheKey]);
+ cellCache[cacheKey] = undefined
+ }
+
+ m.deferred = function () {
+ var deferred = new Deferred();
+ deferred.promise = propify(deferred.promise);
+ return deferred
+ };
+ function propify(promise) {
+ var prop = m.prop();
+ promise.then(prop);
+ prop.then = function(resolve, reject) {
+ return propify(promise.then(resolve, reject))
+ };
+ return prop
+ }
+ //Promiz.mithril.js | Zolmeister | MIT
+ //a modified version of Promiz.js, which does not conform to Promises/A+ for two reasons:
+ //1) `then` callbacks are called synchronously (because setTimeout is too slow, and the setImmediate polyfill is too big
+ //2) throwing subclasses of Error cause the error to be bubbled up instead of triggering rejection (because the spec does not account for the important use case of default browser error handling, i.e. message w/ line number)
+ function Deferred(successCallback, failureCallback) {
+ var RESOLVING = 1, REJECTING = 2, RESOLVED = 3, REJECTED = 4;
+ var self = this, state = 0, promiseValue = 0, next = [];
+
+ self["promise"] = {};
+
+ self["resolve"] = function(value) {
+ if (!state) {
+ promiseValue = value;
+ state = RESOLVING;
+
+ fire()
+ }
+ return this
+ };
+
+ self["reject"] = function(value) {
+ if (!state) {
+ promiseValue = value;
+ state = REJECTING;
+
+ fire()
+ }
+ return this
+ };
+
+ self.promise["then"] = function(successCallback, failureCallback) {
+ var deferred = new Deferred(successCallback, failureCallback);
+ if (state === RESOLVED) {
+ deferred.resolve(promiseValue)
+ }
+ else if (state === REJECTED) {
+ deferred.reject(promiseValue)
+ }
+ else {
+ next.push(deferred)
+ }
+ return deferred.promise
+ };
+
+ function finish(type) {
+ state = type || REJECTED;
+ next.map(function(deferred) {
+ state === RESOLVED && deferred.resolve(promiseValue) || deferred.reject(promiseValue)
+ })
+ }
+
+ function thennable(then, successCallback, failureCallback, notThennableCallback) {
+ if (((promiseValue != null && type.call(promiseValue) === OBJECT) || typeof promiseValue === FUNCTION) && typeof then === FUNCTION) {
+ try {
+ // count protects against abuse calls from spec checker
+ var count = 0;
+ then.call(promiseValue, function(value) {
+ if (count++) return;
+ promiseValue = value;
+ successCallback()
+ }, function (value) {
+ if (count++) return;
+ promiseValue = value;
+ failureCallback()
+ })
+ }
+ catch (e) {
+ m.deferred.onerror(e);
+ promiseValue = e;
+ failureCallback()
+ }
+ } else {
+ notThennableCallback()
+ }
+ }
+
+ function fire() {
+ // check if it's a thenable
+ var then;
+ try {
+ then = promiseValue && promiseValue.then
+ }
+ catch (e) {
+ m.deferred.onerror(e);
+ promiseValue = e;
+ state = REJECTING;
+ return fire()
+ }
+ thennable(then, function() {
+ state = RESOLVING;
+ fire()
+ }, function() {
+ state = REJECTING;
+ fire()
+ }, function() {
+ try {
+ if (state === RESOLVING && typeof successCallback === FUNCTION) {
+ promiseValue = successCallback(promiseValue)
+ }
+ else if (state === REJECTING && typeof failureCallback === "function") {
+ promiseValue = failureCallback(promiseValue);
+ state = RESOLVING
+ }
+ }
+ catch (e) {
+ m.deferred.onerror(e);
+ promiseValue = e;
+ return finish()
+ }
+
+ if (promiseValue === self) {
+ promiseValue = TypeError();
+ finish()
+ }
+ else {
+ thennable(then, function () {
+ finish(RESOLVED)
+ }, finish, function () {
+ finish(state === RESOLVING && RESOLVED)
+ })
+ }
+ })
+ }
+ }
+ m.deferred.onerror = function(e) {
+ if (type.call(e) === "[object Error]" && !e.constructor.toString().match(/ Error/)) throw e
+ };
+
+ m.sync = function(args) {
+ var method = "resolve";
+ function synchronizer(pos, resolved) {
+ return function(value) {
+ results[pos] = value;
+ if (!resolved) method = "reject";
+ if (--outstanding === 0) {
+ deferred.promise(results);
+ deferred[method](results)
+ }
+ return value
+ }
+ }
+
+ var deferred = m.deferred();
+ var outstanding = args.length;
+ var results = new Array(outstanding);
+ if (args.length > 0) {
+ for (var i = 0; i < args.length; i++) {
+ args[i].then(synchronizer(i, true), synchronizer(i, false))
+ }
+ }
+ else deferred.resolve([]);
+
+ return deferred.promise
+ };
+ function identity(value) {return value}
+
+ function ajax(options) {
+ if (options.dataType && options.dataType.toLowerCase() === "jsonp") {
+ var callbackKey = "mithril_callback_" + new Date().getTime() + "_" + (Math.round(Math.random() * 1e16)).toString(36);
+ var script = $document.createElement("script");
+
+ window[callbackKey] = function(resp) {
+ script.parentNode.removeChild(script);
+ options.onload({
+ type: "load",
+ target: {
+ responseText: resp
+ }
+ });
+ window[callbackKey] = undefined
+ };
+
+ script.onerror = function(e) {
+ script.parentNode.removeChild(script);
+
+ options.onerror({
+ type: "error",
+ target: {
+ status: 500,
+ responseText: JSON.stringify({error: "Error making jsonp request"})
+ }
+ });
+ window[callbackKey] = undefined;
+
+ return false
+ };
+
+ script.onload = function(e) {
+ return false
+ };
+
+ script.src = options.url
+ + (options.url.indexOf("?") > 0 ? "&" : "?")
+ + (options.callbackKey ? options.callbackKey : "callback")
+ + "=" + callbackKey
+ + "&" + buildQueryString(options.data || {});
+ $document.body.appendChild(script)
+ }
+ else {
+ var xhr = new window.XMLHttpRequest;
+ xhr.open(options.method, options.url, true, options.user, options.password);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState === 4) {
+ if (xhr.status >= 200 && xhr.status < 300) options.onload({type: "load", target: xhr});
+ else options.onerror({type: "error", target: xhr})
+ }
+ };
+ if (options.serialize === JSON.stringify && options.data && options.method !== "GET") {
+ xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8")
+ }
+ if (options.deserialize === JSON.parse) {
+ xhr.setRequestHeader("Accept", "application/json, text/*");
+ }
+ if (typeof options.config === FUNCTION) {
+ var maybeXhr = options.config(xhr, options);
+ if (maybeXhr != null) xhr = maybeXhr
+ }
+
+ var data = options.method === "GET" || !options.data ? "" : options.data
+ if (data && (type.call(data) != STRING && data.constructor != window.FormData)) {
+ throw "Request data should be either be a string or FormData. Check the `serialize` option in `m.request`";
+ }
+ xhr.send(data);
+ return xhr
+ }
+ }
+ function bindData(xhrOptions, data, serialize) {
+ if (xhrOptions.method === "GET" && xhrOptions.dataType != "jsonp") {
+ var prefix = xhrOptions.url.indexOf("?") < 0 ? "?" : "&";
+ var querystring = buildQueryString(data);
+ xhrOptions.url = xhrOptions.url + (querystring ? prefix + querystring : "")
+ }
+ else xhrOptions.data = serialize(data);
+ return xhrOptions
+ }
+ function parameterizeUrl(url, data) {
+ var tokens = url.match(/:[a-z]\w+/gi);
+ if (tokens && data) {
+ for (var i = 0; i < tokens.length; i++) {
+ var key = tokens[i].slice(1);
+ url = url.replace(tokens[i], data[key]);
+ delete data[key]
+ }
+ }
+ return url
+ }
+
+ m.request = function(xhrOptions) {
+ if (xhrOptions.background !== true) m.startComputation();
+ var deferred = m.deferred();
+ var isJSONP = xhrOptions.dataType && xhrOptions.dataType.toLowerCase() === "jsonp";
+ var serialize = xhrOptions.serialize = isJSONP ? identity : xhrOptions.serialize || JSON.stringify;
+ var deserialize = xhrOptions.deserialize = isJSONP ? identity : xhrOptions.deserialize || JSON.parse;
+ var extract = xhrOptions.extract || function(xhr) {
+ return xhr.responseText.length === 0 && deserialize === JSON.parse ? null : xhr.responseText
+ };
+ xhrOptions.url = parameterizeUrl(xhrOptions.url, xhrOptions.data);
+ xhrOptions = bindData(xhrOptions, xhrOptions.data, serialize);
+ xhrOptions.onload = xhrOptions.onerror = function(e) {
+ try {
+ e = e || event;
+ var unwrap = (e.type === "load" ? xhrOptions.unwrapSuccess : xhrOptions.unwrapError) || identity;
+ var response = unwrap(deserialize(extract(e.target, xhrOptions)));
+ if (e.type === "load") {
+ if (type.call(response) === ARRAY && xhrOptions.type) {
+ for (var i = 0; i < response.length; i++) response[i] = new xhrOptions.type(response[i])
+ }
+ else if (xhrOptions.type) response = new xhrOptions.type(response)
+ }
+ deferred[e.type === "load" ? "resolve" : "reject"](response)
+ }
+ catch (e) {
+ m.deferred.onerror(e);
+ deferred.reject(e)
+ }
+ if (xhrOptions.background !== true) m.endComputation()
+ };
+ ajax(xhrOptions);
+ deferred.promise(xhrOptions.initialValue);
+ return deferred.promise
+ };
+
+ //testing API
+ m.deps = function(mock) {
+ initialize(window = mock || window);
+ return window;
+ };
+ //for internal testing only, do not use `m.deps.factory`
+ m.deps.factory = app;
+
+ return m
+})(typeof window != "undefined" ? window : {});
+
+if (typeof module != "undefined" && module !== null && module.exports) module.exports = m;
+else if (typeof define === "function" && define.amd) define(function() {return m});
diff --git a/2015/assets/js/mithril.min.js b/2015/assets/js/mithril.min.js
new file mode 100644
index 00000000..b6d23fee
--- /dev/null
+++ b/2015/assets/js/mithril.min.js
@@ -0,0 +1,8 @@
+/*
+Mithril v0.1.30
+http://github.com/lhorie/mithril.js
+(c) Leo Horie
+License: MIT
+*/
+var m=function a(b,c){function d(a){C=a.document,D=a.location,F=a.cancelAnimationFrame||a.clearTimeout,E=a.requestAnimationFrame||a.setTimeout}function e(){var a,b=[].slice.call(arguments),c=!(null==b[1]||K.call(b[1])!==G||"tag"in b[1]||"subtree"in b[1]),d=c?b[1]:{},e="class"in d?"class":"className",f={tag:"div",attrs:{}},g=[];if(K.call(b[0])!=I)throw new Error("selector in m(selector, attrs, children) should be a string");for(;a=L.exec(b[0]);)if(""===a[1]&&a[2])f.tag=a[2];else if("#"===a[1])f.attrs.id=a[2];else if("."===a[1])g.push(a[2]);else if("["===a[3][0]){var h=M.exec(a[3]);f.attrs[h[1]]=h[3]||(h[2]?"":!0)}g.length>0&&(f.attrs[e]=g.join(" "));var i=c?b[2]:b[1];f.children=K.call(i)===H?i:b.slice(c?2:1);for(var j in d)j===e?""!==d[j]&&(f.attrs[j]=(f.attrs[j]||"")+" "+d[j]):f.attrs[j]=d[j];return f}function f(a,b,d,e,j,l,m,n,o,p,q){if((null==j||null==j.toString())&&(j=""),"retain"===j.subtree)return l;var r=K.call(l),s=K.call(j);if(null==l||r!==s){if(null!=l)if(d&&d.nodes){var t=n-e,u=t+(s===H?j:l.nodes).length;i(d.nodes.slice(t,u),d.slice(t,u))}else l.nodes&&i(l.nodes,l);l=new j.constructor,l.tag&&(l={}),l.nodes=[]}if(s===H){for(var v=0,w=j.length;w>v;v++)K.call(j[v])===H&&(j=j.concat.apply([],j),v--);for(var x=[],y=l.length===j.length,z=0,A=1,B=2,D=3,E={},F=[],L=!1,v=0;v-1&&(j=j.filter(function(a){return null!=a}));var M=!1;if(j.length!=l.length)M=!0;else for(var O,P,v=0;O=l[v],P=j[v];v++)if(O.attrs&&P.attrs&&O.attrs.key!=P.attrs.key){M=!0;break}if(M){for(var v=0,w=j.length;w>v;v++)if(j[v]&&j[v].attrs)if(null!=j[v].attrs.key){var Q=j[v].attrs.key;E[Q]=E[Q]?{action:D,index:v,from:E[Q].index,element:l.nodes[E[Q].index]||C.createElement("div")}:{action:B,index:v}}else F.push({index:v,element:a.childNodes[v]||C.createElement("div")});var R=[];for(var S in E)R.push(E[S]);for(var T,U=R.sort(g),V=new Array(l.length),v=0;T=U[v];v++){if(T.action===A&&(i(l[T.index].nodes,l[T.index]),V.splice(T.index,1)),T.action===B){var W=C.createElement("div");W.key=j[T.index].attrs.key,a.insertBefore(W,a.childNodes[T.index]||null),V.splice(T.index,0,{attrs:{key:j[T.index].attrs.key},nodes:[W]})}T.action===D&&(a.childNodes[T.index]!==T.element&&null!==T.element&&a.insertBefore(T.element,a.childNodes[T.index]||null),V[T.index]=l[T.from])}for(var v=0,w=F.length;w>v;v++){var T=F[v];a.insertBefore(T.element,a.childNodes[T.index]||null),V[T.index]=l[T.index]}l=V,l.nodes=new Array(a.childNodes.length);for(var X,v=0;X=a.childNodes[v];v++)l.nodes[v]=X}}for(var v=0,Y=0,w=j.length;w>v;v++){var Z=f(a,b,l,n,j[v],l[Y],m,n+z||z,o,p,q);Z!==c&&(Z.nodes.intact||(y=!1),z+=Z.$trusted?(Z.match(/<[^\/]|\>\s*[^<]/g)||[]).length:K.call(Z)===H?Z.length:1,l[Y++]=Z)}if(!y){for(var v=0,w=j.length;w>v;v++)null!=l[v]&&x.push.apply(x,l[v].nodes);for(var $,v=0;$=l.nodes[v];v++)null!=$.parentNode&&x.indexOf($)<0&&i([$],[l[v]]);j.length("key"in j.attrs?1:0);if((j.tag!=l.tag||_.join()!=Object.keys(l.attrs).join()||j.attrs.id!=l.attrs.id)&&(l.nodes.length&&i(l.nodes),l.configContext&&typeof l.configContext.onunload===J&&l.configContext.onunload()),K.call(j.tag)!=I)return;var $,bb=0===l.nodes.length;if(j.attrs.xmlns?p=j.attrs.xmlns:"svg"===j.tag?p="http://www.w3.org/2000/svg":"math"===j.tag&&(p="http://www.w3.org/1998/Math/MathML"),bb?($=j.attrs.is?p===c?C.createElement(j.tag,j.attrs.is):C.createElementNS(p,j.tag,j.attrs.is):p===c?C.createElement(j.tag):C.createElementNS(p,j.tag),l={tag:j.tag,attrs:ab?h($,j.tag,j.attrs,{},p):j.attrs,children:null!=j.children&&j.children.length>0?f($,j.tag,c,c,j.children,l.children,!0,0,j.attrs.contenteditable?$:o,p,q):j.children,nodes:[$]},l.children&&!l.children.nodes&&(l.children.nodes=[]),"select"===j.tag&&j.attrs.value&&h($,j.tag,{value:j.attrs.value},{},p),a.insertBefore($,a.childNodes[n]||null)):($=l.nodes[0],ab&&h($,j.tag,j.attrs,l.attrs,p),l.children=f($,j.tag,c,c,j.children,l.children,!1,0,j.attrs.contenteditable?$:o,p,q),l.nodes.intact=!0,m===!0&&null!=$&&a.insertBefore($,a.childNodes[n]||null)),typeof j.attrs.config===J){var cb=l.configContext=l.configContext||{},db=function(a,b){return function(){return a.attrs.config.apply(a,b)}};q.push(db(j,[$,!bb,cb,l]))}}else if(typeof s!=J){var x;0===l.nodes.length?(j.$trusted?x=k(a,n,j):(x=[C.createTextNode(j)],a.nodeName.match(N)||a.insertBefore(x[0],a.childNodes[n]||null)),l="string number boolean".indexOf(typeof j)>-1?new j.constructor(j):j,l.nodes=x):l.valueOf()!==j.valueOf()||m===!0?(x=l.nodes,o&&o===C.activeElement||(j.$trusted?(i(x,l),x=k(a,n,j)):"textarea"===b?a.value=j:o?o.innerHTML=j:((1===x[0].nodeType||x.length>1)&&(i(l.nodes,l),x=[C.createTextNode(j)]),a.insertBefore(x[0],a.childNodes[n]||null),x[0].nodeValue=j)),l=new j.constructor(j),l.nodes=x):l.nodes.intact=!0}return l}function g(a,b){return a.action-b.action||a.index-b.index}function h(a,b,c,d,e){for(var f in c){var g=c[f],h=d[f];if(f in d&&h===g)"value"===f&&"input"===b&&a.value!=g&&(a.value=g);else{d[f]=g;try{if("config"===f||"key"==f)continue;if(typeof g===J&&0===f.indexOf("on"))a[f]=l(g,a);else if("style"===f&&null!=g&&K.call(g)===G){for(var i in g)(null==h||h[i]!==g[i])&&(a.style[i]=g[i]);for(var i in h)i in g||(a.style[i]="")}else null!=e?"href"===f?a.setAttributeNS("http://www.w3.org/1999/xlink","href",g):"className"===f?a.setAttribute("class",g):a.setAttribute(f,g):f in a&&"list"!==f&&"style"!==f&&"form"!==f&&"type"!==f?("input"!==b||a[f]!==g)&&(a[f]=g):a.setAttribute(f,g)}catch(j){if(j.message.indexOf("Invalid argument")<0)throw j}}}return d}function i(a,b){for(var c=a.length-1;c>-1;c--)if(a[c]&&a[c].parentNode){try{a[c].parentNode.removeChild(a[c])}catch(d){}b=[].concat(b),b[c]&&j(b[c])}0!=a.length&&(a.length=0)}function j(a){if(a.configContext&&typeof a.configContext.onunload===J&&a.configContext.onunload(),a.children)if(K.call(a.children)===H)for(var b,c=0;b=a.children[c];c++)j(b);else a.children.tag&&j(a.children)}function k(a,b,c){var d=a.childNodes[b];if(d){var e=1!=d.nodeType,f=C.createElement("span");e?(a.insertBefore(f,d||null),f.insertAdjacentHTML("beforebegin",c),a.removeChild(f)):d.insertAdjacentHTML("beforebegin",c)}else a.insertAdjacentHTML("beforeend",c);for(var g=[];a.childNodes[b]!==d;)g.push(a.childNodes[b]),b++;return g}function l(a,b){return function(c){c=c||event,e.redraw.strategy("diff"),e.startComputation();try{return a.call(b,c)}finally{ab()}}}function m(a){var b=Q.indexOf(a);return 0>b?Q.push(a)-1:b}function n(a){var b=function(){return arguments.length&&(a=arguments[0]),a};return b.toJSON=function(){return a},b}function o(){for(var a,b="all"===e.redraw.strategy(),c=0;a=T[c];c++)V[c]&&e.render(a,U[c].view?U[c].view(V[c]):$(),b);Y&&(Y(),Y=null),W=null,X=new Date,e.redraw.strategy("diff")}function p(a){return a.slice(db[e.route.mode].length)}function q(a,b,c){bb={};var d=c.indexOf("?");-1!==d&&(bb=u(c.substr(d+1,c.length)),c=c.substr(0,d));for(var f in b){if(f===c)return e.module(a,b[f]),!0;var g=new RegExp("^"+f.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(g.test(c))return c.replace(g,function(){for(var c=f.match(/:[^\/]+/g)||[],d=[].slice.call(arguments,1,-2),g=0,h=c.length;h>g;g++)bb[c[g].replace(/:|\./g,"")]=decodeURIComponent(d[g]);e.module(a,b[f])}),!0}}function r(a){if(a=a||event,!a.ctrlKey&&!a.metaKey&&2!==a.which){a.preventDefault?a.preventDefault():a.returnValue=!1;var b=a.currentTarget||this,c="pathname"===e.route.mode&&b.search?u(b.search.slice(1)):{};e.route(b[e.route.mode].slice(db[e.route.mode].length),c)}}function s(){"hash"!=e.route.mode&&D.hash?D.hash=D.hash:b.scrollTo(0,0)}function t(a,b){var c=[];for(var d in a){var e=b?b+"["+d+"]":d,f=a[d],g=K.call(f),h=null!=f&&g===G?t(f,e):g===H?f.map(function(a){return encodeURIComponent(e+"[]")+"="+encodeURIComponent(a)}).join("&"):encodeURIComponent(e)+"="+encodeURIComponent(f);c.push(h)}return c.join("&")}function u(a){for(var b=a.split("&"),c={},d=0,e=b.length;e>d;d++){var f=b[d].split("=");c[decodeURIComponent(f[0])]=f[1]?decodeURIComponent(f[1]):""}return c}function v(a){var b=m(a);i(a.childNodes,R[b]),R[b]=c}function w(a){var b=e.prop();return a.then(b),b.then=function(b,c){return w(a.then(b,c))},b}function x(a,b){function c(a){l=a||j,n.map(function(a){l===i&&a.resolve(m)||a.reject(m)})}function d(a,b,c,d){if((null!=m&&K.call(m)===G||typeof m===J)&&typeof a===J)try{var f=0;a.call(m,function(a){f++||(m=a,b())},function(a){f++||(m=a,c())})}catch(g){e.deferred.onerror(g),m=g,c()}else d()}function f(){var j;try{j=m&&m.then}catch(n){return e.deferred.onerror(n),m=n,l=h,f()}d(j,function(){l=g,f()},function(){l=h,f()},function(){try{l===g&&typeof a===J?m=a(m):l===h&&"function"==typeof b&&(m=b(m),l=g)}catch(f){return e.deferred.onerror(f),m=f,c()}m===k?(m=TypeError(),c()):d(j,function(){c(i)},c,function(){c(l===g&&i)})})}var g=1,h=2,i=3,j=4,k=this,l=0,m=0,n=[];k.promise={},k.resolve=function(a){return l||(m=a,l=g,f()),this},k.reject=function(a){return l||(m=a,l=h,f()),this},k.promise.then=function(a,b){var c=new x(a,b);return l===i?c.resolve(m):l===j?c.reject(m):n.push(c),c.promise}}function y(a){return a}function z(a){if(!a.dataType||"jsonp"!==a.dataType.toLowerCase()){var d=new b.XMLHttpRequest;if(d.open(a.method,a.url,!0,a.user,a.password),d.onreadystatechange=function(){4===d.readyState&&(d.status>=200&&d.status<300?a.onload({type:"load",target:d}):a.onerror({type:"error",target:d}))},a.serialize===JSON.stringify&&a.data&&"GET"!==a.method&&d.setRequestHeader("Content-Type","application/json; charset=utf-8"),a.deserialize===JSON.parse&&d.setRequestHeader("Accept","application/json, text/*"),typeof a.config===J){var e=a.config(d,a);null!=e&&(d=e)}var f="GET"!==a.method&&a.data?a.data:"";if(f&&K.call(f)!=I&&f.constructor!=b.FormData)throw"Request data should be either be a string or FormData. Check the `serialize` option in `m.request`";return d.send(f),d}var g="mithril_callback_"+(new Date).getTime()+"_"+Math.round(1e16*Math.random()).toString(36),h=C.createElement("script");b[g]=function(d){h.parentNode.removeChild(h),a.onload({type:"load",target:{responseText:d}}),b[g]=c},h.onerror=function(){return h.parentNode.removeChild(h),a.onerror({type:"error",target:{status:500,responseText:JSON.stringify({error:"Error making jsonp request"})}}),b[g]=c,!1},h.onload=function(){return!1},h.src=a.url+(a.url.indexOf("?")>0?"&":"?")+(a.callbackKey?a.callbackKey:"callback")+"="+g+"&"+t(a.data||{}),C.body.appendChild(h)}function A(a,b,c){if("GET"===a.method&&"jsonp"!=a.dataType){var d=a.url.indexOf("?")<0?"?":"&",e=t(b);a.url=a.url+(e?d+e:"")}else a.data=c(b);return a}function B(a,b){var c=a.match(/:[a-z]\w+/gi);if(c&&b)for(var d=0;dk;k++)e[k]()},e.trust=function(a){return a=new String(a),a.$trusted=!0,a},e.prop=function(a){return(null!=a&&K.call(a)===G||typeof a===J)&&typeof a.then===J?w(a):n(a)};var S,T=[],U=[],V=[],W=null,X=0,Y=null,Z=16;e.module=function(a,b){if(!a)throw new Error("Please ensure the DOM element exists before rendering a template into it.");var c=T.indexOf(a);0>c&&(c=T.length);var d=!1;if(V[c]&&typeof V[c].onunload===J){var f={preventDefault:function(){d=!0}};V[c].onunload(f)}if(!d){e.redraw.strategy("all"),e.startComputation(),T[c]=a;var g=S=b=b||{},h=new(b.controller||function(){});return g===S&&(V[c]=h,U[c]=b),ab(),V[c]}},e.redraw=function(a){W&&a!==!0?(new Date-X>Z||E===b.requestAnimationFrame)&&(W>0&&F(W),W=E(o,Z)):(o(),W=E(function(){W=null},Z))},e.redraw.strategy=e.prop();var $=function(){return""},_=0;e.startComputation=function(){_++},e.endComputation=function(){_=Math.max(_-1,0),0===_&&e.redraw()};var ab=function(){"none"==e.redraw.strategy()?(_--,e.redraw.strategy("diff")):e.endComputation()};e.withAttr=function(a,b){return function(c){c=c||event;var d=c.currentTarget||this;b(a in d?d[a]:d.getAttribute(a))}};var bb,cb,db={pathname:"",hash:"#",search:"?"},eb=function(){};return e.route=function(){if(0===arguments.length)return cb;if(3===arguments.length&&K.call(arguments[1])===I){var a=arguments[0],c=arguments[1],d=arguments[2];eb=function(b){var f=cb=p(b);q(a,d,f)||e.route(c,!0)};var f="hash"===e.route.mode?"onhashchange":"onpopstate";b[f]=function(){var a=D[e.route.mode];"pathname"===e.route.mode&&(a+=D.search),cb!=p(a)&&eb(a)},Y=s,b[f]()}else if(arguments[0].addEventListener){{var g=arguments[0];arguments[1],arguments[2]}g.href=("pathname"!==e.route.mode?D.pathname:"")+db[e.route.mode]+this.attrs.href,g.removeEventListener("click",r),g.addEventListener("click",r)}else if(K.call(arguments[0])===I){var h=cb;cb=arguments[0];var i=arguments[1]||{},j=cb.indexOf("?"),k=j>-1?u(cb.slice(j+1)):{};for(var l in i)k[l]=i[l];var m=t(k),n=j>-1?cb.slice(0,j):cb;m&&(cb=n+(-1===n.indexOf("?")?"?":"&")+m);var o=(3===arguments.length?arguments[2]:arguments[1])===!0||h===arguments[0];b.history.pushState?(Y=function(){b.history[o?"replaceState":"pushState"](null,C.title,db[e.route.mode]+cb),s()},eb(db[e.route.mode]+cb)):D[e.route.mode]=cb}},e.route.param=function(a){if(!bb)throw new Error("You must call m.route(element, defaultRoute, routes) before calling m.route.param()");return bb[a]},e.route.mode="search",e.deferred=function(){var a=new x;return a.promise=w(a.promise),a},e.deferred.onerror=function(a){if("[object Error]"===K.call(a)&&!a.constructor.toString().match(/ Error/))throw a},e.sync=function(a){function b(a,b){return function(e){return g[a]=e,b||(c="reject"),0===--f&&(d.promise(g),d[c](g)),e}}var c="resolve",d=e.deferred(),f=a.length,g=new Array(f);if(a.length>0)for(var h=0;h, we must
- // explicitly test if icestats.source is an array.
- if(!data.icestats.source.isArray()) {
- data.icestats.source = [data.icestats.source];
- }
-
- var stats = data.icestats.source.find(function(source) {
- return regexp.test(source.listenurl);
- });
-
- if(stats) {
- callback(stats);
- }
- }
- });
-}
+var app = {};
-/**
- * Schedule a thunk... forever!
- */
-function scheduleEvery(duration, thunk) {
+app.icecastUrl = "http://live.fsf.org";
+
+app.scheduleEvery = function(duration, thunk) {
thunk();
setTimeout(function() {
- scheduleEvery(duration, thunk);
+ app.scheduleEvery(duration, thunk);
}, duration);
-}
+};
-/**
- * Update the document with stats from an IceCast mount.
- */
-function renderStreamStats(stats) {
- function viewCountMessage(viewers) {
- var noun = viewers === 1 ? 'viewer' : 'viewers';
- return [viewers.toString(), noun].join(' ');
+app.nullStats = {
+ listeners: 0,
+ server_name: null,
+ server_description: null
+};
+
+app.streamStats = function(mount) {
+ var statsUrl = app.icecastUrl.concat('/status-json.xsl');
+
+ return m.request({
+ method: "GET",
+ url: statsUrl
+ }).then(function(data) {
+ // Match the end of the listen URL for the mount point.
+ var regexp = new RegExp(mount.concat('$'));
+
+ // Due to , we must
+ // explicitly test if icestats.source is an array.
+ if(!(data.icestats.source instanceof Array)) {
+ data.icestats.source = [data.icestats.source];
+ }
+
+ var stats = data.icestats.source.find(function(source) {
+ return regexp.test(source.listenurl);
+ });
+
+ return stats || app.nullStats;
+ });
+};
+
+app.validStreamInfo = function(stats) {
+ var name = stats.server_name;
+ var desc = stats.server_description;
+
+ return name && desc && name !== "Unspecified name" &&
+ desc !== "Unspecified description";
+};
+
+app.mountToStreamUrl = function(mount) {
+ return app.icecastUrl.concat(mount);
+};
+
+app.changeVideoMount = function(video, mount) {
+ console.log(mount);
+ video.src = app.mountToStreamUrl(mount);
+ video.load();
+ video.play();
+};
+
+app.streams = [
+ {
+ name: "Room 123",
+ speakerMount: "/room123.ogv",
+ desktopMount: "/room123-desktop.ogv",
+ ircChannel: "#libreplanet_room123"
+ }, {
+ name: "Room 141",
+ speakerMount: "/room141.ogv",
+ desktopMount: "/room141-desktop.ogv",
+ ircChannel: "#libreplanet_room141"
+ }, {
+ name: "Room 155",
+ speakerMount: "/room155.ogv",
+ desktopMount: "/room155-desktop.ogv",
+ ircChannel: "#libreplanet_room155"
}
+];
- $('#viewer-counter').html(viewCountMessage(stats.listeners));
- $('#speaker-name').html(stats.server_name);
- $('#talk-title').html(stats.server_description);
-}
+app.controller = function() {
+ var self = this;
-/**
- * Update the document every 10 seconds with stats from an IceCast
- * mount.
- */
-function monitorStream(mount) {
- scheduleEvery(10000, function() {
- withStreamStats('http://live.fsf.org', mount, renderStreamStats);
+ this.stream = m.prop(app.streams[0]);
+ this.stats = m.prop(app.nullStats);
+
+ this.speakerPosition = m.prop({
+ x: 0,
+ y: 0
+ });
+
+ this.showDesktop = m.prop(false);
+
+ this.updateStats = function() {
+ self.stats = app.streamStats(self.stream().speakerMount);
+ };
+
+ app.scheduleEvery(10000, function() {
+ self.updateStats();
});
-}
+};
+
+app.view = function(ctrl) {
+ var stream = ctrl.stream();
+ var pos = ctrl.speakerPosition();
+ var showDesktop = ctrl.showDesktop();
+ var stats = ctrl.stats();
+ console.log(stats);
+
+ function renderDesktopStream() {
+ return m("video.lp-video", {
+ id: "desktop-video",
+ autoplay: true
+ }, [
+ m("source", { src: app.mountToStreamUrl(stream.desktopMount) }),
+ m("p",
+ m("em", [
+ "Your browser does not support the HTML5 video tag, ",
+ m("a", { href: "TODO" }, "[ please download ]"),
+ "the video instead"
+ ]))
+ ]);
+ }
+
+ function renderToggleDesktopStream() {
+ var action = showDesktop ? "Hide desktop stream" : "Show desktop stream";
+
+ return m(".row", [
+ m(".col-sm-offset-4.col-sm-4",
+ m("button.btn.btn-block.btn-default", {
+ onclick: function() {
+ ctrl.showDesktop(!showDesktop);
+ }
+ }, action)
+ )
+ ]);
+ }
+
+ function renderRoomSelector() {
+ return m(".row",
+ m(".col-sm-offset-1.col-sm-10",
+ m("ol.breadcrumb.text-center", app.streams.map(function(s) {
+ return m("li", {
+ class: s === stream ? "active" : null,
+ onclick: function() {
+ var speakerVideo = document.getElementById("speaker-video");
+ var desktopVideo = document.getElementById("desktop-video");
+
+ console.log(s);
+
+ app.changeVideoMount(speakerVideo, s.speakerMount);
+
+ // Video element doesn't exist when the user
+ // hasn't elected to show it.
+ if(desktopVideo) {
+ app.changeVideoMount(desktopVideo, s.desktopMount);
+ }
+
+ ctrl.stream(s);
+ }
+ }, m("a.alt-a", { href: "#" }, s.name));
+ }))));
+ }
+
+ function renderStats() {
+ var info = app.validStreamInfo(stats) ? [
+ m("strong", stats.server_name),
+ " â ",
+ m("i", stats.server_description)
+ ] : null;
+
+ return m(".row", [
+ m(".col-sm-8", info),
+ m(".col-sm-4.text-right", [
+ m("strong", stats.listeners),
+ " watching"
+ ])
+ ]);
+ }
+
+ return [
+ renderRoomSelector(),
+ m("h2", stream.name),
+ renderStats(),
+ m("video.lp-video", {
+ id: "speaker-video",
+ controls: true,
+ autoplay: true
+ }, [
+ m("source", {
+ src: app.mountToStreamUrl(stream.speakerMount)
+ }),
+ m("p",
+ m("em", [
+ "Your browser does not support the HTML5 video tag, ",
+ m("a", { href: "TODO" }, "[ please download ]"),
+ "the video instead"
+ ]))
+ ]),
+ showDesktop ? renderDesktopStream() : null,
+ renderToggleDesktopStream(),
+ m("h2", "IRC"),
+ m("p", "Join the discussion online!"),
+ m("ul", [
+ m("li", [
+ "Conference-wide Freenode IRC channel: ",
+ m("strong", "#libreplanet")
+ ]),
+ m("li", [
+ "Freenode IRC channel for ",
+ stream.name,
+ ": ",
+ m("strong", stream.ircChannel)
+ ]),
+ m("li", [
+ "Conference hashtag for ",
+ m("a", { href: "https://fsf.org/twitter" }, "microblogging"),
+ ": ",
+ m("strong", "#lp2015")
+ ])
+ ])
+ ];
+};
+
+m.module(document.getElementById("stream"), app);
diff --git a/2015/live/index.html b/2015/live/index.html
index 08c9d7fc..33e93f64 100755
--- a/2015/live/index.html
+++ b/2015/live/index.html
@@ -5,20 +5,27 @@
- LibrePlanet from anywhere
- During LibrePlanet, this page will host streaming video of all sessions. If you plan to participate remotely, please bookmark it now and check back during the conference.
+LibrePlanet 2015 — Live
-
- Conference-wide Freenode IRC channel: #libreplanet
- Conference hashtag for microblogging : #lp2015
-
+
+
-
We're creating our most advanced-ever free software streaming system for LibrePlanet 2015. We'd appreciate your donations to help make it as great as possible. Can you chip in?
+
-
+
+
+
+
+
+
+
+
+
diff --git a/server/2015/footer.html b/server/2015/footer.html
index 5a0fc405..9ec354ba 100644
--- a/server/2015/footer.html
+++ b/server/2015/footer.html
@@ -12,7 +12,7 @@
Donate to the FSF .
- Except where otherwise noted, this site and its images, logos and and other media are licensed under
+ Except where otherwise noted, this site and its images, logos and and other media are licensed under
Creative Commons Attribution-ShareAlike 4.0 .
@@ -23,8 +23,17 @@
licensing information documented by Web labels .
+
+ KiwiIRC is licensed under the
+
+ GNU Affero General Public License version 3
+ .
+
+ Complete source code
+
+
-
diff --git a/server/staging/lp15/live_sidebar.html b/server/staging/lp15/live_sidebar.html
index 4d413d19..a2b5a751 100755
--- a/server/staging/lp15/live_sidebar.html
+++ b/server/staging/lp15/live_sidebar.html
@@ -34,7 +34,7 @@
-
+
@@ -79,6 +79,5 @@
href="https://my.fsf.org/donate/privacypolicy.html">Privacy policy
-
-
+
diff --git a/server/staging/lp15/weblabels.html b/server/staging/lp15/weblabels.html
index 851d4a3d..57012621 100644
--- a/server/staging/lp15/weblabels.html
+++ b/server/staging/lp15/weblabels.html
@@ -4,9 +4,9 @@
libreplanet.org - JavaScript License Information
-
+
-
+