Rev1279, Sidebar open on mobile devices

This commit is contained in:
HelloZeroNet 2016-05-02 00:28:23 +02:00
parent 158059071b
commit eedce00d57
3 changed files with 41 additions and 27 deletions

View file

@ -26,19 +26,23 @@ class Sidebar extends Class
initFixbutton: -> initFixbutton: ->
# Detect dragging # Detect dragging
@fixbutton.on "mousedown", (e) => @fixbutton.on "mousedown touchstart", (e) =>
e.preventDefault() e.preventDefault()
# Disable previous listeners # Disable previous listeners
@fixbutton.off "click" @fixbutton.off "click touchstop touchcancel"
@fixbutton.off "mousemove" @fixbutton.off "mousemove touchmove"
# Make sure its not a click # Make sure its not a click
@dragStarted = (+ new Date) @dragStarted = (+ new Date)
@fixbutton.one "mousemove", (e) => @fixbutton.one "mousemove touchmove", (e) =>
@fixbutton_addx = @fixbutton.offset().left-e.pageX mousex = e.pageX
if not mousex
mousex = e.originalEvent.touches[0].pageX
@fixbutton_addx = @fixbutton.offset().left-mousex
@startDrag() @startDrag()
@fixbutton.parent().on "click", (e) => @fixbutton.parent().on "click touchstop touchcancel", (e) =>
@stopDrag() @stopDrag()
@resized() @resized()
$(window).on "resize", @resized $(window).on "resize", @resized
@ -76,11 +80,11 @@ class Sidebar extends Class
e.preventDefault() e.preventDefault()
# Animate drag # Animate drag
@fixbutton.parents().on "mousemove", @animDrag @fixbutton.parents().on "mousemove touchmove", @animDrag
@fixbutton.parents().on "mousemove" ,@waitMove @fixbutton.parents().on "mousemove touchmove" ,@waitMove
# Stop dragging listener # Stop dragging listener
@fixbutton.parents().on "mouseup", (e) => @fixbutton.parents().on "mouseup touchstop touchend touchcancel", (e) =>
e.preventDefault() e.preventDefault()
@stopDrag() @stopDrag()
@ -89,7 +93,7 @@ class Sidebar extends Class
waitMove: (e) => waitMove: (e) =>
if Math.abs(@fixbutton.offset().left - @fixbutton_targetx) > 10 and (+ new Date)-@dragStarted > 100 if Math.abs(@fixbutton.offset().left - @fixbutton_targetx) > 10 and (+ new Date)-@dragStarted > 100
@moved() @moved()
@fixbutton.parents().off "mousemove" ,@waitMove @fixbutton.parents().off "mousemove touchmove" ,@waitMove
moved: -> moved: ->
@log "Moved" @log "Moved"
@ -152,11 +156,13 @@ class Sidebar extends Class
animDrag: (e) => animDrag: (e) =>
mousex = e.pageX mousex = e.pageX
if not mousex
mousex = e.originalEvent.touches[0].pageX
overdrag = @fixbutton_initx-@width-mousex overdrag = @fixbutton_initx-@width-mousex
if overdrag > 0 # Overdragged if overdrag > 0 # Overdragged
overdrag_percent = 1+overdrag/300 overdrag_percent = 1+overdrag/300
mousex = (e.pageX + (@fixbutton_initx-@width)*overdrag_percent)/(1+overdrag_percent) mousex = (mousex + (@fixbutton_initx-@width)*overdrag_percent)/(1+overdrag_percent)
targetx = @fixbutton_initx-mousex-@fixbutton_addx targetx = @fixbutton_initx-mousex-@fixbutton_addx
@fixbutton[0].style.left = (mousex+@fixbutton_addx)+"px" @fixbutton[0].style.left = (mousex+@fixbutton_addx)+"px"
@ -173,8 +179,8 @@ class Sidebar extends Class
# Stop dragging the fixbutton # Stop dragging the fixbutton
stopDrag: -> stopDrag: ->
@fixbutton.parents().off "mousemove" @fixbutton.parents().off "mousemove touchmove"
@fixbutton.off "mousemove" @fixbutton.off "mousemove touchmove"
@fixbutton.css("pointer-events", "") @fixbutton.css("pointer-events", "")
$(".drag-bg").remove() $(".drag-bg").remove()
if not @fixbutton.hasClass("dragging") if not @fixbutton.hasClass("dragging")

View file

