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

Commit

Permalink
Add submenu compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
NastuzziSamy committed May 4, 2018
1 parent 159ea38 commit fbb9eca
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 91 deletions.
78 changes: 41 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,57 @@
- [x] Create a context menu generator
- [ ] Add a context menu to create files or directories
- [ ] Add a context menu in each icon apps
- [ ] Add sub menu compatibility in context menu
- [x] Add sub menu compatibility in context menu
- [ ] Publish a new app (with a different name) and allow any app to create its own context menu(s)
- [ ] Backport to NC 12

# Changelogs
## v0.8.0
- Creation of an object to create simple menus (avalaible for any apps):
- RightClick.Option create an option for a menu with an icon, a text and an onClick function
- RightClick.Options regroup given options for a menu
- RightClick.Menu allow to create a menu object applied to a delimited area
- The next version will allow to have submenus
- Add changelogs https://github.com/NastuzziSamy/files_rightclick/issues/16
### v0.8.1
- Add submenu compatibility
- Optimizations and bugs fixed

## v0.7.0
- Add TODO list
- Optimizations
- Set the NC compatibility to v13 and above https://github.com/NastuzziSamy/files_rightclick/issues/14
### v0.8.0
- Creation of an object to create simple menus (avalaible for any apps):
- RightClick.Option create an option for a menu with an icon, a text and an onClick function
- RightClick.Options regroup given options for a menu
- RightClick.Menu allow to create a menu object applied to a delimited area
- The next version will allow to have submenus
- Add changelogs https://github.com/NastuzziSamy/files_rightclick/issues/16

## v0.6.1
- Add russian translation (thanks to @zorn)
### v0.7.0
- Add TODO list
- Optimizations
- Set the NC compatibility to v13 and above https://github.com/NastuzziSamy/files_rightclick/issues/14

## v0.6.0
- Can now recognized available apps
- Bug fixed:
- Correct loop of death caused by audioplayer incompatibily (now fixed) https://github.com/NastuzziSamy/files_rightclick/issues/10
### v0.6.1
- Add russian translation (thanks to @zorn)

## v0.5.3
- Bugs fixed:
- Share icon didn't show https://github.com/NastuzziSamy/files_rightclick/issues/12
- Right click context fixed
### v0.6.0
- Can now recognized available apps
- Bug fixed:
- Correct loop of death caused by audioplayer incompatibily (now fixed) https://github.com/NastuzziSamy/files_rightclick/issues/10

### v0.5.3
- Bugs fixed:
- Share icon didn't show https://github.com/NastuzziSamy/files_rightclick/issues/12
- Right click context fixed

## v0.5.2
- German text updated (thanks to @worldworm)
- Right click context changed
- German text updated (thanks to @worldworm)
- Right click context changed

## v0.5.1
- Text shortened https://github.com/NastuzziSamy/files_rightclick/issues/9
### v0.5.1
- Text shortened https://github.com/NastuzziSamy/files_rightclick/issues/9

## v0.5.0
- Add portuguese brazil translation (thanks to @darioems)
- Add german translation (thanks to @worldworm)
- Add (un)select options
- Bugs fixed:
- Copy/Move options https://github.com/NastuzziSamy/files_rightclick/issues/5
- Right click menu didn't show when the file was shared by link
### v0.5.0
- Add portuguese brazil translation (thanks to @darioems)
- Add german translation (thanks to @worldworm)
- Add (un)select options
- Bugs fixed:
- Copy/Move options https://github.com/NastuzziSamy/files_rightclick/issues/5
- Right click menu didn't show when the file was shared by link

