/* ---- lib/Animation.coffee ---- */
(function() {
var Animation;
Animation = (function() {
function Animation() {}
Animation.prototype.slideDown = function(elem, props) {
var cstyle, h, margin_bottom, margin_top, padding_bottom, padding_top, transition;
if (elem.offsetTop > 2000) {
return;
}
h = elem.offsetHeight;
cstyle = window.getComputedStyle(elem);
margin_top = cstyle.marginTop;
margin_bottom = cstyle.marginBottom;
padding_top = cstyle.paddingTop;
padding_bottom = cstyle.paddingBottom;
transition = cstyle.transition;
elem.style.boxSizing = "border-box";
elem.style.overflow = "hidden";
elem.style.transform = "scale(0.6)";
elem.style.opacity = "0";
elem.style.height = "0px";
elem.style.marginTop = "0px";
elem.style.marginBottom = "0px";
elem.style.paddingTop = "0px";
elem.style.paddingBottom = "0px";
elem.style.transition = "none";
setTimeout((function() {
elem.className += " animate-inout";
elem.style.height = h + "px";
elem.style.transform = "scale(1)";
elem.style.opacity = "1";
elem.style.marginTop = margin_top;
elem.style.marginBottom = margin_bottom;
elem.style.paddingTop = padding_top;
return elem.style.paddingBottom = padding_bottom;
}), 1);
return elem.addEventListener("transitionend", function() {
elem.classList.remove("animate-inout");
elem.style.transition = elem.style.transform = elem.style.opacity = elem.style.height = null;
elem.style.boxSizing = elem.style.marginTop = elem.style.marginBottom = null;
elem.style.paddingTop = elem.style.paddingBottom = elem.style.overflow = null;
return elem.removeEventListener("transitionend", arguments.callee, false);
});
};
Animation.prototype.slideUp = function(elem, remove_func, props) {
if (elem.offsetTop > 1000) {
return remove_func();
}
elem.className += " animate-back";
elem.style.boxSizing = "border-box";
elem.style.height = elem.offsetHeight + "px";
elem.style.overflow = "hidden";
elem.style.transform = "scale(1)";
elem.style.opacity = "1";
elem.style.pointerEvents = "none";
setTimeout((function() {
elem.style.height = "0px";
elem.style.marginTop = "0px";
elem.style.marginBottom = "0px";
elem.style.paddingTop = "0px";
elem.style.paddingBottom = "0px";
elem.style.transform = "scale(0.8)";
elem.style.borderTopWidth = "0px";
elem.style.borderBottomWidth = "0px";
return elem.style.opacity = "0";
}), 1);
return elem.addEventListener("transitionend", function(e) {
if (e.propertyName === "opacity" || e.elapsedTime >= 0.6) {
elem.removeEventListener("transitionend", arguments.callee, false);
return remove_func();
}
});
};
Animation.prototype.slideUpInout = function(elem, remove_func, props) {
elem.className += " animate-inout";
elem.style.boxSizing = "border-box";
elem.style.height = elem.offsetHeight + "px";
elem.style.overflow = "hidden";
elem.style.transform = "scale(1)";
elem.style.opacity = "1";
elem.style.pointerEvents = "none";
setTimeout((function() {
elem.style.height = "0px";
elem.style.marginTop = "0px";
elem.style.marginBottom = "0px";
elem.style.paddingTop = "0px";
elem.style.paddingBottom = "0px";
elem.style.transform = "scale(0.8)";
elem.style.borderTopWidth = "0px";
elem.style.borderBottomWidth = "0px";
return elem.style.opacity = "0";
}), 1);
return elem.addEventListener("transitionend", function(e) {
if (e.propertyName === "opacity" || e.elapsedTime >= 0.6) {
elem.removeEventListener("transitionend", arguments.callee, false);
return remove_func();
}
});
};
Animation.prototype.showRight = function(elem, props) {
elem.className += " animate";
elem.style.opacity = 0;
elem.style.transform = "TranslateX(-20px) Scale(1.01)";
setTimeout((function() {
elem.style.opacity = 1;
return elem.style.transform = "TranslateX(0px) Scale(1)";
}), 1);
return elem.addEventListener("transitionend", function() {
elem.classList.remove("animate");
return elem.style.transform = elem.style.opacity = null;
});
};
Animation.prototype.show = function(elem, props) {
var delay, ref;
delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
elem.style.opacity = 0;
setTimeout((function() {
return elem.className += " animate";
}), 1);
setTimeout((function() {
return elem.style.opacity = 1;
}), delay);
return elem.addEventListener("transitionend", function() {
elem.classList.remove("animate");
elem.style.opacity = null;
return elem.removeEventListener("transitionend", arguments.callee, false);
});
};
Animation.prototype.hide = function(elem, remove_func, props) {
var delay, ref;
delay = ((ref = arguments[arguments.length - 2]) != null ? ref.delay : void 0) * 1000 || 1;
elem.className += " animate";
setTimeout((function() {
return elem.style.opacity = 0;
}), delay);
return elem.addEventListener("transitionend", function(e) {
if (e.propertyName === "opacity") {
return remove_func();
}
});
};
Animation.prototype.addVisibleClass = function(elem, props) {
return setTimeout(function() {
return elem.classList.add("visible");
});
};
return Animation;
})();
window.Animation = new Animation();
}).call(this);
/* ---- lib/Class.coffee ---- */
(function() {
var Class,
slice = [].slice;
Class = (function() {
function Class() {}
Class.prototype.trace = true;
Class.prototype.log = function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
if (!this.trace) {
return;
}
if (typeof console === 'undefined') {
return;
}
args.unshift("[" + this.constructor.name + "]");
console.log.apply(console, args);
return this;
};
Class.prototype.logStart = function() {
var args, name;
name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
if (!this.trace) {
return;
}
this.logtimers || (this.logtimers = {});
this.logtimers[name] = +(new Date);
if (args.length > 0) {
this.log.apply(this, ["" + name].concat(slice.call(args), ["(started)"]));
}
return this;
};
Class.prototype.logEnd = function() {
var args, ms, name;
name = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
ms = +(new Date) - this.logtimers[name];
this.log.apply(this, ["" + name].concat(slice.call(args), ["(Done in " + ms + "ms)"]));
return this;
};
return Class;
})();
window.Class = Class;
}).call(this);
/* ---- lib/Dollar.coffee ---- */
(function() {
window.$ = function(selector) {
if (selector.startsWith("#")) {
return document.getElementById(selector.replace("#", ""));
}
};
}).call(this);
/* ---- lib/ItemList.coffee ---- */
(function() {
var ItemList;
ItemList = (function() {
function ItemList(item_class1, key1) {
this.item_class = item_class1;
this.key = key1;
this.items = [];
this.items_bykey = {};
}
ItemList.prototype.sync = function(rows, item_class, key) {
var current_obj, i, item, len, results, row;
this.items.splice(0, this.items.length);
results = [];
for (i = 0, len = rows.length; i < len; i++) {
row = rows[i];
current_obj = this.items_bykey[row[this.key]];
if (current_obj) {
current_obj.row = row;
results.push(this.items.push(current_obj));
} else {
item = new this.item_class(row, this);
this.items_bykey[row[this.key]] = item;
results.push(this.items.push(item));
}
}
return results;
};
ItemList.prototype.deleteItem = function(item) {
var index;
index = this.items.indexOf(item);
if (index > -1) {
this.items.splice(index, 1);
} else {
console.log("Can't delete item", item);
}
return delete this.items_bykey[item.row[this.key]];
};
return ItemList;
})();
window.ItemList = ItemList;
}).call(this);
/* ---- lib/Menu.coffee ---- */
(function() {
var Menu,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Menu = (function() {
function Menu() {
this.render = bind(this.render, this);
this.getStyle = bind(this.getStyle, this);
this.renderItem = bind(this.renderItem, this);
this.handleClick = bind(this.handleClick, this);
this.getDirection = bind(this.getDirection, this);
this.storeNode = bind(this.storeNode, this);
this.toggle = bind(this.toggle, this);
this.hide = bind(this.hide, this);
this.show = bind(this.show, this);
this.visible = false;
this.items = [];
this.node = null;
this.height = 0;
this.direction = "bottom";
}
Menu.prototype.show = function() {
var ref;
if ((ref = window.visible_menu) != null) {
ref.hide();
}
this.visible = true;
window.visible_menu = this;
return this.direction = this.getDirection();
};
Menu.prototype.hide = function() {
return this.visible = false;
};
Menu.prototype.toggle = function() {
if (this.visible) {
this.hide();
} else {
this.show();
}
return Page.projector.scheduleRender();
};
Menu.prototype.addItem = function(title, cb, selected) {
if (selected == null) {
selected = false;
}
return this.items.push([title, cb, selected]);
};
Menu.prototype.storeNode = function(node) {
this.node = node;
if (this.visible) {
node.className = node.className.replace("visible", "");
setTimeout(((function(_this) {
return function() {
node.className += " visible";
return node.attributes.style.value = _this.getStyle();
};
})(this)), 20);
node.style.maxHeight = "none";
this.height = node.offsetHeight;
node.style.maxHeight = "0px";
return this.direction = this.getDirection();
}
};
Menu.prototype.getDirection = function() {
if (this.node && this.node.parentNode.getBoundingClientRect().top + this.height + 60 > document.body.clientHeight && this.node.parentNode.getBoundingClientRect().top - this.height > 0) {
return "top";
} else {
return "bottom";
}
};
Menu.prototype.handleClick = function(e) {
var cb, i, item, keep_menu, len, ref, selected, title;
keep_menu = false;
ref = this.items;
for (i = 0, len = ref.length; i < len; i++) {
item = ref[i];
title = item[0], cb = item[1], selected = item[2];
if (title === e.currentTarget.textContent || e.currentTarget["data-title"] === title) {
keep_menu = typeof cb === "function" ? cb(item) : void 0;
break;
}
}
if (keep_menu !== true && cb !== null) {
this.hide();
}
return false;
};
Menu.prototype.renderItem = function(item) {
var cb, classes, href, onclick, selected, title;
title = item[0], cb = item[1], selected = item[2];
if (typeof selected === "function") {
selected = selected();
}
if (title === "---") {
return h("div.menu-item-separator", {
key: Time.timestamp()
});
} else {
if (cb === null) {
href = void 0;
onclick = this.handleClick;
} else if (typeof cb === "string") {
href = cb;
onclick = true;
} else {
href = "#" + title;
onclick = this.handleClick;
}
classes = {
"selected": selected,
"noaction": cb === null
};
return h("a.menu-item", {
href: href,
onclick: onclick,
"data-title": title,
key: title,
classes: classes
}, title);
}
};
Menu.prototype.getStyle = function() {
var max_height, style;
if (this.visible) {
max_height = this.height;
} else {
max_height = 0;
}
style = "max-height: " + max_height + "px";
if (this.direction === "top") {
style += ";margin-top: " + (0 - this.height - 50) + "px";
} else {
style += ";margin-top: 0px";
}
return style;
};
Menu.prototype.render = function(class_name) {
if (class_name == null) {
class_name = "";
}
if (this.visible || this.node) {
return h("div.menu" + class_name, {
classes: {
"visible": this.visible
},
style: this.getStyle(),
afterCreate: this.storeNode
}, this.items.map(this.renderItem));
}
};
return Menu;
})();
window.Menu = Menu;
document.body.addEventListener("mouseup", function(e) {
var menu_node, menu_parents, ref, ref1;
if (!window.visible_menu || !window.visible_menu.node) {
return false;
}
menu_node = window.visible_menu.node;
menu_parents = [menu_node, menu_node.parentNode];
if ((ref = e.target.parentNode, indexOf.call(menu_parents, ref) < 0) && (ref1 = e.target.parentNode.parentNode, indexOf.call(menu_parents, ref1) < 0)) {
window.visible_menu.hide();
return Page.projector.scheduleRender();
}
});
}).call(this);
/* ---- lib/Promise.coffee ---- */
(function() {
var Promise,
slice = [].slice;
Promise = (function() {
Promise.when = function() {
var args, fn, i, len, num_uncompleted, promise, task, task_id, tasks;
tasks = 1 <= arguments.length ? slice.call(arguments, 0) : [];
num_uncompleted = tasks.length;
args = new Array(num_uncompleted);
promise = new Promise();
fn = function(task_id) {
return task.then(function() {
args[task_id] = Array.prototype.slice.call(arguments);
num_uncompleted--;
if (num_uncompleted === 0) {
return promise.complete.apply(promise, args);
}
});
};
for (task_id = i = 0, len = tasks.length; i < len; task_id = ++i) {
task = tasks[task_id];
fn(task_id);
}
return promise;
};
function Promise() {
this.resolved = false;
this.end_promise = null;
this.result = null;
this.callbacks = [];
}
Promise.prototype.resolve = function() {
var back, callback, i, len, ref;
if (this.resolved) {
return false;
}
this.resolved = true;
this.data = arguments;
if (!arguments.length) {
this.data = [true];
}
this.result = this.data[0];
ref = this.callbacks;
for (i = 0, len = ref.length; i < len; i++) {
callback = ref[i];
back = callback.apply(callback, this.data);
}
if (this.end_promise) {
return this.end_promise.resolve(back);
}
};
Promise.prototype.fail = function() {
return this.resolve(false);
};
Promise.prototype.then = function(callback) {
if (this.resolved === true) {
callback.apply(callback, this.data);
return;
}
this.callbacks.push(callback);
return this.end_promise = new Promise();
};
return Promise;
})();
window.Promise = Promise;
/*
s = Date.now()
log = (text) ->
console.log Date.now()-s, Array.prototype.slice.call(arguments).join(", ")
log "Started"
cmd = (query) ->
p = new Promise()
setTimeout ( ->
p.resolve query+" Result"
), 100
return p
back = cmd("SELECT * FROM message").then (res) ->
log res
return "Return from query"
.then (res) ->
log "Back then", res
log "Query started", back
*/
}).call(this);
/* ---- lib/Prototypes.coffee ---- */
(function() {
String.prototype.startsWith = function(s) {
return this.slice(0, s.length) === s;
};
String.prototype.endsWith = function(s) {
return s === '' || this.slice(-s.length) === s;
};
String.prototype.repeat = function(count) {
return new Array(count + 1).join(this);
};
window.isEmpty = function(obj) {
var key;
for (key in obj) {
return false;
}
return true;
};
}).call(this);
/* ---- lib/RateLimitCb.coffee ---- */
(function() {
var call_after_interval, calling, calling_iterval, last_time,
slice = [].slice;
last_time = {};
calling = {};
calling_iterval = {};
call_after_interval = {};
window.RateLimitCb = function(interval, fn, args) {
var cb;
if (args == null) {
args = [];
}
cb = function() {
var left;
left = interval - (Date.now() - last_time[fn]);
if (left <= 0) {
delete last_time[fn];
if (calling[fn]) {
RateLimitCb(interval, fn, calling[fn]);
}
return delete calling[fn];
} else {
return setTimeout((function() {
delete last_time[fn];
if (calling[fn]) {
RateLimitCb(interval, fn, calling[fn]);
}
return delete calling[fn];
}), left);
}
};
if (last_time[fn]) {
return calling[fn] = args;
} else {
last_time[fn] = Date.now();
return fn.apply(this, [cb].concat(slice.call(args)));
}
};
window.RateLimit = function(interval, fn) {
if (calling_iterval[fn] > interval) {
clearInterval(calling[fn]);
delete calling[fn];
}
if (!calling[fn]) {
call_after_interval[fn] = false;
fn();
calling_iterval[fn] = interval;
return calling[fn] = setTimeout((function() {
if (call_after_interval[fn]) {
fn();
}
delete calling[fn];
return delete call_after_interval[fn];
}), interval);
} else {
return call_after_interval[fn] = true;
}
};
/*
window.s = Date.now()
window.load = (done, num) ->
console.log "Loading #{num}...", Date.now()-window.s
setTimeout (-> done()), 1000
RateLimit 500, window.load, [0] # Called instantly
RateLimit 500, window.load, [1]
setTimeout (-> RateLimit 500, window.load, [300]), 300
setTimeout (-> RateLimit 500, window.load, [600]), 600 # Called after 1000ms
setTimeout (-> RateLimit 500, window.load, [1000]), 1000
setTimeout (-> RateLimit 500, window.load, [1200]), 1200 # Called after 2000ms
setTimeout (-> RateLimit 500, window.load, [3000]), 3000 # Called after 3000ms
*/
}).call(this);
/* ---- lib/Text.coffee ---- */
(function() {
var Text,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Text = (function() {
function Text() {}
Text.prototype.toColor = function(text, saturation, lightness) {
var hash, i, j, ref;
if (saturation == null) {
saturation = 30;
}
if (lightness == null) {
lightness = 50;
}
hash = 0;
for (i = j = 0, ref = text.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
hash += text.charCodeAt(i) * i;
hash = hash % 1777;
}
return "hsl(" + (hash % 360) + ("," + saturation + "%," + lightness + "%)");
};
Text.prototype.renderMarked = function(text, options) {
if (options == null) {
options = {};
}
options["gfm"] = true;
options["breaks"] = true;
options["sanitize"] = true;
options["renderer"] = marked_renderer;
text = marked(text, options);
return this.fixHtmlLinks(text);
};
Text.prototype.emailLinks = function(text) {
return text.replace(/([a-zA-Z0-9]+)@zeroid.bit/g, "$1@zeroid.bit");
};
Text.prototype.fixHtmlLinks = function(text) {
if (window.is_proxy) {
return text.replace(/href="http:\/\/(127.0.0.1|localhost):43110/g, 'href="http://zero');
} else {
return text.replace(/href="http:\/\/(127.0.0.1|localhost):43110/g, 'href="');
}
};
Text.prototype.fixLink = function(link) {
var back;
if (window.is_proxy) {
back = link.replace(/http:\/\/(127.0.0.1|localhost):43110/, 'http://zero');
return back.replace(/http:\/\/zero\/([^\/]+\.bit)/, "http://$1");
} else {
return link.replace(/http:\/\/(127.0.0.1|localhost):43110/, '');
}
};
Text.prototype.toUrl = function(text) {
return text.replace(/[^A-Za-z0-9]/g, "+").replace(/[+]+/g, "+").replace(/[+]+$/, "");
};
Text.prototype.getSiteUrl = function(address) {
if (window.is_proxy) {
if (indexOf.call(address, ".") >= 0) {
return "http://" + address + "/";
} else {
return "http://zero/" + address + "/";
}
} else {
return "/" + address + "/";
}
};
Text.prototype.fixReply = function(text) {
return text.replace(/(>.*\n)([^\n>])/gm, "$1\n$2");
};
Text.prototype.toBitcoinAddress = function(text) {
return text.replace(/[^A-Za-z0-9]/g, "");
};
Text.prototype.jsonEncode = function(obj) {
return unescape(encodeURIComponent(JSON.stringify(obj)));
};
Text.prototype.jsonDecode = function(obj) {
return JSON.parse(decodeURIComponent(escape(obj)));
};
Text.prototype.fileEncode = function(obj) {
if (typeof obj === "string") {
return btoa(unescape(encodeURIComponent(obj)));
} else {
return btoa(unescape(encodeURIComponent(JSON.stringify(obj, void 0, '\t'))));
}
};
Text.prototype.utf8Encode = function(s) {
return unescape(encodeURIComponent(s));
};
Text.prototype.utf8Decode = function(s) {
return decodeURIComponent(escape(s));
};
Text.prototype.distance = function(s1, s2) {
var char, extra_parts, j, key, len, match, next_find, next_find_i, val;
s1 = s1.toLocaleLowerCase();
s2 = s2.toLocaleLowerCase();
next_find_i = 0;
next_find = s2[0];
match = true;
extra_parts = {};
for (j = 0, len = s1.length; j < len; j++) {
char = s1[j];
if (char !== next_find) {
if (extra_parts[next_find_i]) {
extra_parts[next_find_i] += char;
} else {
extra_parts[next_find_i] = char;
}
} else {
next_find_i++;
next_find = s2[next_find_i];
}
}
if (extra_parts[next_find_i]) {
extra_parts[next_find_i] = "";
}
extra_parts = (function() {
var results;
results = [];
for (key in extra_parts) {
val = extra_parts[key];
results.push(val);
}
return results;
})();
if (next_find_i >= s2.length) {
return extra_parts.length + extra_parts.join("").length;
} else {
return false;
}
};
Text.prototype.parseQuery = function(query) {
var j, key, len, params, part, parts, ref, val;
params = {};
parts = query.split('&');
for (j = 0, len = parts.length; j < len; j++) {
part = parts[j];
ref = part.split("="), key = ref[0], val = ref[1];
if (val) {
params[decodeURIComponent(key)] = decodeURIComponent(val);
} else {
params["url"] = decodeURIComponent(key);
}
}
return params;
};
Text.prototype.encodeQuery = function(params) {
var back, key, val;
back = [];
if (params.url) {
back.push(params.url);
}
for (key in params) {
val = params[key];
if (!val || key === "url") {
continue;
}
back.push((encodeURIComponent(key)) + "=" + (encodeURIComponent(val)));
}
return back.join("&");
};
Text.prototype.highlight = function(text, search) {
var back, i, j, len, part, parts;
if (!text) {
return [""];
}
parts = text.split(RegExp(search, "i"));
back = [];
for (i = j = 0, len = parts.length; j < len; i = ++j) {
part = parts[i];
back.push(part);
if (i < parts.length - 1) {
back.push(h("span.highlight", {
key: i
}, search));
}
}
return back;
};
Text.prototype.formatSize = function(size) {
var size_mb;
if (isNaN(parseInt(size))) {
return "";
}
size_mb = size / 1024 / 1024;
if (size_mb >= 1000) {
return (size_mb / 1024).toFixed(1) + " GB";
} else if (size_mb >= 100) {
return size_mb.toFixed(0) + " MB";
} else if (size / 1024 >= 1000) {
return size_mb.toFixed(2) + " MB";
} else {
return (parseInt(size) / 1024).toFixed(2) + " KB";
}
};
return Text;
})();
window.is_proxy = document.location.host === "zero" || window.location.pathname === "/";
window.Text = new Text();
}).call(this);
/* ---- lib/Time.coffee ---- */
(function() {
var Time;
Time = (function() {
function Time() {}
Time.prototype.since = function(timestamp) {
var back, minutes, now, secs;
now = +(new Date) / 1000;
if (timestamp > 1000000000000) {
timestamp = timestamp / 1000;
}
secs = now - timestamp;
if (secs < 60) {
back = "Just now";
} else if (secs < 60 * 60) {
minutes = Math.round(secs / 60);
back = "" + minutes + " minutes ago";
} else if (secs < 60 * 60 * 24) {
back = (Math.round(secs / 60 / 60)) + " hours ago";
} else if (secs < 60 * 60 * 24 * 3) {
back = (Math.round(secs / 60 / 60 / 24)) + " days ago";
} else {
back = "on " + this.date(timestamp);
}
back = back.replace(/^1 ([a-z]+)s/, "1 $1");
return back;
};
Time.prototype.dateIso = function(timestamp) {
var tzoffset;
if (timestamp == null) {
timestamp = null;
}
if (!timestamp) {
timestamp = window.Time.timestamp();
}
if (timestamp > 1000000000000) {
timestamp = timestamp / 1000;
}
tzoffset = (new Date()).getTimezoneOffset() * 60;
return (new Date((timestamp - tzoffset) * 1000)).toISOString().split("T")[0];
};
Time.prototype.date = function(timestamp, format) {
var display, parts;
if (timestamp == null) {
timestamp = null;
}
if (format == null) {
format = "short";
}
if (!timestamp) {
timestamp = window.Time.timestamp();
}
if (timestamp > 1000000000000) {
timestamp = timestamp / 1000;
}
parts = (new Date(timestamp * 1000)).toString().split(" ");
if (format === "short") {
display = parts.slice(1, 4);
} else if (format === "day") {
display = parts.slice(1, 3);
} else if (format === "month") {
display = [parts[1], parts[3]];
} else if (format === "long") {
display = parts.slice(1, 5);
}
return display.join(" ").replace(/( [0-9]{4})/, ",$1");
};
Time.prototype.weekDay = function(timestamp) {
if (timestamp > 1000000000000) {
timestamp = timestamp / 1000;
}
return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][(new Date(timestamp * 1000)).getDay()];
};
Time.prototype.timestamp = function(date) {
if (date == null) {
date = "";
}
if (date === "now" || date === "") {
return parseInt(+(new Date) / 1000);
} else {
return parseInt(Date.parse(date) / 1000);
}
};
return Time;
})();
window.Time = new Time;
}).call(this);
/* ---- lib/ZeroFrame.coffee ---- */
(function() {
var ZeroFrame,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
ZeroFrame = (function(superClass) {
extend(ZeroFrame, superClass);
function ZeroFrame(url) {
this.onCloseWebsocket = bind(this.onCloseWebsocket, this);
this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
this.onRequest = bind(this.onRequest, this);
this.onMessage = bind(this.onMessage, this);
this.url = url;
this.waiting_cb = {};
this.wrapper_nonce = document.location.href.replace(/.*wrapper_nonce=([A-Za-z0-9]+).*/, "$1");
this.connect();
this.next_message_id = 1;
this.history_state = {};
this.init();
}
ZeroFrame.prototype.init = function() {
return this;
};
ZeroFrame.prototype.connect = function() {
this.target = window.parent;
window.addEventListener("message", this.onMessage, false);
this.cmd("innerReady");
window.addEventListener("beforeunload", (function(_this) {
return function(e) {
_this.log("save scrollTop", window.pageYOffset);
_this.history_state["scrollTop"] = window.pageYOffset;
return _this.cmd("wrapperReplaceState", [_this.history_state, null]);
};
})(this));
return this.cmd("wrapperGetState", [], (function(_this) {
return function(state) {
if (state != null) {
_this.history_state = state;
}
_this.log("restore scrollTop", state, window.pageYOffset);
if (window.pageYOffset === 0 && state) {
return window.scroll(window.pageXOffset, state.scrollTop);
}
};
})(this));
};
ZeroFrame.prototype.onMessage = function(e) {
var cmd, message;
message = e.data;
cmd = message.cmd;
if (cmd === "response") {
if (this.waiting_cb[message.to] != null) {
return this.waiting_cb[message.to](message.result);
} else {
return this.log("Websocket callback not found:", message);
}
} else if (cmd === "wrapperReady") {
return this.cmd("innerReady");
} else if (cmd === "ping") {
return this.response(message.id, "pong");
} else if (cmd === "wrapperOpenedWebsocket") {
return this.onOpenWebsocket();
} else if (cmd === "wrapperClosedWebsocket") {
return this.onCloseWebsocket();
} else {
return this.onRequest(cmd, message.params);
}
};
ZeroFrame.prototype.onRequest = function(cmd, message) {
return this.log("Unknown request", message);
};
ZeroFrame.prototype.response = function(to, result) {
return this.send({
"cmd": "response",
"to": to,
"result": result
});
};
ZeroFrame.prototype.cmd = function(cmd, params, cb) {
if (params == null) {
params = {};
}
if (cb == null) {
cb = null;
}
return this.send({
"cmd": cmd,
"params": params
}, cb);
};
ZeroFrame.prototype.send = function(message, cb) {
if (cb == null) {
cb = null;
}
message.wrapper_nonce = this.wrapper_nonce;
message.id = this.next_message_id;
this.next_message_id += 1;
this.target.postMessage(message, "*");
if (cb) {
return this.waiting_cb[message.id] = cb;
}
};
ZeroFrame.prototype.onOpenWebsocket = function() {
return this.log("Websocket open");
};
ZeroFrame.prototype.onCloseWebsocket = function() {
return this.log("Websocket close");
};
return ZeroFrame;
})(Class);
window.ZeroFrame = ZeroFrame;
}).call(this);
/* ---- lib/maquette.js ---- */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports'], factory);
} else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
// CommonJS
factory(exports);
} else {
// Browser globals
factory(root.maquette = {});
}
}(this, function (exports) {
'use strict';
;
;
;
;
var NAMESPACE_W3 = 'http://www.w3.org/';
var NAMESPACE_SVG = NAMESPACE_W3 + '2000/svg';
var NAMESPACE_XLINK = NAMESPACE_W3 + '1999/xlink';
// Utilities
var emptyArray = [];
var extend = function (base, overrides) {
var result = {};
Object.keys(base).forEach(function (key) {
result[key] = base[key];
});
if (overrides) {
Object.keys(overrides).forEach(function (key) {
result[key] = overrides[key];
});
}
return result;
};
// Hyperscript helper functions
var same = function (vnode1, vnode2) {
if (vnode1.vnodeSelector !== vnode2.vnodeSelector) {
return false;
}
if (vnode1.properties && vnode2.properties) {
if (vnode1.properties.key !== vnode2.properties.key) {
return false;
}
return vnode1.properties.bind === vnode2.properties.bind;
}
return !vnode1.properties && !vnode2.properties;
};
var toTextVNode = function (data) {
return {
vnodeSelector: '',
properties: undefined,
children: undefined,
text: data.toString(),
domNode: null
};
};
var appendChildren = function (parentSelector, insertions, main) {
for (var i = 0; i < insertions.length; i++) {
var item = insertions[i];
if (Array.isArray(item)) {
appendChildren(parentSelector, item, main);
} else {
if (item !== null && item !== undefined) {
if (!item.hasOwnProperty('vnodeSelector')) {
item = toTextVNode(item);
}
main.push(item);
}
}
}
};
// Render helper functions
var missingTransition = function () {
throw new Error('Provide a transitions object to the projectionOptions to do animations');
};
var DEFAULT_PROJECTION_OPTIONS = {
namespace: undefined,
eventHandlerInterceptor: undefined,
styleApplyer: function (domNode, styleName, value) {
// Provides a hook to add vendor prefixes for browsers that still need it.
domNode.style[styleName] = value;
},
transitions: {
enter: missingTransition,
exit: missingTransition
}
};
var applyDefaultProjectionOptions = function (projectorOptions) {
return extend(DEFAULT_PROJECTION_OPTIONS, projectorOptions);
};
var checkStyleValue = function (styleValue) {
if (typeof styleValue !== 'string') {
throw new Error('Style values must be strings');
}
};
var setProperties = function (domNode, properties, projectionOptions) {
if (!properties) {
return;
}
var eventHandlerInterceptor = projectionOptions.eventHandlerInterceptor;
var propNames = Object.keys(properties);
var propCount = propNames.length;
for (var i = 0; i < propCount; i++) {
var propName = propNames[i];
/* tslint:disable:no-var-keyword: edge case */
var propValue = properties[propName];
/* tslint:enable:no-var-keyword */
if (propName === 'className') {
throw new Error('Property "className" is not supported, use "class".');
} else if (propName === 'class') {
if (domNode.className) {
// May happen if classes is specified before class
domNode.className += ' ' + propValue;
} else {
domNode.className = propValue;
}
} else if (propName === 'classes') {
// object with string keys and boolean values
var classNames = Object.keys(propValue);
var classNameCount = classNames.length;
for (var j = 0; j < classNameCount; j++) {
var className = classNames[j];
if (propValue[className]) {
domNode.classList.add(className);
}
}
} else if (propName === 'styles') {
// object with string keys and string (!) values
var styleNames = Object.keys(propValue);
var styleCount = styleNames.length;
for (var j = 0; j < styleCount; j++) {
var styleName = styleNames[j];
var styleValue = propValue[styleName];
if (styleValue) {
checkStyleValue(styleValue);
projectionOptions.styleApplyer(domNode, styleName, styleValue);
}
}
} else if (propName === 'key') {
continue;
} else if (propValue === null || propValue === undefined) {
continue;
} else {
var type = typeof propValue;
if (type === 'function') {
if (propName.lastIndexOf('on', 0) === 0) {
if (eventHandlerInterceptor) {
propValue = eventHandlerInterceptor(propName, propValue, domNode, properties); // intercept eventhandlers
}
if (propName === 'oninput') {
(function () {
// record the evt.target.value, because IE and Edge sometimes do a requestAnimationFrame between changing value and running oninput
var oldPropValue = propValue;
propValue = function (evt) {
evt.target['oninput-value'] = evt.target.value;
// may be HTMLTextAreaElement as well
oldPropValue.apply(this, [evt]);
};
}());
}
domNode[propName] = propValue;
}
} else if (type === 'string' && propName !== 'value' && propName !== 'innerHTML') {
if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
} else {
domNode.setAttribute(propName, propValue);
}
} else {
domNode[propName] = propValue;
}
}
}
};
var updateProperties = function (domNode, previousProperties, properties, projectionOptions) {
if (!properties) {
return;
}
var propertiesUpdated = false;
var propNames = Object.keys(properties);
var propCount = propNames.length;
for (var i = 0; i < propCount; i++) {
var propName = propNames[i];
// assuming that properties will be nullified instead of missing is by design
var propValue = properties[propName];
var previousValue = previousProperties[propName];
if (propName === 'class') {
if (previousValue !== propValue) {
throw new Error('"class" property may not be updated. Use the "classes" property for conditional css classes.');
}
} else if (propName === 'classes') {
var classList = domNode.classList;
var classNames = Object.keys(propValue);
var classNameCount = classNames.length;
for (var j = 0; j < classNameCount; j++) {
var className = classNames[j];
var on = !!propValue[className];
var previousOn = !!previousValue[className];
if (on === previousOn) {
continue;
}
propertiesUpdated = true;
if (on) {
classList.add(className);
} else {
classList.remove(className);
}
}
} else if (propName === 'styles') {
var styleNames = Object.keys(propValue);
var styleCount = styleNames.length;
for (var j = 0; j < styleCount; j++) {
var styleName = styleNames[j];
var newStyleValue = propValue[styleName];
var oldStyleValue = previousValue[styleName];
if (newStyleValue === oldStyleValue) {
continue;
}
propertiesUpdated = true;
if (newStyleValue) {
checkStyleValue(newStyleValue);
projectionOptions.styleApplyer(domNode, styleName, newStyleValue);
} else {
projectionOptions.styleApplyer(domNode, styleName, '');
}
}
} else {
if (!propValue && typeof previousValue === 'string') {
propValue = '';
}
if (propName === 'value') {
if (domNode[propName] !== propValue && domNode['oninput-value'] !== propValue) {
domNode[propName] = propValue;
// Reset the value, even if the virtual DOM did not change
domNode['oninput-value'] = undefined;
}
// else do not update the domNode, otherwise the cursor position would be changed
if (propValue !== previousValue) {
propertiesUpdated = true;
}
} else if (propValue !== previousValue) {
var type = typeof propValue;
if (type === 'function') {
throw new Error('Functions may not be updated on subsequent renders (property: ' + propName + '). Hint: declare event handler functions outside the render() function.');
}
if (type === 'string' && propName !== 'innerHTML') {
if (projectionOptions.namespace === NAMESPACE_SVG && propName === 'href') {
domNode.setAttributeNS(NAMESPACE_XLINK, propName, propValue);
} else {
domNode.setAttribute(propName, propValue);
}
} else {
if (domNode[propName] !== propValue) {
domNode[propName] = propValue;
}
}
propertiesUpdated = true;
}
}
}
return propertiesUpdated;
};
var findIndexOfChild = function (children, sameAs, start) {
if (sameAs.vnodeSelector !== '') {
// Never scan for text-nodes
for (var i = start; i < children.length; i++) {
if (same(children[i], sameAs)) {
return i;
}
}
}
return -1;
};
var nodeAdded = function (vNode, transitions) {
if (vNode.properties) {
var enterAnimation = vNode.properties.enterAnimation;
if (enterAnimation) {
if (typeof enterAnimation === 'function') {
enterAnimation(vNode.domNode, vNode.properties);
} else {
transitions.enter(vNode.domNode, vNode.properties, enterAnimation);
}
}
}
};
var nodeToRemove = function (vNode, transitions) {
var domNode = vNode.domNode;
if (vNode.properties) {
var exitAnimation = vNode.properties.exitAnimation;
if (exitAnimation) {
domNode.style.pointerEvents = 'none';
var removeDomNode = function () {
if (domNode.parentNode) {
domNode.parentNode.removeChild(domNode);
}
};
if (typeof exitAnimation === 'function') {
exitAnimation(domNode, removeDomNode, vNode.properties);
return;
} else {
transitions.exit(vNode.domNode, vNode.properties, exitAnimation, removeDomNode);
return;
}
}
}
if (domNode.parentNode) {
domNode.parentNode.removeChild(domNode);
}
};
var checkDistinguishable = function (childNodes, indexToCheck, parentVNode, operation) {
var childNode = childNodes[indexToCheck];
if (childNode.vnodeSelector === '') {
return; // Text nodes need not be distinguishable
}
var properties = childNode.properties;
var key = properties ? properties.key === undefined ? properties.bind : properties.key : undefined;
if (!key) {
for (var i = 0; i < childNodes.length; i++) {
if (i !== indexToCheck) {
var node = childNodes[i];
if (same(node, childNode)) {
if (operation === 'added') {
throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' + 'added, but there is now more than one. You must add unique key properties to make them distinguishable.');
} else {
throw new Error(parentVNode.vnodeSelector + ' had a ' + childNode.vnodeSelector + ' child ' + 'removed, but there were more than one. You must add unique key properties to make them distinguishable.');
}
}
}
}
}
};
var createDom;
var updateDom;
var updateChildren = function (vnode, domNode, oldChildren, newChildren, projectionOptions) {
if (oldChildren === newChildren) {
return false;
}
oldChildren = oldChildren || emptyArray;
newChildren = newChildren || emptyArray;
var oldChildrenLength = oldChildren.length;
var newChildrenLength = newChildren.length;
var transitions = projectionOptions.transitions;
var oldIndex = 0;
var newIndex = 0;
var i;
var textUpdated = false;
while (newIndex < newChildrenLength) {
var oldChild = oldIndex < oldChildrenLength ? oldChildren[oldIndex] : undefined;
var newChild = newChildren[newIndex];
if (oldChild !== undefined && same(oldChild, newChild)) {
textUpdated = updateDom(oldChild, newChild, projectionOptions) || textUpdated;
oldIndex++;
} else {
var findOldIndex = findIndexOfChild(oldChildren, newChild, oldIndex + 1);
if (findOldIndex >= 0) {
// Remove preceding missing children
for (i = oldIndex; i < findOldIndex; i++) {
nodeToRemove(oldChildren[i], transitions);
checkDistinguishable(oldChildren, i, vnode, 'removed');
}
textUpdated = updateDom(oldChildren[findOldIndex], newChild, projectionOptions) || textUpdated;
oldIndex = findOldIndex + 1;
} else {
// New child
createDom(newChild, domNode, oldIndex < oldChildrenLength ? oldChildren[oldIndex].domNode : undefined, projectionOptions);
nodeAdded(newChild, transitions);
checkDistinguishable(newChildren, newIndex, vnode, 'added');
}
}
newIndex++;
}
if (oldChildrenLength > oldIndex) {
// Remove child fragments
for (i = oldIndex; i < oldChildrenLength; i++) {
nodeToRemove(oldChildren[i], transitions);
checkDistinguishable(oldChildren, i, vnode, 'removed');
}
}
return textUpdated;
};
var addChildren = function (domNode, children, projectionOptions) {
if (!children) {
return;
}
for (var i = 0; i < children.length; i++) {
createDom(children[i], domNode, undefined, projectionOptions);
}
};
var initPropertiesAndChildren = function (domNode, vnode, projectionOptions) {
addChildren(domNode, vnode.children, projectionOptions);
// children before properties, needed for value property of