@ -224,19 +224,24 @@ window.initScrollable = function () {
} }
Sidebar.prototype.initFixbutton = function() { Sidebar.prototype.initFixbutton = function() {
this.fixbutton.on("mousedown", (function(_this) { this.fixbutton.on("mousedown touchstart", (function(_this) {
return function(e) { return function(e) {
e.preventDefault(); e.preventDefault();
_this.fixbutton.off("click"); _this.fixbutton.off("click touchstop touchcancel");
_this.fixbutton.off("mousemove"); _this.fixbutton.off("mousemove touchmove");
_this.dragStarted = +(new Date); _this.dragStarted = +(new Date);
return _this.fixbutton.one("mousemove", function(e) { return _this.fixbutton.one("mousemove touchmove", function(e) {
_this.fixbutton_addx = _this.fixbutton.offset().left - e.pageX; var mousex;
mousex = e.pageX;
if (!mousex) {
mousex = e.originalEvent.touches[0].pageX;
}
_this.fixbutton_addx = _this.fixbutton.offset().left - mousex;
return _this.startDrag(); return _this.startDrag();
}); });
}; };
})(this)); })(this));
this.fixbutton.parent().on("click", (function(_this) { this.fixbutton.parent().on("click touchstop touchcancel", (function(_this) {
return function(e) { return function(e) {
return _this.stopDrag(); return _this.stopDrag();
}; };
@ -276,9 +281,9 @@ window.initScrollable = function () {
} }
}; };
})(this)); })(this));
this.fixbutton.parents().on("mousemove", this.animDrag); this.fixbutton.parents().on("mousemove touchmove", this.animDrag);
this.fixbutton.parents().on("mousemove", this.waitMove); this.fixbutton.parents().on("mousemove touchmove", this.waitMove);
return this.fixbutton.parents().on("mouseup", (function(_this) { return this.fixbutton.parents().on("mouseup touchstop touchend touchcancel", (function(_this) {
return function(e) { return function(e) {
e.preventDefault(); e.preventDefault();
return _this.stopDrag(); return _this.stopDrag();
@ -289,7 +294,7 @@ window.initScrollable = function () {
Sidebar.prototype.waitMove = function(e) { Sidebar.prototype.waitMove = function(e) {
if (Math.abs(this.fixbutton.offset().left - this.fixbutton_targetx) > 10 && (+(new Date)) - this.dragStarted > 100) { if (Math.abs(this.fixbutton.offset().left - this.fixbutton_targetx) > 10 && (+(new Date)) - this.dragStarted > 100) {
this.moved(); this.moved();
return this.fixbutton.parents().off("mousemove", this.waitMove); return this.fixbutton.parents().off("mousemove touchmove", this.waitMove);
} }
}; };
@ -367,10 +372,13 @@ window.initScrollable = function () {
Sidebar.prototype.animDrag = function(e) { Sidebar.prototype.animDrag = function(e) {
var mousex, overdrag, overdrag_percent, targetx; var mousex, overdrag, overdrag_percent, targetx;
mousex = e.pageX; mousex = e.pageX;
if (!mousex) {
mousex = e.originalEvent.touches[0].pageX;
}
overdrag = this.fixbutton_initx - this.width - mousex; overdrag = this.fixbutton_initx - this.width - mousex;
if (overdrag > 0) { if (overdrag > 0) {
overdrag_percent = 1 + overdrag / 300; overdrag_percent = 1 + overdrag / 300;
mousex = (e.pageX + (this.fixbutton_initx - this.width) * overdrag_percent) / (1 + overdrag_percent); mousex = (mousex + (this.fixbutton_initx - this.width) * overdrag_percent) / (1 + overdrag_percent);
} }
targetx = this.fixbutton_initx - mousex - this.fixbutton_addx; targetx = this.fixbutton_initx - mousex - this.fixbutton_addx;
this.fixbutton[0].style.left = (mousex + this.fixbutton_addx) + "px"; this.fixbutton[0].style.left = (mousex + this.fixbutton_addx) + "px";
@ -386,8 +394,8 @@ window.initScrollable = function () {
Sidebar.prototype.stopDrag = function() { Sidebar.prototype.stopDrag = function() {
var targetx; var targetx;
this.fixbutton.parents().off("mousemove"); this.fixbutton.parents().off("mousemove touchmove");
this.fixbutton.off("mousemove"); this.fixbutton.off("mousemove touchmove");
this.fixbutton.css("pointer-events", ""); this.fixbutton.css("pointer-events", "");
$(".drag-bg").remove(); $(".drag-bg").remove();
if (!this.fixbutton.hasClass("dragging")) { if (!this.fixbutton.hasClass("dragging")) {

View file

@ -8,7 +8,7 @@ class Config(object):
def __init__(self, argv): def __init__(self, argv):
self.version = "0.3.7" self.version = "0.3.7"
self.rev = 1278 self.rev = 1279
self.argv = argv self.argv = argv
self.action = None self.action = None
self.config_file = "zeronet.conf" self.config_file = "zeronet.conf"