Commit d0e64380 authored by Fabian-Andree Heidemann's avatar Fabian-Andree Heidemann
Browse files

Clean-up inflationary use of event.stopPropagation(), fix #2154

parent f4affbc0
......@@ -15,7 +15,6 @@ define(["jquery", "jclass"], function($, JClass) {
// click event on the selection-p
var selectionP = $(".file-selection-p", node);
selectionP.on("click tap", node, function(event) {
event.stopPropagation();
// Needed to avoid double event execution
if ($(event.target).is("span")) {
return;
......@@ -42,7 +41,6 @@ define(["jquery", "jclass"], function($, JClass) {
// click on the node itself
var menuOpenString = vispa.device.hasTouch ? "taphold" : "contextmenu";
node.on(menuOpenString, function(event) {
event.stopPropagation();
var abspath = self.FileBase.helper.abspath(data.name);
var inselection = self.FileBase.selections.entries[abspath];
if (inselection === undefined) {
......@@ -65,8 +63,10 @@ define(["jquery", "jclass"], function($, JClass) {
// to be switched to tap (=single) events
openstring = vispa.device.hasTouch ? "tap" : openstring;
node.on(openstring, function(event) {
// check if event has to be accepted
if ($(event.target).is(".file-selection-p,.file-selection-checkbox")) return;
if (self.FileBase.workflow.currentView.type == "Symbol" && $(event.target).is("span")) return;
event.preventDefault();
event.stopPropagation();
if (self.FileBase.menuitems.menu.hasClass("open")) {
self.FileBase.menuitems.hideMenu();
if (prefOpenstring == "single") {
......@@ -74,7 +74,6 @@ define(["jquery", "jclass"], function($, JClass) {
}
}
if (self.FileBase.workflow.selectmode) {
event.stopPropagation();
self.FileBase.selections.changeSelection(node, true);
} else if ((vispa.device.hasTouch || openstring == "click") && Object.keys(self.FileBase
.selections
......@@ -96,7 +95,6 @@ define(["jquery", "jclass"], function($, JClass) {
self.FileBase.selections.unselectAll();
}
event.preventDefault();
event.stopPropagation();
self.FileBase.menuitems.hideMenu();
self.FileBase.selections.changeSelection(node, true);
});
......@@ -107,7 +105,6 @@ define(["jquery", "jclass"], function($, JClass) {
var self = this;
// ####################################################################
node.on("click tap", ".file-properties", function(event) {
event.stopPropagation();
event.preventDefault();
if (Object.keys(self.FileBase.selections.entries).length > 1) {
return;
......@@ -135,17 +132,20 @@ define(["jquery", "jclass"], function($, JClass) {
setupBkgEvents: function(nodeBkg) {
var self = this;
nodeBkg.on("click tap", function(event) {
// check if event has to be accepted
if (!$(event.target).is(".file-list,.file-content")) return;
if (event.timeStamp == self.lastEvent) {
return;
}
event.preventDefault();
event.stopPropagation();
self.FileBase.selections.unselectAll();
self.FileBase.menuitems.hideMenu();
});
// Don"t use hold menus on touch
var menuOpenString = vispa.device.hasTouch ? "taphold" : "contextmenu";
nodeBkg.on(menuOpenString, function(event) {
// check if event has to be accepted
if (!$(event.target).is(".file-list,.file-content")) return;
self.FileBase.selections.unselectAll();
event.preventDefault();
self.FileBase.menuitems.showMenu(event, "b");
......
define(["jquery", "jclass"], function($, JClass) {
var FileBaseMenuItems = JClass._extend({
init: function(FileBase) {
this.FileBase = FileBase;
......@@ -11,7 +11,7 @@ define(["jquery", "jclass"], function($, JClass) {
y: 36
};
},
makeMenuClickable: function() {
var self = this;
this.menu = $(".file-rightclickmenu", this.FileBase.view.fileContentContainer.parent());
......@@ -19,7 +19,7 @@ define(["jquery", "jclass"], function($, JClass) {
event.preventDefault();
self.hideMenu();
});
var events = ["openFile", "openFolder", "openFolderInNewTab", "rename", "copy", "cut", "remove", "download",
"compress", "info", "select", "createFile", "createFolder", "paste", "upload"
];
......@@ -31,7 +31,7 @@ define(["jquery", "jclass"], function($, JClass) {
});
});
},
getMenuType: function() {
var nNodesSelected = Object.keys(this.FileBase.selections.entries).length;
if (nNodesSelected === 0) {
......@@ -50,22 +50,21 @@ define(["jquery", "jclass"], function($, JClass) {
showMenu: function(event, menuType, position) {
var self = this;
event.preventDefault();
event.stopPropagation();
menuType = menuType === null || menuType === undefined ? this.getMenuType() : menuType;
this.menu.on("contextmenu", function(evt) {
evt.preventDefault();
});
if (menuType === "d") {
self.makeFolderMenu();
} else if (menuType === "f") {
self.makeFileMenu();
} else if (menuType === "b") {
self.makeBkgMenu();
} else if (menuType === "s") {
self.makeSelectionMenu();
}
if ($(window).height() < 300 || $(window).width() < 768) {
position = this.nullPosition;
if (menuType === "d") {
self.makeFolderMenu();
} else if (menuType === "f") {
self.makeFileMenu();
} else if (menuType === "b") {
self.makeBkgMenu();
} else if (menuType === "s") {
self.makeSelectionMenu();
}
if ($(window).height() < 300 || $(window).width() < 768) {
position = this.nullPosition;
}
this.menu.addClass("open");
var submenu = $("ul", this.menu);
......@@ -76,59 +75,59 @@ define(["jquery", "jclass"], function($, JClass) {
top: position.y
});
},
hideMenu: function() {
this.menu.removeClass("open");
},
getContextMenuPostion: function(event, contextMenu) {
var menuPostion = {};
var menuDimension = {};
// store the fileContentContainer fCC
var fCC = this.FileBase.view.fileContentContainer;
var offset = fCC.offset().top;
menuDimension.x = contextMenu.outerWidth();
menuDimension.y = contextMenu.outerHeight();
menuPostion.x = 2 * event.clientX - event.pageX;
menuPostion.y = event.clientY - offset;
if (vispa.device.hasTouch) {
menuPostion.x += 5;
menuPostion.y += 5;
}
// Check if the side borders are reached
//(additional 5 px in the shift are needed to prevent firefox from opening scroll bars)
if (menuPostion.x + menuDimension.x > fCC.width()) {
menuPostion.x = fCC.width() - menuDimension.x - 5;
}
// Check if the lower border is reached
//(additional 5 px in the shift are needed to prevent firefox from opening scroll bars)
if (menuPostion.y + menuDimension.y > fCC.height()) {
menuPostion.y = fCC.height() - menuDimension.y - 5;
}
return menuPostion;
},
makeFileMenu: function() {
this.menu.toggleClass("filemenu", true);
this.menu.toggleClass("foldermenu", false);
this.menu.toggleClass("bkgmenu", false);
this.menu.toggleClass("selectionmenu", false);
},
makeFolderMenu: function() {
this.menu.toggleClass("filemenu", false);
this.menu.toggleClass("foldermenu", true);
this.menu.toggleClass("bkgmenu", false);
this.menu.toggleClass("selectionmenu", false);
},
makeBkgMenu: function() {
this.menu.toggleClass("filemenu", false);
this.menu.toggleClass("foldermenu", false);
......@@ -147,7 +146,7 @@ define(["jquery", "jclass"], function($, JClass) {
$(".paste", this.menu).toggleClass("file-rightclickmenu-itemhide", true);
}
},
makeSelectionMenu: function() {
this.menu.toggleClass("filemenu", false);
this.menu.toggleClass("foldermenu", false);
......
define(["jquery", "jclass", "./bookmark"], function($, JClass, Bookmark) {
var PathBar = JClass._extend({
init: function(FileBase) {
var self = this;
self.FileBase = FileBase;
......@@ -12,7 +12,7 @@ define(["jquery", "jclass", "./bookmark"], function($, JClass, Bookmark) {
this.node = null;
this.tmpl = null;
},
setup: function(node) {
var self = this;
this.node = node;
......@@ -26,7 +26,7 @@ define(["jquery", "jclass", "./bookmark"], function($, JClass, Bookmark) {
self.optionWheel();
});
},
render: function() {
var self = this;
var clicktype = vispa.device.hasTouch ? "tap" : "click";
......@@ -82,7 +82,7 @@ define(["jquery", "jclass", "./bookmark"], function($, JClass, Bookmark) {
self.bookmark.setup(self.node);
});
},
optionWheel: function() {
var self = this;
var clicktype = vispa.device.hasTouch ? "tap" : "click";
......@@ -96,10 +96,13 @@ define(["jquery", "jclass", "./bookmark"], function($, JClass, Bookmark) {
self.FileBase.menuitems.hideMenu();
} else {
self.FileBase.menuitems.showMenu(event, null, position);
// stop propagation and close all other dropdowns manuelly
event.stopPropagation();
$(".open:not(.file-rightclickmenu)").toggleClass("open");
}
});
}
});
return PathBar;
......
......@@ -60,15 +60,15 @@ define(["jquery", "jclass"], function($, JClass) {
}
// make select-all-checkbox clickable
$(".select-all", self.fileContentContainer).click(function() {
setTimeout(function() {
$(this).prop("checked", $(this).prop("checked") ? "" : "checked");
if ($(this).prop("checked")) {
self.FileBase.selections.selectAll();
} else {
self.FileBase.selections.unselectAll();
}
}.bind(this), 0);
$(".select-all", self.fileContentContainer).click(function(event) {
// not intuitive but works
if ($(event.target).prop("checked")) {
self.FileBase.selections.unselectAll();
self.FileBase.selections.selectAll();
$(event.target).prop("checked", "checked");
} else {
self.FileBase.selections.unselectAll();
}
});
// call function for sorting carets
......@@ -144,7 +144,6 @@ define(["jquery", "jclass"], function($, JClass) {
var self = this;
$(".edit-rename", this.fileContentContainer).click(function(event) {
event.stopPropagation();
event.preventDefault();
var node = $(event.currentTarget.parentElement.parentElement);
self.FileBase.selections.unselectAll();
......@@ -153,7 +152,6 @@ define(["jquery", "jclass"], function($, JClass) {
});
$(".edit-download", this.fileContentContainer).click(function(event) {
event.stopPropagation();
event.preventDefault();
var node = $(event.currentTarget.parentElement.parentElement);
self.FileBase.selections.unselectAll();
......@@ -163,7 +161,6 @@ define(["jquery", "jclass"], function($, JClass) {
// sharing not yet implemented
$(".edit-share", this.fileContentContainer).click(function(event) {
event.stopPropagation();
event.preventDefault();
var node = $(event.currentTarget.parentElement.parentElement);
self.FileBase.selections.unselectAll();
......@@ -172,7 +169,6 @@ define(["jquery", "jclass"], function($, JClass) {
});
$(".edit-remove", this.fileContentContainer).click(function(event) {
event.stopPropagation();
event.preventDefault();
var node = $(event.currentTarget.parentElement.parentElement);
self.FileBase.selections.unselectAll();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment