Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #55 from nextcloud/feature/stabilization-better-re…
Browse files Browse the repository at this point in the history
…ndering

Stabilization and better rendering
  • Loading branch information
NastuzziSamy authored Mar 28, 2019
2 parents 736129e + 42dbe16 commit 8136195
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 125 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelogs
## 0.13.0
- Remove regular click option: "Open folder" for example
- Improve outside clicks detection
- Code cleaning

## 0.12.0
- The app repository was transfered to Nextcloud in order to ship the Right click app by default.
- Update README.md and info.xml
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<name>Right click</name>
<summary>Right click menu for Nextcloud</summary>
<description><![CDATA[This app allows users and developers to have a right click menu. Simply use the RightClick object to quickly create context menus. The Files app already shows the actions menu when right clicking on files and folders.]]></description>
<version>0.12.0</version>
<version>0.13.0</version>
<licence>AGPL</licence>
<author mail="[email protected]" homepage="https://samy.nastuzzi.fr">NASTUZZI Samy</author>
<namespace>FilesRightClick</namespace>
Expand Down
7 changes: 0 additions & 7 deletions appinfo/routes.php

This file was deleted.

20 changes: 17 additions & 3 deletions css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
position: fixed;
top: 0;
left: 0;
z-index: 1000;
}

.rightClick.bubble:after {
#rightClickDetector {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 100000;
}

.rightClickMenu {
position: fixed;
z-index: 100001;
}

.rightClickMenu.bubble:after {
display: none;
}

.rightClick-fixed {
.rightClickOpened {
height: 100% !important;
overflow: hidden !important;
}
62 changes: 9 additions & 53 deletions js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
'use strict';

if (!RightClick) {
console.log('The RightClick app is recommanded to have context menus');
console.error('The RightClick app is recommanded to have context menus');
return false;
}

var appName = RightClick.appName;

new RightClick.Menu($('tbody[id=fileList]'), function (event, context, delimiter) {
var options = new RightClick.Options();
var openSubOptions = new RightClick.Options();
var currentFile = $(event.target).closest('tr');
var selectedActions = '.selectedActions .menu-center li';
currentFile.find('.action-menu').click();
$('.actions-selected').click().click();
$('.filesSelectMenu').css('visibility', 'hidden');
$('.actions-selected').click();

var menu = currentFile.find('.fileActionsMenu');
var menuStyle = $('style.rightClickStyle');
Expand Down Expand Up @@ -81,66 +81,20 @@

var share = currentFile.find('.filename .fileactions .action-share');

if (share.length !== 0) {
if (share.length === 0) {
addNewOption('Share', 'shared', t(appName, 'Share ' + (currentFile.attr('data-type') === 'dir' ? 'folder' : 'file')), function () {
share.click();
});
}

if (currentFile.attr('data-type') === 'dir') {
text = t(appName, 'Open folder');
icon = 'filetype-folder-drag-accept';

addNewOpenSubOption('NewTab', 'category-app-bundles', t(appName, 'Open in new tab'), function () {
window.open('?dir=' + currentFile.attr('data-path') + (currentFile.attr('data-path') === '/' ? '' : '/') + currentFile.attr('data-file'), "_blank");
});
}
else if (mimeType === 'text/plain') {
text = t(appName, 'Edit file');
icon = 'edit';
}
else if (mimeType === 'application/pdf') {
text = t(appName, 'Read PDF');
}
else if (mimeType.indexOf('image') >= 0 && RightClick.isAppAvailable('gallery')) {
text = t(appName, 'See picture');

addNewOpenSubOption('Gallery', 'category-multimedia', t(appName, 'Open in Gallery'), function () {
window.open(OC.generateUrl('/apps/gallery') + currentFile.attr('data-path').replace('/', '/#') + (currentFile.attr('data-path') === '/' ? '' : '/') + currentFile.attr('data-file'), "_blank");
});
}
else if (mimeType.indexOf('audio') >= 0 && (RightClick.isAppAvailable(['audioplayer', 'music']))) {
var isReading = function () {
return (currentFile.find('.ioc').length === 1) && (currentFile.find('.ioc').css('display') !== 'none');
};

text = t(appName, 'Play/Pause');
icon = 'play';

onClick = function () {
if (!isReading()) {
currentFile.find('.filename .nametext').click();
}
};
}
else if (mimeType.indexOf('video') >= 0 && RightClick.isAppAvailable('audioplayer')) {
text = t(appName, 'Watch');
icon = 'play';
}
else if (currentFile.attr('data-type') === 'file') {
text = t(appName, 'Open file');
}

addNewOption('Open', icon, text, onClick, true, openSubOptions);

if (!$('#selectedActionsList').hasClass('hidden')) {
addNewOption('Check', 'category-enabled', t(appName, 'Select'), function () {
$(currentFile.find('input.selectCheckBox')).click();
});
}
}

for (var key in menu.find('li')) {
for (var key in menu.find('li:not(.hidden)')) {
if (!isNaN(key)) {
var li = $(menu.find('li')[key]);
var spans = $(li.find('span'));
Expand All @@ -157,8 +111,10 @@
setTimeout(function () {
currentFile.find('.action-menu').click();
$('.fileActionsMenu').css('visibility', 'hidden');
}, 250);
}, 100);

return options;
}, $('#app-content-files #fileList'));
}, $('#app-content-files #fileList'), function () {
$('.filesSelectMenu').css('visibility', 'visible');
});
})(window, jQuery, RightClick);
106 changes: 62 additions & 44 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ var RightClick = RightClick || {};
'use strict';

