c&&1===a.x&&(a=new THREE.Vector2(a.x-1,a.y));0===b.x&&0===b.z&&(a=new THREE.Vector2(c/2/Math.PI+.5,
+a.y));return a.clone()}THREE.Geometry.call(this);this.type="PolyhedronGeometry";this.parameters={vertices:a,indices:b,radius:c,detail:d};c=c||1;d=d||0;for(var k=this,n=0,p=a.length;nr&&(.2>d&&(b[0].x+=1),.2>a&&(b[1].x+=1),.2>q&&(b[2].x+=1));n=0;for(p=this.vertices.length;n
c.y?this.quaternion.set(1,0,0,0):(a.set(c.z,0,-c.x).normalize(),b=Math.acos(c.y),this.quaternion.setFromAxisAngle(a,b))}}();
+THREE.ArrowHelper.prototype.setLength=function(a,b,c){void 0===b&&(b=.2*a);void 0===c&&(c=.2*b);this.line.scale.set(1,a,1);this.line.updateMatrix();this.cone.scale.set(c,b,c);this.cone.position.y=a;this.cone.updateMatrix()};THREE.ArrowHelper.prototype.setColor=function(a){this.line.material.color.set(a);this.cone.material.color.set(a)};
+THREE.BoxHelper=function(a){var b=new THREE.BufferGeometry;b.addAttribute("position",new THREE.BufferAttribute(new Float32Array(72),3));THREE.Line.call(this,b,new THREE.LineBasicMaterial({color:16776960}),THREE.LinePieces);void 0!==a&&this.update(a)};THREE.BoxHelper.prototype=Object.create(THREE.Line.prototype);
+THREE.BoxHelper.prototype.update=function(a){var b=a.geometry;null===b.boundingBox&&b.computeBoundingBox();var c=b.boundingBox.min,b=b.boundingBox.max,d=this.geometry.attributes.position.array;d[0]=b.x;d[1]=b.y;d[2]=b.z;d[3]=c.x;d[4]=b.y;d[5]=b.z;d[6]=c.x;d[7]=b.y;d[8]=b.z;d[9]=c.x;d[10]=c.y;d[11]=b.z;d[12]=c.x;d[13]=c.y;d[14]=b.z;d[15]=b.x;d[16]=c.y;d[17]=b.z;d[18]=b.x;d[19]=c.y;d[20]=b.z;d[21]=b.x;d[22]=b.y;d[23]=b.z;d[24]=b.x;d[25]=b.y;d[26]=c.z;d[27]=c.x;d[28]=b.y;d[29]=c.z;d[30]=c.x;d[31]=b.y;
+d[32]=c.z;d[33]=c.x;d[34]=c.y;d[35]=c.z;d[36]=c.x;d[37]=c.y;d[38]=c.z;d[39]=b.x;d[40]=c.y;d[41]=c.z;d[42]=b.x;d[43]=c.y;d[44]=c.z;d[45]=b.x;d[46]=b.y;d[47]=c.z;d[48]=b.x;d[49]=b.y;d[50]=b.z;d[51]=b.x;d[52]=b.y;d[53]=c.z;d[54]=c.x;d[55]=b.y;d[56]=b.z;d[57]=c.x;d[58]=b.y;d[59]=c.z;d[60]=c.x;d[61]=c.y;d[62]=b.z;d[63]=c.x;d[64]=c.y;d[65]=c.z;d[66]=b.x;d[67]=c.y;d[68]=b.z;d[69]=b.x;d[70]=c.y;d[71]=c.z;this.geometry.attributes.position.needsUpdate=!0;this.geometry.computeBoundingSphere();this.matrix=a.matrixWorld;
+this.matrixAutoUpdate=!1};THREE.BoundingBoxHelper=function(a,b){var c=void 0!==b?b:8947848;this.object=a;this.box=new THREE.Box3;THREE.Mesh.call(this,new THREE.BoxGeometry(1,1,1),new THREE.MeshBasicMaterial({color:c,wireframe:!0}))};THREE.BoundingBoxHelper.prototype=Object.create(THREE.Mesh.prototype);THREE.BoundingBoxHelper.prototype.update=function(){this.box.setFromObject(this.object);this.box.size(this.scale);this.box.center(this.position)};
+THREE.CameraHelper=function(a){function b(a,b,d){c(a,d);c(b,d)}function c(a,b){d.vertices.push(new THREE.Vector3);d.colors.push(new THREE.Color(b));void 0===f[a]&&(f[a]=[]);f[a].push(d.vertices.length-1)}var d=new THREE.Geometry,e=new THREE.LineBasicMaterial({color:16777215,vertexColors:THREE.FaceColors}),f={};b("n1","n2",16755200);b("n2","n4",16755200);b("n4","n3",16755200);b("n3","n1",16755200);b("f1","f2",16755200);b("f2","f4",16755200);b("f4","f3",16755200);b("f3","f1",16755200);b("n1","f1",16755200);
+b("n2","f2",16755200);b("n3","f3",16755200);b("n4","f4",16755200);b("p","n1",16711680);b("p","n2",16711680);b("p","n3",16711680);b("p","n4",16711680);b("u1","u2",43775);b("u2","u3",43775);b("u3","u1",43775);b("c","t",16777215);b("p","c",3355443);b("cn1","cn2",3355443);b("cn3","cn4",3355443);b("cf1","cf2",3355443);b("cf3","cf4",3355443);THREE.Line.call(this,d,e,THREE.LinePieces);this.camera=a;this.matrix=a.matrixWorld;this.matrixAutoUpdate=!1;this.pointMap=f;this.update()};
+THREE.CameraHelper.prototype=Object.create(THREE.Line.prototype);
+THREE.CameraHelper.prototype.update=function(){var a,b,c=new THREE.Vector3,d=new THREE.Camera,e=function(e,g,h,k){c.set(g,h,k).unproject(d);e=b[e];if(void 0!==e)for(g=0,h=e.length;gt;t++){d[0]=r[g[t]];d[1]=r[g[(t+1)%3]];d.sort(f);var s=d.toString();void 0===e[s]?(e[s]={vert1:d[0],vert2:d[1],face1:q,face2:void 0},p++):e[s].face2=q}d=new Float32Array(6*p);f=0;for(s in e)if(g=e[s],void 0===g.face2||
+.9999>k[g.face1].normal.dot(k[g.face2].normal))p=n[g.vert1],d[f++]=p.x,d[f++]=p.y,d[f++]=p.z,p=n[g.vert2],d[f++]=p.x,d[f++]=p.y,d[f++]=p.z;h.addAttribute("position",new THREE.BufferAttribute(d,3));THREE.Line.call(this,h,new THREE.LineBasicMaterial({color:c}),THREE.LinePieces);this.matrix=a.matrixWorld;this.matrixAutoUpdate=!1};THREE.EdgesHelper.prototype=Object.create(THREE.Line.prototype);
+THREE.FaceNormalsHelper=function(a,b,c,d){this.object=a;this.size=void 0!==b?b:1;a=void 0!==c?c:16776960;d=void 0!==d?d:1;b=new THREE.Geometry;c=0;for(var e=this.object.geometry.faces.length;cb;b++)a.faces[b].color=this.colors[4>b?0:1];b=new THREE.MeshBasicMaterial({vertexColors:THREE.FaceColors,wireframe:!0});this.lightSphere=new THREE.Mesh(a,b);this.add(this.lightSphere);
+this.update()};THREE.HemisphereLightHelper.prototype=Object.create(THREE.Object3D.prototype);THREE.HemisphereLightHelper.prototype.dispose=function(){this.lightSphere.geometry.dispose();this.lightSphere.material.dispose()};
+THREE.HemisphereLightHelper.prototype.update=function(){var a=new THREE.Vector3;return function(){this.colors[0].copy(this.light.color).multiplyScalar(this.light.intensity);this.colors[1].copy(this.light.groundColor).multiplyScalar(this.light.intensity);this.lightSphere.lookAt(a.setFromMatrixPosition(this.light.matrixWorld).negate());this.lightSphere.geometry.colorsNeedUpdate=!0}}();
+THREE.PointLightHelper=function(a,b){this.light=a;this.light.updateMatrixWorld();var c=new THREE.SphereGeometry(b,4,2),d=new THREE.MeshBasicMaterial({wireframe:!0,fog:!1});d.color.copy(this.light.color).multiplyScalar(this.light.intensity);THREE.Mesh.call(this,c,d);this.matrix=this.light.matrixWorld;this.matrixAutoUpdate=!1};THREE.PointLightHelper.prototype=Object.create(THREE.Mesh.prototype);THREE.PointLightHelper.prototype.dispose=function(){this.geometry.dispose();this.material.dispose()};
+THREE.PointLightHelper.prototype.update=function(){this.material.color.copy(this.light.color).multiplyScalar(this.light.intensity)};
+THREE.SkeletonHelper=function(a){this.bones=this.getBoneList(a);for(var b=new THREE.Geometry,c=0;cs;s++){d[0]=t[g[s]];d[1]=t[g[(s+1)%3]];d.sort(f);var u=d.toString();void 0===e[u]&&(q[2*p]=d[0],q[2*p+1]=d[1],e[u]=!0,p++)}d=new Float32Array(6*p);m=0;for(r=p;ms;s++)p=
+k[q[2*m+s]],g=6*m+3*s,d[g+0]=p.x,d[g+1]=p.y,d[g+2]=p.z;h.addAttribute("position",new THREE.BufferAttribute(d,3))}else if(a.geometry instanceof THREE.BufferGeometry){if(void 0!==a.geometry.attributes.index){k=a.geometry.attributes.position.array;r=a.geometry.attributes.index.array;n=a.geometry.drawcalls;p=0;0===n.length&&(n=[{count:r.length,index:0,start:0}]);for(var q=new Uint32Array(2*r.length),t=0,v=n.length;ts;s++)d[0]=
+g+r[m+s],d[1]=g+r[m+(s+1)%3],d.sort(f),u=d.toString(),void 0===e[u]&&(q[2*p]=d[0],q[2*p+1]=d[1],e[u]=!0,p++);d=new Float32Array(6*p);m=0;for(r=p;ms;s++)g=6*m+3*s,p=3*q[2*m+s],d[g+0]=k[p],d[g+1]=k[p+1],d[g+2]=k[p+2]}else for(k=a.geometry.attributes.position.array,p=k.length/3,q=p/3,d=new Float32Array(6*p),m=0,r=q;ms;s++)g=18*m+6*s,q=9*m+3*s,d[g+0]=k[q],d[g+1]=k[q+1],d[g+2]=k[q+2],p=9*m+(s+1)%3*3,d[g+3]=k[p],d[g+4]=k[p+1],d[g+5]=k[p+2];h.addAttribute("position",new THREE.BufferAttribute(d,
+3))}THREE.Line.call(this,h,new THREE.LineBasicMaterial({color:c}),THREE.LinePieces);this.matrix=a.matrixWorld;this.matrixAutoUpdate=!1};THREE.WireframeHelper.prototype=Object.create(THREE.Line.prototype);THREE.ImmediateRenderObject=function(){THREE.Object3D.call(this);this.render=function(a){}};THREE.ImmediateRenderObject.prototype=Object.create(THREE.Object3D.prototype);
+THREE.MorphBlendMesh=function(a,b){THREE.Mesh.call(this,a,b);this.animationsMap={};this.animationsList=[];var c=this.geometry.morphTargets.length;this.createAnimation("__default",0,c-1,c/1);this.setAnimationWeight("__default",1)};THREE.MorphBlendMesh.prototype=Object.create(THREE.Mesh.prototype);
+THREE.MorphBlendMesh.prototype.createAnimation=function(a,b,c,d){b={startFrame:b,endFrame:c,length:c-b+1,fps:d,duration:(c-b)/d,lastFrame:0,currentFrame:0,active:!1,time:0,direction:1,weight:1,directionBackwards:!1,mirroredLoop:!1};this.animationsMap[a]=b;this.animationsList.push(b)};
+THREE.MorphBlendMesh.prototype.autoCreateAnimations=function(a){for(var b=/([a-z]+)_?(\d+)/,c,d={},e=this.geometry,f=0,g=e.morphTargets.length;fh.end&&(h.end=f);c||(c=k)}}for(k in d)h=d[k],this.createAnimation(k,h.start,h.end,a);this.firstAnimation=c};
+THREE.MorphBlendMesh.prototype.setAnimationDirectionForward=function(a){if(a=this.animationsMap[a])a.direction=1,a.directionBackwards=!1};THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward=function(a){if(a=this.animationsMap[a])a.direction=-1,a.directionBackwards=!0};THREE.MorphBlendMesh.prototype.setAnimationFPS=function(a,b){var c=this.animationsMap[a];c&&(c.fps=b,c.duration=(c.end-c.start)/c.fps)};
+THREE.MorphBlendMesh.prototype.setAnimationDuration=function(a,b){var c=this.animationsMap[a];c&&(c.duration=b,c.fps=(c.end-c.start)/c.duration)};THREE.MorphBlendMesh.prototype.setAnimationWeight=function(a,b){var c=this.animationsMap[a];c&&(c.weight=b)};THREE.MorphBlendMesh.prototype.setAnimationTime=function(a,b){var c=this.animationsMap[a];c&&(c.time=b)};THREE.MorphBlendMesh.prototype.getAnimationTime=function(a){var b=0;if(a=this.animationsMap[a])b=a.time;return b};
+THREE.MorphBlendMesh.prototype.getAnimationDuration=function(a){var b=-1;if(a=this.animationsMap[a])b=a.duration;return b};THREE.MorphBlendMesh.prototype.playAnimation=function(a){var b=this.animationsMap[a];b?(b.time=0,b.active=!0):console.warn("animation["+a+"] undefined")};THREE.MorphBlendMesh.prototype.stopAnimation=function(a){if(a=this.animationsMap[a])a.active=!1};
+THREE.MorphBlendMesh.prototype.update=function(a){for(var b=0,c=this.animationsList.length;bd.duration||0>d.time)d.direction*=-1,d.time>d.duration&&(d.time=d.duration,d.directionBackwards=!0),0>d.time&&(d.time=0,d.directionBackwards=!1)}else d.time%=d.duration,0>d.time&&(d.time+=d.duration);var f=d.startFrame+THREE.Math.clamp(Math.floor(d.time/e),0,d.length-1),g=d.weight;
+f!==d.currentFrame&&(this.morphTargetInfluences[d.lastFrame]=0,this.morphTargetInfluences[d.currentFrame]=1*g,this.morphTargetInfluences[f]=0,d.lastFrame=d.currentFrame,d.currentFrame=f);e=d.time%e/e;d.directionBackwards&&(e=1-e);this.morphTargetInfluences[d.currentFrame]=e*g;this.morphTargetInfluences[d.lastFrame]=(1-e)*g}}};
diff --git a/plugins/Sidebar/media-globe/world.jpg b/plugins/Sidebar/media-globe/world.jpg
new file mode 100644
index 00000000..222bd939
Binary files /dev/null and b/plugins/Sidebar/media-globe/world.jpg differ
diff --git a/plugins/Sidebar/media/Class.coffee b/plugins/Sidebar/media/Class.coffee
new file mode 100644
index 00000000..d62ab25c
--- /dev/null
+++ b/plugins/Sidebar/media/Class.coffee
@@ -0,0 +1,23 @@
+class Class
+ trace: true
+
+ log: (args...) ->
+ return unless @trace
+ return if typeof console is 'undefined'
+ args.unshift("[#{@.constructor.name}]")
+ console.log(args...)
+ @
+
+ logStart: (name, args...) ->
+ return unless @trace
+ @logtimers or= {}
+ @logtimers[name] = +(new Date)
+ @log "#{name}", args..., "(started)" if args.length > 0
+ @
+
+ logEnd: (name, args...) ->
+ ms = +(new Date)-@logtimers[name]
+ @log "#{name}", args..., "(Done in #{ms}ms)"
+ @
+
+window.Class = Class
\ No newline at end of file
diff --git a/plugins/Sidebar/media/Scrollable.js b/plugins/Sidebar/media/Scrollable.js
new file mode 100644
index 00000000..9173849e
--- /dev/null
+++ b/plugins/Sidebar/media/Scrollable.js
@@ -0,0 +1,89 @@
+/* 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)
+ scroller.style.display = "none"
+ else
+ scroller.style.display = "block"
+ 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;
+ window.addEventListener('mousemove', scrollBarScroll)
+ }
+
+ function stopDrag(evt) {
+ scrollerBeingDragged = false;
+ window.removeEventListener('mousemove', scrollBarScroll)
+ }
+
+ function scrollBarScroll(evt) {
+ if (scrollerBeingDragged === true) {
+ var mouseDifferential = evt.pageY - normalizedPosition;
+ var scrollEquivalent = mouseDifferential * (scrollContentWrapper.scrollHeight / scrollContainer.offsetHeight);
+ scrollContentWrapper.scrollTop = contentPosition + scrollEquivalent;
+ }
+ }
+
+ function updateHeight() {
+ scrollerHeight = calculateScrollerHeight()-10;
+ 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
+ scrollerHeight = calculateScrollerHeight()-10;
+
+ if (scrollerHeight / scrollContainer.offsetHeight < 1){
+ // *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);
+
+ return updateHeight
+};
\ No newline at end of file
diff --git a/plugins/Sidebar/media/Scrollbable.css b/plugins/Sidebar/media/Scrollbable.css
new file mode 100644
index 00000000..7d69a5f3
--- /dev/null
+++ b/plugins/Sidebar/media/Scrollbable.css
@@ -0,0 +1,44 @@
+.scrollable {
+ overflow: hidden;
+}
+
+.scrollable.showScroll::after {
+ position: absolute;
+ content: '';
+ top: 5%;
+ right: 7px;
+ height: 90%;
+ width: 3px;
+ background: rgba(224, 224, 255, .3);
+}
+
+.scrollable .content-wrapper {
+ width: 100%;
+ height: 100%;
+ padding-right: 50%;
+ overflow-y: scroll;
+}
+.scroller {
+ margin-top: 5px;
+ z-index: 5;
+ cursor: pointer;
+ position: absolute;
+ width: 7px;
+ border-radius: 5px;
+ background: #151515;
+ top: 0px;
+ left: 395px;
+ -webkit-transition: top .08s;
+ -moz-transition: top .08s;
+ -ms-transition: top .08s;
+ -o-transition: top .08s;
+ transition: top .08s;
+}
+.content {
+ -webkit-touch-callout: none;
+ -webkit-user-select: none;
+ -khtml-user-select: none;
+ -moz-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+}
\ No newline at end of file
diff --git a/plugins/Sidebar/media/Sidebar.coffee b/plugins/Sidebar/media/Sidebar.coffee
new file mode 100644
index 00000000..869b426f
--- /dev/null
+++ b/plugins/Sidebar/media/Sidebar.coffee
@@ -0,0 +1,318 @@
+class Sidebar extends Class
+ constructor: ->
+ @tag = null
+ @container = null
+ @opened = false
+ @width = 410
+ @fixbutton = $(".fixbutton")
+ @fixbutton_addx = 0
+ @fixbutton_initx = 0
+ @fixbutton_targetx = 0
+ @frame = $("#inner-iframe")
+ @initFixbutton()
+ @dragStarted = 0
+ @globe = null
+
+ @original_set_site_info = wrapper.setSiteInfo # We going to override this, save the original
+
+ # Start in opened state for debugging
+ if false
+ @startDrag()
+ @moved()
+ @fixbutton_targetx = @fixbutton_initx - @width
+ @stopDrag()
+
+
+ initFixbutton: ->
+ # Detect dragging
+ @fixbutton.on "mousedown", (e) =>
+ e.preventDefault()
+
+ # Disable previous listeners
+ @fixbutton.off "click"
+ @fixbutton.off "mousemove"
+
+ # Make sure its not a click
+ @dragStarted = (+ new Date)
+ @fixbutton.one "mousemove", (e) =>
+ @fixbutton_addx = @fixbutton.offset().left-e.pageX
+ @startDrag()
+ @fixbutton.parent().on "click", (e) =>
+ @stopDrag()
+ @fixbutton_initx = @fixbutton.offset().left # Initial x position
+
+
+ # Start dragging the fixbutton
+ startDrag: ->
+ @log "startDrag"
+ @fixbutton_targetx = @fixbutton_initx # Fallback x position
+
+ @fixbutton.addClass("dragging")
+
+ # Fullscreen drag bg to capture mouse events over iframe
+ $("").appendTo(document.body)
+
+ # IE position wrap fix
+ if navigator.userAgent.indexOf('MSIE') != -1 or navigator.appVersion.indexOf('Trident/') > 0
+ @fixbutton.css("pointer-events", "none")
+
+ # Don't go to homepage
+ @fixbutton.one "click", (e) =>
+ @stopDrag()
+ @fixbutton.removeClass("dragging")
+ if Math.abs(@fixbutton.offset().left - @fixbutton_initx) > 5
+ # If moved more than some pixel the button then don't go to homepage
+ e.preventDefault()
+
+ # Animate drag
+ @fixbutton.parents().on "mousemove", @animDrag
+ @fixbutton.parents().on "mousemove" ,@waitMove
+
+ # Stop dragging listener
+ @fixbutton.parents().on "mouseup", (e) =>
+ e.preventDefault()
+ @stopDrag()
+
+
+ # Wait for moving the fixbutton
+ waitMove: (e) =>
+ if Math.abs(@fixbutton.offset().left - @fixbutton_targetx) > 10 and (+ new Date)-@dragStarted > 100
+ @moved()
+ @fixbutton.parents().off "mousemove" ,@waitMove
+
+ moved: ->
+ @log "Moved"
+ @createHtmltag()
+ $(document.body).css("perspective", "1000px").addClass("body-sidebar")
+ $(window).off "resize"
+ $(window).on "resize", =>
+ $(document.body).css "height", $(window).height()
+ @scrollable()
+ $(window).trigger "resize"
+
+ # Override setsiteinfo to catch changes
+ wrapper.setSiteInfo = (site_info) =>
+ @setSiteInfo(site_info)
+ @original_set_site_info.apply(wrapper, arguments)
+
+ setSiteInfo: (site_info) ->
+ @updateHtmlTag()
+ @displayGlobe()
+
+
+ # Create the sidebar html tag
+ createHtmltag: ->
+ if not @container
+ @container = $("""
+
+ """)
+ @container.appendTo(document.body)
+ @tag = @container.find(".sidebar")
+ @updateHtmlTag()
+ @scrollable = window.initScrollable()
+
+
+ updateHtmlTag: ->
+ wrapper.ws.cmd "sidebarGetHtmlTag", {}, (res) =>
+ if @tag.find(".content").children().length == 0 # First update
+ @log "Creating content"
+ morphdom(@tag.find(".content")[0], ''+res+'
')
+ @scrollable()
+
+ else # Not first update, patch the html to keep unchanged dom elements
+ @log "Patching content"
+ morphdom @tag.find(".content")[0], ''+res+'
', {
+ onBeforeMorphEl: (from_el, to_el) -> # Ignore globe loaded state
+ if from_el.className == "globe"
+ return false
+ else
+ return true
+ }
+
+
+ animDrag: (e) =>
+ mousex = e.pageX
+
+ overdrag = @fixbutton_initx-@width-mousex
+ if overdrag > 0 # Overdragged
+ overdrag_percent = 1+overdrag/300
+ mousex = (e.pageX + (@fixbutton_initx-@width)*overdrag_percent)/(1+overdrag_percent)
+ targetx = @fixbutton_initx-mousex-@fixbutton_addx
+
+ @fixbutton.offset
+ left: mousex+@fixbutton_addx
+
+ if @tag
+ @tag.css("transform", "translateX(#{0-targetx}px)")
+
+ # Check if opened
+ if (not @opened and targetx > @width/3) or (@opened and targetx > @width*0.9)
+ @fixbutton_targetx = @fixbutton_initx - @width # Make it opened
+ else
+ @fixbutton_targetx = @fixbutton_initx
+
+
+ # Stop dragging the fixbutton
+ stopDrag: ->
+ @fixbutton.parents().off "mousemove"
+ @fixbutton.off "mousemove"
+ @fixbutton.css("pointer-events", "")
+ $(".drag-bg").remove()
+ if not @fixbutton.hasClass("dragging")
+ return
+ @fixbutton.removeClass("dragging")
+
+ # Move back to initial position
+ if @fixbutton_targetx != @fixbutton.offset().left
+ # Animate fixbutton
+ @fixbutton.stop().animate {"left": @fixbutton_targetx}, 500, "easeOutBack", =>
+ # Switch back to auto align
+ if @fixbutton_targetx == @fixbutton_initx # Closed
+ @fixbutton.css("left", "auto")
+ else # Opened
+ @fixbutton.css("left", @fixbutton_targetx)
+
+ $(".fixbutton-bg").trigger "mouseout" # Switch fixbutton back to normal status
+
+ # Animate sidebar and iframe
+ if @fixbutton_targetx == @fixbutton_initx
+ # Closed
+ targetx = 0
+ @opened = false
+ else
+ # Opened
+ targetx = @width
+ if not @opened
+ @onOpened()
+ @opened = true
+
+ # Revent sidebar transitions
+ @tag.css("transition", "0.4s ease-out")
+ @tag.css("transform", "translateX(-#{targetx}px)").one transitionEnd, =>
+ @tag.css("transition", "")
+ if not @opened
+ @container.remove()
+ @container = null
+ @tag.remove()
+ @tag = null
+
+ # Revert body transformations
+ @log "stopdrag", "opened:", @opened
+ if not @opened
+ @onClosed()
+
+
+ onOpened: ->
+ @log "Opened"
+ @scrollable()
+
+ # Re-calculate height when site admin opened or closed
+ @tag.find("#checkbox-owned").off("click").on "click", =>
+ setTimeout (=>
+ @scrollable()
+ ), 300
+
+ # Site limit button
+ @tag.find("#button-sitelimit").on "click", =>
+ wrapper.ws.cmd "siteSetLimit", $("#input-sitelimit").val(), =>
+ wrapper.notifications.add "done-sitelimit", "done", "Site storage limit modified!", 5000
+ @updateHtmlTag()
+ return false
+
+ # Change identity button
+ @tag.find("#button-identity").on "click", =>
+ wrapper.ws.cmd "certSelect"
+ return false
+
+ # Owned checkbox
+ @tag.find("#checkbox-owned").on "click", =>
+ wrapper.ws.cmd "siteSetOwned", [@tag.find("#checkbox-owned").is(":checked")]
+
+ # Save settings
+ @tag.find("#button-settings").on "click", =>
+ wrapper.ws.cmd "fileGet", "content.json", (res) =>
+ data = JSON.parse(res)
+ data["title"] = $("#settings-title").val()
+ data["description"] = $("#settings-description").val()
+ json_raw = unescape(encodeURIComponent(JSON.stringify(data, undefined, '\t')))
+ wrapper.ws.cmd "fileWrite", ["content.json", btoa(json_raw)], (res) =>
+ if res != "ok" # fileWrite failed
+ wrapper.notifications.add "file-write", "error", "File write error: #{res}"
+ else
+ wrapper.notifications.add "file-write", "done", "Site settings saved!", 5000
+ @updateHtmlTag()
+ return false
+
+ # Sign content.json
+ @tag.find("#button-sign").on "click", =>
+ inner_path = @tag.find("#select-contents").val()
+
+ if wrapper.site_info.privatekey
+ # Privatekey stored in users.json
+ wrapper.ws.cmd "siteSign", ["stored", inner_path], (res) =>
+ wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
+
+ else
+ # Ask the user for privatekey
+ wrapper.displayPrompt "Enter your private key:", "password", "Sign", (privatekey) => # Prompt the private key
+ wrapper.ws.cmd "siteSign", [privatekey, inner_path], (res) =>
+ if res == "ok"
+ wrapper.notifications.add "sign", "done", "#{inner_path} Signed!", 5000
+
+ return false
+
+ # Publish content.json
+ @tag.find("#button-publish").on "click", =>
+ inner_path = @tag.find("#select-contents").val()
+ @tag.find("#button-publish").addClass "loading"
+ wrapper.ws.cmd "sitePublish", {"inner_path": inner_path, "sign": false}, =>
+ @tag.find("#button-publish").removeClass "loading"
+
+ @loadGlobe()
+
+
+ onClosed: ->
+ $(window).off "resize"
+ $(document.body).css("transition", "0.6s ease-in-out").removeClass("body-sidebar").on transitionEnd, (e) =>
+ if e.target == document.body
+ $(document.body).css("height", "auto").css("perspective", "").css("transition", "").off transitionEnd
+ @unloadGlobe()
+
+ # We dont need site info anymore
+ wrapper.setSiteInfo = @original_set_site_info
+
+
+ loadGlobe: =>
+ if @tag.find(".globe").hasClass("loading")
+ setTimeout (=>
+ if typeof(DAT) == "undefined" # Globe script not loaded, do it first
+ $.getScript("/uimedia/globe/all.js", @displayGlobe)
+ else
+ @displayGlobe()
+ ), 600
+
+
+ displayGlobe: =>
+ wrapper.ws.cmd "sidebarGetPeers", [], (globe_data) =>
+ if @globe
+ @globe.scene.remove(@globe.points)
+ @globe.addData( globe_data, {format: 'magnitude', name: "hello", animated: false} )
+ @globe.createPoints()
+ else
+ @globe = new DAT.Globe( @tag.find(".globe")[0], {"imgDir": "/uimedia/globe/"} )
+ @globe.addData( globe_data, {format: 'magnitude', name: "hello"} )
+ @globe.createPoints()
+ @globe.animate()
+ @tag.find(".globe").removeClass("loading")
+
+
+ unloadGlobe: =>
+ if not @globe
+ return false
+ @globe.unload()
+ @globe = null
+
+
+window.sidebar = new Sidebar()
+window.transitionEnd = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend'
diff --git a/plugins/Sidebar/media/Sidebar.css b/plugins/Sidebar/media/Sidebar.css
new file mode 100644
index 00000000..7710305a
--- /dev/null
+++ b/plugins/Sidebar/media/Sidebar.css
@@ -0,0 +1,96 @@
+.drag-bg { width: 100%; height: 100%; position: absolute; }
+.fixbutton.dragging { cursor: -webkit-grabbing; }
+.fixbutton-bg:active { cursor: -webkit-grabbing; }
+
+
+.body-sidebar { background-color: #666 !important; }
+#inner-iframe { transition: 0.3s ease-in-out; transform-origin: left; backface-visibility: hidden; outline: 1px solid transparent }
+.body-sidebar iframe { transform: rotateY(5deg); opacity: 0.8; pointer-events: none } /* translateX(-200px) scale(0.95)*/
+
+/* SIDEBAR */
+
+.sidebar-container { width: 100%; height: 100%; overflow: hidden; position: absolute; }
+.sidebar { background-color: #212121; position: absolute; right: -1200px; height: 100%; width: 1200px; } /*box-shadow: inset 0px 0px 10px #000*/
+.sidebar .content { margin: 30px; font-family: "Segoe UI Light", "Segoe UI", "Helvetica Neue"; color: white; width: 375px; height: 300px; font-weight: 200 }
+.sidebar h1, .sidebar h2 { font-weight: lighter; }
+.sidebar .button { margin: 0px; display: inline-block; }
+
+
+/* FIELDS */
+
+.sidebar .fields { padding: 0px; list-style-type: none; width: 355px; }
+.sidebar .fields > li, .sidebar .fields .settings-owned > li { margin-bottom: 30px }
+.sidebar .fields > li:after, .sidebar .fields .settings-owned > li:after { clear: both; content: ''; display: block }
+.sidebar .fields label { font-family: Consolas, monospace; text-transform: uppercase; font-size: 13px; color: #ACACAC; display: block; margin-bottom: 10px; }
+.sidebar .fields label small { font-weight: normal; color: white; text-transform: none; }
+.sidebar .fields .text { background-color: black; border: 0px; padding: 10px; color: white; border-radius: 3px; width: 250px; font-family: Consolas, monospace; }
+.sidebar .fields .text.long { width: 330px; font-size: 72%; }
+.sidebar .fields .disabled { color: #AAA; background-color: #3B3B3B; }
+.sidebar .fields .text-num { width: 30px; text-align: right; padding-right: 30px; }
+.sidebar .fields .text-post { color: white; font-family: Consolas, monospace; display: inline-block; font-size: 13px; margin-left: -25px; width: 25px; }
+
+/* Select */
+.sidebar .fields select {
+ width: 225px; background-color: #3B3B3B; color: white; font-family: Consolas, monospace; appearance: none;
+ padding: 5px; padding-right: 25px; border: 0px; border-radius: 3px; height: 35px; vertical-align: 1px; box-shadow: 0px 1px 2px rgba(0,0,0,0.5);
+}
+.sidebar .fields .select-down { margin-left: -39px; width: 34px; display: inline-block; transform: rotateZ(90deg); height: 35px; vertical-align: -8px; pointer-events: none; font-weight: bold }
+
+/* Checkbox */
+.sidebar .fields .checkbox { width: 50px; height: 24px; position: relative; z-index: 999; opacity: 0; }
+.sidebar .fields .checkbox-skin { background-color: #CCC; width: 50px; height: 24px; border-radius: 15px; transition: all 0.3s ease-in-out; display: inline-block; margin-left: -59px; }
+.sidebar .fields .checkbox-skin:before {
+ content: ""; position: relative; width: 20px; background-color: white; height: 20px; display: block; border-radius: 100%; margin-top: 2px; margin-left: 2px;
+ transition: all 0.5s cubic-bezier(0.785, 0.135, 0.15, 0.86);
+}
+.sidebar .fields .checkbox:checked ~ .checkbox-skin:before { margin-left: 27px; }
+.sidebar .fields .checkbox:checked ~ .checkbox-skin { background-color: #2ECC71; }
+
+/* Fake input */
+.sidebar .input { font-size: 13px; width: 250px; display: inline-block; overflow: hidden; text-overflow: ellipsis; vertical-align: top }
+
+/* GRAPH */
+
+.graph { padding: 0px; list-style-type: none; width: 351px; background-color: black; height: 10px; border-radius: 8px; overflow: hidden; position: relative;}
+.graph li { height: 100%; position: absolute; }
+.graph-stacked li { position: static; float: left; }
+
+.graph-legend { padding: 0px; list-style-type: none; margin-top: 13px; font-family: Consolas, "Andale Mono", monospace; font-size: 13px; text-transform: capitalize; }
+.sidebar .graph-legend li { margin: 0px; margin-top: 5px; margin-left: 0px; width: 160px; float: left; position: relative; }
+.sidebar .graph-legend li:nth-child(odd) { margin-right: 29px }
+.graph-legend span { position: absolute; }
+.graph-legend b { text-align: right; display: inline-block; width: 50px; float: right; font-weight: normal; }
+.graph-legend li:before { content: '\2022'; font-size: 23px; line-height: 0px; vertical-align: -3px; margin-right: 5px; }
+
+/* COLORS */
+
+.back-green { background-color: #2ECC71 }
+.color-green:before { color: #2ECC71 }
+.back-blue { background-color: #3BAFDA }
+.color-blue:before { color: #3BAFDA }
+.back-darkblue { background-color: #2196F3 }
+.color-darkblue:before { color: #2196F3 }
+.back-purple { background-color: #B10DC9 }
+.color-purple:before { color: #B10DC9 }
+.back-yellow { background-color: #FFDC00 }
+.color-yellow:before { color: #FFDC00 }
+.back-orange { background-color: #FF9800 }
+.color-orange:before { color: #FF9800 }
+.back-gray { background-color: #ECF0F1 }
+.color-gray:before { color: #ECF0F1 }
+.back-black { background-color: #34495E }
+.color-black:before { color: #34495E }
+.back-white { background-color: #EEE }
+.color-white:before { color: #EEE }
+
+
+/* Settings owned */
+
+.owned-title { float: left }
+#checkbox-owned { margin-bottom: 25px; margin-top: 26px; margin-left: 11px; }
+#checkbox-owned ~ .settings-owned { opacity: 0; max-height: 0px; transition: all 0.3s linear; overflow: hidden }
+#checkbox-owned:checked ~ .settings-owned { opacity: 1; max-height: 400px }
+
+/* Globe */
+.globe { width: 360px; height: 360px }
+.globe.loading { background: url(/uimedia/img/loading-circle.gif) center center no-repeat }
\ No newline at end of file
diff --git a/plugins/Sidebar/media/all.css b/plugins/Sidebar/media/all.css
new file mode 100644
index 00000000..76b8acdd
--- /dev/null
+++ b/plugins/Sidebar/media/all.css
@@ -0,0 +1,150 @@
+
+
+/* ---- plugins/Sidebar/media/Scrollbable.css ---- */
+
+
+.scrollable {
+ overflow: hidden;
+}
+
+.scrollable.showScroll::after {
+ position: absolute;
+ content: '';
+ top: 5%;
+ right: 7px;
+ height: 90%;
+ width: 3px;
+ background: rgba(224, 224, 255, .3);
+}
+
+.scrollable .content-wrapper {
+ width: 100%;
+ height: 100%;
+ padding-right: 50%;
+ overflow-y: scroll;
+}
+.scroller {
+ margin-top: 5px;
+ z-index: 5;
+ cursor: pointer;
+ position: absolute;
+ width: 7px;
+ -webkit-border-radius: 5px; -moz-border-radius: 5px; -o-border-radius: 5px; -ms-border-radius: 5px; border-radius: 5px ;
+ background: #151515;
+ top: 0px;
+ left: 395px;
+ -webkit-transition: top .08s;
+ -moz-transition: top .08s;
+ -ms-transition: top .08s;
+ -o-transition: top .08s;
+ -webkit-transition: top .08s; -moz-transition: top .08s; -o-transition: top .08s; -ms-transition: top .08s; transition: top .08s ;
+}
+.content {
+ -webkit-touch-callout: none;
+ -webkit-user-select: none;
+ -khtml-user-select: none;
+ -moz-user-select: none;
+ -ms-user-select: none;
+ user-select: none;
+}
+
+
+/* ---- plugins/Sidebar/media/Sidebar.css ---- */
+
+
+.drag-bg { width: 100%; height: 100%; position: absolute; }
+.fixbutton.dragging { cursor: -webkit-grabbing; }
+.fixbutton-bg:active { cursor: -webkit-grabbing; }
+
+
+.body-sidebar { background-color: #666 !important; }
+#inner-iframe { -webkit-transition: 0.3s ease-in-out; -moz-transition: 0.3s ease-in-out; -o-transition: 0.3s ease-in-out; -ms-transition: 0.3s ease-in-out; transition: 0.3s ease-in-out ; transform-origin: left; backface-visibility: hidden; outline: 1px solid transparent }
+.body-sidebar iframe { -webkit-transform: rotateY(5deg); -moz-transform: rotateY(5deg); -o-transform: rotateY(5deg); -ms-transform: rotateY(5deg); transform: rotateY(5deg) ; opacity: 0.8; pointer-events: none } /* translateX(-200px) scale(0.95)*/
+
+/* SIDEBAR */
+
+.sidebar-container { width: 100%; height: 100%; overflow: hidden; position: absolute; }
+.sidebar { background-color: #212121; position: absolute; right: -1200px; height: 100%; width: 1200px; } /*box-shadow: inset 0px 0px 10px #000*/
+.sidebar .content { margin: 30px; font-family: "Segoe UI Light", "Segoe UI", "Helvetica Neue"; color: white; width: 375px; height: 300px; font-weight: 200 }
+.sidebar h1, .sidebar h2 { font-weight: lighter; }
+.sidebar .button { margin: 0px; display: inline-block; }
+
+
+/* FIELDS */
+
+.sidebar .fields { padding: 0px; list-style-type: none; width: 355px; }
+.sidebar .fields > li, .sidebar .fields .settings-owned > li { margin-bottom: 30px }
+.sidebar .fields > li:after, .sidebar .fields .settings-owned > li:after { clear: both; content: ''; display: block }
+.sidebar .fields label { font-family: Consolas, monospace; text-transform: uppercase; font-size: 13px; color: #ACACAC; display: block; margin-bottom: 10px; }
+.sidebar .fields label small { font-weight: normal; color: white; text-transform: none; }
+.sidebar .fields .text { background-color: black; border: 0px; padding: 10px; color: white; -webkit-border-radius: 3px; -moz-border-radius: 3px; -o-border-radius: 3px; -ms-border-radius: 3px; border-radius: 3px ; width: 250px; font-family: Consolas, monospace; }
+.sidebar .fields .text.long { width: 330px; font-size: 72%; }
+.sidebar .fields .disabled { color: #AAA; background-color: #3B3B3B; }
+.sidebar .fields .text-num { width: 30px; text-align: right; padding-right: 30px; }
+.sidebar .fields .text-post { color: white; font-family: Consolas, monospace; display: inline-block; font-size: 13px; margin-left: -25px; width: 25px; }
+
+/* Select */
+.sidebar .fields select {
+ width: 225px; background-color: #3B3B3B; color: white; font-family: Consolas, monospace; -webkit-appearance: none; -moz-appearance: none; -o-appearance: none; -ms-appearance: none; appearance: none ;
+ padding: 5px; padding-right: 25px; border: 0px; -webkit-border-radius: 3px; -moz-border-radius: 3px; -o-border-radius: 3px; -ms-border-radius: 3px; border-radius: 3px ; height: 35px; vertical-align: 1px; -webkit-box-shadow: 0px 1px 2px rgba(0,0,0,0.5); -moz-box-shadow: 0px 1px 2px rgba(0,0,0,0.5); -o-box-shadow: 0px 1px 2px rgba(0,0,0,0.5); -ms-box-shadow: 0px 1px 2px rgba(0,0,0,0.5); box-shadow: 0px 1px 2px rgba(0,0,0,0.5) ;
+}
+.sidebar .fields .select-down { margin-left: -39px; width: 34px; display: inline-block; -webkit-transform: rotateZ(90deg); -moz-transform: rotateZ(90deg); -o-transform: rotateZ(90deg); -ms-transform: rotateZ(90deg); transform: rotateZ(90deg) ; height: 35px; vertical-align: -8px; pointer-events: none; font-weight: bold }
+
+/* Checkbox */
+.sidebar .fields .checkbox { width: 50px; height: 24px; position: relative; z-index: 999; opacity: 0; }
+.sidebar .fields .checkbox-skin { background-color: #CCC; width: 50px; height: 24px; -webkit-border-radius: 15px; -moz-border-radius: 15px; -o-border-radius: 15px; -ms-border-radius: 15px; border-radius: 15px ; -webkit-transition: all 0.3s ease-in-out; -moz-transition: all 0.3s ease-in-out; -o-transition: all 0.3s ease-in-out; -ms-transition: all 0.3s ease-in-out; transition: all 0.3s ease-in-out ; display: inline-block; margin-left: -59px; }
+.sidebar .fields .checkbox-skin:before {
+ content: ""; position: relative; width: 20px; background-color: white; height: 20px; display: block; -webkit-border-radius: 100%; -moz-border-radius: 100%; -o-border-radius: 100%; -ms-border-radius: 100%; border-radius: 100% ; margin-top: 2px; margin-left: 2px;
+ -webkit-transition: all 0.5s cubic-bezier(0.785, 0.135, 0.15, 0.86); -moz-transition: all 0.5s cubic-bezier(0.785, 0.135, 0.15, 0.86); -o-transition: all 0.5s cubic-bezier(0.785, 0.135, 0.15, 0.86); -ms-transition: all 0.5s cubic-bezier(0.785, 0.135, 0.15, 0.86); transition: all 0.5s cubic-bezier(0.785, 0.135, 0.15, 0.86) ;
+}
+.sidebar .fields .checkbox:checked ~ .checkbox-skin:before { margin-left: 27px; }
+.sidebar .fields .checkbox:checked ~ .checkbox-skin { background-color: #2ECC71; }
+
+/* Fake input */
+.sidebar .input { font-size: 13px; width: 250px; display: inline-block; overflow: hidden; text-overflow: ellipsis; vertical-align: top }
+
+/* GRAPH */
+
+.graph { padding: 0px; list-style-type: none; width: 351px; background-color: black; height: 10px; -webkit-border-radius: 8px; -moz-border-radius: 8px; -o-border-radius: 8px; -ms-border-radius: 8px; border-radius: 8px ; overflow: hidden; position: relative;}
+.graph li { height: 100%; position: absolute; }
+.graph-stacked li { position: static; float: left; }
+
+.graph-legend { padding: 0px; list-style-type: none; margin-top: 13px; font-family: Consolas, "Andale Mono", monospace; font-size: 13px; text-transform: capitalize; }
+.sidebar .graph-legend li { margin: 0px; margin-top: 5px; margin-left: 0px; width: 160px; float: left; position: relative; }
+.sidebar .graph-legend li:nth-child(odd) { margin-right: 29px }
+.graph-legend span { position: absolute; }
+.graph-legend b { text-align: right; display: inline-block; width: 50px; float: right; font-weight: normal; }
+.graph-legend li:before { content: '\2022'; font-size: 23px; line-height: 0px; vertical-align: -3px; margin-right: 5px; }
+
+/* COLORS */
+
+.back-green { background-color: #2ECC71 }
+.color-green:before { color: #2ECC71 }
+.back-blue { background-color: #3BAFDA }
+.color-blue:before { color: #3BAFDA }
+.back-darkblue { background-color: #2196F3 }
+.color-darkblue:before { color: #2196F3 }
+.back-purple { background-color: #B10DC9 }
+.color-purple:before { color: #B10DC9 }
+.back-yellow { background-color: #FFDC00 }
+.color-yellow:before { color: #FFDC00 }
+.back-orange { background-color: #FF9800 }
+.color-orange:before { color: #FF9800 }
+.back-gray { background-color: #ECF0F1 }
+.color-gray:before { color: #ECF0F1 }
+.back-black { background-color: #34495E }
+.color-black:before { color: #34495E }
+.back-white { background-color: #EEE }
+.color-white:before { color: #EEE }
+
+
+/* Settings owned */
+
+.owned-title { float: left }
+#checkbox-owned { margin-bottom: 25px; margin-top: 26px; margin-left: 11px; }
+#checkbox-owned ~ .settings-owned { opacity: 0; max-height: 0px; -webkit-transition: all 0.3s linear; -moz-transition: all 0.3s linear; -o-transition: all 0.3s linear; -ms-transition: all 0.3s linear; transition: all 0.3s linear ; overflow: hidden }
+#checkbox-owned:checked ~ .settings-owned { opacity: 1; max-height: 400px }
+
+/* Globe */
+.globe { width: 360px; height: 360px }
+.globe.loading { background: url(/uimedia/img/loading-circle.gif) center center no-repeat }
\ No newline at end of file
diff --git a/plugins/Sidebar/media/all.js b/plugins/Sidebar/media/all.js
new file mode 100644
index 00000000..73b73c8b
--- /dev/null
+++ b/plugins/Sidebar/media/all.js
@@ -0,0 +1,882 @@
+
+
+/* ---- plugins/Sidebar/media/Class.coffee ---- */
+
+
+(function() {
+ var Class,
+ __slice = [].slice;
+
+ Class = (function() {
+ function Class() {}
+
+ Class.prototype.trace = true;
+
+ Class.prototype.log = function() {
+ var args;
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ if (!this.trace) {
+ return;
+ }
+ if (typeof console === 'undefined') {
+ return;
+ }
+ args.unshift("[" + this.constructor.name + "]");
+ console.log.apply(console, args);
+ return this;
+ };
+
+ Class.prototype.logStart = function() {
+ var args, name;
+ name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+ if (!this.trace) {
+ return;
+ }
+ this.logtimers || (this.logtimers = {});
+ this.logtimers[name] = +(new Date);
+ if (args.length > 0) {
+ this.log.apply(this, ["" + name].concat(__slice.call(args), ["(started)"]));
+ }
+ return this;
+ };
+
+ Class.prototype.logEnd = function() {
+ var args, ms, name;
+ name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+ ms = +(new Date) - this.logtimers[name];
+ this.log.apply(this, ["" + name].concat(__slice.call(args), ["(Done in " + ms + "ms)"]));
+ return this;
+ };
+
+ return Class;
+
+ })();
+
+ window.Class = Class;
+
+}).call(this);
+
+
+/* ---- plugins/Sidebar/media/Scrollable.js ---- */
+
+
+/* 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)
+ scroller.style.display = "none"
+ else
+ scroller.style.display = "block"
+ 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;
+ window.addEventListener('mousemove', scrollBarScroll)
+ }
+
+ function stopDrag(evt) {
+ scrollerBeingDragged = false;
+ window.removeEventListener('mousemove', scrollBarScroll)
+ }
+
+ function scrollBarScroll(evt) {
+ if (scrollerBeingDragged === true) {
+ var mouseDifferential = evt.pageY - normalizedPosition;
+ var scrollEquivalent = mouseDifferential * (scrollContentWrapper.scrollHeight / scrollContainer.offsetHeight);
+ scrollContentWrapper.scrollTop = contentPosition + scrollEquivalent;
+ }
+ }
+
+ function updateHeight() {
+ scrollerHeight = calculateScrollerHeight()-10;
+ 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
+ scrollerHeight = calculateScrollerHeight()-10;
+
+ if (scrollerHeight / scrollContainer.offsetHeight < 1){
+ // *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);
+
+ return updateHeight
+};
+
+
+/* ---- plugins/Sidebar/media/Sidebar.coffee ---- */
+
+
+(function() {
+ var Sidebar,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __extends = 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;
+
+ Sidebar = (function(_super) {
+ __extends(Sidebar, _super);
+
+ function Sidebar() {
+ 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.waitMove = __bind(this.waitMove, this);
+ this.tag = null;
+ this.container = null;
+ this.opened = false;
+ this.width = 410;
+ this.fixbutton = $(".fixbutton");
+ this.fixbutton_addx = 0;
+ this.fixbutton_initx = 0;
+ this.fixbutton_targetx = 0;
+ this.frame = $("#inner-iframe");
+ this.initFixbutton();
+ this.dragStarted = 0;
+ this.globe = null;
+ this.original_set_site_info = wrapper.setSiteInfo;
+ if (false) {
+ this.startDrag();
+ this.moved();
+ this.fixbutton_targetx = this.fixbutton_initx - this.width;
+ this.stopDrag();
+ }
+ }
+
+ Sidebar.prototype.initFixbutton = function() {
+ this.fixbutton.on("mousedown", (function(_this) {
+ return function(e) {
+ e.preventDefault();
+ _this.fixbutton.off("click");
+ _this.fixbutton.off("mousemove");
+ _this.dragStarted = +(new Date);
+ return _this.fixbutton.one("mousemove", function(e) {
+ _this.fixbutton_addx = _this.fixbutton.offset().left - e.pageX;
+ return _this.startDrag();
+ });
+ };
+ })(this));
+ this.fixbutton.parent().on("click", (function(_this) {
+ return function(e) {
+ return _this.stopDrag();
+ };
+ })(this));
+ return this.fixbutton_initx = this.fixbutton.offset().left;
+ };
+
+ Sidebar.prototype.startDrag = function() {
+ this.log("startDrag");
+ this.fixbutton_targetx = this.fixbutton_initx;
+ this.fixbutton.addClass("dragging");
+ $("").appendTo(document.body);
+ 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) {
+ _this.stopDrag();
+ _this.fixbutton.removeClass("dragging");
+ if (Math.abs(_this.fixbutton.offset().left - _this.fixbutton_initx) > 5) {
+ return e.preventDefault();
+ }
+ };
+ })(this));
+ this.fixbutton.parents().on("mousemove", this.animDrag);
+ this.fixbutton.parents().on("mousemove", this.waitMove);
+ return this.fixbutton.parents().on("mouseup", (function(_this) {
+ return function(e) {
+ e.preventDefault();
+ return _this.stopDrag();
+ };
+ })(this));
+ };
+
+ Sidebar.prototype.waitMove = function(e) {
+ if (Math.abs(this.fixbutton.offset().left - this.fixbutton_targetx) > 10 && (+(new Date)) - this.dragStarted > 100) {
+ this.moved();
+ return this.fixbutton.parents().off("mousemove", this.waitMove);
+ }
+ };
+
+ Sidebar.prototype.moved = function() {
+ this.log("Moved");
+ this.createHtmltag();
+ $(document.body).css("perspective", "1000px").addClass("body-sidebar");
+ $(window).off("resize");
+ $(window).on("resize", (function(_this) {
+ return function() {
+ $(document.body).css("height", $(window).height());
+ return _this.scrollable();
+ };
+ })(this));
+ $(window).trigger("resize");
+ return wrapper.setSiteInfo = (function(_this) {
+ return function(site_info) {
+ _this.setSiteInfo(site_info);
+ return _this.original_set_site_info.apply(wrapper, arguments);
+ };
+ })(this);
+ };
+
+ Sidebar.prototype.setSiteInfo = function(site_info) {
+ this.updateHtmlTag();
+ return this.displayGlobe();
+ };
+
+ Sidebar.prototype.createHtmltag = function() {
+ if (!this.container) {
+ this.container = $("");
+ this.container.appendTo(document.body);
+ this.tag = this.container.find(".sidebar");
+ this.updateHtmlTag();
+ return this.scrollable = window.initScrollable();
+ }
+ };
+
+ Sidebar.prototype.updateHtmlTag = function() {
+ return wrapper.ws.cmd("sidebarGetHtmlTag", {}, (function(_this) {
+ return function(res) {
+ if (_this.tag.find(".content").children().length === 0) {
+ _this.log("Creating content");
+ morphdom(_this.tag.find(".content")[0], '' + res + '
');
+ return _this.scrollable();
+ } else {
+ _this.log("Patching content");
+ return morphdom(_this.tag.find(".content")[0], '' + res + '
', {
+ onBeforeMorphEl: function(from_el, to_el) {
+ if (from_el.className === "globe") {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ });
+ }
+ };
+ })(this));
+ };
+
+ Sidebar.prototype.animDrag = function(e) {
+ var mousex, overdrag, overdrag_percent, targetx;
+ mousex = e.pageX;
+ overdrag = this.fixbutton_initx - this.width - mousex;
+ if (overdrag > 0) {
+ overdrag_percent = 1 + overdrag / 300;
+ mousex = (e.pageX + (this.fixbutton_initx - this.width) * overdrag_percent) / (1 + overdrag_percent);
+ }
+ targetx = this.fixbutton_initx - mousex - this.fixbutton_addx;
+ this.fixbutton.offset({
+ left: mousex + this.fixbutton_addx
+ });
+ if (this.tag) {
+ this.tag.css("transform", "translateX(" + (0 - targetx) + "px)");
+ }
+ if ((!this.opened && targetx > this.width / 3) || (this.opened && targetx > this.width * 0.9)) {
+ return this.fixbutton_targetx = this.fixbutton_initx - this.width;
+ } else {
+ return this.fixbutton_targetx = this.fixbutton_initx;
+ }
+ };
+
+ Sidebar.prototype.stopDrag = function() {
+ var targetx;
+ this.fixbutton.parents().off("mousemove");
+ this.fixbutton.off("mousemove");
+ this.fixbutton.css("pointer-events", "");
+ $(".drag-bg").remove();
+ if (!this.fixbutton.hasClass("dragging")) {
+ return;
+ }
+ this.fixbutton.removeClass("dragging");
+ if (this.fixbutton_targetx !== this.fixbutton.offset().left) {
+ this.fixbutton.stop().animate({
+ "left": this.fixbutton_targetx
+ }, 500, "easeOutBack", (function(_this) {
+ return function() {
+ if (_this.fixbutton_targetx === _this.fixbutton_initx) {
+ _this.fixbutton.css("left", "auto");
+ } else {
+ _this.fixbutton.css("left", _this.fixbutton_targetx);
+ }
+ return $(".fixbutton-bg").trigger("mouseout");
+ };
+ })(this));
+ if (this.fixbutton_targetx === this.fixbutton_initx) {
+ targetx = 0;
+ this.opened = false;
+ } else {
+ targetx = this.width;
+ if (!this.opened) {
+ this.onOpened();
+ }
+ this.opened = true;
+ }
+ 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;
+ _this.tag.remove();
+ return _this.tag = null;
+ }
+ };
+ })(this));
+ this.log("stopdrag", "opened:", this.opened);
+ if (!this.opened) {
+ return this.onClosed();
+ }
+ }
+ };
+
+ Sidebar.prototype.onOpened = function() {
+ this.log("Opened");
+ this.scrollable();
+ this.tag.find("#checkbox-owned").off("click").on("click", (function(_this) {
+ return function() {
+ return setTimeout((function() {
+ return _this.scrollable();
+ }), 300);
+ };
+ })(this));
+ this.tag.find("#button-sitelimit").on("click", (function(_this) {
+ return function() {
+ wrapper.ws.cmd("siteSetLimit", $("#input-sitelimit").val(), function() {
+ wrapper.notifications.add("done-sitelimit", "done", "Site storage limit modified!", 5000);
+ return _this.updateHtmlTag();
+ });
+ return false;
+ };
+ })(this));
+ this.tag.find("#button-identity").on("click", (function(_this) {
+ return function() {
+ wrapper.ws.cmd("certSelect");
+ return false;
+ };
+ })(this));
+ this.tag.find("#checkbox-owned").on("click", (function(_this) {
+ return function() {
+ return wrapper.ws.cmd("siteSetOwned", [_this.tag.find("#checkbox-owned").is(":checked")]);
+ };
+ })(this));
+ this.tag.find("#button-settings").on("click", (function(_this) {
+ return function() {
+ wrapper.ws.cmd("fileGet", "content.json", function(res) {
+ 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')));
+ return wrapper.ws.cmd("fileWrite", ["content.json", btoa(json_raw)], function(res) {
+ if (res !== "ok") {
+ return wrapper.notifications.add("file-write", "error", "File write error: " + res);
+ } else {
+ wrapper.notifications.add("file-write", "done", "Site settings saved!", 5000);
+ return _this.updateHtmlTag();
+ }
+ });
+ });
+ return false;
+ };
+ })(this));
+ this.tag.find("#button-sign").on("click", (function(_this) {
+ return function() {
+ var inner_path;
+ inner_path = _this.tag.find("#select-contents").val();
+ if (wrapper.site_info.privatekey) {
+ wrapper.ws.cmd("siteSign", ["stored", inner_path], function(res) {
+ return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
+ });
+ } else {
+ wrapper.displayPrompt("Enter your private key:", "password", "Sign", function(privatekey) {
+ return wrapper.ws.cmd("siteSign", [privatekey, inner_path], function(res) {
+ if (res === "ok") {
+ return wrapper.notifications.add("sign", "done", inner_path + " Signed!", 5000);
+ }
+ });
+ });
+ }
+ return false;
+ };
+ })(this));
+ this.tag.find("#button-publish").on("click", (function(_this) {
+ return function() {
+ var inner_path;
+ inner_path = _this.tag.find("#select-contents").val();
+ _this.tag.find("#button-publish").addClass("loading");
+ return wrapper.ws.cmd("sitePublish", {
+ "inner_path": inner_path,
+ "sign": false
+ }, function() {
+ return _this.tag.find("#button-publish").removeClass("loading");
+ });
+ };
+ })(this));
+ return this.loadGlobe();
+ };
+
+ Sidebar.prototype.onClosed = function() {
+ $(window).off("resize");
+ $(document.body).css("transition", "0.6s ease-in-out").removeClass("body-sidebar").on(transitionEnd, (function(_this) {
+ return function(e) {
+ if (e.target === document.body) {
+ $(document.body).css("height", "auto").css("perspective", "").css("transition", "").off(transitionEnd);
+ return _this.unloadGlobe();
+ }
+ };
+ })(this));
+ return wrapper.setSiteInfo = this.original_set_site_info;
+ };
+
+ Sidebar.prototype.loadGlobe = function() {
+ if (this.tag.find(".globe").hasClass("loading")) {
+ return setTimeout(((function(_this) {
+ return function() {
+ if (typeof DAT === "undefined") {
+ return $.getScript("/uimedia/globe/all.js", _this.displayGlobe);
+ } else {
+ return _this.displayGlobe();
+ }
+ };
+ })(this)), 600);
+ }
+ };
+
+ Sidebar.prototype.displayGlobe = function() {
+ return wrapper.ws.cmd("sidebarGetPeers", [], (function(_this) {
+ return function(globe_data) {
+ if (_this.globe) {
+ _this.globe.scene.remove(_this.globe.points);
+ _this.globe.addData(globe_data, {
+ format: 'magnitude',
+ name: "hello",
+ animated: false
+ });
+ _this.globe.createPoints();
+ } else {
+ _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();
+ }
+ return _this.tag.find(".globe").removeClass("loading");
+ };
+ })(this));
+ };
+
+ Sidebar.prototype.unloadGlobe = function() {
+ if (!this.globe) {
+ return false;
+ }
+ this.globe.unload();
+ return this.globe = null;
+ };
+
+ return Sidebar;
+
+ })(Class);
+
+ window.sidebar = new Sidebar();
+
+ window.transitionEnd = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend';
+
+}).call(this);
+
+
+
+/* ---- plugins/Sidebar/media/morphdom.js ---- */
+
+
+(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 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.
+ */
+ /*INPUT: function(fromEl, toEl) {
+ 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. -->
or --> 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)
+});
\ No newline at end of file
diff --git a/plugins/Sidebar/media/morphdom.js b/plugins/Sidebar/media/morphdom.js
new file mode 100644
index 00000000..6829eef3
--- /dev/null
+++ b/plugins/Sidebar/media/morphdom.js
@@ -0,0 +1,340 @@
+(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
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.
+ */
+ /*INPUT: function(fromEl, toEl) {
+ 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. -->
or --> 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)
+});
\ No newline at end of file
diff --git a/plugins/Stats/StatsPlugin.py b/plugins/Stats/StatsPlugin.py
index 52b64266..43edefdd 100644
--- a/plugins/Stats/StatsPlugin.py
+++ b/plugins/Stats/StatsPlugin.py
@@ -116,7 +116,7 @@ class UiRequestPlugin(object):
# Sites
yield "
Sites:"
yield "
"
- yield "address | connected | peers | content.json |
"
+ yield "address | connected | peers | content.json | out | in |
"
for site in self.server.sites.values():
yield self.formatTableRow([
(
@@ -130,6 +130,8 @@ class UiRequestPlugin(object):
len(site.peers)
)),
("%s", len(site.content_manager.contents)),
+ ("%.0fkB", site.settings.get("bytes_sent", 0) / 1024),
+ ("%.0fkB", site.settings.get("bytes_recv", 0) / 1024),
])
yield "" % site.address
for key, peer in site.peers.items():
diff --git a/plugins/Zeroname/UiRequestPlugin.py b/plugins/Zeroname/UiRequestPlugin.py
index 0019015d..d080a312 100644
--- a/plugins/Zeroname/UiRequestPlugin.py
+++ b/plugins/Zeroname/UiRequestPlugin.py
@@ -25,6 +25,9 @@ class UiRequestPlugin(object):
referer_path = re.sub("http[s]{0,1}://.*?/", "/", referer).replace("/media", "") # Remove site address
referer_path = re.sub("\?.*", "", referer_path) # Remove http params
+ if not re.sub("^http[s]{0,1}://", "", referer).startswith(self.env["HTTP_HOST"]): # Different origin
+ return False
+
if self.isProxyRequest(): # Match to site domain
referer = re.sub("^http://zero[/]+", "http://", referer) # Allow /zero access
referer_site_address = re.match("http[s]{0,1}://(.*?)(/|$)", referer).group(1)
diff --git a/src/Config.py b/src/Config.py
index 47ac9919..18a37786 100644
--- a/src/Config.py
+++ b/src/Config.py
@@ -7,8 +7,8 @@ import ConfigParser
class Config(object):
def __init__(self, argv):
- self.version = "0.3.1"
- self.rev = 338
+ self.version = "0.3.2"
+ self.rev = 351
self.argv = argv
self.action = None
self.createParser()
diff --git a/src/Connection/Connection.py b/src/Connection/Connection.py
index 303faed0..b1b63f70 100644
--- a/src/Connection/Connection.py
+++ b/src/Connection/Connection.py
@@ -176,6 +176,9 @@ class Connection(object):
self.last_message_time = time.time()
if message.get("cmd") == "response": # New style response
if message["to"] in self.waiting_requests:
+ if self.last_send_time:
+ ping = time.time() - self.last_send_time
+ self.last_ping_delay = ping
self.waiting_requests[message["to"]].set(message) # Set the response to event
del self.waiting_requests[message["to"]]
elif message["to"] == 0: # Other peers handshake
diff --git a/src/Db/Db.py b/src/Db/Db.py
index 34713c6e..4c9bce02 100644
--- a/src/Db/Db.py
+++ b/src/Db/Db.py
@@ -12,14 +12,14 @@ opened_dbs = []
# Close idle databases to save some memory
-def cleanup():
+def dbCleanup():
while 1:
time.sleep(60 * 5)
for db in opened_dbs[:]:
if time.time() - db.last_query_time > 60 * 3:
db.close()
-gevent.spawn(cleanup)
+gevent.spawn(dbCleanup)
class Db:
diff --git a/src/File/FileRequest.py b/src/File/FileRequest.py
index d147d18b..116f7d18 100644
--- a/src/File/FileRequest.py
+++ b/src/File/FileRequest.py
@@ -139,10 +139,11 @@ class FileRequest(object):
with StreamingMsgpack.FilePart(file_path, "rb") as file:
file.seek(params["location"])
file.read_bytes = FILE_BUFF
+ file_size = os.fstat(file.fileno()).st_size
back = {
"body": file,
- "size": os.fstat(file.fileno()).st_size,
- "location": min(file.tell() + FILE_BUFF, os.fstat(file.fileno()).st_size)
+ "size": file_size,
+ "location": min(file.tell() + FILE_BUFF, file_size)
}
if config.debug_socket:
self.log.debug(
@@ -150,8 +151,11 @@ class FileRequest(object):
(file_path, params["location"], back["location"])
)
self.response(back, streaming=True)
+
+ bytes_sent = min(FILE_BUFF, file_size - params["location"]) # Number of bytes we going to send
+ site.settings["bytes_sent"] = site.settings.get("bytes_sent", 0) + bytes_sent
if config.debug_socket:
- self.log.debug("File %s sent" % file_path)
+ self.log.debug("File %s at position %s sent %s bytes" % (file_path, params["location"], bytes_sent))
# Add peer to site if not added before
connected_peer = site.addPeer(self.connection.ip, self.connection.port)
@@ -174,10 +178,11 @@ class FileRequest(object):
self.log.debug("Opening file: %s" % params["inner_path"])
with site.storage.open(params["inner_path"]) as file:
file.seek(params["location"])
- stream_bytes = min(FILE_BUFF, os.fstat(file.fileno()).st_size-params["location"])
+ file_size = os.fstat(file.fileno()).st_size
+ stream_bytes = min(FILE_BUFF, file_size - params["location"])
back = {
- "size": os.fstat(file.fileno()).st_size,
- "location": min(file.tell() + FILE_BUFF, os.fstat(file.fileno()).st_size),
+ "size": file_size,
+ "location": min(file.tell() + FILE_BUFF, file_size),
"stream_bytes": stream_bytes
}
if config.debug_socket:
@@ -187,8 +192,10 @@ class FileRequest(object):
)
self.response(back)
self.sendRawfile(file, read_bytes=FILE_BUFF)
+
+ site.settings["bytes_sent"] = site.settings.get("bytes_sent", 0) + stream_bytes
if config.debug_socket:
- self.log.debug("File %s sent" % params["inner_path"])
+ self.log.debug("File %s at position %s sent %s bytes" % (params["inner_path"], params["location"], stream_bytes))
# Add peer to site if not added before
connected_peer = site.addPeer(self.connection.ip, self.connection.port)
diff --git a/src/Peer/Peer.py b/src/Peer/Peer.py
index ba7089c4..b408ced0 100644
--- a/src/Peer/Peer.py
+++ b/src/Peer/Peer.py
@@ -151,6 +151,7 @@ class Peer(object):
self.download_bytes += back["location"]
self.download_time += (time.time() - s)
+ self.site.settings["bytes_recv"] = self.site.settings.get("bytes_recv", 0) + back["location"]
buff.seek(0)
return buff
@@ -177,6 +178,7 @@ class Peer(object):
self.download_bytes += back["location"]
self.download_time += (time.time() - s)
+ self.site.settings["bytes_recv"] = self.site.settings.get("bytes_recv", 0) + back["location"]
buff.seek(0)
return buff
diff --git a/src/Site/Site.py b/src/Site/Site.py
index 7bc56e6a..c7830f06 100644
--- a/src/Site/Site.py
+++ b/src/Site/Site.py
@@ -137,11 +137,11 @@ class Site:
self.log.debug("%s: Downloading %s includes..." % (inner_path, len(include_threads)))
gevent.joinall(include_threads)
- self.log.debug("%s: Includes downloaded" % inner_path)
+ self.log.debug("%s: Includes download ended" % inner_path)
self.log.debug("%s: Downloading %s files, changed: %s..." % (inner_path, len(file_threads), len(changed)))
gevent.joinall(file_threads)
- self.log.debug("%s: All file downloaded in %.2fs" % (inner_path, time.time() - s))
+ self.log.debug("%s: DownloadContent ended in %.2fs" % (inner_path, time.time() - s))
return True
@@ -159,7 +159,10 @@ class Site:
# Download all files of the site
@util.Noparallel(blocking=False)
def download(self, check_size=False, blind_includes=False):
- self.log.debug("Start downloading, bad_files: %s, check_size: %s, blind_includes: %s" % (self.bad_files, check_size, blind_includes))
+ self.log.debug(
+ "Start downloading, bad_files: %s, check_size: %s, blind_includes: %s" %
+ (self.bad_files, check_size, blind_includes)
+ )
gevent.spawn(self.announce)
if check_size: # Check the size first
valid = self.downloadContent(download_files=False) # Just download content.json files
@@ -221,7 +224,7 @@ class Site:
for i in range(3):
updaters.append(gevent.spawn(self.updater, peers_try, queried, since))
- gevent.joinall(updaters, timeout=5) # Wait 5 sec to workers
+ gevent.joinall(updaters, timeout=10) # Wait 10 sec to workers done query modifications
time.sleep(0.1)
self.log.debug("Queried listModifications from: %s" % queried)
return queried
@@ -420,7 +423,7 @@ class Site:
elif self.settings["serving"] is False: # Site not serving
return False
else: # Wait until file downloaded
- self.bad_files[inner_path] = self.bad_files.get(inner_path,0)+1 # Mark as bad file
+ self.bad_files[inner_path] = self.bad_files.get(inner_path, 0) + 1 # Mark as bad file
if not self.content_manager.contents.get("content.json"): # No content.json, download it first!
self.log.debug("Need content.json first")
gevent.spawn(self.announce)
diff --git a/src/Site/SiteStorage.py b/src/Site/SiteStorage.py
index e6c03a3d..4e73839c 100644
--- a/src/Site/SiteStorage.py
+++ b/src/Site/SiteStorage.py
@@ -210,6 +210,11 @@ class SiteStorage:
raise Exception("File not allowed: %s" % file_path)
return file_path
+ # Get site dir relative path
+ def getInnerPath(self, path):
+ inner_path = re.sub("^%s/" % re.escape(self.directory), "", path)
+ return inner_path
+
# Verify all files sha512sum using content.json
def verifyFiles(self, quick_check=False): # Fast = using file size
bad_files = []
diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py
index f34c7443..381a17dd 100644
--- a/src/Ui/UiWebsocket.py
+++ b/src/Ui/UiWebsocket.py
@@ -57,14 +57,18 @@ class UiWebsocket(object):
while True:
try:
message = ws.receive()
- if message:
- self.handleRequest(message)
except Exception, err:
- if err.message != 'Connection is already closed':
+ self.log.error("WebSocket receive error: %s" % err)
+ return "Bye." # Close connection
+
+ if message:
+ try:
+ self.handleRequest(message)
+ except Exception, err:
if config.debug: # Allow websocket errors to appear on /Debug
sys.modules["main"].DebugHook.handleError()
- self.log.error("WebSocket error: %s" % Debug.formatException(err))
- return "Bye."
+ self.log.error("WebSocket handleRequest error: %s" % err)
+ self.cmd("error", "Internal error: %s" % err)
# Event in a channel
def event(self, channel, *params):
@@ -138,8 +142,10 @@ class UiWebsocket(object):
func(req["id"], **params)
elif type(params) is list:
func(req["id"], *params)
- else:
+ elif params:
func(req["id"], params)
+ else:
+ func(req["id"])
# Format site info
def formatSiteInfo(self, site, create_user=True):
@@ -170,7 +176,7 @@ class UiWebsocket(object):
"bad_files": len(site.bad_files),
"size_limit": site.getSizeLimit(),
"next_size_limit": site.getNextSizeLimit(),
- "peers": site.settings.get("peers", len(site.peers)),
+ "peers": max(site.settings.get("peers", 0), len(site.peers)),
"started_task_num": site.worker_manager.started_task_num,
"tasks": len(site.worker_manager.tasks),
"workers": len(site.worker_manager.workers),
@@ -404,7 +410,7 @@ class UiWebsocket(object):
if auth_address == cert["auth_address"]:
active = domain
title = cert["auth_user_name"] + "@" + domain
- if domain in accepted_domains:
+ if domain in accepted_domains or not accepted_domains:
accounts.append([domain, title, ""])
else:
accounts.append([domain, title, "disabled"])
@@ -527,7 +533,7 @@ class UiWebsocket(object):
gevent.spawn(new_site.announce)
def actionSiteSetLimit(self, to, size_limit):
- self.site.settings["size_limit"] = size_limit
+ self.site.settings["size_limit"] = int(size_limit)
self.site.saveSettings()
self.response(to, "Site size limit changed to %sMB" % size_limit)
self.site.download(blind_includes=True)
diff --git a/src/Ui/media/Wrapper.coffee b/src/Ui/media/Wrapper.coffee
index 1333bedb..5d244977 100644
--- a/src/Ui/media/Wrapper.coffee
+++ b/src/Ui/media/Wrapper.coffee
@@ -49,7 +49,11 @@ class Wrapper
else
@sendInner message # Pass message to inner frame
else if cmd == "notification" # Display notification
- @notifications.add("notification-#{message.id}", message.params[0], message.params[1], message.params[2])
+ type = message.params[0]
+ id = "notification-#{message.id}"
+ if "-" in message.params[0] # - in first param: message id definied
+ [id, type] = message.params[0].split("-")
+ @notifications.add(id, type, message.params[1], message.params[2])
else if cmd == "prompt" # Prompt input
@displayPrompt message.params[0], message.params[1], message.params[2], (res) =>
@ws.response message.id, res
@@ -57,6 +61,8 @@ class Wrapper
@sendInner message # Pass to inner frame
if message.params.address == @address # Current page
@setSiteInfo message.params
+ else if cmd == "error"
+ @notifications.add("notification-#{message.id}", "error", message.params, 0)
else if cmd == "updating" # Close connection
@ws.ws.close()
@ws.onCloseWebsocket(null, 4000)
diff --git a/src/Ui/media/Wrapper.css b/src/Ui/media/Wrapper.css
index e2941308..67f4f99b 100644
--- a/src/Ui/media/Wrapper.css
+++ b/src/Ui/media/Wrapper.css
@@ -7,13 +7,17 @@ a { color: black }
#inner-iframe { width: 100%; height: 100%; position: absolute; border: 0px } /*; transition: all 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.8s ease-in-out*/
#inner-iframe.back { transform: scale(0.95) translate(-300px, 0px); opacity: 0.4 }
-.button { padding: 5px 10px; margin-left: 10px; background-color: #FFF85F; border-bottom: 2px solid #CDBD1E; border-radius: 2px; text-decoration: none; transition: all 0.5s; }
+.button { padding: 5px 10px; margin-left: 10px; background-color: #FFF85F; border-bottom: 2px solid #CDBD1E; border-radius: 2px; text-decoration: none; transition: all 0.5s; background-position: left center; }
.button:hover { background-color: #FFF400; border-bottom: 2px solid #4D4D4C; transition: none }
.button:active { position: relative; top: 1px }
.button-Delete { background-color: #e74c3c; border-bottom-color: #c0392b; color: white }
.button-Delete:hover { background-color: #FF5442; border-bottom-color: #8E2B21 }
+.button.loading {
+ color: rgba(0,0,0,0); background: #999 url(img/loading.gif) no-repeat center center;
+ transition: all 0.5s ease-out ; pointer-events: none; border-bottom: 2px solid #666
+}
/* Fixbutton */
diff --git a/src/Ui/media/all.css b/src/Ui/media/all.css
index b59f612c..29b470d8 100644
--- a/src/Ui/media/all.css
+++ b/src/Ui/media/all.css
@@ -12,13 +12,17 @@ a { color: black }
#inner-iframe { width: 100%; height: 100%; position: absolute; border: 0px } /*; transition: all 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.8s ease-in-out*/
#inner-iframe.back { -webkit-transform: scale(0.95) translate(-300px, 0px); -moz-transform: scale(0.95) translate(-300px, 0px); -o-transform: scale(0.95) translate(-300px, 0px); -ms-transform: scale(0.95) translate(-300px, 0px); transform: scale(0.95) translate(-300px, 0px) ; opacity: 0.4 }
-.button { padding: 5px 10px; margin-left: 10px; background-color: #FFF85F; border-bottom: 2px solid #CDBD1E; -webkit-border-radius: 2px; -moz-border-radius: 2px; -o-border-radius: 2px; -ms-border-radius: 2px; border-radius: 2px ; text-decoration: none; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; -o-transition: all 0.5s; -ms-transition: all 0.5s; transition: all 0.5s ; }
+.button { padding: 5px 10px; margin-left: 10px; background-color: #FFF85F; border-bottom: 2px solid #CDBD1E; -webkit-border-radius: 2px; -moz-border-radius: 2px; -o-border-radius: 2px; -ms-border-radius: 2px; border-radius: 2px ; text-decoration: none; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; -o-transition: all 0.5s; -ms-transition: all 0.5s; transition: all 0.5s ; background-position: left center; }
.button:hover { background-color: #FFF400; border-bottom: 2px solid #4D4D4C; -webkit-transition: none ; -moz-transition: none ; -o-transition: none ; -ms-transition: none ; transition: none }
.button:active { position: relative; top: 1px }
.button-Delete { background-color: #e74c3c; border-bottom-color: #c0392b; color: white }
.button-Delete:hover { background-color: #FF5442; border-bottom-color: #8E2B21 }
+.button.loading {
+ color: rgba(0,0,0,0); background: #999 url(img/loading.gif) no-repeat center center;
+ -webkit-transition: all 0.5s ease-out ; -moz-transition: all 0.5s ease-out ; -o-transition: all 0.5s ease-out ; -ms-transition: all 0.5s ease-out ; transition: all 0.5s ease-out ; pointer-events: none; border-bottom: 2px solid #666
+}
/* Fixbutton */
diff --git a/src/Ui/media/all.js b/src/Ui/media/all.js
index 1d589c4d..570edfd6 100644
--- a/src/Ui/media/all.js
+++ b/src/Ui/media/all.js
@@ -758,6 +758,7 @@ jQuery.extend( jQuery.easing,
(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() {
@@ -810,7 +811,7 @@ jQuery.extend( jQuery.easing,
}
Wrapper.prototype.onMessageWebsocket = function(e) {
- var cmd, message;
+ var cmd, id, message, type, _ref;
message = JSON.parse(e.data);
cmd = message.cmd;
if (cmd === "response") {
@@ -820,7 +821,12 @@ jQuery.extend( jQuery.easing,
return this.sendInner(message);
}
} else if (cmd === "notification") {
- return this.notifications.add("notification-" + message.id, message.params[0], message.params[1], message.params[2]);
+ type = message.params[0];
+ id = "notification-" + 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]);
} else if (cmd === "prompt") {
return this.displayPrompt(message.params[0], message.params[1], message.params[2], (function(_this) {
return function(res) {
@@ -832,6 +838,8 @@ jQuery.extend( jQuery.easing,
if (message.params.address === this.address) {
return this.setSiteInfo(message.params);
}
+ } else if (cmd === "error") {
+ return this.notifications.add("notification-" + message.id, "error", message.params, 0);
} else if (cmd === "updating") {
this.ws.ws.close();
return this.ws.onCloseWebsocket(null, 4000);
diff --git a/src/Ui/media/img/loading-circle.gif b/src/Ui/media/img/loading-circle.gif
new file mode 100644
index 00000000..14844e03
Binary files /dev/null and b/src/Ui/media/img/loading-circle.gif differ
diff --git a/src/Ui/media/img/loading.gif b/src/Ui/media/img/loading.gif
new file mode 100644
index 00000000..27d0aa81
Binary files /dev/null and b/src/Ui/media/img/loading.gif differ
diff --git a/src/util/RateLimit.py b/src/util/RateLimit.py
index 55933e40..f87f58af 100644
--- a/src/util/RateLimit.py
+++ b/src/util/RateLimit.py
@@ -78,14 +78,14 @@ def call(event, allowed_again=10, func=None, *args, **kwargs):
# Cleanup expired events every 3 minutes
-def cleanup():
+def rateLimitCleanup():
while 1:
expired = time.time() - 60 * 2 # Cleanup if older than 2 minutes
for event in called_db.keys():
if called_db[event] < expired:
del called_db[event]
time.sleep(60 * 3) # Every 3 minutes
-gevent.spawn(cleanup)
+gevent.spawn(rateLimitCleanup)
if __name__ == "__main__":
|