2015-08-16 11:51:00 +02:00
2019-09-02 14:17:35 +02:00
/* ---- Class.coffee ---- */
2015-08-16 11:51:00 +02:00
( function ( ) {
var Class ,
2017-06-19 15:32:58 +02:00
slice = [ ] . slice ;
2015-08-16 11:51:00 +02:00
Class = ( function ( ) {
function Class ( ) { }
Class . prototype . trace = true ;
Class . prototype . log = function ( ) {
var args ;
2017-06-19 15:32:58 +02:00
args = 1 <= arguments . length ? slice . call ( arguments , 0 ) : [ ] ;
2015-08-16 11:51:00 +02:00
if ( ! this . trace ) {
return ;
}
if ( typeof console === 'undefined' ) {
return ;
}
args . unshift ( "[" + this . constructor . name + "]" ) ;
console . log . apply ( console , args ) ;
return this ;
} ;
Class . prototype . logStart = function ( ) {
var args , name ;
2017-06-19 15:32:58 +02:00
name = arguments [ 0 ] , args = 2 <= arguments . length ? slice . call ( arguments , 1 ) : [ ] ;
2015-08-16 11:51:00 +02:00
if ( ! this . trace ) {
return ;
}
this . logtimers || ( this . logtimers = { } ) ;
this . logtimers [ name ] = + ( new Date ) ;
if ( args . length > 0 ) {
2017-06-19 15:32:58 +02:00
this . log . apply ( this , [ "" + name ] . concat ( slice . call ( args ) , [ "(started)" ] ) ) ;
2015-08-16 11:51:00 +02:00
}
return this ;
} ;
Class . prototype . logEnd = function ( ) {
var args , ms , name ;
2017-06-19 15:32:58 +02:00
name = arguments [ 0 ] , args = 2 <= arguments . length ? slice . call ( arguments , 1 ) : [ ] ;
2015-08-16 11:51:00 +02:00
ms = + ( new Date ) - this . logtimers [ name ] ;
2017-06-19 15:32:58 +02:00
this . log . apply ( this , [ "" + name ] . concat ( slice . call ( args ) , [ "(Done in " + ms + "ms)" ] ) ) ;
2015-08-16 11:51:00 +02:00
return this ;
} ;
return Class ;
} ) ( ) ;
window . Class = Class ;
} ) . call ( this ) ;
2020-02-07 16:42:26 +01:00
2019-09-02 14:17:35 +02:00
/* ---- Console.coffee ---- */
2018-09-17 15:33:45 +02:00
( function ( ) {
2019-07-01 16:19:12 +02:00
var Console ,
2018-09-17 15:33:45 +02:00
bind = function ( fn , me ) { return function ( ) { return fn . apply ( me , arguments ) ; } ; } ,
extend = function ( child , parent ) { for ( var key in parent ) { if ( hasProp . call ( parent , key ) ) child [ key ] = parent [ key ] ; } function ctor ( ) { this . constructor = child ; } ctor . prototype = parent . prototype ; child . prototype = new ctor ( ) ; child . _ _super _ _ = parent . prototype ; return child ; } ,
hasProp = { } . hasOwnProperty ;
2019-07-01 16:19:12 +02:00
Console = ( function ( superClass ) {
extend ( Console , superClass ) ;
2018-09-17 15:33:45 +02:00
2019-07-01 16:19:12 +02:00
function Console ( sidebar ) {
var handleMessageWebsocket _original ;
2018-09-17 15:33:45 +02:00
this . sidebar = sidebar ;
2019-10-06 03:08:32 +02:00
this . handleTabClick = bind ( this . handleTabClick , this ) ;
this . changeFilter = bind ( this . changeFilter , this ) ;
2018-09-17 15:33:45 +02:00
this . stopDragY = bind ( this . stopDragY , this ) ;
2019-07-01 16:19:12 +02:00
this . cleanup = bind ( this . cleanup , this ) ;
2018-09-17 15:33:45 +02:00
this . onClosed = bind ( this . onClosed , this ) ;
this . onOpened = bind ( this . onOpened , this ) ;
this . open = bind ( this . open , this ) ;
2019-07-01 16:19:12 +02:00
this . close = bind ( this . close , this ) ;
this . loadConsoleText = bind ( this . loadConsoleText , this ) ;
this . addLines = bind ( this . addLines , this ) ;
this . formatLine = bind ( this . formatLine , this ) ;
this . checkTextIsBottom = bind ( this . checkTextIsBottom , this ) ;
2018-09-17 15:33:45 +02:00
this . tag = null ;
this . opened = false ;
2019-07-01 16:19:12 +02:00
this . filter = null ;
2019-10-06 03:08:32 +02:00
this . tab _types = [
{
title : "All" ,
filter : ""
} , {
title : "Info" ,
filter : "INFO"
} , {
title : "Warning" ,
filter : "WARNING"
} , {
title : "Error" ,
filter : "ERROR"
}
] ;
this . read _size = 32 * 1024 ;
this . tab _active = "" ;
2019-07-01 16:19:12 +02:00
handleMessageWebsocket _original = this . sidebar . wrapper . handleMessageWebsocket ;
this . sidebar . wrapper . handleMessageWebsocket = ( function ( _this ) {
return function ( message ) {
if ( message . cmd === "logLineAdd" && message . params . stream _id === _this . stream _id ) {
return _this . addLines ( message . params . lines ) ;
} else {
return handleMessageWebsocket _original ( message ) ;
}
} ;
} ) ( this ) ;
2019-10-06 03:08:32 +02:00
$ ( window ) . on ( "hashchange" , ( function ( _this ) {
return function ( ) {
2019-10-06 03:32:04 +02:00
if ( window . top . location . hash === "#ZeroNet:Console" ) {
2019-10-06 03:08:32 +02:00
return _this . open ( ) ;
}
} ;
} ) ( this ) ) ;
2019-10-06 03:32:04 +02:00
if ( window . top . location . hash === "#ZeroNet:Console" ) {
2018-09-17 15:33:45 +02:00
setTimeout ( ( ( function ( _this ) {
return function ( ) {
return _this . open ( ) ;
} ;
} ) ( this ) ) , 10 ) ;
}
}
2019-07-01 16:19:12 +02:00
Console . prototype . createHtmltag = function ( ) {
2019-10-06 03:08:32 +02:00
var j , len , ref , tab , tab _type ;
2018-09-17 15:33:45 +02:00
if ( ! this . container ) {
2019-10-06 03:08:32 +02:00
this . container = $ ( "<div class=\"console-container\">\n <div class=\"console\">\n <div class=\"console-top\">\n <div class=\"console-tabs\"></div>\n <div class=\"console-text\">Loading...</div>\n </div>\n <div class=\"console-middle\">\n <div class=\"mynode\"></div>\n <div class=\"peers\">\n <div class=\"peer\"><div class=\"line\"></div><a href=\"#\" class=\"icon\">\u25BD</div></div>\n </div>\n </div>\n </div>\n</div>" ) ;
2019-07-01 16:19:12 +02:00
this . text = this . container . find ( ".console-text" ) ;
this . text _elem = this . text [ 0 ] ;
2019-10-06 03:08:32 +02:00
this . tabs = this . container . find ( ".console-tabs" ) ;
2019-07-01 16:19:12 +02:00
this . text . on ( "mousewheel" , ( function ( _this ) {
return function ( e ) {
if ( e . originalEvent . deltaY < 0 ) {
_this . text . stop ( ) ;
}
return RateLimit ( 300 , _this . checkTextIsBottom ) ;
} ;
} ) ( this ) ) ;
this . text . is _bottom = true ;
2018-09-17 15:33:45 +02:00
this . container . appendTo ( document . body ) ;
2019-07-01 16:19:12 +02:00
this . tag = this . container . find ( ".console" ) ;
2019-10-06 03:08:32 +02:00
ref = this . tab _types ;
for ( j = 0 , len = ref . length ; j < len ; j ++ ) {
tab _type = ref [ j ] ;
tab = $ ( "<a></a>" , {
href : "#" ,
"data-filter" : tab _type . filter
} ) . text ( tab _type . title ) ;
if ( tab _type . filter === this . tab _active ) {
tab . addClass ( "active" ) ;
}
tab . on ( "click" , this . handleTabClick ) ;
this . tabs . append ( tab ) ;
}
2019-07-01 16:19:12 +02:00
this . container . on ( "mousedown touchend touchcancel" , ( function ( _this ) {
return function ( e ) {
if ( e . target !== e . currentTarget ) {
return true ;
}
_this . log ( "closing" ) ;
if ( $ ( document . body ) . hasClass ( "body-console" ) ) {
_this . close ( ) ;
return true ;
}
} ;
} ) ( this ) ) ;
return this . loadConsoleText ( ) ;
}
} ;
Console . prototype . checkTextIsBottom = function ( ) {
return this . text . is _bottom = Math . round ( this . text _elem . scrollTop + this . text _elem . clientHeight ) >= this . text _elem . scrollHeight - 15 ;
} ;
Console . prototype . toColor = function ( text , saturation , lightness ) {
var hash , i , j , ref ;
if ( saturation == null ) {
saturation = 60 ;
}
if ( lightness == null ) {
lightness = 70 ;
}
hash = 0 ;
for ( i = j = 0 , ref = text . length - 1 ; 0 <= ref ? j <= ref : j >= ref ; i = 0 <= ref ? ++ j : -- j ) {
hash += text . charCodeAt ( i ) * i ;
hash = hash % 1777 ;
}
return "hsl(" + ( hash % 360 ) + ( "," + saturation + "%," + lightness + "%)" ) ;
} ;
Console . prototype . formatLine = function ( line ) {
var added , level , match , module , ref , text ;
match = line . match ( /(\[.*?\])[ ]+(.*?)[ ]+(.*?)[ ]+(.*)/ ) ;
if ( ! match ) {
return line . replace ( /\</g , "<" ) . replace ( /\>/g , ">" ) ;
}
ref = line . match ( /(\[.*?\])[ ]+(.*?)[ ]+(.*?)[ ]+(.*)/ ) , line = ref [ 0 ] , added = ref [ 1 ] , level = ref [ 2 ] , module = ref [ 3 ] , text = ref [ 4 ] ;
added = "<span style='color: #dfd0fa'>" + added + "</span>" ;
level = "<span style='color: " + ( this . toColor ( level , 100 ) ) + ";'>" + level + "</span>" ;
module = "<span style='color: " + ( this . toColor ( module , 60 ) ) + "; font-weight: bold;'>" + module + "</span>" ;
text = text . replace ( /(Site:[A-Za-z0-9\.]+)/g , "<span style='color: #AAAAFF'>$1</span>" ) ;
text = text . replace ( /\</g , "<" ) . replace ( /\>/g , ">" ) ;
return added + " " + level + " " + module + " " + text ;
} ;
Console . prototype . addLines = function ( lines , animate ) {
var html _lines , j , len , line ;
if ( animate == null ) {
animate = true ;
2018-09-17 15:33:45 +02:00
}
2019-07-01 16:19:12 +02:00
html _lines = [ ] ;
this . logStart ( "formatting" ) ;
for ( j = 0 , len = lines . length ; j < len ; j ++ ) {
line = lines [ j ] ;
html _lines . push ( this . formatLine ( line ) ) ;
}
this . logEnd ( "formatting" ) ;
this . logStart ( "adding" ) ;
this . text . append ( html _lines . join ( "<br>" ) + "<br>" ) ;
this . logEnd ( "adding" ) ;
if ( this . text . is _bottom && animate ) {
return this . text . stop ( ) . animate ( {
scrollTop : this . text _elem . scrollHeight - this . text _elem . clientHeight + 1
} , 600 , 'easeInOutCubic' ) ;
}
} ;
Console . prototype . loadConsoleText = function ( ) {
this . sidebar . wrapper . ws . cmd ( "consoleLogRead" , {
2019-10-06 03:08:32 +02:00
filter : this . filter ,
read _size : this . read _size
2019-07-01 16:19:12 +02:00
} , ( function ( _this ) {
return function ( res ) {
var pos _diff , size _read , size _total ;
_this . text . html ( "" ) ;
pos _diff = res [ "pos_end" ] - res [ "pos_start" ] ;
size _read = Math . round ( pos _diff / 1024 ) ;
size _total = Math . round ( res [ 'pos_end' ] / 1024 ) ;
2019-10-06 03:08:32 +02:00
_this . text . append ( "<br><br>" ) ;
2019-07-01 16:19:12 +02:00
_this . text . append ( "Displaying " + res . lines . length + " of " + res . num _found + " lines found in the last " + size _read + "kB of the log file. (" + size _total + "kB total)<br>" ) ;
_this . addLines ( res . lines , false ) ;
return _this . text _elem . scrollTop = _this . text _elem . scrollHeight ;
} ;
} ) ( this ) ) ;
2019-10-06 03:08:32 +02:00
if ( this . stream _id ) {
this . sidebar . wrapper . ws . cmd ( "consoleLogStreamRemove" , {
stream _id : this . stream _id
} ) ;
}
2019-07-01 16:19:12 +02:00
return this . sidebar . wrapper . ws . cmd ( "consoleLogStream" , {
filter : this . filter
} , ( function ( _this ) {
return function ( res ) {
return _this . stream _id = res . stream _id ;
} ;
} ) ( this ) ) ;
} ;
Console . prototype . close = function ( ) {
2019-10-06 03:08:32 +02:00
window . top . location . hash = "" ;
2019-07-01 16:19:12 +02:00
this . sidebar . move _lock = "y" ;
this . sidebar . startDrag ( ) ;
return this . sidebar . stopDrag ( ) ;
2018-09-17 15:33:45 +02:00
} ;
2019-07-01 16:19:12 +02:00
Console . prototype . open = function ( ) {
2019-10-06 03:08:32 +02:00
this . sidebar . startDrag ( ) ;
this . sidebar . moved ( "y" ) ;
this . sidebar . fixbutton _targety = this . sidebar . page _height - this . sidebar . fixbutton _inity - 50 ;
return this . sidebar . stopDrag ( ) ;
2018-09-17 15:33:45 +02:00
} ;
2019-07-01 16:19:12 +02:00
Console . prototype . onOpened = function ( ) {
2018-09-17 15:33:45 +02:00
this . sidebar . onClosed ( ) ;
return this . log ( "onOpened" ) ;
} ;
2019-07-01 16:19:12 +02:00
Console . prototype . onClosed = function ( ) {
$ ( document . body ) . removeClass ( "body-console" ) ;
if ( this . stream _id ) {
return this . sidebar . wrapper . ws . cmd ( "consoleLogStreamRemove" , {
stream _id : this . stream _id
} ) ;
}
2018-09-17 15:33:45 +02:00
} ;
2019-07-01 16:19:12 +02:00
Console . prototype . cleanup = function ( ) {
if ( this . container ) {
this . container . remove ( ) ;
return this . container = null ;
}
} ;
Console . prototype . stopDragY = function ( ) {
2018-09-17 15:33:45 +02:00
var targety ;
if ( this . sidebar . fixbutton _targety === this . sidebar . fixbutton _inity ) {
targety = 0 ;
this . opened = false ;
} else {
targety = this . sidebar . fixbutton _targety - this . sidebar . fixbutton _inity ;
this . onOpened ( ) ;
this . opened = true ;
}
if ( this . tag ) {
this . tag . css ( "transition" , "0.5s ease-out" ) ;
this . tag . css ( "transform" , "translateY(" + targety + "px)" ) . one ( transitionEnd , ( function ( _this ) {
return function ( ) {
_this . tag . css ( "transition" , "" ) ;
if ( ! _this . opened ) {
2019-07-01 16:19:12 +02:00
return _this . cleanup ( ) ;
2018-09-17 15:33:45 +02:00
}
} ;
} ) ( this ) ) ;
}
2019-07-01 16:19:12 +02:00
this . log ( "stopDragY" , "opened:" , this . opened , targety ) ;
2018-09-17 15:33:45 +02:00
if ( ! this . opened ) {
return this . onClosed ( ) ;
}
} ;
2019-10-06 03:08:32 +02:00
Console . prototype . changeFilter = function ( filter ) {
this . filter = filter ;
if ( this . filter === "" ) {
this . read _size = 32 * 1024 ;
} else {
2020-02-07 16:42:26 +01:00
this . read _size = 5 * 1024 * 1024 ;
2019-10-06 03:08:32 +02:00
}
return this . loadConsoleText ( ) ;
} ;
Console . prototype . handleTabClick = function ( e ) {
var elem ;
elem = $ ( e . currentTarget ) ;
this . tab _active = elem . data ( "filter" ) ;
$ ( "a" , this . tabs ) . removeClass ( "active" ) ;
elem . addClass ( "active" ) ;
this . changeFilter ( this . tab _active ) ;
return false ;
} ;
2019-07-01 16:19:12 +02:00
return Console ;
2018-09-17 15:33:45 +02:00
} ) ( Class ) ;
2019-07-01 16:19:12 +02:00
window . Console = Console ;
2018-09-17 15:33:45 +02:00
} ) . call ( this ) ;
2019-10-06 03:08:32 +02:00
2019-09-02 14:17:35 +02:00
/* ---- Menu.coffee ---- */
2017-12-31 14:10:00 +01:00
( function ( ) {
var Menu ,
slice = [ ] . slice ;
Menu = ( function ( ) {
function Menu ( button ) {
this . button = button ;
this . elem = $ ( ".menu.template" ) . clone ( ) . removeClass ( "template" ) ;
this . elem . appendTo ( "body" ) ;
this . items = [ ] ;
}
Menu . prototype . show = function ( ) {
2018-01-21 18:14:12 +01:00
var button _pos , left ;
2017-12-31 14:10:00 +01:00
if ( window . visible _menu && window . visible _menu . button [ 0 ] === this . button [ 0 ] ) {
window . visible _menu . hide ( ) ;
return this . hide ( ) ;
} else {
button _pos = this . button . offset ( ) ;
2018-01-21 18:14:12 +01:00
left = button _pos . left ;
2017-12-31 14:10:00 +01:00
this . elem . css ( {
"top" : button _pos . top + this . button . outerHeight ( ) ,
2018-01-21 18:14:12 +01:00
"left" : left
2017-12-31 14:10:00 +01:00
} ) ;
this . button . addClass ( "menu-active" ) ;
this . elem . addClass ( "visible" ) ;
2018-01-21 18:14:12 +01:00
if ( this . elem . position ( ) . left + this . elem . width ( ) + 20 > window . innerWidth ) {
this . elem . css ( "left" , window . innerWidth - this . elem . width ( ) - 20 ) ;
}
2017-12-31 14:10:00 +01:00
if ( window . visible _menu ) {
window . visible _menu . hide ( ) ;
}
return window . visible _menu = this ;
}
} ;
Menu . prototype . hide = function ( ) {
this . elem . removeClass ( "visible" ) ;
this . button . removeClass ( "menu-active" ) ;
return window . visible _menu = null ;
} ;
Menu . prototype . addItem = function ( title , cb ) {
var item ;
item = $ ( ".menu-item.template" , this . elem ) . clone ( ) . removeClass ( "template" ) ;
item . html ( title ) ;
item . on ( "click" , ( function ( _this ) {
return function ( ) {
if ( ! cb ( item ) ) {
_this . hide ( ) ;
}
return false ;
} ;
} ) ( this ) ) ;
item . appendTo ( this . elem ) ;
this . items . push ( item ) ;
return item ;
} ;
Menu . prototype . log = function ( ) {
var args ;
args = 1 <= arguments . length ? slice . call ( arguments , 0 ) : [ ] ;
return console . log . apply ( console , [ "[Menu]" ] . concat ( slice . call ( args ) ) ) ;
} ;
return Menu ;
} ) ( ) ;
window . Menu = Menu ;
$ ( "body" ) . on ( "click" , function ( e ) {
if ( window . visible _menu && e . target !== window . visible _menu . button [ 0 ] && $ ( e . target ) . parent ( ) [ 0 ] !== window . visible _menu . elem [ 0 ] ) {
return window . visible _menu . hide ( ) ;
}
} ) ;
} ) . call ( this ) ;
2020-02-07 16:42:26 +01:00
2019-09-02 14:17:35 +02:00
/* ---- RateLimit.coffee ---- */
2016-03-06 19:28:22 +01:00
( 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 ) ;
2020-02-07 16:42:26 +01:00
2019-09-02 14:17:35 +02:00
/* ---- Scrollable.js ---- */
2015-08-16 11:51:00 +02:00
/* via http://jsfiddle.net/elGrecode/00dgurnn/ */
window . initScrollable = function ( ) {
var scrollContainer = document . querySelector ( '.scrollable' ) ,
scrollContentWrapper = document . querySelector ( '.scrollable .content-wrapper' ) ,
scrollContent = document . querySelector ( '.scrollable .content' ) ,
contentPosition = 0 ,
scrollerBeingDragged = false ,
scroller ,
topPosition ,
scrollerHeight ;
function calculateScrollerHeight ( ) {
// *Calculation of how tall scroller should be
var visibleRatio = scrollContainer . offsetHeight / scrollContentWrapper . scrollHeight ;
if ( visibleRatio == 1 )
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scroller . style . display = "none" ;
2015-08-16 11:51:00 +02:00
else
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scroller . style . display = "block" ;
2015-08-16 11:51:00 +02:00
return visibleRatio * scrollContainer . offsetHeight ;
}
function moveScroller ( evt ) {
// Move Scroll bar to top offset
var scrollPercentage = evt . target . scrollTop / scrollContentWrapper . scrollHeight ;
topPosition = scrollPercentage * ( scrollContainer . offsetHeight - 5 ) ; // 5px arbitrary offset so scroll bar doesn't move too far beyond content wrapper bounding box
scroller . style . top = topPosition + 'px' ;
}
function startDrag ( evt ) {
normalizedPosition = evt . pageY ;
contentPosition = scrollContentWrapper . scrollTop ;
scrollerBeingDragged = true ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
window . addEventListener ( 'mousemove' , scrollBarScroll ) ;
return false ;
2015-08-16 11:51:00 +02:00
}
function stopDrag ( evt ) {
scrollerBeingDragged = false ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
window . removeEventListener ( 'mousemove' , scrollBarScroll ) ;
2015-08-16 11:51:00 +02:00
}
function scrollBarScroll ( evt ) {
if ( scrollerBeingDragged === true ) {
2015-11-05 23:19:36 +01:00
evt . preventDefault ( ) ;
2015-08-16 11:51:00 +02:00
var mouseDifferential = evt . pageY - normalizedPosition ;
var scrollEquivalent = mouseDifferential * ( scrollContentWrapper . scrollHeight / scrollContainer . offsetHeight ) ;
scrollContentWrapper . scrollTop = contentPosition + scrollEquivalent ;
}
}
function updateHeight ( ) {
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scrollerHeight = calculateScrollerHeight ( ) - 10 ;
2015-08-16 11:51:00 +02:00
scroller . style . height = scrollerHeight + 'px' ;
}
function createScroller ( ) {
// *Creates scroller element and appends to '.scrollable' div
// create scroller element
scroller = document . createElement ( "div" ) ;
scroller . className = 'scroller' ;
// determine how big scroller should be based on content
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
scrollerHeight = calculateScrollerHeight ( ) - 10 ;
2015-08-16 11:51:00 +02:00
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
if ( scrollerHeight / scrollContainer . offsetHeight < 1 ) {
2015-08-16 11:51:00 +02:00
// *If there is a need to have scroll bar based on content size
scroller . style . height = scrollerHeight + 'px' ;
// append scroller to scrollContainer div
scrollContainer . appendChild ( scroller ) ;
// show scroll path divot
scrollContainer . className += ' showScroll' ;
// attach related draggable listeners
scroller . addEventListener ( 'mousedown' , startDrag ) ;
window . addEventListener ( 'mouseup' , stopDrag ) ;
}
}
createScroller ( ) ;
// *** Listeners ***
scrollContentWrapper . addEventListener ( 'scroll' , moveScroller ) ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
return updateHeight ;
2015-08-16 11:51:00 +02:00
} ;
2019-09-02 14:17:35 +02:00
/* ---- Sidebar.coffee ---- */
2015-08-16 11:51:00 +02:00
( function ( ) {
2018-02-21 03:15:04 +01:00
var Sidebar , wrapper ,
2017-04-12 17:36:50 +02:00
bind = function ( fn , me ) { return function ( ) { return fn . apply ( me , arguments ) ; } ; } ,
extend = function ( child , parent ) { for ( var key in parent ) { if ( hasProp . call ( parent , key ) ) child [ key ] = parent [ key ] ; } function ctor ( ) { this . constructor = child ; } ctor . prototype = parent . prototype ; child . prototype = new ctor ( ) ; child . _ _super _ _ = parent . prototype ; return child ; } ,
2017-06-13 10:47:15 +02:00
hasProp = { } . hasOwnProperty ,
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 ; } ;
2015-08-16 11:51:00 +02:00
2017-04-12 17:36:50 +02:00
Sidebar = ( function ( superClass ) {
extend ( Sidebar , superClass ) ;
2015-08-16 11:51:00 +02:00
2018-02-21 03:15:04 +01:00
function Sidebar ( wrapper1 ) {
this . wrapper = wrapper1 ;
2017-04-12 17:36:50 +02:00
this . unloadGlobe = bind ( this . unloadGlobe , this ) ;
this . displayGlobe = bind ( this . displayGlobe , this ) ;
this . loadGlobe = bind ( this . loadGlobe , this ) ;
this . animDrag = bind ( this . animDrag , this ) ;
this . setHtmlTag = bind ( this . setHtmlTag , this ) ;
this . waitMove = bind ( this . waitMove , this ) ;
this . resized = bind ( this . resized , this ) ;
2015-08-16 11:51:00 +02:00
this . tag = null ;
this . container = null ;
this . opened = false ;
this . width = 410 ;
2019-07-01 16:19:12 +02:00
this . console = new Console ( this ) ;
2015-08-16 11:51:00 +02:00
this . fixbutton = $ ( ".fixbutton" ) ;
this . fixbutton _addx = 0 ;
2018-09-17 15:33:45 +02:00
this . fixbutton _addy = 0 ;
2015-08-16 11:51:00 +02:00
this . fixbutton _initx = 0 ;
2018-09-17 15:33:45 +02:00
this . fixbutton _inity = 15 ;
2015-08-16 11:51:00 +02:00
this . fixbutton _targetx = 0 ;
2018-09-17 15:33:45 +02:00
this . move _lock = null ;
2016-01-09 18:49:34 +01:00
this . page _width = $ ( window ) . width ( ) ;
2018-09-17 15:33:45 +02:00
this . page _height = $ ( window ) . height ( ) ;
2015-08-16 11:51:00 +02:00
this . frame = $ ( "#inner-iframe" ) ;
this . initFixbutton ( ) ;
this . dragStarted = 0 ;
this . globe = null ;
2016-09-04 17:46:09 +02:00
this . preload _html = null ;
2018-02-21 03:15:04 +01:00
this . original _set _site _info = this . wrapper . setSiteInfo ;
2020-02-07 16:42:26 +01:00
if ( window . top . location . hash === "#ZeroNet:OpenSidebar" ) {
2015-08-16 11:51:00 +02:00
this . startDrag ( ) ;
2020-02-07 16:42:26 +01:00
this . moved ( "x" ) ;
2015-08-16 11:51:00 +02:00
this . fixbutton _targetx = this . fixbutton _initx - this . width ;
this . stopDrag ( ) ;
}
}
Sidebar . prototype . initFixbutton = function ( ) {
2016-05-02 00:28:23 +02:00
this . fixbutton . on ( "mousedown touchstart" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( e ) {
2016-12-14 10:28:41 +01:00
if ( e . button > 0 ) {
2016-12-14 00:44:06 +01:00
return ;
}
2015-08-16 11:51:00 +02:00
e . preventDefault ( ) ;
2017-05-06 02:13:26 +02:00
_this . fixbutton . off ( "click touchend touchcancel" ) ;
2015-08-16 11:51:00 +02:00
_this . dragStarted = + ( new Date ) ;
2019-04-04 13:28:38 +02:00
$ ( ".drag-bg" ) . remove ( ) ;
$ ( "<div class='drag-bg'></div>" ) . appendTo ( document . body ) ;
return $ ( "body" ) . one ( "mousemove touchmove" , function ( e ) {
2018-09-17 15:33:45 +02:00
var mousex , mousey ;
2016-05-02 00:28:23 +02:00
mousex = e . pageX ;
2018-09-17 15:33:45 +02:00
mousey = e . pageY ;
2016-05-02 00:28:23 +02:00
if ( ! mousex ) {
mousex = e . originalEvent . touches [ 0 ] . pageX ;
2018-09-17 15:33:45 +02:00
mousey = e . originalEvent . touches [ 0 ] . pageY ;
2016-05-02 00:28:23 +02:00
}
_this . fixbutton _addx = _this . fixbutton . offset ( ) . left - mousex ;
2018-09-17 15:33:45 +02:00
_this . fixbutton _addy = _this . fixbutton . offset ( ) . top - mousey ;
2015-08-16 11:51:00 +02:00
return _this . startDrag ( ) ;
} ) ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . fixbutton . parent ( ) . on ( "click touchend touchcancel" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( e ) {
2017-07-29 13:45:57 +02:00
if ( ( + ( new Date ) ) - _this . dragStarted < 100 ) {
window . top . location = _this . fixbutton . find ( ".fixbutton-bg" ) . attr ( "href" ) ;
}
2015-08-16 11:51:00 +02:00
return _this . stopDrag ( ) ;
} ;
} ) ( this ) ) ;
2016-01-09 18:49:34 +01:00
this . resized ( ) ;
return $ ( window ) . on ( "resize" , this . resized ) ;
} ;
Sidebar . prototype . resized = function ( ) {
this . page _width = $ ( window ) . width ( ) ;
2018-09-17 15:33:45 +02:00
this . page _height = $ ( window ) . height ( ) ;
2016-01-09 18:49:34 +01:00
this . fixbutton _initx = this . page _width - 75 ;
if ( this . opened ) {
return this . fixbutton . css ( {
left : this . fixbutton _initx - this . width
} ) ;
} else {
return this . fixbutton . css ( {
left : this . fixbutton _initx
} ) ;
}
2015-08-16 11:51:00 +02:00
} ;
Sidebar . prototype . startDrag = function ( ) {
2019-07-01 16:19:12 +02:00
this . log ( "startDrag" , this . fixbutton _initx , this . fixbutton _inity ) ;
2015-08-16 11:51:00 +02:00
this . fixbutton _targetx = this . fixbutton _initx ;
2019-07-01 16:19:12 +02:00
this . fixbutton _targety = this . fixbutton _inity ;
2015-08-16 11:51:00 +02:00
this . fixbutton . addClass ( "dragging" ) ;
if ( navigator . userAgent . indexOf ( 'MSIE' ) !== - 1 || navigator . appVersion . indexOf ( 'Trident/' ) > 0 ) {
this . fixbutton . css ( "pointer-events" , "none" ) ;
}
this . fixbutton . one ( "click" , ( function ( _this ) {
return function ( e ) {
2018-09-17 15:33:45 +02:00
var moved _x , moved _y ;
2015-08-16 11:51:00 +02:00
_this . stopDrag ( ) ;
_this . fixbutton . removeClass ( "dragging" ) ;
2018-09-17 15:33:45 +02:00
moved _x = Math . abs ( _this . fixbutton . offset ( ) . left - _this . fixbutton _initx ) ;
moved _y = Math . abs ( _this . fixbutton . offset ( ) . top - _this . fixbutton _inity ) ;
if ( moved _x > 5 || moved _y > 10 ) {
2015-08-16 11:51:00 +02:00
return e . preventDefault ( ) ;
}
} ;
} ) ( this ) ) ;
2016-05-02 00:28:23 +02:00
this . fixbutton . parents ( ) . on ( "mousemove touchmove" , this . animDrag ) ;
this . fixbutton . parents ( ) . on ( "mousemove touchmove" , this . waitMove ) ;
2018-10-24 13:59:10 +02:00
return this . fixbutton . parents ( ) . one ( "mouseup touchend touchcancel" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( e ) {
e . preventDefault ( ) ;
return _this . stopDrag ( ) ;
} ;
} ) ( this ) ) ;
} ;
Sidebar . prototype . waitMove = function ( e ) {
2018-09-17 15:33:45 +02:00
var moved _x , moved _y ;
document . body . style . perspective = "1000px" ;
document . body . style . height = "100%" ;
document . body . style . willChange = "perspective" ;
document . documentElement . style . height = "100%" ;
moved _x = Math . abs ( parseInt ( this . fixbutton [ 0 ] . style . left ) - this . fixbutton _targetx ) ;
moved _y = Math . abs ( parseInt ( this . fixbutton [ 0 ] . style . top ) - this . fixbutton _targety ) ;
if ( moved _x > 5 && ( + ( new Date ) ) - this . dragStarted + moved _x > 50 ) {
this . moved ( "x" ) ;
this . fixbutton . stop ( ) . animate ( {
"top" : this . fixbutton _inity
} , 1000 ) ;
return this . fixbutton . parents ( ) . off ( "mousemove touchmove" , this . waitMove ) ;
} else if ( moved _y > 5 && ( + ( new Date ) ) - this . dragStarted + moved _y > 50 ) {
this . moved ( "y" ) ;
2016-05-02 00:28:23 +02:00
return this . fixbutton . parents ( ) . off ( "mousemove touchmove" , this . waitMove ) ;
2015-08-16 11:51:00 +02:00
}
} ;
2018-09-17 15:33:45 +02:00
Sidebar . prototype . moved = function ( direction ) {
2016-03-16 00:40:37 +01:00
var img ;
2018-09-17 15:33:45 +02:00
this . log ( "Moved" , direction ) ;
this . move _lock = direction ;
if ( direction === "y" ) {
2019-07-01 16:19:12 +02:00
$ ( document . body ) . addClass ( "body-console" ) ;
return this . console . createHtmltag ( ) ;
2018-09-17 15:33:45 +02:00
}
2015-08-16 11:51:00 +02:00
this . createHtmltag ( ) ;
2018-09-17 15:33:45 +02:00
$ ( document . body ) . addClass ( "body-sidebar" ) ;
this . container . on ( "mousedown touchend touchcancel" , ( function ( _this ) {
return function ( e ) {
if ( e . target !== e . currentTarget ) {
return true ;
}
_this . log ( "closing" ) ;
if ( $ ( document . body ) . hasClass ( "body-sidebar" ) ) {
_this . close ( ) ;
return true ;
}
} ;
} ) ( this ) ) ;
2015-08-16 11:51:00 +02:00
$ ( window ) . off ( "resize" ) ;
$ ( window ) . on ( "resize" , ( function ( _this ) {
return function ( ) {
$ ( document . body ) . css ( "height" , $ ( window ) . height ( ) ) ;
2016-01-09 18:49:34 +01:00
_this . scrollable ( ) ;
return _this . resized ( ) ;
2015-08-16 11:51:00 +02:00
} ;
} ) ( this ) ) ;
2018-02-21 03:15:04 +01:00
this . wrapper . setSiteInfo = ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( site _info ) {
_this . setSiteInfo ( site _info ) ;
2018-02-21 03:15:04 +01:00
return _this . original _set _site _info . apply ( _this . wrapper , arguments ) ;
2015-08-16 11:51:00 +02:00
} ;
} ) ( this ) ;
2016-03-16 00:40:37 +01:00
img = new Image ( ) ;
return img . src = "/uimedia/globe/world.jpg" ;
2015-08-16 11:51:00 +02:00
} ;
Sidebar . prototype . setSiteInfo = function ( site _info ) {
2016-04-18 02:24:14 +02:00
RateLimit ( 1500 , ( function ( _this ) {
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return function ( ) {
return _this . updateHtmlTag ( ) ;
} ;
} ) ( this ) ) ;
2016-03-16 00:40:37 +01:00
return RateLimit ( 30000 , ( function ( _this ) {
return function ( ) {
return _this . displayGlobe ( ) ;
} ;
} ) ( this ) ) ;
2015-08-16 11:51:00 +02:00
} ;
Sidebar . prototype . createHtmltag = function ( ) {
2016-03-06 19:28:22 +01:00
this . when _loaded = $ . Deferred ( ) ;
2015-08-16 11:51:00 +02:00
if ( ! this . container ) {
this . container = $ ( "<div class=\"sidebar-container\"><div class=\"sidebar scrollable\"><div class=\"content-wrapper\"><div class=\"content\">\n</div></div></div></div>" ) ;
this . container . appendTo ( document . body ) ;
this . tag = this . container . find ( ".sidebar" ) ;
this . updateHtmlTag ( ) ;
return this . scrollable = window . initScrollable ( ) ;
}
} ;
Sidebar . prototype . updateHtmlTag = function ( ) {
2016-09-04 17:46:09 +02:00
if ( this . preload _html ) {
this . setHtmlTag ( this . preload _html ) ;
return this . preload _html = null ;
} else {
2018-02-21 03:15:04 +01:00
return this . wrapper . ws . cmd ( "sidebarGetHtmlTag" , { } , this . setHtmlTag ) ;
2016-09-04 17:46:09 +02:00
}
} ;
Sidebar . prototype . setHtmlTag = function ( res ) {
if ( this . tag . find ( ".content" ) . children ( ) . length === 0 ) {
this . log ( "Creating content" ) ;
this . container . addClass ( "loaded" ) ;
morphdom ( this . tag . find ( ".content" ) [ 0 ] , '<div class="content">' + res + '</div>' ) ;
2018-09-21 02:17:53 +02:00
this . when _loaded . resolve ( ) ;
2016-09-04 17:46:09 +02:00
} else {
2018-09-21 02:17:53 +02:00
morphdom ( this . tag . find ( ".content" ) [ 0 ] , '<div class="content">' + res + '</div>' , {
2016-09-04 17:46:09 +02:00
onBeforeMorphEl : function ( from _el , to _el ) {
if ( from _el . className === "globe" || from _el . className . indexOf ( "noupdate" ) >= 0 ) {
return false ;
} else {
return true ;
}
2015-08-16 11:51:00 +02:00
}
2016-09-04 17:46:09 +02:00
} ) ;
}
2018-09-21 02:17:53 +02:00
this . tag . find ( "#privatekey-add" ) . off ( "click, touchend" ) . on ( "click touchend" , ( function ( _this ) {
return function ( e ) {
_this . wrapper . displayPrompt ( "Enter your private key:" , "password" , "Save" , "" , function ( privatekey ) {
return _this . wrapper . ws . cmd ( "userSetSitePrivatekey" , [ privatekey ] , function ( res ) {
return _this . wrapper . notifications . add ( "privatekey" , "done" , "Private key saved for site signing" , 5000 ) ;
} ) ;
} ) ;
return false ;
} ;
} ) ( this ) ) ;
2020-02-07 16:42:26 +01:00
return this . tag . find ( "#privatekey-forget" ) . off ( "click, touchend" ) . on ( "click touchend" , ( function ( _this ) {
2018-09-21 02:17:53 +02:00
return function ( e ) {
2020-02-07 16:42:26 +01:00
_this . wrapper . displayConfirm ( "Remove saved private key for this site?" , "Forget" , function ( res ) {
2018-10-04 15:43:25 +02:00
if ( ! res ) {
return false ;
}
return _this . wrapper . ws . cmd ( "userSetSitePrivatekey" , [ "" ] , function ( res ) {
return _this . wrapper . notifications . add ( "privatekey" , "done" , "Saved private key removed" , 5000 ) ;
} ) ;
2018-09-21 02:17:53 +02:00
} ) ;
return false ;
} ;
} ) ( this ) ) ;
2015-08-16 11:51:00 +02:00
} ;
Sidebar . prototype . animDrag = function ( e ) {
2018-09-17 15:33:45 +02:00
var mousex , mousey , overdrag , overdrag _percent , targetx , targety ;
2015-08-16 11:51:00 +02:00
mousex = e . pageX ;
2018-09-17 15:33:45 +02:00
mousey = e . pageY ;
if ( ! mousex && e . originalEvent . touches ) {
2016-05-02 00:28:23 +02:00
mousex = e . originalEvent . touches [ 0 ] . pageX ;
2018-09-17 15:33:45 +02:00
mousey = e . originalEvent . touches [ 0 ] . pageY ;
2016-05-02 00:28:23 +02:00
}
2015-08-16 11:51:00 +02:00
overdrag = this . fixbutton _initx - this . width - mousex ;
if ( overdrag > 0 ) {
overdrag _percent = 1 + overdrag / 300 ;
2016-05-02 00:28:23 +02:00
mousex = ( mousex + ( this . fixbutton _initx - this . width ) * overdrag _percent ) / ( 1 + overdrag _percent ) ;
2015-08-16 11:51:00 +02:00
}
targetx = this . fixbutton _initx - mousex - this . fixbutton _addx ;
2018-09-17 15:33:45 +02:00
targety = this . fixbutton _inity - mousey - this . fixbutton _addy ;
if ( this . move _lock === "x" ) {
targety = this . fixbutton _inity ;
} else if ( this . move _lock === "y" ) {
targetx = this . fixbutton _initx ;
}
if ( ! this . move _lock || this . move _lock === "x" ) {
this . fixbutton [ 0 ] . style . left = ( mousex + this . fixbutton _addx ) + "px" ;
if ( this . tag ) {
this . tag [ 0 ] . style . transform = "translateX(" + ( 0 - targetx ) + "px)" ;
}
}
if ( ! this . move _lock || this . move _lock === "y" ) {
this . fixbutton [ 0 ] . style . top = ( mousey + this . fixbutton _addy ) + "px" ;
2019-07-01 16:19:12 +02:00
if ( this . console . tag ) {
this . console . tag [ 0 ] . style . transform = "translateY(" + ( 0 - targety ) + "px)" ;
2018-09-17 15:33:45 +02:00
}
2015-08-16 11:51:00 +02:00
}
if ( ( ! this . opened && targetx > this . width / 3 ) || ( this . opened && targetx > this . width * 0.9 ) ) {
2018-09-17 15:33:45 +02:00
this . fixbutton _targetx = this . fixbutton _initx - this . width ;
2015-08-16 11:51:00 +02:00
} else {
2018-09-17 15:33:45 +02:00
this . fixbutton _targetx = this . fixbutton _initx ;
}
2019-07-01 16:19:12 +02:00
if ( ( ! this . console . opened && 0 - targety > this . page _height / 10 ) || ( this . console . opened && 0 - targety > this . page _height * 0.8 ) ) {
2018-09-17 15:33:45 +02:00
return this . fixbutton _targety = this . page _height - this . fixbutton _inity - 50 ;
} else {
return this . fixbutton _targety = this . fixbutton _inity ;
2015-08-16 11:51:00 +02:00
}
} ;
Sidebar . prototype . stopDrag = function ( ) {
2018-09-17 15:33:45 +02:00
var left , top ;
2016-05-02 00:28:23 +02:00
this . fixbutton . parents ( ) . off ( "mousemove touchmove" ) ;
this . fixbutton . off ( "mousemove touchmove" ) ;
2015-08-16 11:51:00 +02:00
this . fixbutton . css ( "pointer-events" , "" ) ;
$ ( ".drag-bg" ) . remove ( ) ;
if ( ! this . fixbutton . hasClass ( "dragging" ) ) {
return ;
}
this . fixbutton . removeClass ( "dragging" ) ;
2019-07-01 16:19:12 +02:00
if ( this . fixbutton _targetx !== this . fixbutton . offset ( ) . left || this . fixbutton _targety !== this . fixbutton . offset ( ) . top ) {
2018-09-17 15:33:45 +02:00
if ( this . move _lock === "y" ) {
top = this . fixbutton _targety ;
left = this . fixbutton _initx ;
}
if ( this . move _lock === "x" ) {
top = this . fixbutton _inity ;
left = this . fixbutton _targetx ;
}
2015-08-16 11:51:00 +02:00
this . fixbutton . stop ( ) . animate ( {
2018-09-17 15:33:45 +02:00
"left" : left ,
"top" : top
2015-08-16 11:51:00 +02:00
} , 500 , "easeOutBack" , ( function ( _this ) {
return function ( ) {
if ( _this . fixbutton _targetx === _this . fixbutton _initx ) {
_this . fixbutton . css ( "left" , "auto" ) ;
} else {
2018-09-17 15:33:45 +02:00
_this . fixbutton . css ( "left" , left ) ;
2015-08-16 11:51:00 +02:00
}
return $ ( ".fixbutton-bg" ) . trigger ( "mouseout" ) ;
} ;
} ) ( this ) ) ;
2018-09-17 15:33:45 +02:00
this . stopDragX ( ) ;
2019-07-01 16:19:12 +02:00
this . console . stopDragY ( ) ;
2018-09-17 15:33:45 +02:00
}
return this . move _lock = null ;
} ;
Sidebar . prototype . stopDragX = function ( ) {
var targetx ;
if ( this . fixbutton _targetx === this . fixbutton _initx || this . move _lock === "y" ) {
targetx = 0 ;
this . opened = false ;
} else {
targetx = this . width ;
if ( this . opened ) {
this . onOpened ( ) ;
2015-08-16 11:51:00 +02:00
} else {
2018-09-17 15:33:45 +02:00
this . when _loaded . done ( ( function ( _this ) {
2016-11-18 20:15:29 +01:00
return function ( ) {
2018-09-17 15:33:45 +02:00
return _this . onOpened ( ) ;
2016-11-18 20:15:29 +01:00
} ;
} ) ( this ) ) ;
}
2018-09-17 15:33:45 +02:00
this . opened = true ;
}
if ( this . tag ) {
this . tag . css ( "transition" , "0.4s ease-out" ) ;
this . tag . css ( "transform" , "translateX(-" + targetx + "px)" ) . one ( transitionEnd , ( function ( _this ) {
return function ( ) {
_this . tag . css ( "transition" , "" ) ;
if ( ! _this . opened ) {
_this . container . remove ( ) ;
_this . container = null ;
2018-10-05 15:08:42 +02:00
if ( _this . tag ) {
_this . tag . remove ( ) ;
return _this . tag = null ;
}
2018-09-17 15:33:45 +02:00
}
} ;
} ) ( this ) ) ;
}
this . log ( "stopdrag" , "opened:" , this . opened ) ;
if ( ! this . opened ) {
return this . onClosed ( ) ;
2015-08-16 11:51:00 +02:00
}
} ;
2019-05-29 16:03:48 +02:00
Sidebar . prototype . sign = function ( inner _path , privatekey ) {
this . wrapper . displayProgress ( "sign" , "Signing: " + inner _path + "..." , 0 ) ;
return this . wrapper . ws . cmd ( "siteSign" , {
privatekey : privatekey ,
inner _path : inner _path ,
update _changed _files : true
} , ( function ( _this ) {
return function ( res ) {
if ( res === "ok" ) {
return _this . wrapper . displayProgress ( "sign" , inner _path + " signed!" , 100 ) ;
} else {
return _this . wrapper . displayProgress ( "sign" , "Error signing " + inner _path , - 1 ) ;
}
} ;
} ) ( this ) ) ;
} ;
Sidebar . prototype . publish = function ( inner _path , privatekey ) {
return this . wrapper . ws . cmd ( "sitePublish" , {
privatekey : privatekey ,
inner _path : inner _path ,
sign : true ,
update _changed _files : true
} , ( function ( _this ) {
return function ( res ) {
if ( res === "ok" ) {
return _this . wrapper . notifications . add ( "sign" , "done" , inner _path + " Signed and published!" , 5000 ) ;
}
} ;
} ) ( this ) ) ;
} ;
2015-08-16 11:51:00 +02:00
Sidebar . prototype . onOpened = function ( ) {
2017-12-31 16:56:17 +01:00
var menu ;
2015-08-16 11:51:00 +02:00
this . log ( "Opened" ) ;
this . scrollable ( ) ;
2018-03-10 02:01:49 +01:00
this . tag . find ( "#checkbox-owned, #checkbox-autodownloadoptional" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( ) {
return setTimeout ( ( function ( ) {
return _this . scrollable ( ) ;
} ) , 300 ) ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-sitelimit" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "siteSetLimit" , $ ( "#input-sitelimit" ) . val ( ) , function ( res ) {
2017-04-12 17:36:50 +02:00
if ( res === "ok" ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . notifications . add ( "done-sitelimit" , "done" , "Site storage limit modified!" , 5000 ) ;
2017-04-12 17:36:50 +02:00
}
2015-08-16 11:51:00 +02:00
return _this . updateHtmlTag ( ) ;
} ) ;
return false ;
2016-04-18 02:24:14 +02:00
} ;
} ) ( this ) ) ;
2018-03-10 02:01:49 +01:00
this . tag . find ( "#button-autodownload_bigfile_size_limit" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
return function ( ) {
_this . wrapper . ws . cmd ( "siteSetAutodownloadBigfileLimit" , $ ( "#input-autodownload_bigfile_size_limit" ) . val ( ) , function ( res ) {
if ( res === "ok" ) {
_this . wrapper . notifications . add ( "done-bigfilelimit" , "done" , "Site bigfile auto download limit modified!" , 5000 ) ;
}
return _this . updateHtmlTag ( ) ;
} ) ;
return false ;
} ;
} ) ( this ) ) ;
2020-02-07 16:42:26 +01:00
this . tag . find ( "#button-autodownload_previous" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
return function ( ) {
_this . wrapper . ws . cmd ( "siteUpdate" , {
"address" : _this . wrapper . site _info . address ,
"check_files" : true
} , function ( ) {
return _this . wrapper . notifications . add ( "done-download_optional" , "done" , "Optional files downloaded" , 5000 ) ;
} ) ;
_this . wrapper . notifications . add ( "start-download_optional" , "info" , "Optional files download started" , 5000 ) ;
return false ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-dbreload" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2016-04-18 02:24:14 +02:00
return function ( ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "dbReload" , [ ] , function ( ) {
_this . wrapper . notifications . add ( "done-dbreload" , "done" , "Database schema reloaded!" , 5000 ) ;
2016-08-10 12:53:45 +02:00
return _this . updateHtmlTag ( ) ;
} ) ;
return false ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-dbrebuild" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2016-08-10 12:53:45 +02:00
return function ( ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . notifications . add ( "done-dbrebuild" , "info" , "Database rebuilding...." ) ;
2019-07-01 16:19:12 +02:00
_this . wrapper . ws . cmd ( "dbRebuild" , [ ] , function ( ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . notifications . add ( "done-dbrebuild" , "done" , "Database rebuilt!" , 5000 ) ;
2016-04-18 02:24:14 +02:00
return _this . updateHtmlTag ( ) ;
} ) ;
return false ;
2015-08-16 11:51:00 +02:00
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-update" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return function ( ) {
_this . tag . find ( "#button-update" ) . addClass ( "loading" ) ;
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "siteUpdate" , _this . wrapper . site _info . address , function ( ) {
_this . wrapper . notifications . add ( "done-updated" , "done" , "Site updated!" , 5000 ) ;
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return _this . tag . find ( "#button-update" ) . removeClass ( "loading" ) ;
} ) ;
return false ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-pause" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return function ( ) {
_this . tag . find ( "#button-pause" ) . addClass ( "hidden" ) ;
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "sitePause" , _this . wrapper . site _info . address ) ;
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return false ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-resume" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return function ( ) {
_this . tag . find ( "#button-resume" ) . addClass ( "hidden" ) ;
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "siteResume" , _this . wrapper . site _info . address ) ;
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return false ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-delete" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
return function ( ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . displayConfirm ( "Are you sure?" , [ "Delete this site" , "Blacklist" ] , function ( confirmed ) {
2017-05-11 18:02:37 +02:00
if ( confirmed === 1 ) {
_this . tag . find ( "#button-delete" ) . addClass ( "loading" ) ;
2018-02-21 03:15:04 +01:00
return _this . wrapper . ws . cmd ( "siteDelete" , _this . wrapper . site _info . address , function ( ) {
2017-05-11 18:02:37 +02:00
return document . location = $ ( ".fixbutton-bg" ) . attr ( "href" ) ;
} ) ;
} else if ( confirmed === 2 ) {
2018-02-21 03:15:04 +01:00
return _this . wrapper . displayPrompt ( "Blacklist this site" , "text" , "Delete and Blacklist" , "Reason" , function ( reason ) {
2017-05-11 18:02:37 +02:00
_this . tag . find ( "#button-delete" ) . addClass ( "loading" ) ;
2018-06-28 14:07:06 +02:00
_this . wrapper . ws . cmd ( "siteblockAdd" , [ _this . wrapper . site _info . address , reason ] ) ;
2018-02-21 03:15:04 +01:00
return _this . wrapper . ws . cmd ( "siteDelete" , _this . wrapper . site _info . address , function ( ) {
2017-05-11 18:02:37 +02:00
return document . location = $ ( ".fixbutton-bg" ) . attr ( "href" ) ;
} ) ;
} ) ;
}
Rev957, Sidebar displays onion peers in graph, Sidebar display bad file retry number, Sidebar site Update/Pause/Delete, Ratelimit sidebar update, Encoded typo, Fix onion findHashId, More retry for bad files, Log file path errors, Testcase for self findhashIds, Testcase for Tor findHashId, Better Tor version parse, UiWebsocket callback on update/pause/resume/delete, Skip invalid postMessage messages
2016-03-09 00:48:57 +01:00
} ) ;
return false ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#checkbox-owned" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
return function ( ) {
2018-02-21 03:15:04 +01:00
return _this . wrapper . ws . cmd ( "siteSetOwned" , [ _this . tag . find ( "#checkbox-owned" ) . is ( ":checked" ) ] ) ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#checkbox-autodownloadoptional" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
return function ( ) {
2018-02-21 03:15:04 +01:00
return _this . wrapper . ws . cmd ( "siteSetAutodownloadoptional" , [ _this . tag . find ( "#checkbox-autodownloadoptional" ) . is ( ":checked" ) ] ) ;
Rev571, Optional file sizes to sidebar, Download all optional files option in sidebar, Optional file number in peer stats, Delete removed or changed optional files, Auto download optional files if autodownloadoptional checked, SiteReload command, Peer use global file server if no site defined, Allow browser cache video files, Allow more keepalive connections, Gevent 1.1 ranged request bugfix, Dont sent optional files details on websocket, Remove files from workermanager tasks if no longer in bad_files, Notify local client about changes on external siteSign
2015-11-09 00:44:03 +01:00
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-identity" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "certSelect" ) ;
2015-08-16 11:51:00 +02:00
return false ;
} ;
} ) ( this ) ) ;
2017-05-06 02:13:26 +02:00
this . tag . find ( "#button-settings" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( ) {
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "fileGet" , "content.json" , function ( res ) {
2015-08-16 11:51:00 +02:00
var data , json _raw ;
data = JSON . parse ( res ) ;
data [ "title" ] = $ ( "#settings-title" ) . val ( ) ;
data [ "description" ] = $ ( "#settings-description" ) . val ( ) ;
json _raw = unescape ( encodeURIComponent ( JSON . stringify ( data , void 0 , '\t' ) ) ) ;
2018-02-21 03:15:04 +01:00
return _this . wrapper . ws . cmd ( "fileWrite" , [ "content.json" , btoa ( json _raw ) , true ] , function ( res ) {
2015-08-16 11:51:00 +02:00
if ( res !== "ok" ) {
2018-02-21 03:15:04 +01:00
return _this . wrapper . notifications . add ( "file-write" , "error" , "File write error: " + res ) ;
2015-08-16 11:51:00 +02:00
} else {
2018-02-21 03:15:04 +01:00
_this . wrapper . notifications . add ( "file-write" , "done" , "Site settings saved!" , 5000 ) ;
if ( _this . wrapper . site _info . privatekey ) {
_this . wrapper . ws . cmd ( "siteSign" , {
2017-08-09 14:15:44 +02:00
privatekey : "stored" ,
inner _path : "content.json" ,
update _changed _files : true
} ) ;
}
2015-08-16 11:51:00 +02:00
return _this . updateHtmlTag ( ) ;
}
} ) ;
} ) ;
return false ;
} ;
} ) ( this ) ) ;
2018-03-19 16:05:14 +01:00
this . tag . find ( "#link-directory" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2018-03-11 09:14:17 +01:00
return function ( ) {
2018-03-19 16:05:14 +01:00
_this . wrapper . ws . cmd ( "serverShowdirectory" , [ "site" , _this . wrapper . site _info . address ] ) ;
return false ;
2018-03-11 09:14:17 +01:00
} ;
} ) ( this ) ) ;
2018-07-19 20:42:04 +02:00
this . tag . find ( "#link-copypeers" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
return function ( e ) {
var copy _text , handler ;
copy _text = e . currentTarget . href ;
handler = function ( e ) {
e . clipboardData . setData ( 'text/plain' , copy _text ) ;
e . preventDefault ( ) ;
_this . wrapper . notifications . add ( "copy" , "done" , "Site address with peers copied to your clipboard" , 5000 ) ;
return document . removeEventListener ( 'copy' , handler , true ) ;
} ;
document . addEventListener ( 'copy' , handler , true ) ;
document . execCommand ( 'copy' ) ;
return false ;
} ;
} ) ( this ) ) ;
2017-12-30 15:43:56 +01:00
$ ( document ) . on ( "click touchend" , ( function ( _this ) {
return function ( ) {
2018-03-06 12:06:21 +01:00
var ref , ref1 ;
if ( ( ref = _this . tag ) != null ) {
ref . find ( "#button-sign-publish-menu" ) . removeClass ( "visible" ) ;
}
return ( ref1 = _this . tag ) != null ? ref1 . find ( ".contents + .flex" ) . removeClass ( "sign-publish-flex" ) : void 0 ;
2017-12-30 15:43:56 +01:00
} ;
} ) ( this ) ) ;
2018-12-04 01:45:01 +01:00
this . tag . find ( ".contents-content" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
return function ( e ) {
$ ( "#input-contents" ) . val ( e . currentTarget . innerText ) ;
return false ;
} ;
} ) ( this ) ) ;
2018-01-21 18:14:12 +01:00
menu = new Menu ( this . tag . find ( "#menu-sign-publish" ) ) ;
menu . elem . css ( "margin-top" , "-130px" ) ;
2017-12-31 17:48:28 +01:00
menu . addItem ( "Sign" , ( function ( _this ) {
2017-12-30 15:45:19 +01:00
return function ( ) {
var inner _path ;
inner _path = _this . tag . find ( "#input-contents" ) . val ( ) ;
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "fileRules" , {
2017-12-30 15:45:19 +01:00
inner _path : inner _path
2019-05-29 16:03:48 +02:00
} , function ( rules ) {
2017-12-30 15:45:19 +01:00
var ref ;
2019-05-29 16:03:48 +02:00
if ( ref = _this . wrapper . site _info . auth _address , indexOf . call ( rules . signers , ref ) >= 0 ) {
return _this . sign ( inner _path ) ;
} else if ( _this . wrapper . site _info . privatekey ) {
return _this . sign ( inner _path , "stored" ) ;
2017-12-30 15:45:19 +01:00
} else {
2018-02-21 03:15:04 +01:00
return _this . wrapper . displayPrompt ( "Enter your private key:" , "password" , "Sign" , "" , function ( privatekey ) {
2019-05-29 16:03:48 +02:00
return _this . sign ( inner _path , privatekey ) ;
2017-12-30 15:45:19 +01:00
} ) ;
}
} ) ;
2017-12-31 17:48:28 +01:00
_this . tag . find ( ".contents + .flex" ) . removeClass ( "active" ) ;
return menu . hide ( ) ;
} ;
} ) ( this ) ) ;
menu . addItem ( "Publish" , ( function ( _this ) {
return function ( ) {
var inner _path ;
inner _path = _this . tag . find ( "#input-contents" ) . val ( ) ;
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "sitePublish" , {
2017-12-31 17:48:28 +01:00
"inner_path" : inner _path ,
"sign" : false
} ) ;
_this . tag . find ( ".contents + .flex" ) . removeClass ( "active" ) ;
return menu . hide ( ) ;
} ;
} ) ( this ) ) ;
this . tag . find ( "#menu-sign-publish" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
return function ( ) {
if ( window . visible _menu === menu ) {
_this . tag . find ( ".contents + .flex" ) . removeClass ( "active" ) ;
menu . hide ( ) ;
} else {
_this . tag . find ( ".contents + .flex" ) . addClass ( "active" ) ;
_this . tag . find ( ".content-wrapper" ) . prop ( "scrollTop" , 10000 ) ;
menu . show ( ) ;
}
2017-12-30 15:45:19 +01:00
return false ;
} ;
} ) ( this ) ) ;
2017-12-31 17:48:28 +01:00
$ ( "body" ) . on ( "click" , ( function ( _this ) {
return function ( ) {
2018-02-21 03:15:04 +01:00
if ( _this . tag ) {
return _this . tag . find ( ".contents + .flex" ) . removeClass ( "active" ) ;
}
2017-12-31 17:48:28 +01:00
} ;
} ) ( this ) ) ;
this . tag . find ( "#button-sign-publish" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
2015-08-16 11:51:00 +02:00
return function ( ) {
var inner _path ;
2016-03-06 19:28:22 +01:00
inner _path = _this . tag . find ( "#input-contents" ) . val ( ) ;
2018-02-21 03:15:04 +01:00
_this . wrapper . ws . cmd ( "fileRules" , {
2017-06-13 10:47:15 +02:00
inner _path : inner _path
2019-05-29 16:03:48 +02:00
} , function ( rules ) {
2017-06-13 10:47:15 +02:00
var ref ;
2019-05-29 16:03:48 +02:00
if ( ref = _this . wrapper . site _info . auth _address , indexOf . call ( rules . signers , ref ) >= 0 ) {
return _this . publish ( inner _path , null ) ;
} else if ( _this . wrapper . site _info . privatekey ) {
return _this . publish ( inner _path , "stored" ) ;
2017-06-13 10:47:15 +02:00
} else {
2018-02-21 03:15:04 +01:00
return _this . wrapper . displayPrompt ( "Enter your private key:" , "password" , "Sign" , "" , function ( privatekey ) {
2019-05-29 16:03:48 +02:00
return _this . publish ( inner _path , privatekey ) ;
2017-06-13 10:47:15 +02:00
} ) ;
}
} ) ;
2017-12-30 19:46:53 +01:00
return false ;
2015-08-16 11:51:00 +02:00
} ;
} ) ( this ) ) ;
2017-07-29 13:45:57 +02:00
this . tag . find ( ".close" ) . off ( "click touchend" ) . on ( "click touchend" , ( function ( _this ) {
return function ( e ) {
2018-09-17 15:33:45 +02:00
_this . close ( ) ;
2017-07-29 13:45:57 +02:00
return false ;
} ;
} ) ( this ) ) ;
2015-08-16 11:51:00 +02:00
return this . loadGlobe ( ) ;
} ;
2018-09-17 15:33:45 +02:00
Sidebar . prototype . close = function ( ) {
this . move _lock = "x" ;
this . startDrag ( ) ;
return this . stopDrag ( ) ;
} ;
2015-08-16 11:51:00 +02:00
Sidebar . prototype . onClosed = function ( ) {
$ ( window ) . off ( "resize" ) ;
2016-01-09 18:49:34 +01:00
$ ( window ) . on ( "resize" , this . resized ) ;
2015-08-16 11:51:00 +02:00
$ ( document . body ) . css ( "transition" , "0.6s ease-in-out" ) . removeClass ( "body-sidebar" ) . on ( transitionEnd , ( function ( _this ) {
return function ( e ) {
2019-07-01 16:19:12 +02:00
if ( e . target === document . body && ! $ ( document . body ) . hasClass ( "body-sidebar" ) && ! $ ( document . body ) . hasClass ( "body-console" ) ) {
2018-09-17 15:33:45 +02:00
$ ( document . body ) . css ( "height" , "auto" ) . css ( "perspective" , "" ) . css ( "will-change" , "" ) . css ( "transition" , "" ) . off ( transitionEnd ) ;
2015-08-16 11:51:00 +02:00
return _this . unloadGlobe ( ) ;
}
} ;
} ) ( this ) ) ;
2018-02-21 03:15:04 +01:00
return this . wrapper . setSiteInfo = this . original _set _site _info ;
2015-08-16 11:51:00 +02:00
} ;
Sidebar . prototype . loadGlobe = function ( ) {
if ( this . tag . find ( ".globe" ) . hasClass ( "loading" ) ) {
return setTimeout ( ( ( function ( _this ) {
return function ( ) {
2018-11-26 00:14:30 +01:00
var script _tag ;
2015-08-16 11:51:00 +02:00
if ( typeof DAT === "undefined" ) {
2018-11-26 00:14:30 +01:00
script _tag = $ ( "<script>" ) ;
script _tag . attr ( "nonce" , _this . wrapper . script _nonce ) ;
script _tag . attr ( "src" , "/uimedia/globe/all.js" ) ;
script _tag . on ( "load" , _this . displayGlobe ) ;
return document . head . appendChild ( script _tag [ 0 ] ) ;
2015-08-16 11:51:00 +02:00
} else {
2016-03-16 00:40:37 +01:00
return _this . displayGlobe ( ) ;
2015-08-16 11:51:00 +02:00
}
} ;
} ) ( this ) ) , 600 ) ;
}
} ;
Sidebar . prototype . displayGlobe = function ( ) {
2016-03-18 19:20:49 +01:00
var img ;
img = new Image ( ) ;
img . src = "/uimedia/globe/world.jpg" ;
return img . onload = ( function ( _this ) {
return function ( ) {
2018-02-21 03:15:04 +01:00
return _this . wrapper . ws . cmd ( "sidebarGetPeers" , [ ] , function ( globe _data ) {
2018-09-17 15:33:45 +02:00
var e , ref , ref1 , ref2 ;
2016-03-18 19:20:49 +01:00
if ( _this . globe ) {
_this . globe . scene . remove ( _this . globe . points ) ;
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
_this . globe . addData ( globe _data , {
format : 'magnitude' ,
2016-03-18 19:20:49 +01:00
name : "hello" ,
animated : false
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
} ) ;
_this . globe . createPoints ( ) ;
2018-09-17 15:33:45 +02:00
return ( ref = _this . tag ) != null ? ref . find ( ".globe" ) . removeClass ( "loading" ) : void 0 ;
2016-05-16 22:29:55 +02:00
} else if ( typeof DAT !== "undefined" ) {
2016-03-18 19:20:49 +01:00
try {
_this . globe = new DAT . Globe ( _this . tag . find ( ".globe" ) [ 0 ] , {
"imgDir" : "/uimedia/globe/"
} ) ;
_this . globe . addData ( globe _data , {
format : 'magnitude' ,
name : "hello"
} ) ;
_this . globe . createPoints ( ) ;
_this . globe . animate ( ) ;
2017-04-12 17:36:50 +02:00
} catch ( error ) {
e = error ;
2016-03-18 19:20:49 +01:00
console . log ( "WebGL error" , e ) ;
2018-09-17 15:33:45 +02:00
if ( ( ref1 = _this . tag ) != null ) {
ref1 . find ( ".globe" ) . addClass ( "error" ) . text ( "WebGL not supported" ) ;
2016-08-10 12:53:45 +02:00
}
2016-03-18 19:20:49 +01:00
}
2018-09-17 15:33:45 +02:00
return ( ref2 = _this . tag ) != null ? ref2 . find ( ".globe" ) . removeClass ( "loading" ) : void 0 ;
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
}
2016-03-18 19:20:49 +01:00
} ) ;
2015-08-16 11:51:00 +02:00
} ;
2016-03-18 19:20:49 +01:00
} ) ( this ) ;
2015-08-16 11:51:00 +02:00
} ;
Sidebar . prototype . unloadGlobe = function ( ) {
if ( ! this . globe ) {
return false ;
}
this . globe . unload ( ) ;
return this . globe = null ;
} ;
return Sidebar ;
} ) ( Class ) ;
2018-02-21 03:15:04 +01:00
wrapper = window . wrapper ;
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
setTimeout ( ( function ( ) {
2018-02-21 03:15:04 +01:00
return window . sidebar = new Sidebar ( wrapper ) ;
Rev900, Sidebar filestats bar width round fix, Sidebar WebGL not supported error, Sidebar optimalizations, Trayicon gray shadow, Trim end of line whitespace from json files, Fix testweb testcase, Implement experimental postMessage nonce security, Return None when testing external ip, Window opener security check and message, Increase timeout for large files
2016-02-10 02:30:04 +01:00
} ) , 500 ) ;
2015-08-16 11:51:00 +02:00
window . transitionEnd = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend' ;
} ) . call ( this ) ;
2020-02-07 16:42:26 +01:00
2019-09-02 14:17:35 +02:00
/* ---- morphdom.js ---- */
2015-08-16 11:51:00 +02:00
( function ( f ) { if ( typeof exports === "object" && typeof module !== "undefined" ) { module . exports = f ( ) } else if ( typeof define === "function" && define . amd ) { define ( [ ] , f ) } else { var g ; if ( typeof window !== "undefined" ) { g = window } else if ( typeof global !== "undefined" ) { g = global } else if ( typeof self !== "undefined" ) { g = self } else { g = this } g . morphdom = f ( ) } } ) ( function ( ) { var define , module , exports ; return ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; var f = new Error ( "Cannot find module '" + o + "'" ) ; throw f . code = "MODULE_NOT_FOUND" , f } var l = n [ o ] = { exports : { } } ; t [ o ] [ 0 ] . call ( l . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ? n : e ) } , l , l . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 : [ function ( require , module , exports ) {
var specialElHandlers = {
/ * *
* Needed for IE . Apparently IE doesn ' t think
* that "selected" is an attribute when reading
* over the attributes using selectEl . attributes
* /
OPTION : function ( fromEl , toEl ) {
if ( ( fromEl . selected = toEl . selected ) ) {
fromEl . setAttribute ( 'selected' , '' ) ;
} else {
fromEl . removeAttribute ( 'selected' , '' ) ;
}
} ,
/ * *
* The "value" attribute is special for the < input > element
* since it sets the initial value . Changing the "value"
* attribute without changing the "value" property will have
* no effect since it is only used to the set the initial value .
* Similar for the "checked" attribute .
* /
/ * I N P U T : f u n c t i o n ( f r o m E l , t o E l ) {
fromEl . checked = toEl . checked ;
fromEl . value = toEl . value ;
if ( ! toEl . hasAttribute ( 'checked' ) ) {
fromEl . removeAttribute ( 'checked' ) ;
}
if ( ! toEl . hasAttribute ( 'value' ) ) {
fromEl . removeAttribute ( 'value' ) ;
}
} * /
} ;
function noop ( ) { }
/ * *
* Loop over all of the attributes on the target node and make sure the
* original DOM node has the same attributes . If an attribute
* found on the original node is not on the new node then remove it from
* the original node
* @ param { HTMLElement } fromNode
* @ param { HTMLElement } toNode
* /
function morphAttrs ( fromNode , toNode ) {
var attrs = toNode . attributes ;
var i ;
var attr ;
var attrName ;
var attrValue ;
var foundAttrs = { } ;
for ( i = attrs . length - 1 ; i >= 0 ; i -- ) {
attr = attrs [ i ] ;
if ( attr . specified !== false ) {
attrName = attr . name ;
attrValue = attr . value ;
foundAttrs [ attrName ] = true ;
if ( fromNode . getAttribute ( attrName ) !== attrValue ) {
fromNode . setAttribute ( attrName , attrValue ) ;
}
}
}
// Delete any extra attributes found on the original DOM element that weren't
// found on the target element.
attrs = fromNode . attributes ;
for ( i = attrs . length - 1 ; i >= 0 ; i -- ) {
attr = attrs [ i ] ;
if ( attr . specified !== false ) {
attrName = attr . name ;
if ( ! foundAttrs . hasOwnProperty ( attrName ) ) {
fromNode . removeAttribute ( attrName ) ;
}
}
}
}
/ * *
* Copies the children of one DOM element to another DOM element
* /
function moveChildren ( from , to ) {
var curChild = from . firstChild ;
while ( curChild ) {
var nextChild = curChild . nextSibling ;
to . appendChild ( curChild ) ;
curChild = nextChild ;
}
return to ;
}
function morphdom ( fromNode , toNode , options ) {
if ( ! options ) {
options = { } ;
}
if ( typeof toNode === 'string' ) {
var newBodyEl = document . createElement ( 'body' ) ;
newBodyEl . innerHTML = toNode ;
toNode = newBodyEl . childNodes [ 0 ] ;
}
var savedEls = { } ; // Used to save off DOM elements with IDs
var unmatchedEls = { } ;
var onNodeDiscarded = options . onNodeDiscarded || noop ;
var onBeforeMorphEl = options . onBeforeMorphEl || noop ;
var onBeforeMorphElChildren = options . onBeforeMorphElChildren || noop ;
function removeNodeHelper ( node , nestedInSavedEl ) {
var id = node . id ;
// If the node has an ID then save it off since we will want
// to reuse it in case the target DOM tree has a DOM element
// with the same ID
if ( id ) {
savedEls [ id ] = node ;
} else if ( ! nestedInSavedEl ) {
// If we are not nested in a saved element then we know that this node has been
// completely discarded and will not exist in the final DOM.
onNodeDiscarded ( node ) ;
}
if ( node . nodeType === 1 ) {
var curChild = node . firstChild ;
while ( curChild ) {
removeNodeHelper ( curChild , nestedInSavedEl || id ) ;
curChild = curChild . nextSibling ;
}
}
}
function walkDiscardedChildNodes ( node ) {
if ( node . nodeType === 1 ) {
var curChild = node . firstChild ;
while ( curChild ) {
if ( ! curChild . id ) {
// We only want to handle nodes that don't have an ID to avoid double
// walking the same saved element.
onNodeDiscarded ( curChild ) ;
// Walk recursively
walkDiscardedChildNodes ( curChild ) ;
}
curChild = curChild . nextSibling ;
}
}
}
function removeNode ( node , parentNode , alreadyVisited ) {
parentNode . removeChild ( node ) ;
if ( alreadyVisited ) {
if ( ! node . id ) {
onNodeDiscarded ( node ) ;
walkDiscardedChildNodes ( node ) ;
}
} else {
removeNodeHelper ( node ) ;
}
}
function morphEl ( fromNode , toNode , alreadyVisited ) {
if ( toNode . id ) {
// If an element with an ID is being morphed then it is will be in the final
// DOM so clear it out of the saved elements collection
delete savedEls [ toNode . id ] ;
}
if ( onBeforeMorphEl ( fromNode , toNode ) === false ) {
return ;
}
morphAttrs ( fromNode , toNode ) ;
if ( onBeforeMorphElChildren ( fromNode , toNode ) === false ) {
return ;
}
var curToNodeChild = toNode . firstChild ;
var curFromNodeChild = fromNode . firstChild ;
var curToNodeId ;
var fromNextSibling ;
var toNextSibling ;
var savedEl ;
var unmatchedEl ;
outer : while ( curToNodeChild ) {
toNextSibling = curToNodeChild . nextSibling ;
curToNodeId = curToNodeChild . id ;
while ( curFromNodeChild ) {
var curFromNodeId = curFromNodeChild . id ;
fromNextSibling = curFromNodeChild . nextSibling ;
if ( ! alreadyVisited ) {
if ( curFromNodeId && ( unmatchedEl = unmatchedEls [ curFromNodeId ] ) ) {
unmatchedEl . parentNode . replaceChild ( curFromNodeChild , unmatchedEl ) ;
morphEl ( curFromNodeChild , unmatchedEl , alreadyVisited ) ;
curFromNodeChild = fromNextSibling ;
continue ;
}
}
var curFromNodeType = curFromNodeChild . nodeType ;
if ( curFromNodeType === curToNodeChild . nodeType ) {
var isCompatible = false ;
if ( curFromNodeType === 1 ) { // Both nodes being compared are Element nodes
if ( curFromNodeChild . tagName === curToNodeChild . tagName ) {
// We have compatible DOM elements
if ( curFromNodeId || curToNodeId ) {
// If either DOM element has an ID then we handle
// those differently since we want to match up
// by ID
if ( curToNodeId === curFromNodeId ) {
isCompatible = true ;
}
} else {
isCompatible = true ;
}
}
if ( isCompatible ) {
// We found compatible DOM elements so add a
// task to morph the compatible DOM elements
morphEl ( curFromNodeChild , curToNodeChild , alreadyVisited ) ;
}
} else if ( curFromNodeType === 3 ) { // Both nodes being compared are Text nodes
isCompatible = true ;
curFromNodeChild . nodeValue = curToNodeChild . nodeValue ;
}
if ( isCompatible ) {
curToNodeChild = toNextSibling ;
curFromNodeChild = fromNextSibling ;
continue outer ;
}
}
// No compatible match so remove the old node from the DOM
removeNode ( curFromNodeChild , fromNode , alreadyVisited ) ;
curFromNodeChild = fromNextSibling ;
}
if ( curToNodeId ) {
if ( ( savedEl = savedEls [ curToNodeId ] ) ) {
morphEl ( savedEl , curToNodeChild , true ) ;
curToNodeChild = savedEl ; // We want to append the saved element instead
} else {
// The current DOM element in the target tree has an ID
// but we did not find a match in any of the corresponding
// siblings. We just put the target element in the old DOM tree
// but if we later find an element in the old DOM tree that has
// a matching ID then we will replace the target element
// with the corresponding old element and morph the old element
unmatchedEls [ curToNodeId ] = curToNodeChild ;
}
}
// If we got this far then we did not find a candidate match for our "to node"
// and we exhausted all of the children "from" nodes. Therefore, we will just
// append the current "to node" to the end
fromNode . appendChild ( curToNodeChild ) ;
curToNodeChild = toNextSibling ;
curFromNodeChild = fromNextSibling ;
}
// We have processed all of the "to nodes". If curFromNodeChild is non-null then
// we still have some from nodes left over that need to be removed
while ( curFromNodeChild ) {
fromNextSibling = curFromNodeChild . nextSibling ;
removeNode ( curFromNodeChild , fromNode , alreadyVisited ) ;
curFromNodeChild = fromNextSibling ;
}
var specialElHandler = specialElHandlers [ fromNode . tagName ] ;
if ( specialElHandler ) {
specialElHandler ( fromNode , toNode ) ;
}
}
var morphedNode = fromNode ;
var morphedNodeType = morphedNode . nodeType ;
var toNodeType = toNode . nodeType ;
// Handle the case where we are given two DOM nodes that are not
// compatible (e.g. <div> --> <span> or <div> --> TEXT)
if ( morphedNodeType === 1 ) {
if ( toNodeType === 1 ) {
if ( morphedNode . tagName !== toNode . tagName ) {
onNodeDiscarded ( fromNode ) ;
morphedNode = moveChildren ( morphedNode , document . createElement ( toNode . tagName ) ) ;
}
} else {
// Going from an element node to a text node
return toNode ;
}
} else if ( morphedNodeType === 3 ) { // Text node
if ( toNodeType === 3 ) {
morphedNode . nodeValue = toNode . nodeValue ;
return morphedNode ;
} else {
onNodeDiscarded ( fromNode ) ;
// Text node to something else
return toNode ;
}
}
morphEl ( morphedNode , toNode , false ) ;
// Fire the "onNodeDiscarded" event for any saved elements
// that never found a new home in the morphed DOM
for ( var savedElId in savedEls ) {
if ( savedEls . hasOwnProperty ( savedElId ) ) {
var savedEl = savedEls [ savedElId ] ;
onNodeDiscarded ( savedEl ) ;
walkDiscardedChildNodes ( savedEl ) ;
}
}
if ( morphedNode !== fromNode && fromNode . parentNode ) {
fromNode . parentNode . replaceChild ( morphedNode , fromNode ) ;
}
return morphedNode ;
}
module . exports = morphdom ;
} , { } ] } , { } , [ 1 ] ) ( 1 )
2019-07-01 16:19:12 +02:00
} ) ;