@@ -56,102 +56,109 @@ class ContextMenuClass {
5656 }
5757
5858 rightClick() {
59+ $('[data-action="toggleMenu"]').on('mousedown', () => {
60+ event.preventDefault();
61+ this.showMenu(event);
62+ });
5963 $('#file_listing > tbody td').on('contextmenu', event => {
64+ this.showMenu(event);
65+ });
66+ }
6067
61- const parent = $(event.target).closest('tr');
62- const menu = $(this.makeMenu(parent));
68+ showMenu(event) {
69+ const parent = $(event.target).closest('tr');
70+ const menu = $(this.makeMenu(parent));
6371
64- if (parent.data('type') === 'disabled') return;
65- event.preventDefault();
72+ if (parent.data('type') === 'disabled') return;
73+ event.preventDefault();
74+
75+ $(menu).appendTo('body');
76+ $(menu).data('invokedOn', $(event.target)).show().css({
77+ position: 'absolute',
78+ left: event.pageX - 150,
79+ top: event.pageY,
80+ });
81+
82+ this.activeLine = parent;
83+ this.activeLine.addClass('active');
84+
85+ @can (' download-files' , $server )
86+ if (parent.data('type') === 'file') {
87+ $(menu).find('li[data-action="download"]').removeClass('hidden');
88+ }
89+ @endcan
90+
91+ @can (' compress-files' , $server )
92+ if (parent.data('type') === 'folder') {
93+ $(menu).find('li[data-action="compress"]').removeClass('hidden');
94+ }
95+ @endcan
96+
97+ @can (' decompress-files' , $server )
98+ if (_.without(['application/zip', 'application/gzip', 'application/x-gzip'], parent.data('mime')).length < 3) {
99+ $(menu).find('li[data-action="decompress"]').removeClass('hidden');
100+ }
101+ @endcan
102+
103+ // Handle Events
104+ const Actions = new ActionsClass(parent, menu);
105+ @can (' move-files' , $server )
106+ $(menu).find('li[data-action="move"]').unbind().on('click', e => {
107+ e.preventDefault();
108+ Actions.move();
109+ });
110+ @endcan
111+
112+ @can (' copy-files' , $server )
113+ $(menu).find('li[data-action="copy"]').unbind().on('click', e => {
114+ e.preventDefault();
115+ Actions.copy();
116+ });
117+ @endcan
118+
119+ @can (' move-files' , $server )
120+ $(menu).find('li[data-action="rename"]').unbind().on('click', e => {
121+ e.preventDefault();
122+ Actions.rename();
123+ });
124+ @endcan
125+
126+ @can (' compress-files' , $server )
127+ $(menu).find('li[data-action="compress"]').unbind().on('click', e => {
128+ e.preventDefault();
129+ Actions.compress();
130+ });
131+ @endcan
66132
67- $(menu).appendTo('body');
68- $(menu).data('invokedOn', $(event.target)).show().css({
69- position: 'absolute',
70- left: event.pageX,
71- top: event.pageY,
133+ @can (' decompress-files' , $server )
134+ $(menu).find('li[data-action="decompress"]').unbind().on('click', e => {
135+ e.preventDefault();
136+ Actions.decompress();
72137 });
138+ @endcan
73139
74- this.activeLine = parent;
75- this.activeLine.addClass('active');
76-
77- @can (' download-files' , $server )
78- if (parent.data('type') === 'file') {
79- $(menu).find('li[data-action="download"]').removeClass('hidden');
80- }
81- @endcan
82-
83- @can (' compress-files' , $server )
84- if (parent.data('type') === 'folder') {
85- $(menu).find('li[data-action="compress"]').removeClass('hidden');
86- }
87- @endcan
88-
89- @can (' decompress-files' , $server )
90- if (_.without(['application/zip', 'application/gzip', 'application/x-gzip'], parent.data('mime')).length < 3) {
91- $(menu).find('li[data-action="decompress"]').removeClass('hidden');
92- }
93- @endcan
94-
95- // Handle Events
96- const Actions = new ActionsClass(parent, menu);
97- @can (' move-files' , $server )
98- $(menu).find('li[data-action="move"]').unbind().on('click', e => {
99- e.preventDefault();
100- Actions.move();
101- });
102- @endcan
103-
104- @can (' copy-files' , $server )
105- $(menu).find('li[data-action="copy"]').unbind().on('click', e => {
106- e.preventDefault();
107- Actions.copy();
108- });
109- @endcan
110-
111- @can (' move-files' , $server )
112- $(menu).find('li[data-action="rename"]').unbind().on('click', e => {
113- e.preventDefault();
114- Actions.rename();
115- });
116- @endcan
117-
118- @can (' compress-files' , $server )
119- $(menu).find('li[data-action="compress"]').unbind().on('click', e => {
120- e.preventDefault();
121- Actions.compress();
122- });
123- @endcan
124-
125- @can (' decompress-files' , $server )
126- $(menu).find('li[data-action="decompress"]').unbind().on('click', e => {
127- e.preventDefault();
128- Actions.decompress();
129- });
130- @endcan
131-
132- @can (' create-files' , $server )
133- $(menu).find('li[data-action="folder"]').unbind().on('click', e => {
134- e.preventDefault();
135- Actions.folder();
136- });
137- @endcan
138-
139- @can (' download-files' , $server )
140- $(menu).find('li[data-action="download"]').unbind().on('click', e => {
141- e.preventDefault();
142- Actions.download();
143- });
144- @endcan
145-
146- $(menu).find('li[data-action="delete"]').unbind().on('click', e => {
140+ @can (' create-files' , $server )
141+ $(menu).find('li[data-action="folder"]').unbind().on('click', e => {
147142 e.preventDefault();
148- Actions.delete ();
143+ Actions.folder ();
149144 });
145+ @endcan
150146
151- $(window).on('click', () => {
152- $(menu).remove();
153- if(!_.isNull(this.activeLine)) this.activeLine.removeClass('active');
147+ @can (' download-files' , $server )
148+ $(menu).find('li[data-action="download"]').unbind().on('click', e => {
149+ e.preventDefault();
150+ Actions.download();
154151 });
152+ @endcan
153+
154+ $(menu).find('li[data-action="delete"]').unbind().on('click', e => {
155+ e.preventDefault();
156+ Actions.delete();
157+ });
158+
159+ $(window).on('click', () => {
160+ $(menu).remove();
161+ if(!_.isNull(this.activeLine)) this.activeLine.removeClass('active');
155162 });
156163 }
157164
0 commit comments