exports.appName = 'files_rightclick';

$.get(OC.generateUrl('/apps/files_rightclick/ajax/applications'), function (data) {
exports.availableApplications = data;
});

exports.isAppAvailable = function (appNames) {
if (!(appNames instanceof Array))
appNames = [appNames];

for (var i = 0; i < appNames.length; i++) {
if (exports.availableApplications.includes(appNames[i]))
return true;
}

return false;
exports.selectors = {
containerId: 'rightClickMenus',
detectorId: 'rightClickDetector',
menuId: 'rightClickMenu',
menuClass: 'rightClickMenu',
subMenuClass: 'rightClickSubMenu',
openedClass: 'rightClickOpened',
arrowClass: 'rightClickArrow',
};

// Object where all options are listed for one (sub)menu
Expand Down Expand Up @@ -67,7 +60,7 @@ var RightClick = RightClick || {};
return this.add(options, this.getNbrOfOptions());
};

// Generate all options html
// Generate all html options
this.generate = function () {
var ul = $('<ul>');

Expand Down Expand Up @@ -183,7 +176,7 @@ var RightClick = RightClick || {};

if (this.subOptions instanceof exports.Options && this.subOptions.getNbrOfOptions() > 0) {
var sub = $('<a>').append($('<span>').text('▶')
.css('padding-right', '10px')).addClass('rightClickArrow')
.css('padding-right', '10px')).addClass(exports.selectors.arrowClass)
.attr('style', 'width: auto; padding-right: 0px !important');

new exports.Menu(sub, this.subOptions, li).setAsSubMenu().setAlsoOnHover().setAlsoOnLeftClick();
Expand Down Expand Up @@ -226,24 +219,32 @@ var RightClick = RightClick || {};
return this.element !== undefined;
}

