Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_rightclick.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNastuzziSamy <samy@nastuzzi.fr>2018-05-01 19:34:55 +0300
committerNastuzziSamy <samy@nastuzzi.fr>2018-05-01 19:51:14 +0300
commit313ad234ff846fe90d60d63e666da7a803f4cb60 (patch)
treecb99898c2b8c2649c0aafe94229c44b221b93845
parent87b577a2436679420b5f10ade96cc7e89b685499 (diff)
Optimization and js code is now strictv0.7.0
-rw-r--r--README.md1
-rw-r--r--appinfo/app.php29
-rw-r--r--appinfo/info.xml2
-rw-r--r--js/files.js19
-rw-r--r--js/script.js374
5 files changed, 218 insertions, 207 deletions
diff --git a/README.md b/README.md
index 4d539a9..c34fcc0 100644
--- a/README.md
+++ b/README.md
@@ -36,3 +36,4 @@
- [ ] Add a context menu in each icon apps
- [ ] Add sub menu compatibility in context menu
- [ ] Fork the app (with a different name) and allow any app to create its own context menu(s)
+- [ ] Backport to NC 12
diff --git a/appinfo/app.php b/appinfo/app.php
index 6648ef0..a06dfc7 100644
--- a/appinfo/app.php
+++ b/appinfo/app.php
@@ -1,18 +1,19 @@
<?php
- $eventDispatcher = \OC::$server->getEventDispatcher();
+$includes = [
+ 'Files' => 'files',
+ 'Files_Sharing' => 'files',
+];
- $eventDispatcher->addListener(
- 'OCA\Files::loadAdditionalScripts',
- function () {
- \OCP\Util::addScript('files_rightclick', 'script');
- }
- );
+\OCP\Util::addScript('files_rightclick', 'script');
- $eventDispatcher->addListener(
- 'OCA\Files_Sharing::loadAdditionalScripts',
- function () {
- \OCP\Util::addScript('files_rightclick', 'script');
- }
- );
-?>
+$eventDispatcher = \OC::$server->getEventDispatcher();
+
+foreach ($includes as $app => $include) {
+ $eventDispatcher->addListener(
+ 'OCA\\'.$app.'::loadAdditionalScripts',
+ function () use ($include) {
+ \OCP\Util::addScript('files_rightclick', $include);
+ }
+ );
+}
diff --git a/appinfo/info.xml b/appinfo/info.xml
index c51c86d..3e7c7f0 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,7 +5,7 @@
<name>Files Right Click</name>
<summary>Add a simple right click menu on the files Nextcloud app</summary>
<description><![CDATA[Not anymore useful to click on the 3 dots button to popup the file menu, now right click on a specific file where you want to access to its menu to simply show it.]]></description>
- <version>0.6.0</version>
+ <version>0.7.0</version>
<licence>AGPL</licence>
<author mail="samy@nastuzzi.fr" homepage="https://github.com/NastuzziSamy/files_rightclick.git">NASTUZZI Samy</author>
<namespace>FilesRightClick</namespace>
diff --git a/js/files.js b/js/files.js
new file mode 100644
index 0000000..9f216d8
--- /dev/null
+++ b/js/files.js
@@ -0,0 +1,19 @@
+var RightClick = RightClick || {};
+
+(function(window, $, RightClick, undefined) {
+ 'use strict';
+
+ var availableApplications = [];
+
+ $.get('/apps/files_rightclick/ajax/applications.php', function (data) {
+ try {
+ availableApplications = JSON.parse(data);
+ }
+ catch (error) {
+ availableApplications = [];
+ }
+ });
+
+ $('<style class="rightClickStyle"></style>').appendTo('head');
+ $('table[id*=filestable]').contextmenu(RightClick.openContextOnRightClick);
+})(window, jQuery, RightClick);
diff --git a/js/script.js b/js/script.js
index 81adb9b..291fc76 100644
--- a/js/script.js
+++ b/js/script.js
@@ -1,195 +1,185 @@
-var openContextOnRightClick = function (event) {
- if ($('tbody').has(event.target).length === 0)
- return;
+var RightClick = RightClick || {};
+
+(function(window, $, exports, undefined) {
+ 'use strict';
+
+ exports.openContextOnRightClick = function (event) {
+ if ($('tbody').has(event.target).length === 0)
+ return;
+
+ event.stopPropagation();
+ event.preventDefault();
+
+ var appName = 'files_rightclick';
+ var currentFile = $(event.target).closest('tr');
+ var leftToRemove = currentFile.find('.selection').width();
+
+ if (currentFile.find('.fileActionsMenu').length != 0) {
+ currentFile.find('.fileActionsMenu').remove();
+ currentFile.removeClass('mouseOver');
+ currentFile.removeClass('highlighted');
+ currentFile.find('.action-menu').removeClass('open');
+
+ return false;
+ }
+
+ setTimeout(function () {
+ if ($(event.target).parent().hasClass('fileactions') || $(event.target).parent().parent().hasClass('fileactions')) {
+ $(event.target).click();
+ return false;
+ }
+ else
+ currentFile.find('.action-menu').click();
+
+ var menu = currentFile.find('.fileActionsMenu');
+ var menuStyle = $('style.rightClickStyle');
+ var selectedActionsList = $('.selectedActions');
+ var top = (event.pageY - currentFile.offset().top + (currentFile.height() / 4));
+ var left = event.pageX - currentFile.offset().left - leftToRemove - (menu.width() / 2) - 4;
+ var generateNewOption = function (action, icon, text, onClick, prepend) {
+ if (prepend === undefined)
+ prepend = true;
+
+ var newOption = $('<li><a href="#" class="menuitem action permanent" data-action="' + action + '"><span class="icon icon-' + icon + '"></span><span>' + text + '</span></a></li>').on('click', function (event) {
+ event.stopPropagation();
+ event.preventDefault();
+
+ menu.remove();
+ currentFile.removeClass('mouseOver');
+ currentFile.removeClass('highlighted');
+ currentFile.find('.action-menu').removeClass('open');
+
+ onClick();
+ });
+
+ if (prepend) {
+ menu.find('ul').prepend(
+ newOption
+ );
+ }
+ else {
+ menu.find('ul').append(
+ newOption
+ );
+ }
+ };
+
+ menu.addClass('rightClickMenu');
+
+ if (left < (-leftToRemove)) {
+ left = (-leftToRemove);
+
+ if ((event.pageX - currentFile.offset().left) <= 11)
+ menuStyle.text('.fileActionsMenu.rightClickMenu{border-top-left-radius:0} .fileActionsMenu.rightClickMenu:after{left:0}');
+ else
+ menuStyle.text('.fileActionsMenu.rightClickMenu:after{transform:translateX(-50%);left:' + (event.pageX - currentFile.offset().left) + 'px}');
+ } else if (left + menu.width() + leftToRemove + 10 > currentFile.width()) {
+ left = currentFile.width() - leftToRemove - menu.width() - 10;
+
+ if ((event.pageX - currentFile.offset().left - leftToRemove - left) >= (menu.width() - 11))
+ menuStyle.text('.fileActionsMenu.rightClickMenu{border-top-right-radius:0} .fileActionsMenu.rightClickMenu:after{right:0}');
+ else
+ menuStyle.text('.fileActionsMenu.rightClickMenu:after{transform:translateX(-50%);left:' + (event.pageX - currentFile.offset().left - leftToRemove - left) + 'px}');
+ } else
+ menuStyle.text('.fileActionsMenu.rightClickMenu:after{transform:translateX(-50%);left:' + (menu.width() / 2) + 'px}');
+
+ menu.css({
+ right: 'auto',
+ top: top,
+ left: left
+ });
+
+ if (currentFile.hasClass('selected')) {
+ menu.find('ul').html('');
+
+ generateNewOption('Check', 'category-disabled', t(appName, 'Unselect'), function () {
+ $(currentFile.find('input.selectCheckBox')).click();
+ });
+
+ $.each(selectedActionsList, function (i, selectedActions) {
+ $.each($(selectedActions).find('a'), function (j, selectedAction) {
+ 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 () {
+ action.click()
+ }, false);
+ }
+ });
+ });
+ }
+ else {
+ var mimeType = currentFile.attr('data-mime');
+ var text = '';
+ var icon = 'toggle';
+ var onClick = function () {
+ currentFile.find('.filename .nametext').click();
+ };
+
+ 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 () {
+ share.click();
+ });
+ }
+
+ if (currentFile.attr('data-type') === 'dir') {
+ text = t(appName, 'Open folder');
+ icon = 'filetype-folder-drag-accept';
+
+ generateNewOption('Open', '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 && availableApplications.includes('gallery')) {
+ text = t(appName, 'See picture');
+
+ generateNewOption('Open', '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");
+ });
+ }
+ else if (mimeType.indexOf('audio') >= 0 && (availableApplications.includes('audioplayer') || availableApplications.includes('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 && availableApplications.includes('audioplayer')) {
+ text = t(appName, 'Watch');
+ icon = 'play';
+ }
+ else if (currentFile.attr('data-type') === 'file') {
+ text = t(appName, 'Open file');
+ }
+
+ if (text !== '') {
+ generateNewOption('Open', icon, text, onClick);
+ }
+
+ if (!$('#selectedActionsList').hasClass('hidden')) {
+ generateNewOption('Check', 'category-enabled', t(appName, 'Select'), function () {
+ $(currentFile.find('input.selectCheckBox')).click();
+ });
+ }
+ }
+ }, 200)
- event.stopPropagation();
- event.preventDefault();
-
- var appName = 'files_rightclick';
- var currentFile = $(event.target).closest('tr');
- var leftToRemove = currentFile.find('.selection').width();
-
- if (currentFile.find('.fileActionsMenu').length != 0) {
- currentFile.find('.fileActionsMenu').remove();
- currentFile.removeClass('mouseOver');
- currentFile.removeClass('highlighted');
- currentFile.find('.action-menu').removeClass('open');
-
- return false;
- }
-
- setTimeout(function () {
- if ($(event.target).parent().hasClass('fileactions') || $(event.target).parent().parent().hasClass('fileactions')) {
- $(event.target).click();
return false;
- }
- else
- currentFile.find('.action-menu').click();
-
- var menu = currentFile.find('.fileActionsMenu');
- var menuStyle = $('style.rightClickStyle');
- var selectedActionsList = $('.selectedActions');
- var top = (event.pageY - currentFile.offset().top + (currentFile.height() / 4));
- var left = event.pageX - currentFile.offset().left - leftToRemove - (menu.width() / 2) - 4;
- var generateNewOption = function (action, icon, text, onClick, prepend) {
- if (prepend === undefined)
- prepend = true;
-
- var newOption = $('<li><a href="#" class="menuitem action permanent" data-action="' + action + '"><span class="icon icon-' + icon + '"></span><span>' + text + '</span></a></li>').on('click', function (event) {
- event.stopPropagation();
- event.preventDefault();
-
- menu.remove();
- currentFile.removeClass('mouseOver');
- currentFile.removeClass('highlighted');
- currentFile.find('.action-menu').removeClass('open');
-
- onClick();
- });
-
- if (prepend) {
- menu.find('ul').prepend(
- newOption
- );
- }
- else {
- menu.find('ul').append(
- newOption
- );
- }
};
-
- menu.addClass('rightClickMenu');
-
- if (left < (-leftToRemove)) {
- right = menu.width();
- left = (-leftToRemove);
-
- if ((event.pageX - currentFile.offset().left) <= 11)
- menuStyle.text('.fileActionsMenu.rightClickMenu{border-top-left-radius:0} .fileActionsMenu.rightClickMenu:after{left:0}');
- else
- menuStyle.text('.fileActionsMenu.rightClickMenu:after{transform:translateX(-50%);left:' + (event.pageX - currentFile.offset().left) + 'px}');
- } else if (left + menu.width() + leftToRemove + 10 > currentFile.width()) {
- right = 0;
- left = currentFile.width() - leftToRemove - menu.width() - 10;
-
- if ((event.pageX - currentFile.offset().left - leftToRemove - left) >= (menu.width() - 11))
- menuStyle.text('.fileActionsMenu.rightClickMenu{border-top-right-radius:0} .fileActionsMenu.rightClickMenu:after{right:0}');
- else
- menuStyle.text('.fileActionsMenu.rightClickMenu:after{transform:translateX(-50%);left:' + (event.pageX - currentFile.offset().left - leftToRemove - left) + 'px}');
- } else
- menuStyle.text('.fileActionsMenu.rightClickMenu:after{transform:translateX(-50%);left:' + (menu.width() / 2) + 'px}');
-
- menu.css({
- right: 'auto',
- top: top,
- left: left
- });
-
- if (currentFile.hasClass('selected')) {
- menu.find('ul').html('');
-
- generateNewOption('Check', 'category-disabled', t(appName, 'Unselect'), function () {
- $(currentFile.find('input.selectCheckBox')).click();
- });
-
- $.each(selectedActionsList, function (i, selectedActions) {
- $.each($(selectedActions).find('a'), function (j, selectedAction) {
- 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 () {
- action.click()
- }, false);
- }
- });
- });
- }
- else {
- var mimeType = currentFile.attr('data-mime');
- var text = '';
- var icon = 'toggle';
- var onClick = function () {
- currentFile.find('.filename .nametext').click();
- };
-
- 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 () {
- share.click();
- });
- }
-
- if (currentFile.attr('data-type') === 'dir') {
- text = t(appName, 'Open folder');
- icon = 'filetype-folder-drag-accept';
-
- generateNewOption('Open', '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 && availableApplications.includes('gallery')) {
- text = t(appName, 'See picture');
-
- generateNewOption('Open', '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");
- });
- }
- else if (mimeType.indexOf('audio') >= 0 && (availableApplications.includes('audioplayer') || availableApplications.includes('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 && availableApplications.includes('audioplayer')) {
- text = t(appName, 'Watch');
- icon = 'play';
- }
- else if (currentFile.attr('data-type') === 'file') {
- text = t(appName, 'Open file');
- }
-
- if (text !== '') {
- generateNewOption('Open', icon, text, onClick);
- }
-
- if (!$('#selectedActionsList').hasClass('hidden')) {
- generateNewOption('Check', 'category-enabled', t(appName, 'Select'), function () {
- $(currentFile.find('input.selectCheckBox')).click();
- });
- }
- }
- }, 200)
-
- return false;
-};
-
-var availableApplications = [];
-
-$.get('/apps/files_rightclick/ajax/applications.php', function (data) {
- try {
- availableApplications = JSON.parse(data);
- }
- catch (error) {
- availableApplications = [];
- }
-});
-
-$('<style class="rightClickStyle"></style>').appendTo('head');
-$('table[id*=filestable]').contextmenu(openContextOnRightClick);
+})(window, jQuery, RightClick);