diff options
author | Nastuzzi Samy <samy@nastuzzi.fr> | 2019-03-28 14:40:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-28 14:40:47 +0300 |
commit | 8136195d383b25d806898e200904cbc1a4420448 (patch) | |
tree | 83923b3cf9f4b7779d5c9b28a7f0ed0d83a25523 | |
parent | 736129eed0f19cb3df41ef2ed3d7f566649e5bc4 (diff) | |
parent | 42dbe16b9dd8e4377895dc0ad6dba3e993d9e1ef (diff) |
Merge pull request #55 from nextcloud/feature/stabilization-better-renderingv0.13.0
Stabilization and better rendering
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | appinfo/info.xml | 2 | ||||
-rw-r--r-- | appinfo/routes.php | 7 | ||||
-rw-r--r-- | css/app.css | 20 | ||||
-rw-r--r-- | js/files.js | 62 | ||||
-rw-r--r-- | js/script.js | 106 | ||||
-rw-r--r-- | lib/Controller/AjaxController.php | 17 |
7 files changed, 94 insertions, 125 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 325724d..9a2618e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/appinfo/info.xml b/appinfo/info.xml index 190f4cb..91663d4 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -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="samy@nastuzzi.fr" homepage="https://samy.nastuzzi.fr">NASTUZZI Samy</author> <namespace>FilesRightClick</namespace> diff --git a/appinfo/routes.php b/appinfo/routes.php deleted file mode 100644 index 0efddc1..0000000 --- a/appinfo/routes.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -return [ - 'routes' => [ - ['name' => 'ajax#applications', 'url' => '/ajax/applications', 'verb' => 'GET'], - ] -]; diff --git a/css/app.css b/css/app.css index f2fa564..fcbbc30 100644 --- a/css/app.css +++ b/css/app.css @@ -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; } diff --git a/js/files.js b/js/files.js index 0caf995..9f8d9f6 100644 --- a/js/files.js +++ b/js/files.js @@ -2,7 +2,7 @@ '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; } @@ -10,11 +10,11 @@ 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'); @@ -81,58 +81,12 @@ 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(); @@ -140,7 +94,7 @@ } } - 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')); @@ -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); diff --git a/js/script.js b/js/script.js index e5aab4a..036743a 100644 --- a/js/script.js +++ b/js/script.js @@ -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 @@ -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>'); @@ -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(); @@ -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(); @@ -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); @@ -302,7 +306,6 @@ var RightClick = RightClick || {}; 'top': top, 'left': left, 'right': 'auto', - 'z-index': 10000 }); var optionsDisabled = options.isDisabled(); @@ -310,6 +313,7 @@ var RightClick = RightClick || {}; if (optionsDisabled) menu.element.css('background-color', '#AAA'); + menu.element.on('contextmenu', () => false); menu.element.on('mouseleave', function (event) { if (menu.isOpenedOnHover) menu.close(); @@ -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; @@ -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) { @@ -425,10 +427,10 @@ var RightClick = RightClick || {}; } if (isEscape) { - var length = exports.menus.length; - - if (length) { + if (exports.isAMenuOpened()) { exports.closeAllMenus(); + + event.stopPropagation(); } } }; @@ -436,12 +438,28 @@ var RightClick = RightClick || {}; 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); diff --git a/lib/Controller/AjaxController.php b/lib/Controller/AjaxController.php deleted file mode 100644 index a984a00..0000000 --- a/lib/Controller/AjaxController.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -namespace OCA\FilesRightClick\Controller; - -use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\JSONResponse; - -class AjaxController extends Controller -{ - /** - * @NoAdminRequired - */ - public function applications() - { - return new JSONResponse(\OC_App::getEnabledApps()); - } -} |