## v0.4.0
- First release in the NC appstore
- Add right click on files
- Add custom options for each type of file
### v0.4.0
- First release in the NC appstore
- Add right click on files
- Add custom options for each type of file
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>Files Right Click</name>
<summary>Add a rightclick menu generator for any Nextcloud apps</summary>
<description><![CDATA[This app will allow users but also developers to have a right click menu. Simply use the RightClick object to create quickly and easly menus. Already files app got a right click menu]]></description>
<version>0.8.0</version>
<version>0.8.1</version>
<licence>AGPL</licence>
<author mail="samy@nastuzzi.fr" homepage="https://github.com/NastuzziSamy/files_rightclick.git">NASTUZZI Samy</author>
<namespace>FilesRightClick</namespace>
Expand Down
43 changes: 29 additions & 14 deletions js/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ var RightClick = RightClick || {};
new RightClick.Menu($('tbody[id*=fileList]'), function (event, currentFile, delimiter) {
var appName = 'files_rightclick';
var options = new RightClick.Options();
var openSubOptions = new RightClick.Options();

currentFile.find('.action-menu').click();

var menu = currentFile.find('.fileActionsMenu');
var menuStyle = $('style.rightClickStyle');
var selectedActionsList = $('.selectedActions');
var generateNewOption = function (action, icon, text, onClick, prepend) {
if (prepend === undefined)
prepend = true;

var option = new RightClick.Option(action, text, 'icon icon-' + icon, function (event) {
var generateNewOption = function (action, icon, text, onClick, prepend, subOptions) {
return new RightClick.Option(action, text, 'icon-' + icon, onClick ? function (event, context) {
event.stopPropagation();
event.preventDefault();

Expand All @@ -41,21 +39,38 @@ var RightClick = RightClick || {};
currentFile.removeClass('highlighted');
currentFile.find('.action-menu').removeClass('open');

onClick();
});
onClick(event, context);
} : undefined, subOptions);
};
var addNewOption = function (action, icon, text, onClick, prepend, subOptions) {
if (prepend === undefined)
prepend = true;

var option = generateNewOption(action, icon, text, onClick, prepend, subOptions);

if (prepend)
options.prepend(option);
else
options.append(option);
};
var addNewOpenSubOption = function (action, icon, text, onClick, prepend, subOptions) {
if (prepend === undefined)
prepend = true;

var option = generateNewOption(action, icon, text, onClick, prepend, subOptions);

if (prepend)
openSubOptions.prepend(option);
else
openSubOptions.append(option);
};

menu.css('visibility', 'hidden');

if (currentFile.hasClass('selected')) {
menu.find('ul').html('');

generateNewOption('Check', 'category-disabled', t(appName, 'Unselect'), function () {
addNewOption('Check', 'category-disabled', t(appName, 'Unselect'), function () {
$(currentFile.find('input.selectCheckBox')).click();
});

Expand All @@ -64,7 +79,7 @@ var RightClick = RightClick || {};
var action = $(selectedAction);

if (action.is(":visible")) {
generateNewOption(action.attr('class'), $(action.find('span.icon')).attr('class').replace('icon', '').replace(' ', '').replace('icon-', ''), $(action.find('span:not(.icon)')).text(), function () {
addNewOption(action.attr('class'), $(action.find('span.icon')).attr('class').replace('icon', '').replace(' ', '').replace('icon-', ''), $(action.find('span:not(.icon)')).text(), function () {
action.click()
}, false);
}
Expand All @@ -82,7 +97,7 @@ var RightClick = RightClick || {};
var share = currentFile.find('.filename .fileactions .action-share');

if (share.length !== 0) {
generateNewOption('Share', 'share', t(appName, 'Share ' + (currentFile.attr('data-type') === 'dir' ? 'folder' : 'file')), function () {
addNewOption('Share', 'share', t(appName, 'Share ' + (currentFile.attr('data-type') === 'dir' ? 'folder' : 'file')), function () {
share.click();
});
}
Expand All @@ -91,7 +106,7 @@ var RightClick = RightClick || {};
text = t(appName, 'Open folder');
icon = 'filetype-folder-drag-accept';

generateNewOption('NewTab', 'category-app-bundles', t(appName, 'Open in new tab'), function () {
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");
});
}
Expand All @@ -105,7 +120,7 @@ var RightClick = RightClick || {};
else if (mimeType.indexOf('image') >= 0 && availableApplications.includes('gallery')) {
text = t(appName, 'See picture');

generateNewOption('Gallery', 'category-multimedia', t(appName, 'Open in Gallery'), function () {
addNewOpenSubOption('Gallery', 'category-multimedia', t(appName, 'Open in Gallery'), function () {
window.open('/apps/gallery' + currentFile.attr('data-path').replace('/', '/#') + (currentFile.attr('data-path') === '/' ? '' : '/') + currentFile.attr('data-file'), "_blank");
});
}
Expand All @@ -132,11 +147,11 @@ var RightClick = RightClick || {};
}

if (text !== '') {
generateNewOption('Open', icon, text, onClick);
addNewOption('Open', icon, text, onClick, true, openSubOptions);
}

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

0 comments on commit fbb9eca

Please sign in to comment.