var onClick = function (event) {
var onClick = function (event, originalEvent) {
event.stopPropagation();
event.preventDefault();

if (originalEvent) {
event.clientX = originalEvent.clientX;
event.clientY = originalEvent.clientY;
}

var delimiter = $(this);
var context = menu.context;
var options = menu.options;
var params = menu.params;

if (menu.isSubMenu) {
if (!exports.closeAllSubMenus())
return false;
if (!exports.closeAllSubMenus()) {
return !exports.clean();
}
}
else if (!exports.closeAllMenus()) {
return !exports.clean();
}
else if (!exports.closeAllMenus())
return false;

if (menu.isOpened())
return false;
if (menu.isOpened()) {
return !exports.clean();
}

exports.prepare();

Expand All @@ -258,14 +259,17 @@ var RightClick = RightClick || {};
if (typeof options === "function")
options = options(event, context, delimiter);

if (options.getNbrOfOptions() === 0)
return;
if (options.getNbrOfOptions() === 0) {
return !exports.clean();
}

var className = exports.selectors.menuClass + ' bubble open';

menu.element = $('<div>', menu.isSubMenu ? {
'class': 'rightClick rightSubMenu bubble open'
'class': exports.selectord.subMenuClass + ' ' + className
} : {
'id': 'rightClickMenu',
'class': 'rightClick bubble open'
'id': exports.selectors.menuId,
'class': className
}).append(options.generate());

menu.element.appendTo(exports.container);
Expand Down Expand Up @@ -302,14 +306,14 @@ var RightClick = RightClick || {};
'top': top,
'left': left,
'right': 'auto',
'z-index': 10000
});

var optionsDisabled = options.isDisabled();

if (optionsDisabled)
menu.element.css('background-color', '#AAA');

menu.element.on('contextmenu', () => false);
menu.element.on('mouseleave', function (event) {
if (menu.isOpenedOnHover)
menu.close();
Expand Down Expand Up @@ -393,14 +397,11 @@ var RightClick = RightClick || {};
return true;
};

exports.isAMenuOpened = function (key) {
for (key; key < exports.menus.length; key++) {
exports.isAMenuOpened = function () {
for (var key = 0; key < exports.menus.length; key++) {
if (exports.menus[key].isOpened()) {
return true;
}
else {
return exports.isAMenuOpened(++key);
}
}

return false;
Expand All @@ -409,9 +410,10 @@ var RightClick = RightClick || {};
exports.prepare = function () {
if (!exports.isAMenuOpened()) {
$(window).on('resize', exports.closeAllMenus);
$('body').on('click contextmenu', exports.closeAllMenus);
$('body').addClass('rightClick-fixed');
$('body').addClass(exports.selectors.openedClass);
}

$('#' + exports.selectors.detectorId).css('display', 'block');
}

exports.onKeyUp = function (event) {
Expand All @@ -425,23 +427,39 @@ var RightClick = RightClick || {};
}

if (isEscape) {
var length = exports.menus.length;

if (length) {
if (exports.isAMenuOpened()) {
exports.closeAllMenus();

event.stopPropagation();
}
}
};

exports.clean = function () {
if (!exports.isAMenuOpened()) {
$(window).off('resize', exports.closeAllMenus);
$('body').off('click contextmenu', exports.closeAllMenus);
$('body').removeClass('rightClick-fixed');
$('body').removeClass(exports.selectors.openedClass);
$('#' + exports.selectors.detectorId).css('display', 'none');

document.onkeyup = exports.onKeyUp;
return true;
}

return false;
};

exports.container = $('<div id="rightClickContainer"></div>').appendTo('body');
exports.propagateRightClick = function (event) {
exports.closeAllMenus();
event.preventDefault();
event.stopPropagation();

$(document.elementFromPoint(event.clientX, event.clientY)).trigger('contextmenu', event);
}

exports.container = $('<div id="' + exports.selectors.containerId + '"></div>').appendTo('body');
exports.detector = $('<div id="' + exports.selectors.detectorId + '"></div>').appendTo('body');

exports.detector.on('click resize', exports.closeAllMenus);
exports.detector.on('contextmenu', exports.propagateRightClick);

document.onkeyup = exports.onKeyUp;
})(window, jQuery, RightClick);
17 changes: 0 additions & 17 deletions lib/Controller/AjaxController.php

This file was deleted.

0 comments on commit 8136195

Please sign in to comment.