ZeroNet/src/Ui/media/all.js

2125 lines
152 KiB
JavaScript
Raw Normal View History

2019-10-06 03:20:58 +02:00
/* ---- lib/00-jquery.min.js ---- */
2018-10-20 02:22:38 +02:00
/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */
!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){"use strict";var n=[],r=e.document,i=Object.getPrototypeOf,o=n.slice,a=n.concat,s=n.push,u=n.indexOf,l={},c=l.toString,f=l.hasOwnProperty,p=f.toString,d=p.call(Object),h={},g=function e(t){return"function"==typeof t&&"number"!=typeof t.nodeType},y=function e(t){return null!=t&&t===t.window},v={type:!0,src:!0,noModule:!0};function m(e,t,n){var i,o=(t=t||r).createElement("script");if(o.text=e,n)for(i in v)n[i]&&(o[i]=n[i]);t.head.appendChild(o).parentNode.removeChild(o)}function x(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[c.call(e)]||"object":typeof e}var b="3.3.1",w=function(e,t){return new w.fn.init(e,t)},T=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;w.fn=w.prototype={jquery:"3.3.1",constructor:w,length:0,toArray:function(){return o.call(this)},get:function(e){return null==e?o.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=w.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return w.each(this,e)},map:function(e){return this.pushStack(w.map(this,function(t,n){return e.call(t,n,t)}))},slice:function(){return this.pushStack(o.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(n>=0&&n<t?[this[n]]:[])},end:function(){return this.prevObject||this.constructor()},push:s,sort:n.sort,splice:n.splice},w.extend=w.fn.extend=function(){var e,t,n,r,i,o,a=arguments[0]||{},s=1,u=arguments.length,l=!1;for("boolean"==typeof a&&(l=a,a=arguments[s]||{},s++),"object"==typeof a||g(a)||(a={}),s===u&&(a=this,s--);s<u;s++)if(null!=(e=arguments[s]))for(t in e)n=a[t],a!==(r=e[t])&&(l&&r&&(w.isPlainObject(r)||(i=Array.isArray(r)))?(i?(i=!1,o=n&&Array.isArray(n)?n:[]):o=n&&w.isPlainObject(n)?n:{},a[t]=w.extend(l,o,r)):void 0!==r&&(a[t]=r));return a},w.extend({expando:"jQuery"+("3.3.1"+Math.random()).replace(/\D/g,""),isReady:!0,error:function(e){throw new Error(e)},noop:function(){},isPlainObject:function(e){var t,n;return!(!e||"[object Object]"!==c.call(e))&&(!(t=i(e))||"function"==typeof(n=f.call(t,"constructor")&&t.constructor)&&p.call(n)===d)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},globalEval:function(e){m(e)},each:function(e,t){var n,r=0;if(C(e)){for(n=e.length;r<n;r++)if(!1===t.call(e[r],r,e[r]))break}else for(r in e)if(!1===t.call(e[r],r,e[r]))break;return e},trim:function(e){return null==e?"":(e+"").replace(T,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(C(Object(e))?w.merge(n,"string"==typeof e?[e]:e):s.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:u.call(t,e,n)},merge:function(e,t){for(var n=+t.length,r=0,i=e.length;r<n;r++)e[i++]=t[r];return e.length=i,e},grep:function(e,t,n){for(var r,i=[],o=0,a=e.length,s=!n;o<a;o++)(r=!t(e[o],o))!==s&&i.push(e[o]);return i},map:function(e,t,n){var r,i,o=0,s=[];if(C(e))for(r=e.length;o<r;o++)null!=(i=t(e[o],o,n))&&s.push(i);else for(o in e)null!=(i=t(e[o],o,n))&&s.push(i);return a.apply([],s)},guid:1,support:h}),"function"==typeof Symbol&&(w.fn[Symbol.iterator]=n[Symbol.iterator]),w.each("Boolean Number String Function Array Date RegExp Object Error Symbol".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function C(e){var t=!!e&&"length"in e&&e.length,n=x(e);return!g(e)&&!y(e)&&("array"===n||0===t||"number"==typeof t&&t>0&&t-1 in e)}var E=function(e){var t,n,r,i,o,a,s,u,l,c,f,p,d,h,g,y,v,m,x,b="sizzle"+1*new Date,w=e.document,T=0,C=0,E=ae(),k=ae(),S=ae(),D=function(e,t){return e===t&&(f=!0),0},N={}.hasOwnProperty,A=[],j=A.pop,q=A.push,L=A.push,H=A.slice,O=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},P="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",R="(?:\\\\.|[\\w-
2019-10-06 03:20:58 +02:00
/* ---- 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);
2019-10-06 03:20:58 +02:00
/* ---- lib/Translate.coffee ---- */
(function() {
window._ = function(s) {
return s;
};
}).call(this);
2019-10-06 03:20:58 +02:00
/* ---- lib/ZeroWebsocket.coffee ---- */
(function() {
var ZeroWebsocket,
2018-02-21 03:15:04 +01:00
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
slice = [].slice;
ZeroWebsocket = (function() {
function ZeroWebsocket(url) {
2018-02-21 03:15:04 +01:00
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.response = bind(this.response, 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;
2018-02-21 03:15:04 +01:00
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return console.log.apply(console, ["[ZeroWebsocket]"].concat(slice.call(args)));
};
ZeroWebsocket.prototype.onOpenWebsocket = function(e) {
2018-02-21 03:15:04 +01:00
var i, len, message, ref;
this.log("Open");
2016-11-07 22:53:07 +01:00
this.connected = true;
2018-02-21 03:15:04 +01:00
ref = this.message_queue;
for (i = 0, len = ref.length; i < len; i++) {
message = ref[i];
2016-11-07 22:53:07 +01:00
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);
2019-10-06 03:20:58 +02:00
/* ---- 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"
}
2019-10-06 03:20:58 +02:00
/* ---- 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);
2019-10-06 03:20:58 +02:00
/* ---- lib/jquery.easing.js ---- */
/*
2018-10-20 02:22:38 +02:00
* jQuery Easing v1.4.1 - http://gsgd.co.uk/sandbox/jquery/easing/
* Open source under the BSD License.
* Copyright © 2008 George McGinley Smith
* All rights reserved.
2018-10-20 02:22:38 +02:00
* https://raw.github.com/gdsmith/jquery-easing/master/LICENSE
*/
2018-10-20 02:22:38 +02:00
(function (factory) {
if (typeof define === "function" && define.amd) {
define(['jquery'], function ($) {
return factory($);
});
} else if (typeof module === "object" && typeof module.exports === "object") {
exports = factory(require('jquery'));
} else {
factory(jQuery);
}
})(function($){
2018-10-20 02:22:38 +02:00
// Preserve the original jQuery "swing" easing as "jswing"
if (typeof $.easing !== 'undefined') {
$.easing['jswing'] = $.easing['swing'];
}
var pow = Math.pow,
sqrt = Math.sqrt,
sin = Math.sin,
cos = Math.cos,
PI = Math.PI,
c1 = 1.70158,
c2 = c1 * 1.525,
c3 = c1 + 1,
c4 = ( 2 * PI ) / 3,
c5 = ( 2 * PI ) / 4.5;
// x is the fraction of animation progress, in the range 0..1
function bounceOut(x) {
var n1 = 7.5625,
d1 = 2.75;
if ( x < 1/d1 ) {
return n1*x*x;
} else if ( x < 2/d1 ) {
return n1*(x-=(1.5/d1))*x + .75;
} else if ( x < 2.5/d1 ) {
return n1*(x-=(2.25/d1))*x + .9375;
} else {
return n1*(x-=(2.625/d1))*x + .984375;
}
}
$.extend( $.easing,
{
def: 'easeOutQuad',
2018-10-20 02:22:38 +02:00
swing: function (x) {
return $.easing[$.easing.def](x);
},
2018-10-20 02:22:38 +02:00
easeInQuad: function (x) {
return x * x;
},
2018-10-20 02:22:38 +02:00
easeOutQuad: function (x) {
return 1 - ( 1 - x ) * ( 1 - x );
},
2018-10-20 02:22:38 +02:00
easeInOutQuad: function (x) {
return x < 0.5 ?
2 * x * x :
1 - pow( -2 * x + 2, 2 ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInCubic: function (x) {
return x * x * x;
},
2018-10-20 02:22:38 +02:00
easeOutCubic: function (x) {
return 1 - pow( 1 - x, 3 );
},
2018-10-20 02:22:38 +02:00
easeInOutCubic: function (x) {
return x < 0.5 ?
4 * x * x * x :
1 - pow( -2 * x + 2, 3 ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInQuart: function (x) {
return x * x * x * x;
},
2018-10-20 02:22:38 +02:00
easeOutQuart: function (x) {
return 1 - pow( 1 - x, 4 );
},
2018-10-20 02:22:38 +02:00
easeInOutQuart: function (x) {
return x < 0.5 ?
8 * x * x * x * x :
1 - pow( -2 * x + 2, 4 ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInQuint: function (x) {
return x * x * x * x * x;
},
2018-10-20 02:22:38 +02:00
easeOutQuint: function (x) {
return 1 - pow( 1 - x, 5 );
},
2018-10-20 02:22:38 +02:00
easeInOutQuint: function (x) {
return x < 0.5 ?
16 * x * x * x * x * x :
1 - pow( -2 * x + 2, 5 ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInSine: function (x) {
return 1 - cos( x * PI/2 );
},
2018-10-20 02:22:38 +02:00
easeOutSine: function (x) {
return sin( x * PI/2 );
},
2018-10-20 02:22:38 +02:00
easeInOutSine: function (x) {
return -( cos( PI * x ) - 1 ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInExpo: function (x) {
return x === 0 ? 0 : pow( 2, 10 * x - 10 );
},
2018-10-20 02:22:38 +02:00
easeOutExpo: function (x) {
return x === 1 ? 1 : 1 - pow( 2, -10 * x );
},
2018-10-20 02:22:38 +02:00
easeInOutExpo: function (x) {
return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ?
pow( 2, 20 * x - 10 ) / 2 :
( 2 - pow( 2, -20 * x + 10 ) ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInCirc: function (x) {
return 1 - sqrt( 1 - pow( x, 2 ) );
},
2018-10-20 02:22:38 +02:00
easeOutCirc: function (x) {
return sqrt( 1 - pow( x - 1, 2 ) );
},
2018-10-20 02:22:38 +02:00
easeInOutCirc: function (x) {
return x < 0.5 ?
( 1 - sqrt( 1 - pow( 2 * x, 2 ) ) ) / 2 :
( sqrt( 1 - pow( -2 * x + 2, 2 ) ) + 1 ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInElastic: function (x) {
return x === 0 ? 0 : x === 1 ? 1 :
-pow( 2, 10 * x - 10 ) * sin( ( x * 10 - 10.75 ) * c4 );
},
2018-10-20 02:22:38 +02:00
easeOutElastic: function (x) {
return x === 0 ? 0 : x === 1 ? 1 :
pow( 2, -10 * x ) * sin( ( x * 10 - 0.75 ) * c4 ) + 1;
},
2018-10-20 02:22:38 +02:00
easeInOutElastic: function (x) {
return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ?
-( pow( 2, 20 * x - 10 ) * sin( ( 20 * x - 11.125 ) * c5 )) / 2 :
pow( 2, -20 * x + 10 ) * sin( ( 20 * x - 11.125 ) * c5 ) / 2 + 1;
},
2018-10-20 02:22:38 +02:00
easeInBack: function (x) {
return c3 * x * x * x - c1 * x * x;
},
2018-10-20 02:22:38 +02:00
easeOutBack: function (x) {
return 1 + c3 * pow( x - 1, 3 ) + c1 * pow( x - 1, 2 );
},
2018-10-20 02:22:38 +02:00
easeInOutBack: function (x) {
return x < 0.5 ?
( pow( 2 * x, 2 ) * ( ( c2 + 1 ) * 2 * x - c2 ) ) / 2 :
( pow( 2 * x - 2, 2 ) *( ( c2 + 1 ) * ( x * 2 - 2 ) + c2 ) + 2 ) / 2;
},
2018-10-20 02:22:38 +02:00
easeInBounce: function (x) {
return 1 - bounceOut( 1 - x );
},
2018-10-20 02:22:38 +02:00
easeOutBounce: bounceOut,
easeInOutBounce: function (x) {
return x < 0.5 ?
( 1 - bounceOut( 1 - 2 * x ) ) / 2 :
( 1 + bounceOut( 2 * x - 1 ) ) / 2;
}
});
2018-10-20 02:22:38 +02:00
});
2019-10-06 03:20:58 +02:00
/* ---- 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({
2018-10-30 04:47:19 +01:00
"opacity": 0.9,
"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);
2019-10-06 03:20:58 +02:00
/* ---- Infopanel.coffee ---- */
2019-02-02 00:12:50 +01:00
(function() {
var Infopanel,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
2019-02-02 00:12:50 +01:00
Infopanel = (function() {
function Infopanel(elem) {
this.elem = elem;
this.setAction = bind(this.setAction, this);
2019-02-09 13:56:21 +01:00
this.setClosedNum = bind(this.setClosedNum, this);
this.setTitle = bind(this.setTitle, this);
this.open = bind(this.open, this);
this.close = bind(this.close, this);
this.hide = bind(this.hide, this);
this.updateEvents = bind(this.updateEvents, this);
this.unfold = bind(this.unfold, this);
this.show = bind(this.show, this);
2019-02-02 00:12:50 +01:00
this.visible = false;
}
Infopanel.prototype.show = function(closed) {
if (closed == null) {
closed = false;
}
2020-09-04 17:57:56 +02:00
this.elem.parent().addClass("visible");
if (closed) {
return this.close();
} else {
return this.open();
}
};
Infopanel.prototype.unfold = function() {
this.elem.toggleClass("unfolded");
return false;
};
Infopanel.prototype.updateEvents = function() {
this.elem.off("click");
this.elem.find(".close").off("click");
this.elem.find(".line").off("click");
this.elem.find(".line").on("click", this.unfold);
if (this.elem.hasClass("closed")) {
return this.elem.on("click", (function(_this) {
return function() {
_this.onOpened();
return _this.open();
};
})(this));
} else {
return this.elem.find(".close").on("click", (function(_this) {
return function() {
_this.onClosed();
return _this.close();
};
})(this));
}
2019-02-02 00:12:50 +01:00
};
Infopanel.prototype.hide = function() {
2020-09-04 17:57:56 +02:00
return this.elem.parent().removeClass("visible");
2019-02-02 00:12:50 +01:00
};
Infopanel.prototype.close = function() {
this.elem.addClass("closed");
this.updateEvents();
return false;
};
Infopanel.prototype.open = function() {
this.elem.removeClass("closed");
this.updateEvents();
return false;
};
2019-02-02 00:12:50 +01:00
Infopanel.prototype.setTitle = function(line1, line2) {
this.elem.find(".line-1").text(line1);
return this.elem.find(".line-2").text(line2);
};
2019-02-09 13:56:21 +01:00
Infopanel.prototype.setClosedNum = function(num) {
return this.elem.find(".closed-num").text(num);
};
2019-02-02 00:12:50 +01:00
Infopanel.prototype.setAction = function(title, func) {
return this.elem.find(".button").text(title).off("click").on("click", func);
};
return Infopanel;
})();
window.Infopanel = Infopanel;
}).call(this);
2019-10-06 03:20:58 +02:00
/* ---- Loading.coffee ---- */
(function() {
2020-01-04 16:54:20 +01:00
var Loading,
slice = [].slice;
Loading = (function() {
2018-02-22 23:34:18 +01:00
function Loading(wrapper) {
this.wrapper = wrapper;
if (window.show_loadingscreen) {
this.showScreen();
}
2016-08-10 12:28:05 +02:00
this.timer_hide = null;
2020-09-04 17:57:56 +02:00
this.timer_set = null;
}
Loading.prototype.setProgress = function(percent) {
2016-08-10 12:28:05 +02:00
if (this.timer_hide) {
clearInterval(this.timer_hide);
}
2020-09-04 17:57:56 +02:00
return this.timer_set = RateLimit(500, function() {
return $(".progressbar").css({
"transform": "scaleX(" + (parseInt(percent * 100) / 100) + ")"
}).css("opacity", "1").css("display", "block");
});
};
Loading.prototype.hideProgress = function() {
2020-01-04 16:54:20 +01:00
this.log("hideProgress");
2020-09-04 17:57:56 +02:00
if (this.timer_set) {
clearInterval(this.timer_set);
}
2016-08-10 12:28:05 +02:00
return this.timer_hide = setTimeout(((function(_this) {
return function() {
return $(".progressbar").css({
"transform": "scaleX(1)"
}).css("opacity", "0").hideLater(1000);
2016-08-10 12:28:05 +02:00
};
})(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;
2020-01-04 16:54:20 +01:00
this.log("Displaying large site confirmation");
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>");
2018-02-22 23:34:18 +01:00
button.on("click", (function(_this) {
return function() {
2018-04-28 22:08:43 +02:00
button.addClass("loading");
2018-02-22 23:34:18 +01:00
return _this.wrapper.setSizeLimit(site_info.next_size_limit);
};
})(this));
line.after(button);
return setTimeout(((function(_this) {
return function() {
return _this.printLine('Ready.');
};
})(this)), 100);
}
};
2018-04-28 22:08:43 +02:00
Loading.prototype.showTrackerTorBridge = function(server_info) {
var button, line;
if ($(".console .button-settrackerbridge").length === 0 && !server_info.tor_use_meek_bridges) {
line = this.printLine("Tracker connection error detected.", "error");
button = $("<a href='#Enable+Tor+bridges' class='button button-settrackerbridge'>" + "Use Tor meek bridges for tracker connections" + "</a>");
button.on("click", (function(_this) {
return function() {
button.addClass("loading");
_this.wrapper.ws.cmd("configSet", ["tor_use_bridges", ""]);
_this.wrapper.ws.cmd("configSet", ["trackers_proxy", "tor"]);
_this.wrapper.ws.cmd("siteUpdate", {
address: _this.wrapper.site_info.address,
announce: true
});
2018-04-28 22:08:43 +02:00
_this.wrapper.reloadIframe();
return false;
};
})(this));
line.after(button);
if (!server_info.tor_has_meek_bridges) {
button.addClass("disabled");
return this.printLine("No meek bridge support in your client, please <a href='https://github.com/HelloZeroNet/ZeroNet#how-to-join'>download the latest bundle</a>.", "warning");
}
}
};
Loading.prototype.hideScreen = function() {
2020-01-04 16:54:20 +01:00
this.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;
};
2020-01-04 16:54:20 +01:00
Loading.prototype.log = function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return console.log.apply(console, ["[Loading]"].concat(slice.call(args)));
};
return Loading;
})();
window.Loading = Loading;
}).call(this);
2019-10-06 03:20:58 +02:00
/* ---- 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;
}
2017-10-21 11:01:57 +02:00
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") {
2019-04-08 18:15:02 +02:00
$(".body", elem).html("<div class='message'><span class='multiline'>" + body + "</span></div>");
} 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);
}
2019-10-30 02:28:37 +01:00
width = Math.min(elem.outerWidth() + 50, 580);
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({
2019-10-06 03:20:58 +02:00
"width": width - 50
2017-07-28 15:36:49 +02:00
});
$(".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));
2018-03-06 12:03:10 +01:00
$("input", elem).on("keyup", (function(_this) {
return function(e) {
if (e.keyCode === 13) {
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);
2019-10-06 03:20:58 +02:00
/* ---- 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) {
2018-04-28 22:08:43 +02:00
this.reloadIframe = bind(this.reloadIframe, this);
this.setSizeLimit = bind(this.setSizeLimit, this);
2019-02-02 00:12:50 +01:00
this.updateModifiedPanel = bind(this.updateModifiedPanel, this);
this.sitePublish = bind(this.sitePublish, this);
this.siteSign = bind(this.siteSign, this);
2018-02-21 03:15:04 +01:00
this.onWrapperLoad = bind(this.onWrapperLoad, this);
this.onPageLoad = bind(this.onPageLoad, this);
this.onCloseWebsocket = bind(this.onCloseWebsocket, this);
this.onOpenWebsocket = bind(this.onOpenWebsocket, this);
2018-02-21 03:15:04 +01:00
this.handleMessage = bind(this.handleMessage, this);
this.cmd = bind(this.cmd, this);
this.onMessageInner = bind(this.onMessageInner, this);
this.handleMessageWebsocket = bind(this.handleMessageWebsocket, this);
this.onMessageWebsocket = bind(this.onMessageWebsocket, this);
2018-02-21 03:15:04 +01:00
this.verifyEvent = bind(this.verifyEvent, this);
this.log("Created!");
2018-02-22 23:34:18 +01:00
this.loading = new Loading(this);
this.notifications = new Notifications($(".notifications"));
2019-02-02 00:12:50 +01:00
this.infopanel = new Infopanel($(".infopanel"));
this.infopanel.onClosed = (function(_this) {
return function() {
return _this.ws.cmd("siteSetSettingsValue", ["modified_files_notification", false]);
};
})(this);
this.infopanel.onOpened = (function(_this) {
return function() {
return _this.ws.cmd("siteSetSettingsValue", ["modified_files_notification", true]);
};
})(this);
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;
2018-02-21 03:15:04 +01:00
this.next_cmd_message_id = -1;
this.site_info = null;
2018-04-28 22:08:43 +02:00
this.server_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;
2018-04-28 22:08:43 +02:00
this.announcer_line = null;
this.web_notifications = {};
2020-09-04 17:57:56 +02:00
this.is_title_changed = false;
this.allowed_event_constructors = [window.MouseEvent, window.KeyboardEvent, window.PointerEvent];
2018-02-21 03:15:04 +01:00
window.onload = this.onPageLoad;
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();
}
2018-02-21 03:15:04 +01:00
Wrapper.prototype.verifyEvent = function(allowed_target, e) {
var ref;
if (!e.originalEvent.isTrusted) {
throw "Event not trusted";
}
if (ref = e.originalEvent.constructor, indexOf.call(this.allowed_event_constructors, ref) < 0) {
throw "Invalid event constructor: " + e.constructor + " not in " + (JSON.stringify(this.allowed_event_constructors));
2018-02-21 03:15:04 +01:00
}
if (e.originalEvent.currentTarget !== allowed_target[0]) {
throw "Invalid event target: " + e.originalEvent.currentTarget + " != " + allowed_target[0];
}
};
Wrapper.prototype.onMessageWebsocket = function(e) {
var message;
message = JSON.parse(e.data);
return this.handleMessageWebsocket(message);
};
Wrapper.prototype.handleMessageWebsocket = function(message) {
var cmd, id, ref, script_tag, type;
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);
2018-04-28 22:08:43 +02:00
} else if (cmd === "setAnnouncerInfo") {
this.sendInner(message);
if (message.params.address === this.address) {
this.setAnnouncerInfo(message.params);
}
return this.updateProgress(message.params);
} else if (cmd === "error") {
return this.notifications.add("notification-" + message.id, "error", message.params, 0);
} else if (cmd === "updating") {
2019-04-09 15:06:33 +02:00
this.log("Updating: Closing websocket");
this.ws.ws.close();
return this.ws.onCloseWebsocket(null, 4000);
2018-11-26 00:05:17 +01:00
} else if (cmd === "redirect") {
return window.top.location = message.params;
2017-11-29 13:48:30 +01:00
} else if (cmd === "injectHtml") {
return $("body").append(message.params);
2018-11-26 00:05:17 +01:00
} else if (cmd === "injectScript") {
script_tag = $("<script>");
script_tag.attr("nonce", this.script_nonce);
script_tag.html(message.params);
return document.head.appendChild(script_tag[0]);
} else {
return this.sendInner(message);
}
};
Wrapper.prototype.onMessageInner = function(e) {
2018-02-21 03:15:04 +01:00
var message;
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;
}
2018-02-21 03:15:04 +01:00
return this.handleMessage(message);
};
Wrapper.prototype.cmd = function(cmd, params, cb) {
var message;
if (params == null) {
params = {};
}
if (cb == null) {
cb = null;
}
message = {};
message.cmd = cmd;
message.params = params;
message.id = this.next_cmd_message_id;
if (cb) {
this.ws.waiting_cb[message.id] = cb;
}
this.next_cmd_message_id -= 1;
return this.handleMessage(message);
};
Wrapper.prototype.handleMessage = function(message) {
var cmd, query, ref;
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") {
2020-09-04 17:57:56 +02:00
this.log("wrapperSetTitle", message.params);
$("head title").text(message.params);
return this.is_title_changed = true;
} 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 (cmd === "wrapperWebNotification") {
return this.actionWebNotification(message);
} else if (cmd === "wrapperCloseWebNotification") {
return this.actionCloseWebNotification(message);
} else {
if (message.id < 1000000) {
if (message.cmd === "fileWrite" && !this.modified_panel_updater_timer && (typeof site_info !== "undefined" && site_info !== null ? (ref = site_info.settings) != null ? ref.own : void 0 : void 0)) {
2019-02-02 00:12:50 +01:00
this.modified_panel_updater_timer = setTimeout(((function(_this) {
return function() {
_this.updateModifiedPanel();
return _this.modified_panel_updater_timer = null;
};
})(this)), 1000);
}
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;
elem = document.getElementById("inner-iframe");
request_fullscreen = elem.requestFullScreen || elem.webkitRequestFullscreen || elem.mozRequestFullScreen || elem.msRequestFullScreen;
return request_fullscreen.call(elem);
2016-12-30 19:32:36 +01:00
};
Wrapper.prototype.actionWebNotification = function(message) {
2019-04-17 11:39:00 +02:00
return $.when(this.event_site_info).done((function(_this) {
return function() {
var res;
if (Notification.permission === "granted") {
return _this.displayWebNotification(message);
2019-04-17 11:39:00 +02:00
} else if (Notification.permission === "denied") {
res = {
"error": "Web notifications are disabled by the user"
2019-04-17 11:39:00 +02:00
};
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": res
});
} else {
return Notification.requestPermission().then(function(permission) {
if (permission === "granted") {
return _this.displayWebNotification(message);
2019-04-17 11:39:00 +02:00
}
});
}
};
})(this));
};
Wrapper.prototype.actionCloseWebNotification = function(message) {
2019-04-17 18:56:19 +02:00
return $.when(this.event_site_info).done((function(_this) {
return function() {
var id;
2019-04-17 18:56:19 +02:00
id = message.params[0];
return _this.web_notifications[id].close();
2019-04-17 18:56:19 +02:00
};
})(this));
};
Wrapper.prototype.displayWebNotification = function(message) {
2019-04-17 11:39:00 +02:00
var id, notification, options, title;
title = message.params[0];
id = message.params[1];
options = message.params[2];
notification = new Notification(title, options);
this.web_notifications[id] = notification;
2019-04-17 11:39:00 +02:00
notification.onshow = (function(_this) {
return function() {
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": "ok"
});
};
})(this);
notification.onclick = (function(_this) {
return function(e) {
if (!options.focus_tab) {
e.preventDefault();
}
return _this.sendInner({
"cmd": "webNotificationClick",
2019-04-17 11:39:00 +02:00
"params": {
"id": id
}
});
};
})(this);
return notification.onclose = (function(_this) {
return function() {
2019-04-17 18:56:19 +02:00
_this.sendInner({
"cmd": "webNotificationClose",
2019-04-17 11:39:00 +02:00
"params": {
"id": id
}
});
return delete _this.web_notifications[id];
2019-04-17 11:39:00 +02:00
};
})(this);
};
2016-08-10 12:28:05 +02:00
Wrapper.prototype.actionPermissionAdd = function(message) {
var permission;
permission = message.params;
2018-02-21 03:15:04 +01:00
return $.when(this.event_site_info).done((function(_this) {
return function() {
if (indexOf.call(_this.site_info.settings.permissions, permission) >= 0) {
return false;
}
return _this.ws.cmd("permissionDetails", permission, 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(res) {
return _this.sendInner({
"cmd": "response",
"to": message.id,
"result": res
});
});
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]);
};
2018-03-06 12:03:10 +01:00
Wrapper.prototype.displayConfirm = function(body, captions, cb) {
var button, buttons, caption, fn, i, j, len;
body = $("<span class='message-outer'><span class='message'>" + body + "</span></span>");
2017-05-18 03:05:02 +02:00
buttons = $("<span class='buttons'></span>");
if (!(captions instanceof Array)) {
captions = [captions];
}
2018-02-21 03:15:04 +01:00
fn = (function(_this) {
return function(button) {
return button.on("click", function(e) {
_this.verifyEvent(button, e);
cb(parseInt(e.currentTarget.dataset.value));
return false;
});
};
})(this);
for (i = j = 0, len = captions.length; j < len; i = ++j) {
caption = captions[i];
2018-03-06 12:03:10 +01:00
button = $("<a></a>", {
href: "#" + caption,
"class": "button button-confirm button-" + caption + " button-" + (i + 1),
"data-value": i + 1
});
button.text(caption);
2018-02-21 03:15:04 +01:00
fn(button);
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'></span>").html(message);
if (placeholder == null) {
2017-11-29 13:48:30 +01:00
placeholder = "";
}
2018-03-06 12:03:10 +01:00
input = $("<input/>", {
type: type,
"class": "input button-" + type,
placeholder: placeholder
});
input.on("keyup", (function(_this) {
return function(e) {
2018-02-21 03:15:04 +01:00
_this.verifyEvent(input, e);
if (e.keyCode === 13) {
2018-02-21 03:15:04 +01:00
return cb(input.val());
}
};
})(this));
body.append(input);
2018-03-06 12:03:10 +01:00
button = $("<a></a>", {
href: "#" + caption,
"class": "button button-" + caption
}).text(caption);
button.on("click", (function(_this) {
2018-02-21 03:15:04 +01:00
return function(e) {
_this.verifyEvent(button, e);
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));
};
Wrapper.prototype.displayProgress = function(type, body, percent) {
var circle, elem, offset, width;
percent = Math.min(100, percent) / 100;
2017-01-16 13:41:11 +01:00
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'>" + body + "</span>" + circle;
elem = $(".notification-" + type);
2017-01-16 13:41:11 +01:00
if (elem.length) {
width = $(".body .message", elem).outerWidth();
$(".body .message", elem).html(body);
2017-01-16 13:41:11 +01:00
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(type, "progress", $(body));
2017-01-16 13:41:11 +01:00
}
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 (percent >= 1) {
2017-01-16 13:41:11 +01:00
$(".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 (percent < 0) {
2017-01-16 13:41:11 +01:00
$(".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.actionProgress = function(message) {
message.params = this.toHtmlSafe(message.params);
return this.displayProgress(message.params[0], message.params[1], message.params[2]);
};
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) {
2018-02-21 03:15:04 +01:00
return this.reload(message.params[0]);
2016-08-10 12:28:05 +02:00
};
Wrapper.prototype.reload = function(url_post) {
2019-10-06 03:20:58 +02:00
var current_url;
if (url_post == null) {
url_post = "";
}
2020-01-04 16:54:20 +01:00
this.log("Reload");
2019-10-06 03:20:58 +02:00
current_url = window.location.toString().replace(/#.*/g, "");
if (url_post) {
2019-10-06 03:20:58 +02:00
if (current_url.indexOf("?") > 0) {
return window.location = current_url + "&" + url_post;
} else {
2019-10-06 03:20:58 +02:00
return window.location = current_url + "?" + 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) {
return $.when(this.event_site_info).done((function(_this) {
return function() {
var back;
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
});
};
})(this));
};
Wrapper.prototype.onOpenWebsocket = function(e) {
2018-04-28 22:08:43 +02:00
if (window.show_loadingscreen) {
this.ws.cmd("channelJoin", {
"channels": ["siteChanged", "serverChanged", "announcerChanged"]
});
} else {
this.ws.cmd("channelJoin", {
"channels": ["siteChanged", "serverChanged"]
});
}
if (!this.wrapperWsInited && this.inner_ready) {
this.sendInner({
"cmd": "wrapperOpenedWebsocket"
});
this.wrapperWsInited = true;
}
2018-04-28 22:08:43 +02:00
if (window.show_loadingscreen) {
this.ws.cmd("serverInfo", [], (function(_this) {
return function(server_info) {
return _this.server_info = server_info;
};
})(this));
this.ws.cmd("announcerInfo", [], (function(_this) {
return function(announcer_info) {
return _this.setAnnouncerInfo(announcer_info);
};
})(this));
}
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);
};
2018-02-21 03:15:04 +01:00
Wrapper.prototype.onPageLoad = function(e) {
var ref;
2020-01-04 16:54:20 +01:00
this.log("onPageLoad");
this.inner_loaded = true;
if (!this.inner_ready) {
this.sendInner({
"cmd": "wrapperReady"
});
}
if (this.ws.ws.readyState === 1 && !this.site_info) {
return this.reloadSiteInfo();
2020-09-04 17:57:56 +02:00
} else if (this.site_info && (((ref = this.site_info.content) != null ? ref.title : void 0) != null) && !this.is_title_changed) {
window.document.title = this.site_info.content.title + " - ZeroNet";
return this.log("Setting title to", window.document.title);
}
};
2018-02-21 03:15:04 +01:00
Wrapper.prototype.onWrapperLoad = function() {
2018-11-26 00:05:17 +01:00
this.script_nonce = window.script_nonce;
this.wrapper_key = window.wrapper_key;
2018-02-21 03:15:04 +01:00
delete window.wrapper;
delete window.wrapper_key;
2018-11-26 00:05:17 +01:00
delete window.script_nonce;
2018-02-21 03:15:04 +01:00
return $("#script_init").remove();
};
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) {
2018-10-20 02:22:38 +02:00
var ref;
_this.address = site_info.address;
_this.setSiteInfo(site_info);
2020-01-04 16:54:20 +01:00
if (site_info.settings.size > site_info.size_limit * 1024 * 1024 && !_this.loading.screen_visible) {
_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);
}
});
2020-01-04 16:54:20 +01:00
});
}
2020-09-04 17:57:56 +02:00
if ((((ref = site_info.content) != null ? ref.title : void 0) != null) && !_this.is_title_changed) {
window.document.title = site_info.content.title + " - ZeroNet";
return _this.log("Setting title to", window.document.title);
}
};
})(this));
};
Wrapper.prototype.setSiteInfo = function(site_info) {
2019-02-02 00:12:50 +01:00
var ref, ref1, ref2, ref3;
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();
}
2020-09-04 17:57:56 +02:00
if (site_info.content && !this.is_title_changed) {
window.document.title = site_info.content.title + " - ZeroNet";
2020-01-04 16:54:20 +01:00
this.log("Required file " + window.file_inner_path + " 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) {
2020-01-04 16:54:20 +01:00
this.log("Loading screen visible, but inner loaded");
this.loading.hideScreen();
}
2019-02-02 00:12:50 +01:00
if ((site_info != null ? (ref = site_info.settings) != null ? ref.own : void 0 : void 0) && (site_info != null ? (ref1 = site_info.settings) != null ? ref1.modified : void 0 : void 0) !== ((ref2 = this.site_info) != null ? (ref3 = ref2.settings) != null ? ref3.modified : void 0 : void 0)) {
this.updateModifiedPanel();
}
2020-01-04 16:54:20 +01:00
if (this.loading.screen_visible && site_info.settings.size > site_info.size_limit * 1024 * 1024) {
this.log("Site too large");
this.loading.showTooLarge(site_info);
}
2016-08-10 12:28:05 +02:00
this.site_info = site_info;
return this.event_site_info.resolve();
};
2019-02-02 00:12:50 +01:00
Wrapper.prototype.siteSign = function(inner_path, cb) {
if (this.site_info.privatekey) {
this.infopanel.elem.find(".button").addClass("loading");
return this.ws.cmd("siteSign", {
privatekey: "stored",
inner_path: inner_path,
update_changed_files: true
}, (function(_this) {
return function(res) {
if (res === "ok") {
if (typeof cb === "function") {
cb(true);
}
} else {
if (typeof cb === "function") {
cb(false);
}
}
return _this.infopanel.elem.find(".button").removeClass("loading");
};
})(this));
} else {
return this.displayPrompt("Enter your private key:", "password", "Sign", "", (function(_this) {
return function(privatekey) {
_this.infopanel.elem.find(".button").addClass("loading");
return _this.ws.cmd("siteSign", {
privatekey: privatekey,
inner_path: inner_path,
update_changed_files: true
}, function(res) {
if (res === "ok") {
if (typeof cb === "function") {
cb(true);
}
} else {
if (typeof cb === "function") {
cb(false);
}
}
return _this.infopanel.elem.find(".button").removeClass("loading");
});
};
})(this));
}
};
Wrapper.prototype.sitePublish = function(inner_path) {
return this.ws.cmd("sitePublish", {
"inner_path": inner_path,
"sign": false
});
};
Wrapper.prototype.updateModifiedPanel = function() {
return this.ws.cmd("siteListModifiedFiles", [], (function(_this) {
return function(res) {
var closed, num, ref;
num = (ref = res.modified_files) != null ? ref.length : void 0;
2019-02-02 00:12:50 +01:00
if (num > 0) {
closed = _this.site_info.settings.modified_files_notification === false;
_this.infopanel.show(closed);
2019-02-02 00:12:50 +01:00
} else {
_this.infopanel.hide();
}
if (num > 0) {
_this.infopanel.setTitle(res.modified_files.length + " modified file" + (num > 1 ? 's' : ''), res.modified_files.join(", "));
2019-02-09 13:56:21 +01:00
_this.infopanel.setClosedNum(num);
2019-02-02 00:12:50 +01:00
_this.infopanel.setAction("Sign & Publish", function() {
_this.siteSign("content.json", function(res) {
if (res) {
_this.notifications.add("sign", "done", "content.json Signed!", 5000);
return _this.sitePublish("content.json");
}
});
return false;
});
}
return _this.log("siteListModifiedFiles", num, res);
2019-02-02 00:12:50 +01:00
};
})(this));
};
2018-04-28 22:08:43 +02:00
Wrapper.prototype.setAnnouncerInfo = function(announcer_info) {
var key, ref, status_db, status_line, val;
status_db = {
announcing: [],
error: [],
announced: []
};
2018-04-28 22:08:43 +02:00
ref = announcer_info.stats;
for (key in ref) {
val = ref[key];
2018-10-08 15:34:40 +02:00
if (val.status) {
status_db[val.status].push(val);
}
2018-04-28 22:08:43 +02:00
}
status_line = "Trackers announcing: " + status_db.announcing.length + ", error: " + status_db.error.length + ", done: " + status_db.announced.length;
2018-04-28 22:08:43 +02:00
if (this.announcer_line) {
this.announcer_line.text(status_line);
} else {
this.announcer_line = this.loading.printLine(status_line);
}
if (status_db.error.length > (status_db.announced.length + status_db.announcing.length) && status_db.announced.length < 3) {
2018-04-28 22:08:43 +02:00
return this.loading.showTrackerTorBridge(this.server_info);
}
};
2016-08-10 12:28:05 +02:00
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 {
2018-03-06 12:03:10 +01:00
value = String(value).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
2018-02-21 03:15:04 +01:00
value = value.replace(/&lt;([\/]{0,1}(br|b|u|i|small))&gt;/g, "<$1>");
}
values[i] = value;
}
return values;
};
Wrapper.prototype.setSizeLimit = function(size_limit, reload) {
if (reload == null) {
reload = true;
}
2020-01-04 16:54:20 +01:00
this.log("setSizeLimit: " + size_limit + ", reload: " + reload);
this.inner_loaded = false;
this.ws.cmd("siteSetLimit", [size_limit], (function(_this) {
return function(res) {
if (res !== "ok") {
return false;
}
_this.loading.printLine(res);
_this.inner_loaded = false;
if (reload) {
2018-04-28 22:08:43 +02:00
return _this.reloadIframe();
}
};
})(this));
return false;
2018-04-28 22:08:43 +02:00
};
Wrapper.prototype.reloadIframe = function() {
var src;
src = $("iframe").attr("src");
return this.ws.cmd("serverGetWrapperNonce", [], (function(_this) {
return function(wrapper_nonce) {
src = src.replace(/wrapper_nonce=[A-Za-z0-9]+/, "wrapper_nonce=" + wrapper_nonce);
_this.log("Reloading iframe using url", src);
return $("iframe").attr("src", src);
};
})(this));
};
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'
};
}
2019-04-15 15:44:04 +02:00
ws_url = proto.ws + ":" + origin.replace(proto.http + ":", "") + "/ZeroNet-Internal/Websocket?wrapper_key=" + window.wrapper_key;
window.wrapper = new Wrapper(ws_url);
}).call(this);
2018-02-21 03:15:04 +01:00
2019-10-06 03:20:58 +02:00
/* ---- WrapperZeroFrame.coffee ---- */
2018-02-21 03:15:04 +01:00
(function() {
var WrapperZeroFrame,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
WrapperZeroFrame = (function() {
function WrapperZeroFrame(wrapper) {
this.certSelectGotoSite = bind(this.certSelectGotoSite, this);
this.response = bind(this.response, this);
this.cmd = bind(this.cmd, this);
this.wrapperCmd = wrapper.cmd;
this.wrapperResponse = wrapper.ws.response;
console.log("WrapperZeroFrame", wrapper);
}
WrapperZeroFrame.prototype.cmd = function(cmd, params, cb) {
if (params == null) {
params = {};
}
if (cb == null) {
cb = null;
}
return this.wrapperCmd(cmd, params, cb);
};
WrapperZeroFrame.prototype.response = function(to, result) {
return this.wrapperResponse(to, result);
};
WrapperZeroFrame.prototype.isProxyRequest = function() {
return window.location.pathname === "/";
};
WrapperZeroFrame.prototype.certSelectGotoSite = function(elem) {
var href;
href = $(elem).attr("href");
if (this.isProxyRequest()) {
return $(elem).attr("href", "http://zero" + href);
}
};
return WrapperZeroFrame;
})();
window.zeroframe = new WrapperZeroFrame(window.wrapper);
}).call(this);
2019-10-06 03:20:58 +02:00
/* ---- ZeroSiteTheme.coffee ---- */
(function() {
var DARK, LIGHT, changeColorScheme, detectColorScheme, displayNotification, mqDark, mqLight,
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; };
DARK = "(prefers-color-scheme: dark)";
LIGHT = "(prefers-color-scheme: light)";
mqDark = window.matchMedia(DARK);
mqLight = window.matchMedia(LIGHT);
changeColorScheme = function(theme) {
zeroframe.cmd("userGetGlobalSettings", [], function(user_settings) {
if (user_settings.theme !== theme) {
user_settings.theme = theme;
zeroframe.cmd("userSetGlobalSettings", [user_settings], function(status) {
if (status === "ok") {
location.reload();
}
});
}
});
};
displayNotification = function(arg) {
var matches, media;
matches = arg.matches, media = arg.media;
if (!matches) {
return;
}
zeroframe.cmd("siteInfo", [], function(site_info) {
if (indexOf.call(site_info.settings.permissions, "ADMIN") >= 0) {
zeroframe.cmd("wrapperNotification", ["info", "Your system's theme has been changed.<br>Please reload site to use it."]);
} else {
zeroframe.cmd("wrapperNotification", ["info", "Your system's theme has been changed.<br>Please open ZeroHello to use it."]);
}
});
};
detectColorScheme = function() {
if (mqDark.matches) {
changeColorScheme("dark");
} else if (mqLight.matches) {
changeColorScheme("light");
}
mqDark.addListener(displayNotification);
mqLight.addListener(displayNotification);
};
zeroframe.cmd("userGetGlobalSettings", [], function(user_settings) {
if (user_settings.use_system_theme === true) {
detectColorScheme();
}
});
2019-08-02 20:11:00 +02:00
}).call(this);