ZeroNet/src/Ui/media/all.js

1566 lines
134 KiB
JavaScript
Raw Normal View History

/* ---- src/Ui/media/lib/00-jquery.min.js ---- */
/*! jQuery v2.1.3 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */
!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.3",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)+1>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"n
},removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length<c?n.queue(this[0],a):void 0===b?this:this.each(function(){var c=n.queue(this,a,b);n._queueHooks(this,a),"fx"===a&&"inprogress"!==c[0]&&n.dequeue(this,a)})},dequeue:function(a){return this.each(function(){n.dequeue(this,a)})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,b){var c,d=1,e=n.Deferred(),f=this,g=this.length,h=function(){--d||e.resolveWith(f,[f])};"string"!=typeof a&&(b=a,a=void 0),a=a||"fx";while(g--)c=L.get(f[g],a+"queueHooks"),c&&c.empty&&(d++,c.empty.add(h));return h(),e.promise(b)}});var Q=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,R=["Top","Right","Bottom","Left"],S=function(a,b){return a=b||a,"none"===n.css(a,"display")||!n.contains(a.ownerDocument,a)},T=/^(?:checkbox|radio)$/i;!function(){var a=l.createDocumentFragment(),b=a.appendChild(l.createElement("div")),c=l.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="<textarea>x</textarea>",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateTyp
},removeAttr:function(a,b){var c,d,e=0,f=b&&b.match(E);if(f&&1===a.nodeType)while(c=f[e++])d=n.propFix[c]||c,n.expr.match.bool.test(c)&&(a[d]=!1),a.removeAttribute(c)},attrHooks:{type:{set:function(a,b){if(!k.radioValue&&"radio"===b&&n.nodeName(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}}}),Zb={set:function(a,b,c){return b===!1?n.removeAttr(a,c):a.setAttribute(c,c),c}},n.each(n.expr.match.bool.source.match(/\w+/g),function(a,b){var c=$b[b]||n.find.attr;$b[b]=function(a,b,d){var e,f;return d||(f=$b[b],$b[b]=e,e=null!=c(a,b,d)?b.toLowerCase():null,$b[b]=f),e}});var _b=/^(?:input|select|textarea|button)$/i;n.fn.extend({prop:function(a,b){return J(this,n.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[n.propFix[a]||a]})}}),n.extend({propFix:{"for":"htmlFor","class":"className"},prop:function(a,b,c){var d,e,f,g=a.nodeType;if(a&&3!==g&&8!==g&&2!==g)return f=1!==g||!n.isXMLDoc(a),f&&(b=n.propFix[b]||b,e=n.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){return a.hasAttribute("tabindex")||_b.test(a.nodeName)||a.href?a.tabIndex:-1}}}}),k.optSelected||(n.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null}}),n.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){n.propFix[this.toLowerCase()]=this});var ac=/[\t\r\n\f]/g;n.fn.extend({addClass:function(a){var b,c,d,e,f,g,h="string"==typeof a&&a,i=0,j=this.length;if(n.isFunction(a))return this.each(function(b){n(this).addClass(a.call(this,b,this.className))});if(h)for(b=(a||"").match(E)||[];j>i;i++)if(c=this[i],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ac," "):" ")){f=0;while(e=b[f++])d.indexOf(" "+e+" ")<0&&(d+=e+" ");g=n.trim(d),c.className!==g&&(c.className=g)}return this},removeClass:function(a){var b,c,d,e,f,g,h=0===arguments.length||"string"==typeof a&&a,i=0,j=this.length;if(n.isFunction(a))return this.each(function(b){n(this).removeClass(a.call(this,b,this.className))});if(h)for(b=(a||"").match(E)||[];j>i;i++)if(c=this[i],d=1===c.nodeType&&(c.className?(" "+c.className+" ").replace(ac," "):"")){f=0;while(e=b[f++])while(d.indexOf(" "+e+" ")>=0)d=d.replace(" "+e+" "," ");g=a?n.trim(d):"",c.className!==g&&(c.className=g)}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):this.each(n.isFunction(a)?function(c){n(this).toggleClass(a.call(this,c,this.className,b),b)}:function(){if("string"===c){var b,d=0,e=n(this),f=a.match(E)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else(c===U||"boolean"===c)&&(this.className&&L.set(this,"__className__",this.className),this.className=this.className||a===!1?"":L.get(this,"__className__")||"")})},hasClass:function(a){for(var b=" "+a+" ",c=0,d=this.length;d>c;c++)if(1===this[c].nodeType&&(" "+this[c].className+" ").replace(ac," ").indexOf(b)>=0)return!0;return!1}});var bc=/\r/g;n.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=n.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,n(this).val()):a,null==e?e="":"number"==typeof e?e+="":n.isArray(e)&&(e=n.map(e,function(a){return null==a?"":a+""})),b=n.valHooks[this.type]||n.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=n.valHooks[e.type]||n.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(bc,""):null==c?"":c)}}}),n.extend({valHooks:{option:{get:function(a){var b=n.find.attr(a,"value");return null!=b?b:n.trim(n.text(a))}},select:{get:function(a){for(var b,c,d=a.options,e=a.selectedIndex,f="select-one"===a.type||0>e,g=f?null:[],h=f?e+1:d.length,i=0>e?h:f?e:0;h>i;i++)if(c=d[i],!(!c.selected&&i!==e||(k.optDisabled?c.disabled:null!==c.getAttribute("disabled"))||c.par
/* ---- src/Ui/media/lib/RateLimit.coffee ---- */
(function() {
var call_after_interval, limits;
limits = {};
call_after_interval = {};
window.RateLimit = function(interval, fn) {
if (!limits[fn]) {
call_after_interval[fn] = false;
fn();
return limits[fn] = setTimeout((function() {
if (call_after_interval[fn]) {
fn();
}
delete limits[fn];
return delete call_after_interval[fn];
}), interval);
} else {
return call_after_interval[fn] = true;
}
};
}).call(this);
/* ---- src/Ui/media/lib/ZeroWebsocket.coffee ---- */
(function() {
var ZeroWebsocket,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__slice = [].slice;
ZeroWebsocket = (function() {
function ZeroWebsocket(url) {
this.onCloseWebsocket = __bind(this.onCloseWebsocket, this);
this.onErrorWebsocket = __bind(this.onErrorWebsocket, this);
this.onOpenWebsocket = __bind(this.onOpenWebsocket, this);
this.log = __bind(this.log, this);
this.route = __bind(this.route, this);
this.onMessage = __bind(this.onMessage, this);
this.url = url;
this.next_message_id = 1;
this.waiting_cb = {};
this.init();
}
ZeroWebsocket.prototype.init = function() {
return this;
};
ZeroWebsocket.prototype.connect = function() {
this.ws = new WebSocket(this.url);
this.ws.onmessage = this.onMessage;
this.ws.onopen = this.onOpenWebsocket;
this.ws.onerror = this.onErrorWebsocket;
2016-11-07 22:53:07 +01:00
this.ws.onclose = this.onCloseWebsocket;
this.connected = false;
return this.message_queue = [];
};
ZeroWebsocket.prototype.onMessage = function(e) {
var cmd, message;
message = JSON.parse(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 === "ping") {
return this.response(message.id, "pong");
} else {
return this.route(cmd, message);
}
};
ZeroWebsocket.prototype.route = function(cmd, message) {
return this.log("Unknown command", message);
};
ZeroWebsocket.prototype.response = function(to, result) {
return this.send({
"cmd": "response",
"to": to,
"result": result
});
};
ZeroWebsocket.prototype.cmd = function(cmd, params, cb) {
if (params == null) {
params = {};
}
if (cb == null) {
cb = null;
}
return this.send({
"cmd": cmd,
"params": params
}, cb);
};
ZeroWebsocket.prototype.send = function(message, cb) {
if (cb == null) {
cb = null;
}
if (message.id == null) {
message.id = this.next_message_id;
this.next_message_id += 1;
}
2016-11-07 22:53:07 +01:00
if (this.connected) {
this.ws.send(JSON.stringify(message));
} else {
this.log("Not connected, adding message to queue");
this.message_queue.push(message);
}
if (cb) {
return this.waiting_cb[message.id] = cb;
}
};
ZeroWebsocket.prototype.log = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return console.log.apply(console, ["[ZeroWebsocket]"].concat(__slice.call(args)));
};
ZeroWebsocket.prototype.onOpenWebsocket = function(e) {
2016-11-07 22:53:07 +01:00
var message, _i, _len, _ref;
this.log("Open");
2016-11-07 22:53:07 +01:00
this.connected = true;
_ref = this.message_queue;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
message = _ref[_i];
this.ws.send(JSON.stringify(message));
}
this.message_queue = [];
if (this.onOpen != null) {
return this.onOpen(e);
}
};
ZeroWebsocket.prototype.onErrorWebsocket = function(e) {
this.log("Error", e);
if (this.onError != null) {
return this.onError(e);
}
};
ZeroWebsocket.prototype.onCloseWebsocket = function(e, reconnect) {
if (reconnect == null) {
reconnect = 10000;
}
this.log("Closed", e);
2016-11-07 22:53:07 +01:00
this.connected = false;
if (e && e.code === 1000 && e.wasClean === false) {
this.log("Server error, please reload the page", e.wasClean);
} else {
setTimeout(((function(_this) {
return function() {
_this.log("Reconnecting...");
return _this.connect();
};
})(this)), reconnect);
}
if (this.onClose != null) {
return this.onClose(e);
}
};
return ZeroWebsocket;
})();
window.ZeroWebsocket = ZeroWebsocket;
}).call(this);
/* ---- src/Ui/media/lib/jquery.cssanim.js ---- */
jQuery.cssHooks['scale'] = {
get: function(elem, computed) {
var match = window.getComputedStyle(elem)[transform_property].match("[0-9\.]+")
if (match) {
var scale = parseFloat(match[0])
return scale
} else {
return 1.0
}
},
set: function(elem, val) {
//var transforms = $(elem).css("transform").match(/[0-9\.]+/g)
var transforms = window.getComputedStyle(elem)[transform_property].match(/[0-9\.]+/g)
if (transforms) {
transforms[0] = val
transforms[3] = val
//$(elem).css("transform", 'matrix('+transforms.join(", ")+")")
elem.style[transform_property] = 'matrix('+transforms.join(", ")+')'
} else {
elem.style[transform_property] = "scale("+val+")"
}
}
}
jQuery.fx.step.scale = function(fx) {
jQuery.cssHooks['scale'].set(fx.elem, fx.now)
};
if (window.getComputedStyle(document.body).transform) {
transform_property = "transform"
} else {
transform_property = "webkitTransform"
}
/* ---- src/Ui/media/lib/jquery.csslater.coffee ---- */
(function() {
jQuery.fn.readdClass = function(class_name) {
var elem;
elem = this;
elem.removeClass(class_name);
setTimeout((function() {
return elem.addClass(class_name);
}), 1);
return this;
};
jQuery.fn.removeLater = function(time) {
var elem;
if (time == null) {
time = 500;
}
elem = this;
setTimeout((function() {
return elem.remove();
}), time);
return this;
};
jQuery.fn.hideLater = function(time) {
var elem;
if (time == null) {
time = 500;
}
elem = this;
setTimeout((function() {
if (elem.css("opacity") === 0) {
return elem.css("display", "none");
}
}), time);
return this;
};
jQuery.fn.addClassLater = function(class_name, time) {
var elem;
if (time == null) {
time = 5;
}
elem = this;
setTimeout((function() {
return elem.addClass(class_name);
}), time);
return this;
};
jQuery.fn.cssLater = function(name, val, time) {
var elem;
if (time == null) {
time = 500;
}
elem = this;
setTimeout((function() {
return elem.css(name, val);
}), time);
return this;
};
}).call(this);
/* ---- src/Ui/media/lib/jquery.easing.1.3.js ---- */
/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*
* Uses the built in easing capabilities added In jQuery 1.1
* to offer multiple easing options
*
* TERMS OF USE - jQuery Easing
*
* Open source under the BSD License.
*
* Copyright © 2008 George McGinley Smith
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the author nor the names of contributors may be used to endorse
* or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
def: 'easeOutQuad',
swing: function (x, t, b, c, d) {
//alert(jQuery.easing.default);
return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
},
easeInQuad: function (x, t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutQuad: function (x, t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
easeInOutQuad: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeInCubic: function (x, t, b, c, d) {
return c*(t/=d)*t*t + b;
},
easeOutCubic: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
},
easeInOutCubic: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
},
easeInQuart: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t + b;
},
easeOutQuart: function (x, t, b, c, d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeInOutQuart: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
return -c/2 * ((t-=2)*t*t*t - 2) + b;
},
easeInQuint: function (x, t, b, c, d) {
return c*(t/=d)*t*t*t*t + b;
},
easeOutQuint: function (x, t, b, c, d) {
return c*((t=t/d-1)*t*t*t*t + 1) + b;
},
easeInOutQuint: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
return c/2*((t-=2)*t*t*t*t + 2) + b;
},
easeInSine: function (x, t, b, c, d) {
return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
},
easeOutSine: function (x, t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
},
easeInOutSine: function (x, t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
},
easeInExpo: function (x, t, b, c, d) {
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
},
easeOutExpo: function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
},
easeInOutExpo: function (x, t, b, c, d) {
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
},
easeInCirc: function (x, t, b, c, d) {
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeOutCirc: function (x, t, b, c, d) {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeInOutCirc: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
},
easeInElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
},
easeOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
},
easeInOutElastic: function (x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
},
easeInBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*(t/=d)*t*((s+1)*t - s) + b;
},
easeOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
easeInOutBack: function (x, t, b, c, d, s) {
if (s == undefined) s = 1.70158;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
},
easeInBounce: function (x, t, b, c, d) {
return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
},
easeOutBounce: function (x, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
},
easeInOutBounce: function (x, t, b, c, d) {
if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
}
});
/*
*
* TERMS OF USE - EASING EQUATIONS
*
* Open source under the BSD License.
*
* Copyright © 2001 Robert Penner
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of the author nor the names of contributors may be used to endorse
* or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* ---- src/Ui/media/Fixbutton.coffee ---- */
(function() {
var Fixbutton;
Fixbutton = (function() {
function Fixbutton() {
this.dragging = false;
$(".fixbutton-bg").on("mouseover", function() {
$(".fixbutton-bg").stop().animate({
"scale": 0.7
}, 800, "easeOutElastic");
$(".fixbutton-burger").stop().animate({
"opacity": 1.5,
"left": 0
}, 800, "easeOutElastic");
return $(".fixbutton-text").stop().animate({
"opacity": 0,
"left": 20
}, 300, "easeOutCubic");
});
$(".fixbutton-bg").on("mouseout", function() {
if ($(".fixbutton").hasClass("dragging")) {
return true;
}
$(".fixbutton-bg").stop().animate({
"scale": 0.6
}, 300, "easeOutCubic");
$(".fixbutton-burger").stop().animate({
"opacity": 0,
"left": -20
}, 300, "easeOutCubic");
return $(".fixbutton-text").stop().animate({
"opacity": 1,
"left": 0
}, 300, "easeOutBack");
});
/*$(".fixbutton-bg").on "click", ->
return false
*/
$(".fixbutton-bg").on("mousedown", function() {});
$(".fixbutton-bg").on("mouseup", function() {});
}
return Fixbutton;
})();
window.Fixbutton = Fixbutton;
}).call(this);
/* ---- src/Ui/media/Loading.coffee ---- */
(function() {
var Loading;
Loading = (function() {
function Loading() {
if (window.show_loadingscreen) {
this.showScreen();
}
2016-08-10 12:28:05 +02:00
this.timer_hide = null;
}
Loading.prototype.setProgress = function(percent) {
2016-08-10 12:28:05 +02:00
if (this.timer_hide) {
clearInterval(this.timer_hide);
}
return RateLimit(200, function() {
return $(".progressbar").css("width", percent * 100 + "%").css("opacity", "1").css("display", "block");
});
};
Loading.prototype.hideProgress = function() {
console.log("hideProgress");
2016-08-10 12:28:05 +02:00
return this.timer_hide = setTimeout(((function(_this) {
return function() {
return $(".progressbar").css("width", "100%").css("opacity", "0").hideLater(1000);
};
})(this)), 300);
};
Loading.prototype.showScreen = function() {
$(".loadingscreen").css("display", "block").addClassLater("ready");
this.screen_visible = true;
return this.printLine("&nbsp;&nbsp;&nbsp;Connecting...");
};
Loading.prototype.showTooLarge = function(site_info) {
var button, line;
if ($(".console .button-setlimit").length === 0) {
line = this.printLine("Site size: <b>" + (parseInt(site_info.settings.size / 1024 / 1024)) + "MB</b> is larger than default allowed " + (parseInt(site_info.size_limit)) + "MB", "warning");
2016-11-18 20:07:26 +01:00
button = $("<a href='#Set+limit' class='button button-setlimit'>" + ("Open site and set size limit to " + site_info.next_size_limit + "MB") + "</a>");
button.on("click", (function() {
return window.wrapper.setSizeLimit(site_info.next_size_limit);
}));
line.after(button);
return setTimeout(((function(_this) {
return function() {
return _this.printLine('Ready.');
};
})(this)), 100);
}
};
Loading.prototype.hideScreen = function() {
console.log("hideScreen");
if (!$(".loadingscreen").hasClass("done")) {
if (this.screen_visible) {
$(".loadingscreen").addClass("done").removeLater(2000);
} else {
$(".loadingscreen").remove();
}
}
return this.screen_visible = false;
};
Loading.prototype.print = function(text, type) {
var last_line;
if (type == null) {
type = "normal";
}
if (!this.screen_visible) {
return false;
}
$(".loadingscreen .console .cursor").remove();
last_line = $(".loadingscreen .console .console-line:last-child");
if (type === "error") {
text = "<span class='console-error'>" + text + "</span>";
}
return last_line.html(last_line.html() + text);
};
Loading.prototype.printLine = function(text, type) {
var line;
if (type == null) {
type = "normal";
}
if (!this.screen_visible) {
return false;
}
$(".loadingscreen .console .cursor").remove();
if (type === "error") {
text = "<span class='console-error'>" + text + "</span>";
} else {
text = text + "<span class='cursor'> </span>";
}
line = $("<div class='console-line'>" + text + "</div>").appendTo(".loadingscreen .console");
if (type === "warning") {
line.addClass("console-warning");
}
return line;
};
return Loading;
})();
window.Loading = Loading;
}).call(this);
/* ---- src/Ui/media/Notifications.coffee ---- */
(function() {
var Notifications,
2017-07-18 20:55:53 +02:00
slice = [].slice;
Notifications = (function() {
2017-07-18 20:55:53 +02:00
function Notifications(elem1) {
this.elem = elem1;
this;
}
Notifications.prototype.test = function() {
setTimeout(((function(_this) {
return function() {
_this.add("connection", "error", "Connection lost to <b>UiServer</b> on <b>localhost</b>!");
return _this.add("message-Anyone", "info", "New from <b>Anyone</b>.");
};
})(this)), 1000);
return setTimeout(((function(_this) {
return function() {
return _this.add("connection", "done", "<b>UiServer</b> connection recovered.", 5000);
};
})(this)), 3000);
};
Notifications.prototype.add = function(id, type, body, timeout) {
2017-07-18 20:55:53 +02:00
var elem, i, len, ref, width;
if (timeout == null) {
timeout = 0;
}
id = id.replace(/[^A-Za-z0-9]/g, "");
2017-07-18 20:55:53 +02:00
ref = $(".notification-" + id);
for (i = 0, len = ref.length; i < len; i++) {
elem = ref[i];
this.close($(elem));
}
elem = $(".notification.template", this.elem).clone().removeClass("template");
elem.addClass("notification-" + type).addClass("notification-" + id);
2017-01-16 13:41:11 +01:00
if (type === "progress") {
elem.addClass("notification-done");
}
if (type === "error") {
$(".notification-icon", elem).html("!");
} else if (type === "done") {
$(".notification-icon", elem).html("<div class='icon-success'></div>");
2017-01-16 13:41:11 +01:00
} else if (type === "progress") {
$(".notification-icon", elem).html("<div class='icon-success'></div>");
} else if (type === "ask") {
$(".notification-icon", elem).html("?");
} else {
$(".notification-icon", elem).html("i");
}
if (typeof body === "string") {
$(".body", elem).html("<span class='message'>" + body + "</span>");
} else {
$(".body", elem).html("").append(body);
}
elem.appendTo(this.elem);
if (timeout) {
$(".close", elem).remove();
setTimeout(((function(_this) {
return function() {
return _this.close(elem);
};
})(this)), timeout);
}
width = elem.outerWidth();
if (!timeout) {
width += 20;
}
if (elem.outerHeight() > 55) {
elem.addClass("long");
}
elem.css({
"width": "50px",
"transform": "scale(0.01)"
});
elem.animate({
"scale": 1
}, 800, "easeOutElastic");
elem.animate({
"width": width
}, 700, "easeInOutCubic");
2017-07-28 15:36:49 +02:00
$(".body", elem).css({
"width": width - 80
});
$(".body", elem).cssLater("box-shadow", "0px 0px 5px rgba(0,0,0,0.1)", 1000);
$(".close, .button", elem).on("click", (function(_this) {
return function() {
_this.close(elem);
return false;
};
})(this));
2017-01-16 13:41:11 +01:00
$(".select", elem).on("click", (function(_this) {
return function() {
return _this.close(elem);
};
})(this));
2017-01-16 13:41:11 +01:00
return elem;
};
Notifications.prototype.close = function(elem) {
elem.stop().animate({
"width": 0,
"opacity": 0
}, 700, "easeInOutCubic");
return elem.slideUp(300, (function() {
return elem.remove();
}));
};
Notifications.prototype.log = function() {
var args;
2017-07-18 20:55:53 +02:00
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return console.log.apply(console, ["[Notifications]"].concat(slice.call(args)));
};
return Notifications;
})();
window.Notifications = Notifications;
}).call(this);
/* ---- src/Ui/media/Wrapper.coffee ---- */
(function() {
var Wrapper, origin, proto, ws_url,
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; },
slice = [].slice;
Wrapper = (function() {
function Wrapper(ws_url) {
this.gotoSite = bind(this.gotoSite, this);
this.setSizeLimit = bind(this.setSizeLimit, this);
this.onLoad = bind(this.onLoad, this);
this.onCloseWebsocket = bind(this.onCloseWebsocket, this);
this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
this.onMessageInner = bind(this.onMessageInner, this);
this.onMessageWebsocket = bind(this.onMessageWebsocket, this);
this.log("Created!");
this.loading = new Loading();
this.notifications = new Notifications($(".notifications"));
this.fixbutton = new Fixbutton();
window.addEventListener("message", this.onMessageInner, false);
this.inner = document.getElementById("inner-iframe").contentWindow;
this.ws = new ZeroWebsocket(ws_url);
this.ws.next_message_id = 1000000;
this.ws.onOpen = this.onOpenWebsocket;
this.ws.onClose = this.onCloseWebsocket;
this.ws.onMessage = this.onMessageWebsocket;
this.ws.connect();
this.ws_error = null;
this.site_info = null;
this.event_site_info = $.Deferred();
this.inner_loaded = false;
this.inner_ready = false;
this.wrapperWsInited = false;
this.site_error = null;
this.address = null;
2016-03-26 00:20:53 +01:00
this.opener_tested = false;
window.onload = this.onLoad;
window.onhashchange = (function(_this) {
return function(e) {
var src;
_this.log("Hashchange", window.location.hash);
if (window.location.hash) {
src = $("#inner-iframe").attr("src").replace(/#.*/, "") + window.location.hash;
return $("#inner-iframe").attr("src", src);
}
};
})(this);
window.onpopstate = (function(_this) {
return function(e) {
return _this.sendInner({
"cmd": "wrapperPopState",
"params": {
"href": document.location.href,
"state": e.state
}
});
};
})(this);
$("#inner-iframe").focus();
}
Wrapper.prototype.onMessageWebsocket = function(e) {
var cmd, id, message, ref, type;
message = JSON.parse(e.data);
cmd = message.cmd;
if (cmd === "response") {
if (this.ws.waiting_cb[message.to] != null) {
return this.ws.waiting_cb[message.to](message.result);
} else {
return this.sendInner(message);
}
} else if (cmd === "notification") {
type = message.params[0];
2017-07-18 20:55:53 +02:00
id = "notification-ws-" + message.id;
if (indexOf.call(message.params[0], "-") >= 0) {
ref = message.params[0].split("-"), id = ref[0], type = ref[1];
}
return this.notifications.add(id, type, message.params[1], message.params[2]);
2017-01-16 13:41:11 +01:00
} else if (cmd === "progress") {
return this.actionProgress(message);
} else if (cmd === "prompt") {
return this.displayPrompt(message.params[0], message.params[1], message.params[2], message.params[3], (function(_this) {
return function(res) {
return _this.ws.response(message.id, res);
};
})(this));
} else if (cmd === "confirm") {
return this.displayConfirm(message.params[0], message.params[1], (function(_this) {
return function(res) {
return _this.ws.response(message.id, res);
};
})(this));
} else if (cmd === "setSiteInfo") {
this.sendInner(message);
if (message.params.address === this.address) {
2016-08-10 12:28:05 +02:00
this.setSiteInfo(message.params);
}
2016-08-10 12:28:05 +02:00
return this.updateProgress(message.params);
} else if (cmd === "error") {
return this.notifications.add("notification-" + message.id, "error", message.params, 0);
} else if (cmd === "updating") {
this.ws.ws.close();
return this.ws.onCloseWebsocket(null, 4000);
} else {
return this.sendInner(message);
}
};
Wrapper.prototype.onMessageInner = function(e) {
var cmd, message, query;
2016-03-26 00:20:53 +01:00
if (!window.postmessage_nonce_security && this.opener_tested === false) {
if (window.opener && window.opener !== window) {
this.log("Opener present", window.opener);
this.displayOpenerDialog();
return false;
} else {
2016-03-26 00:20:53 +01:00
this.opener_tested = true;
}
}
message = e.data;
if (!message.cmd) {
2017-08-09 14:21:09 +02:00
this.log("Invalid message:", message);
return false;
}
if (window.postmessage_nonce_security && message.wrapper_nonce !== window.wrapper_nonce) {
this.log("Message nonce error:", message.wrapper_nonce, '!=', window.wrapper_nonce);
return;
}
cmd = message.cmd;
if (cmd === "innerReady") {
this.inner_ready = true;
if (this.ws.ws.readyState === 1 && !this.wrapperWsInited) {
this.sendInner({
"cmd": "wrapperOpenedWebsocket"
});
return this.wrapperWsInited = true;
}
} else if (cmd === "innerLoaded" || cmd === "wrapperInnerLoaded") {
if (window.location.hash) {
$("#inner-iframe")[0].src += window.location.hash;
return this.log("Added hash to location", $("#inner-iframe")[0].src);
}
} else if (cmd === "wrapperNotification") {
return this.actionNotification(message);
} else if (cmd === "wrapperConfirm") {
return this.actionConfirm(message);
} else if (cmd === "wrapperPrompt") {
return this.actionPrompt(message);
2017-01-16 13:41:11 +01:00
} else if (cmd === "wrapperProgress") {
return this.actionProgress(message);
} else if (cmd === "wrapperSetViewport") {
return this.actionSetViewport(message);
2016-11-22 02:06:32 +01:00
} else if (cmd === "wrapperSetTitle") {
return $("head title").text(message.params);
} else if (cmd === "wrapperReload") {
return this.actionReload(message);
} else if (cmd === "wrapperGetLocalStorage") {
return this.actionGetLocalStorage(message);
} else if (cmd === "wrapperSetLocalStorage") {
return this.actionSetLocalStorage(message);
} else if (cmd === "wrapperPushState") {
query = this.toRelativeQuery(message.params[2]);
return window.history.pushState(message.params[0], message.params[1], query);
} else if (cmd === "wrapperReplaceState") {
query = this.toRelativeQuery(message.params[2]);
return window.history.replaceState(message.params[0], message.params[1], query);
} else if (cmd === "wrapperGetState") {
return this.sendInner({
"cmd": "response",
"to": message.id,
"result": window.history.state
});
} else if (cmd === "wrapperGetAjaxKey") {
return this.sendInner({
"cmd": "response",
"to": message.id,
"result": window.ajax_key
});
2016-03-19 18:05:08 +01:00
} else if (cmd === "wrapperOpenWindow") {
return this.actionOpenWindow(message.params);
2016-08-10 12:28:05 +02:00
} else if (cmd === "wrapperPermissionAdd") {
return this.actionPermissionAdd(message);
2016-12-30 19:32:36 +01:00
} else if (cmd === "wrapperRequestFullscreen") {
return this.actionRequestFullscreen();
} else {
if (message.id < 1000000) {
return this.ws.send(message);
} else {
return this.log("Invalid inner message id");
}
}
};
Wrapper.prototype.toRelativeQuery = function(query) {
var back;
if (query == null) {
query = null;
}
if (query === null) {
query = window.location.search;
}
back = window.location.pathname;
2016-12-14 00:25:47 +01:00
if (back.match(/^\/[^\/]+$/)) {
back += "/";
}
if (query.startsWith("#")) {
back = query;
} else if (query.replace("?", "")) {
back += "?" + query.replace("?", "");
}
return back;
};
Wrapper.prototype.displayOpenerDialog = function() {
var elem;
elem = $("<div class='opener-overlay'><div class='dialog'>You have opened this page by clicking on a link. Please, confirm if you want to load this site.<a href='?' target='_blank' class='button'>Open site</a></div></div>");
elem.find('a').on("click", function() {
window.open("?", "_blank");
window.close();
return false;
});
return $("body").prepend(elem);
};
2016-03-19 18:05:08 +01:00
Wrapper.prototype.actionOpenWindow = function(params) {
var w;
if (typeof params === "string") {
w = window.open();
w.opener = null;
return w.location = params;
} else {
w = window.open(null, params[1], params[2]);
2016-03-19 18:05:08 +01:00
w.opener = null;
return w.location = params[0];
}
};
2016-12-30 19:32:36 +01:00
Wrapper.prototype.actionRequestFullscreen = function() {
var elem, request_fullscreen;
if (indexOf.call(this.site_info.settings.permissions, "Fullscreen") >= 0) {
2016-12-30 19:32:36 +01:00
elem = document.getElementById("inner-iframe");
request_fullscreen = elem.requestFullScreen || elem.webkitRequestFullscreen || elem.mozRequestFullScreen || elem.msRequestFullScreen;
request_fullscreen.call(elem);
return setTimeout(((function(_this) {
return function() {
if (window.innerHeight !== screen.height) {
return _this.displayConfirm("This site requests permission:" + " <b>Fullscreen</b>", "Grant", function() {
return request_fullscreen.call(elem);
});
}
};
})(this)), 100);
} else {
return this.displayConfirm("This site requests permission:" + " <b>Fullscreen</b>", "Grant", (function(_this) {
return function() {
_this.site_info.settings.permissions.push("Fullscreen");
_this.actionRequestFullscreen();
return _this.ws.cmd("permissionAdd", "Fullscreen");
};
})(this));
}
};
2016-08-10 12:28:05 +02:00
Wrapper.prototype.actionPermissionAdd = function(message) {
var permission;
permission = message.params;
return this.ws.cmd("permissionDetails", permission, (function(_this) {
return function(permission_details) {
return _this.displayConfirm("This site requests permission:" + (" <b>" + (_this.toHtmlSafe(permission)) + "</b>") + ("<br><small style='color: #4F4F4F'>" + permission_details + "</small>"), "Grant", function() {
return _this.ws.cmd("permissionAdd", permission, function() {
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": "Granted"
});
2016-08-10 12:28:05 +02:00
});
});
};
})(this));
};
Wrapper.prototype.actionNotification = function(message) {
var body;
message.params = this.toHtmlSafe(message.params);
body = $("<span class='message'>" + message.params[1] + "</span>");
return this.notifications.add("notification-" + message.id, message.params[0], body, message.params[2]);
};
Wrapper.prototype.displayConfirm = function(message, captions, cb) {
2017-05-18 03:05:02 +02:00
var body, button, buttons, caption, i, j, len;
body = $("<span class='message-outer'><span class='message'>" + message + "</span></span>");
buttons = $("<span class='buttons'></span>");
if (!(captions instanceof Array)) {
captions = [captions];
}
for (i = j = 0, len = captions.length; j < len; i = ++j) {
caption = captions[i];
2017-05-18 03:05:02 +02:00
button = $("<a href='#" + caption + "' class='button button-confirm button-" + caption + " button-" + (i + 1) + "' data-value='" + (i + 1) + "'>" + caption + "</a>");
button.on("click", (function(_this) {
return function(e) {
cb(parseInt(e.currentTarget.dataset.value));
return false;
};
})(this));
2017-05-18 03:05:02 +02:00
buttons.append(button);
}
2017-05-18 03:05:02 +02:00
body.append(buttons);
this.notifications.add("notification-" + caption, "ask", body);
2017-05-18 03:05:02 +02:00
buttons.first().focus();
return $(".notification").scrollLeft(0);
};
Wrapper.prototype.actionConfirm = function(message, cb) {
var caption;
if (cb == null) {
cb = false;
}
message.params = this.toHtmlSafe(message.params);
if (message.params[1]) {
caption = message.params[1];
} else {
caption = "ok";
}
return this.displayConfirm(message.params[0], caption, (function(_this) {
return function(res) {
_this.sendInner({
"cmd": "response",
"to": message.id,
"result": res
});
return false;
};
})(this));
};
Wrapper.prototype.displayPrompt = function(message, type, caption, placeholder, cb) {
var body, button, input;
body = $("<span class='message'>" + message + "</span>");
input = $("<input type='" + type + "' class='input button-" + type + "' placeholder='" + placeholder + "'/>");
input.on("keyup", (function(_this) {
return function(e) {
if (e.keyCode === 13) {
return button.trigger("click");
}
};
})(this));
body.append(input);
button = $("<a href='#" + caption + "' class='button button-" + caption + "'>" + caption + "</a>");
button.on("click", (function(_this) {
return function() {
cb(input.val());
return false;
};
})(this));
body.append(button);
this.notifications.add("notification-" + message.id, "ask", body);
input.focus();
return $(".notification").scrollLeft(0);
};
Wrapper.prototype.actionPrompt = function(message) {
var caption, placeholder, type;
message.params = this.toHtmlSafe(message.params);
if (message.params[1]) {
type = message.params[1];
} else {
type = "text";
}
caption = message.params[2] ? message.params[2] : "OK";
2017-05-23 12:42:02 +02:00
if (message.params[3] != null) {
placeholder = message.params[3];
} else {
placeholder = "";
}
return this.displayPrompt(message.params[0], type, caption, placeholder, (function(_this) {
return function(res) {
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": res
});
};
})(this));
};
2017-01-16 13:41:11 +01:00
Wrapper.prototype.actionProgress = function(message) {
var body, circle, elem, offset, percent, width;
message.params = this.toHtmlSafe(message.params);
percent = Math.min(100, message.params[2]) / 100;
offset = 75 - (percent * 75);
circle = "<div class=\"circle\"><svg class=\"circle-svg\" width=\"30\" height=\"30\" viewport=\"0 0 30 30\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle r=\"12\" cx=\"15\" cy=\"15\" fill=\"transparent\" class=\"circle-bg\"></circle>\n <circle r=\"12\" cx=\"15\" cy=\"15\" fill=\"transparent\" class=\"circle-fg\" style=\"stroke-dashoffset: " + offset + "\"></circle>\n</svg></div>";
body = "<span class='message'>" + message.params[1] + "</span>" + circle;
elem = $(".notification-" + message.params[0]);
if (elem.length) {
width = $(".body .message", elem).outerWidth();
$(".body .message", elem).html(message.params[1]);
if ($(".body .message", elem).css("width") === "") {
$(".body .message", elem).css("width", width);
}
$(".body .circle-fg", elem).css("stroke-dashoffset", offset);
} else {
elem = this.notifications.add(message.params[0], "progress", $(body));
}
if (percent > 0) {
$(".body .circle-bg", elem).css({
"animation-play-state": "paused",
"stroke-dasharray": "180px"
});
}
if ($(".notification-icon", elem).data("done")) {
return false;
} else if (message.params[2] >= 100) {
$(".circle-fg", elem).css("transition", "all 0.3s ease-in-out");
setTimeout((function() {
$(".notification-icon", elem).css({
transform: "scale(1)",
opacity: 1
});
return $(".notification-icon .icon-success", elem).css({
transform: "rotate(45deg) scale(1)"
});
}), 300);
setTimeout(((function(_this) {
return function() {
return _this.notifications.close(elem);
};
})(this)), 3000);
return $(".notification-icon", elem).data("done", true);
} else if (message.params[2] < 0) {
$(".body .circle-fg", elem).css("stroke", "#ec6f47").css("transition", "transition: all 0.3s ease-in-out");
setTimeout(((function(_this) {
return function() {
$(".notification-icon", elem).css({
transform: "scale(1)",
opacity: 1
});
elem.removeClass("notification-done").addClass("notification-error");
return $(".notification-icon .icon-success", elem).removeClass("icon-success").html("!");
};
})(this)), 300);
return $(".notification-icon", elem).data("done", true);
}
};
Wrapper.prototype.actionSetViewport = function(message) {
this.log("actionSetViewport", message);
if ($("#viewport").length > 0) {
return $("#viewport").attr("content", this.toHtmlSafe(message.params));
} else {
return $('<meta name="viewport" id="viewport">').attr("content", this.toHtmlSafe(message.params)).appendTo("head");
}
};
2016-08-10 12:28:05 +02:00
Wrapper.prototype.actionReload = function(message) {
return this.reload();
};
Wrapper.prototype.reload = function(url_post) {
if (url_post == null) {
url_post = "";
}
if (url_post) {
if (window.location.toString().indexOf("?") > 0) {
return window.location += "&" + url_post;
} else {
return window.location += "?" + url_post;
}
} else {
return window.location.reload();
}
};
Wrapper.prototype.actionGetLocalStorage = function(message) {
return $.when(this.event_site_info).done((function(_this) {
return function() {
var data;
data = localStorage.getItem("site." + _this.site_info.address + "." + _this.site_info.auth_address);
if (!data) {
data = localStorage.getItem("site." + _this.site_info.address);
if (data) {
localStorage.setItem("site." + _this.site_info.address + "." + _this.site_info.auth_address, data);
localStorage.removeItem("site." + _this.site_info.address);
_this.log("Migrated LocalStorage from global to auth_address based");
}
}
if (data) {
data = JSON.parse(data);
}
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": data
});
};
})(this));
};
Wrapper.prototype.actionSetLocalStorage = function(message) {
var back;
2016-08-10 12:28:05 +02:00
back = localStorage.setItem("site." + this.site_info.address + "." + this.site_info.auth_address, JSON.stringify(message.params));
return this.sendInner({
"cmd": "response",
"to": message.id,
"result": back
});
};
Wrapper.prototype.onOpenWebsocket = function(e) {
this.ws.cmd("channelJoin", {
"channel": "siteChanged"
});
if (!this.wrapperWsInited && this.inner_ready) {
this.sendInner({
"cmd": "wrapperOpenedWebsocket"
});
this.wrapperWsInited = true;
}
if (this.inner_loaded) {
this.reloadSiteInfo();
}
setTimeout(((function(_this) {
return function() {
if (!_this.site_info) {
return _this.reloadSiteInfo();
}
};
})(this)), 2000);
if (this.ws_error) {
this.notifications.add("connection", "done", "Connection with <b>UiServer Websocket</b> recovered.", 6000);
return this.ws_error = null;
}
};
Wrapper.prototype.onCloseWebsocket = function(e) {
this.wrapperWsInited = false;
return setTimeout(((function(_this) {
return function() {
_this.sendInner({
"cmd": "wrapperClosedWebsocket"
});
if (e && e.code === 1000 && e.wasClean === false) {
return _this.ws_error = _this.notifications.add("connection", "error", "UiServer Websocket error, please reload the page.");
} else if (e && e.code === 1001 && e.wasClean === true) {
} else if (!_this.ws_error) {
return _this.ws_error = _this.notifications.add("connection", "error", "Connection with <b>UiServer Websocket</b> was lost. Reconnecting...");
}
};
})(this)), 1000);
};
Wrapper.prototype.onLoad = function(e) {
var ref;
this.inner_loaded = true;
if (!this.inner_ready) {
this.sendInner({
"cmd": "wrapperReady"
});
}
if (this.ws.ws.readyState === 1 && !this.site_info) {
return this.reloadSiteInfo();
} else if (this.site_info && (((ref = this.site_info.content) != null ? ref.title : void 0) != null)) {
window.document.title = this.site_info.content.title + " - ZeroNet";
return this.log("Setting title to", window.document.title);
}
};
Wrapper.prototype.sendInner = function(message) {
return this.inner.postMessage(message, '*');
};
Wrapper.prototype.reloadSiteInfo = function() {
var params;
if (this.loading.screen_visible) {
params = {
"file_status": window.file_inner_path
};
} else {
params = {};
}
return this.ws.cmd("siteInfo", params, (function(_this) {
return function(site_info) {
_this.address = site_info.address;
_this.setSiteInfo(site_info);
if (site_info.settings.size > site_info.size_limit * 1024 * 1024) {
if (_this.loading.screen_visible) {
_this.loading.showTooLarge(site_info);
} else {
_this.displayConfirm("Site is larger than allowed: " + ((site_info.settings.size / 1024 / 1024).toFixed(1)) + "MB/" + site_info.size_limit + "MB", "Set limit to " + site_info.next_size_limit + "MB", function() {
return _this.ws.cmd("siteSetLimit", [site_info.next_size_limit], function(res) {
if (res === "ok") {
return _this.notifications.add("size_limit", "done", "Site storage limit modified!", 5000);
}
});
});
}
}
if (site_info.content) {
window.document.title = site_info.content.title + " - ZeroNet";
return _this.log("Setting title to", window.document.title);
}
};
})(this));
};
Wrapper.prototype.setSiteInfo = function(site_info) {
if (site_info.event != null) {
if (site_info.event[0] === "file_added" && site_info.bad_files) {
this.loading.printLine(site_info.bad_files + " files needs to be downloaded");
} else if (site_info.event[0] === "file_done") {
this.loading.printLine(site_info.event[1] + " downloaded");
if (site_info.event[1] === window.file_inner_path) {
this.loading.hideScreen();
if (!this.site_info) {
this.reloadSiteInfo();
}
if (site_info.content) {
window.document.title = site_info.content.title + " - ZeroNet";
this.log("Required file done, setting title to", window.document.title);
}
2017-01-27 12:09:23 +01:00
if (!window.show_loadingscreen) {
this.notifications.add("modified", "info", "New version of this page has just released.<br>Reload to see the modified content.");
}
}
} else if (site_info.event[0] === "file_failed") {
this.site_error = site_info.event[1];
if (site_info.settings.size > site_info.size_limit * 1024 * 1024) {
this.loading.showTooLarge(site_info);
} else {
this.loading.printLine(site_info.event[1] + " download failed", "error");
}
} else if (site_info.event[0] === "peers_added") {
this.loading.printLine("Peers found: " + site_info.peers);
}
}
if (this.loading.screen_visible && !this.site_info) {
if (site_info.peers > 1) {
this.loading.printLine("Peers found: " + site_info.peers);
} else {
this.site_error = "No peers found";
this.loading.printLine("No peers found");
}
}
if (!this.site_info && !this.loading.screen_visible && $("#inner-iframe").attr("src").replace("?wrapper=False", "").replace(/\?wrapper_nonce=[A-Za-z0-9]+/, "").indexOf("?") === -1) {
if (site_info.size_limit * 1.1 < site_info.next_size_limit) {
this.displayConfirm("Running out of size limit (" + ((site_info.settings.size / 1024 / 1024).toFixed(1)) + "MB/" + site_info.size_limit + "MB)", "Set limit to " + site_info.next_size_limit + "MB", (function(_this) {
return function() {
_this.ws.cmd("siteSetLimit", [site_info.next_size_limit], function(res) {
if (res === "ok") {
return _this.notifications.add("size_limit", "done", "Site storage limit modified!", 5000);
}
});
return false;
};
})(this));
}
}
if (this.loading.screen_visible && this.inner_loaded && site_info.settings.size < site_info.size_limit * 1024 * 1024 && site_info.settings.size > 0) {
this.loading.hideScreen();
}
2016-08-10 12:28:05 +02:00
this.site_info = site_info;
return this.event_site_info.resolve();
};
Wrapper.prototype.updateProgress = function(site_info) {
if (site_info.tasks > 0 && site_info.started_task_num > 0) {
return this.loading.setProgress(1 - (Math.max(site_info.tasks, site_info.bad_files) / site_info.started_task_num));
} else {
2016-08-10 12:28:05 +02:00
return this.loading.hideProgress();
}
};
Wrapper.prototype.toHtmlSafe = function(values) {
var i, j, len, value;
if (!(values instanceof Array)) {
values = [values];
}
for (i = j = 0, len = values.length; j < len; i = ++j) {
value = values[i];
if (value instanceof Array) {
value = this.toHtmlSafe(value);
} else {
value = String(value).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
value = value.replace(/&lt;([\/]{0,1}(br|b|u|i))&gt;/g, "<$1>");
}
values[i] = value;
}
return values;
};
Wrapper.prototype.setSizeLimit = function(size_limit, reload) {
if (reload == null) {
reload = true;
}
this.ws.cmd("siteSetLimit", [size_limit], (function(_this) {
return function(res) {
var src;
if (res !== "ok") {
return false;
}
_this.loading.printLine(res);
_this.inner_loaded = false;
if (reload) {
src = $("iframe").attr("src");
$("iframe").attr("src", "");
return $("iframe").attr("src", src);
}
};
})(this));
return false;
};
Wrapper.prototype.isProxyRequest = function() {
return window.location.pathname === "/";
};
Wrapper.prototype.gotoSite = function(elem) {
var href;
href = $(elem).attr("href");
if (this.isProxyRequest()) {
return $(elem).attr("href", "http://zero" + href);
}
};
Wrapper.prototype.log = function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return console.log.apply(console, ["[Wrapper]"].concat(slice.call(args)));
};
return Wrapper;
})();
2016-04-20 23:22:39 +02:00
origin = window.server_url || window.location.href.replace(/(\:\/\/.*?)\/.*/, "$1");
if (origin.indexOf("https:") === 0) {
proto = {
ws: 'wss',
http: 'https'
};
} else {
proto = {
ws: 'ws',
http: 'http'
};
}
ws_url = proto.ws + ":" + origin.replace(proto.http + ":", "") + "/Websocket?wrapper_key=" + window.wrapper_key;
window.wrapper = new Wrapper(ws_url);
2017-08-09 14:21:09 +02:00
}).call(this);