From 0d583ea34144270053b7006d29cf57e89cdba48b Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sat, 11 Jul 2015 14:39:09 +0200 Subject: [PATCH] Updated contextMenu.js (ES2015) --- dist/main.js | Bin 179680 -> 179967 bytes src/scripts/contextMenu.js | 268 ++++++++++++++++++------------------- 2 files changed, 130 insertions(+), 138 deletions(-) diff --git a/dist/main.js b/dist/main.js index e9c3526864b2f98ea30a62dc730d5655f0217d8e..5161103574d1037f85f380ea40f35904554ba65b 100644 GIT binary patch delta 1067 zcmchWPe_w-7{~c;k}#%D5}hT?z17%gylUB{<;YuPyF`T`i{|#~R@?i^_D(3L{W(M@ z!P7$+L>IeS6mJ(vXjrB69W)({Xdh`%&)RaKu9*5kDCsP7P>&lNF zY~X-dCRPlHLGCbfqRST;cQTH0E#NcvaTbd}GYPa)df@1Gb)Gz8U>;UOrfQ&3RNr9x=)8#UL@O>^zgp+iJes1dfa;>Q}@Uf$<<;Q9T3&*~p8@|$aa zju$;N_8nRJbPp;M=-X!;Bx?|7s3V9*eJO}Lpsrqo^_D&;pv8W;IGfAvb4za7(?~Z% z5U8&gx%6lNon#$^pCV^XN#vM8;dxDpwR+8FO;UaCvLj}*kT1zLhf`QDi48v0!4ypu zn5C`N=E>DcnN#tKN-57 zPNjhfWP6J|%6STodis$>Unj8F;NMSAhOv+ChfzWw2BOu~VWe)7W_o1i^QgJ&R9k>) za0Ue_aUg6HBvoXRLsOZ2on0^p45|`?DL->N5{pO5jvqAmHlnn&QPT)=pi;*O__eJg zBe+QAqo^htMH3~D;Swohc&8tKk0k7Ac4|zMyfUj{HV?IjP(ZEYI7Hp!a8XJKb<`5V z098)lH6>2sb^>p;ttn9G%_R6VW&6GgEluJm)vX{^ub9FKQ2R7)5N7ZxJI?k0H77?s z#>8%wo%XM6dN7Nkg0S0qDITJU^)w<6SQ+KnnKeYYH4^b8c*Rou29!J z{CfIF9dza`aa}a2g3# bj(hnF-EE}FrXBjj7E@#FPv^X*pXdGp6k$=E diff --git a/src/scripts/contextMenu.js b/src/scripts/contextMenu.js index 7648ecc..255f9ea 100644 --- a/src/scripts/contextMenu.js +++ b/src/scripts/contextMenu.js @@ -7,37 +7,37 @@ contextMenu = {} contextMenu.add = function(e) { - var items = [ - { type: 'item', title: build.iconic('image') + 'Upload Photo', fn: function() { $('#upload_files').click() } }, + let items = [ + { type: 'item', title: build.iconic('image') + 'Upload Photo', fn: () => $('#upload_files').click() }, { type: 'separator' }, { type: 'item', title: build.iconic('link-intact') + 'Import from Link', fn: upload.start.url }, { type: 'item', title: build.iconic('dropbox', 'ionicons') + 'Import from Dropbox', fn: upload.start.dropbox }, { type: 'item', title: build.iconic('terminal') + 'Import from Server', fn: upload.start.server }, { type: 'separator' }, { type: 'item', title: build.iconic('folder') + 'New Album', fn: album.add } - ]; + ] - basicContext.show(items, e.originalEvent); + basicContext.show(items, e.originalEvent) - upload.notify(); + upload.notify() } contextMenu.settings = function(e) { - var items = [ + let items = [ { type: 'item', title: build.iconic('person') + 'Change Login', fn: settings.setLogin }, { type: 'item', title: build.iconic('sort-ascending') + 'Change Sorting', fn: settings.setSorting }, { type: 'item', title: build.iconic('dropbox', 'ionicons') + 'Set Dropbox', fn: settings.setDropboxKey }, { type: 'separator' }, - { type: 'item', title: build.iconic('info') + 'About Lychee', fn: function() { window.open(lychee.website) } }, - { type: 'item', title: build.iconic('wrench') + 'Diagnostics', fn: function() { window.open('plugins/check/') } }, - { type: 'item', title: build.iconic('align-left') + 'Show Log', fn: function() { window.open('plugins/displaylog/') } }, + { type: 'item', title: build.iconic('info') + 'About Lychee', fn: () => window.open(lychee.website) }, + { type: 'item', title: build.iconic('wrench') + 'Diagnostics', fn: () => window.open('plugins/check/') }, + { type: 'item', title: build.iconic('align-left') + 'Show Log', fn: () => window.open('plugins/displaylog/') }, { type: 'separator' }, { type: 'item', title: build.iconic('account-logout') + 'Sign Out', fn: lychee.logout } - ]; + ] - basicContext.show(items, e.originalEvent); + basicContext.show(items, e.originalEvent) } @@ -47,107 +47,103 @@ contextMenu.album = function(albumID, e) { // fn must call basicContext.close() first, // in order to keep the selection - if (albumID==='0'||albumID==='f'||albumID==='s'||albumID==='r') return false; + if (albumID==='0' || albumID==='f' || albumID==='s' || albumID==='r') return false // Show merge-item when there's more than one album - var showMerge = (albums.json && albums.json.albums && Object.keys(albums.json.albums).length>1); + let showMerge = (albums.json && albums.json.albums && Object.keys(albums.json.albums).length>1) - var items = [ - { type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { album.setTitle([albumID]) } }, - { type: 'item', title: build.iconic('collapse-left') + 'Merge', visible: showMerge, fn: function () { basicContext.close(); contextMenu.mergeAlbum(albumID, e) } }, - { type: 'item', title: build.iconic('trash') + 'Delete', fn: function() { album.delete([albumID]) } } - ]; + let items = [ + { type: 'item', title: build.iconic('pencil') + 'Rename', fn: () => album.setTitle([albumID]) }, + { type: 'item', title: build.iconic('collapse-left') + 'Merge', visible: showMerge, fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumID, e) } }, + { type: 'item', title: build.iconic('trash') + 'Delete', fn: () => album.delete([albumID]) } + ] - $('.album[data-id="' + albumID + '"]').addClass('active'); + $('.album[data-id="' + albumID + '"]').addClass('active') - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) } contextMenu.albumMulti = function(albumIDs, e) { - multiselect.stopResize(); + multiselect.stopResize() // Automatically merge selected albums when albumIDs contains more than one album // Show list of albums otherwise - var autoMerge = (albumIDs.length>1 ? true : false); + let autoMerge = (albumIDs.length>1 ? true : false) // Show merge-item when there's more than one album - var showMerge = (albums.json && albums.json.albums && Object.keys(albums.json.albums).length>1); + let showMerge = (albums.json && albums.json.albums && Object.keys(albums.json.albums).length>1) - var items = [ - { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { album.setTitle(albumIDs) } }, - { type: 'item', title: build.iconic('collapse-left') + 'Merge All', visible: showMerge && autoMerge, fn: function () { album.merge(albumIDs) } }, - { type: 'item', title: build.iconic('collapse-left') + 'Merge', visible: showMerge && !autoMerge, fn: function () { basicContext.close(); contextMenu.mergeAlbum(albumIDs[0], e) } }, - { type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { album.delete(albumIDs) } } - ]; + let items = [ + { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: () => album.setTitle(albumIDs) }, + { type: 'item', title: build.iconic('collapse-left') + 'Merge All', visible: showMerge && autoMerge, fn: () => album.merge(albumIDs) }, + { type: 'item', title: build.iconic('collapse-left') + 'Merge', visible: showMerge && !autoMerge, fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumIDs[0], e) } }, + { type: 'item', title: build.iconic('trash') + 'Delete All', fn: () => album.delete(albumIDs) } + ] - items.push(); + items.push() - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) } contextMenu.albumTitle = function(albumID, e) { - var items = []; - api.post('Album::getAll', {}, function(data) { - if (data.albums&&data.num>1) { + let items = [] + + if (data.albums && data.num>1) { // Generate list of albums - $.each(data.albums, function(index) { + $.each(data.albums, function() { - var that = this, - title = ''; + if (!this.thumbs[0]) this.thumbs[0] = 'src/images/no_cover.svg' - if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg'; + let title = `
${ this.title }
` - title = "
" + that.title + "
"; + if (this.id!=albumID) items.push({ type: 'item', title, fn: () => lychee.goto(this.id) }) - if (that.id!=albumID) items.push({ type: 'item', title, fn: function() { lychee.goto(that.id) } }); + }) - }); - - items.unshift({ type: 'separator' }); + items.unshift({ type: 'separator' }) } - items.unshift({ type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { album.setTitle([albumID]) } }); + items.unshift({ type: 'item', title: build.iconic('pencil') + 'Rename', fn: () => album.setTitle([albumID]) }) - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) - }); + }) } contextMenu.mergeAlbum = function(albumID, e) { - var items = []; - api.post('Album::getAll', {}, function(data) { - if (data.albums&&data.num>1) { + let items = [] - $.each(data.albums, function(){ + if (data.albums && data.num>1) { - var that = this; + $.each(data.albums, function() { - if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg'; - that.contextTitle = "
" + that.title + "
"; + if (!this.thumbs[0]) this.thumbs[0] = 'src/images/no_cover.svg' - if (that.id!=albumID) items.push({ type: 'item', title: that.contextTitle, fn: function() { album.merge([albumID, that.id]) } }); + let title = `
${ this.title }
` - }); + if (this.id!=albumID) items.push({ type: 'item', title, fn: () => album.merge([albumID, this.id]) }) + + }) } - if (items.length===0) return false; + if (items.length===0) return false - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) - }); + }) } @@ -157,19 +153,19 @@ contextMenu.photo = function(photoID, e) { // fn must call basicContext.close() first, // in order to keep the selection - var items = [ - { type: 'item', title: build.iconic('star') + 'Star', fn: function() { photo.setStar([photoID]) } }, - { type: 'item', title: build.iconic('tag') + 'Tags', fn: function() { photo.editTags([photoID]) } }, + let items = [ + { type: 'item', title: build.iconic('star') + 'Star', fn: () => photo.setStar([photoID]) }, + { type: 'item', title: build.iconic('tag') + 'Tags', fn: () => photo.editTags([photoID]) }, { type: 'separator' }, - { type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { photo.setTitle([photoID]) } }, - { type: 'item', title: build.iconic('layers') + 'Duplicate', fn: function() { photo.duplicate([photoID]) } }, - { type: 'item', title: build.iconic('folder') + 'Move', fn: function() { basicContext.close(); contextMenu.move([photoID], e); } }, - { type: 'item', title: build.iconic('trash') + 'Delete', fn: function() { photo.delete([photoID]) } } - ]; + { type: 'item', title: build.iconic('pencil') + 'Rename', fn: () => photo.setTitle([photoID]) }, + { type: 'item', title: build.iconic('layers') + 'Duplicate', fn: () => photo.duplicate([photoID]) }, + { type: 'item', title: build.iconic('folder') + 'Move', fn: () => { basicContext.close(); contextMenu.move([photoID], e) } }, + { type: 'item', title: build.iconic('trash') + 'Delete', fn: () => photo.delete([photoID]) } + ] - $('.photo[data-id="' + photoID + '"]').addClass('active'); + $('.photo[data-id="' + photoID + '"]').addClass('active') - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) } @@ -179,49 +175,46 @@ contextMenu.photoMulti = function(photoIDs, e) { // fn must call basicContext.close() first, // in order to keep the selection and multiselect - multiselect.stopResize(); + multiselect.stopResize() - var items = [ - { type: 'item', title: build.iconic('star') + 'Star All', fn: function() { photo.setStar(photoIDs) } }, - { type: 'item', title: build.iconic('tag') + 'Tag All', fn: function() { photo.editTags(photoIDs) } }, + let items = [ + { type: 'item', title: build.iconic('star') + 'Star All', fn: () => photo.setStar(photoIDs) }, + { type: 'item', title: build.iconic('tag') + 'Tag All', fn: () => photo.editTags(photoIDs) }, { type: 'separator' }, - { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { photo.setTitle(photoIDs) } }, - { type: 'item', title: build.iconic('layers') + 'Duplicate All', fn: function() { photo.duplicate(photoIDs) } }, - { type: 'item', title: build.iconic('folder') + 'Move All', fn: function() { basicContext.close(); contextMenu.move(photoIDs, e); } }, - { type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { photo.delete(photoIDs) } } - ]; + { type: 'item', title: build.iconic('pencil') + 'Rename All', fn: () => photo.setTitle(photoIDs) }, + { type: 'item', title: build.iconic('layers') + 'Duplicate All', fn: () => photo.duplicate(photoIDs) }, + { type: 'item', title: build.iconic('folder') + 'Move All', fn: () => { basicContext.close(); contextMenu.move(photoIDs, e) } }, + { type: 'item', title: build.iconic('trash') + 'Delete All', fn: () => photo.delete(photoIDs) } + ] - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) } contextMenu.photoTitle = function(albumID, photoID, e) { - var items = [ - { type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { photo.setTitle([photoID]) } } - ]; + let items = [ + { type: 'item', title: build.iconic('pencil') + 'Rename', fn: () => photo.setTitle([photoID]) } + ] - var data = album.json; + let data = album.json - if (data.content!==false&&data.num>1) { + if (data.content!==false && data.num>1) { - items.push({ type: 'separator' }); + items.push({ type: 'separator' }) // Generate list of albums $.each(data.content, function(index) { - var that = this, - title = ''; + let title = `
${ this.title }
` - title = "
" + that.title + "
"; + if (this.id!=photoID) items.push({ type: 'item', title, fn: () => lychee.goto(albumID + '/' + this.id) }) - if (that.id!=photoID) items.push({ type: 'item', title, fn: function() { lychee.goto(albumID + '/' + that.id) } }); - - }); + }) } - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) } @@ -230,20 +223,20 @@ contextMenu.photoMore = function(photoID, e) { // Show download-item when // a) Public mode is off // b) Downloadable is 1 and public mode is on - var showDownload = lychee.publicMode===false || ((album.json && album.json.downloadable && album.json.downloadable==='1') && lychee.publicMode===true); + let showDownload = lychee.publicMode===false || ((album.json && album.json.downloadable && album.json.downloadable==='1') && lychee.publicMode===true) - var items = [ - { type: 'item', title: build.iconic('fullscreen-enter') + 'Full Photo', fn: function() { window.open(photo.getDirectLink()) } }, - { type: 'item', title: build.iconic('cloud-download') + 'Download', visible: showDownload, fn: function() { photo.getArchive(photoID) } } - ]; + let items = [ + { type: 'item', title: build.iconic('fullscreen-enter') + 'Full Photo', fn: () => window.open(photo.getDirectLink()) }, + { type: 'item', title: build.iconic('cloud-download') + 'Download', visible: showDownload, fn: () => photo.getArchive(photoID) } + ] - basicContext.show(items, e.originalEvent); + basicContext.show(items, e.originalEvent) } contextMenu.move = function(photoIDs, e) { - var items = []; + var items = [] api.post('Album::getAll', {}, function(data) { @@ -252,89 +245,88 @@ contextMenu.move = function(photoIDs, e) { // Show only 'Add album' when no album available items = [ { type: 'item', title: 'New Album', fn: album.add } - ]; + ] } else { // Generate list of albums - $.each(data.albums, function(index) { + $.each(data.albums, function() { - var that = this; + if (!this.thumbs[0]) this.thumbs[0] = 'src/images/no_cover.svg' - if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg'; - that.title = "
" + that.title + "
"; + let title = `
${ this.title }
` - if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum(photoIDs, that.id) } }); + if (this.id!=album.getID()) items.push({ type: 'item', title, fn: () => photo.setAlbum(photoIDs, this.id) }) - }); + }) // Show Unsorted when unsorted is not the current album if (album.getID()!=='0') { - items.unshift({ type: 'separator' }); - items.unshift({ type: 'item', title: 'Unsorted', fn: function() { photo.setAlbum(photoIDs, 0) } }); + items.unshift({ type: 'separator' }) + items.unshift({ type: 'item', title: 'Unsorted', fn: () => photo.setAlbum(photoIDs, 0) }) } } - basicContext.show(items, e.originalEvent, contextMenu.close); + basicContext.show(items, e.originalEvent, contextMenu.close) - }); + }) } contextMenu.sharePhoto = function(photoID, e) { - var link = photo.getViewLink(photoID), - iconClass = 'ionicons'; + let link = photo.getViewLink(photoID), + iconClass = 'ionicons' - if (photo.json.public==='2') link = location.href; + if (photo.json.public==='2') link = location.href - var items = [ - { type: 'item', title: '', fn: function() {}, class: 'noHover' }, + let items = [ + { type: 'item', title: ``, fn: () => {}, class: 'noHover' }, { type: 'separator' }, - { type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: function() { photo.share(photoID, 0) } }, - { type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: function() { photo.share(photoID, 1) } }, - { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: function() { photo.share(photoID, 2) } }, - { type: 'item', title: build.iconic('dropbox', iconClass) + 'Dropbox', fn: function() { photo.share(photoID, 3) } }, - { type: 'item', title: build.iconic('link-intact') + 'Direct Link', fn: function() { window.open(photo.getDirectLink()) } }, + { type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: () => photo.share(photoID, 0) }, + { type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: () => photo.share(photoID, 1) }, + { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: () => photo.share(photoID, 2) }, + { type: 'item', title: build.iconic('dropbox', iconClass) + 'Dropbox', fn: () => photo.share(photoID, 3) }, + { type: 'item', title: build.iconic('link-intact') + 'Direct Link', fn: () => window.open(photo.getDirectLink()) }, { type: 'separator' }, - { type: 'item', title: build.iconic('ban') + 'Make Private', fn: function() { photo.setPublic(photoID) } } - ]; + { type: 'item', title: build.iconic('ban') + 'Make Private', fn: () => photo.setPublic(photoID) } + ] - basicContext.show(items, e.originalEvent); - $('.basicContext input#link').focus().select(); + basicContext.show(items, e.originalEvent) + $('.basicContext input#link').focus().select() } contextMenu.shareAlbum = function(albumID, e) { - var iconClass = 'ionicons'; + let iconClass = 'ionicons' - var items = [ - { type: 'item', title: '', fn: function() {}, class: 'noHover' }, + let items = [ + { type: 'item', title: ``, fn: () => {}, class: 'noHover' }, { type: 'separator' }, - { type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: function() { album.share('twitter') } }, - { type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: function() { album.share('facebook') } }, - { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: function() { album.share('mail') } }, + { type: 'item', title: build.iconic('twitter', iconClass) + 'Twitter', fn: () => album.share('twitter') }, + { type: 'item', title: build.iconic('facebook', iconClass) + 'Facebook', fn: () => album.share('facebook') }, + { type: 'item', title: build.iconic('envelope-closed') + 'Mail', fn: () => album.share('mail') }, { type: 'separator' }, - { type: 'item', title: build.iconic('pencil') + 'Edit Sharing', fn: function() { album.setPublic(albumID, true, e) } }, - { type: 'item', title: build.iconic('ban') + 'Make Private', fn: function() { album.setPublic(albumID, false) } } - ]; + { type: 'item', title: build.iconic('pencil') + 'Edit Sharing', fn: () => album.setPublic(albumID, true, e) }, + { type: 'item', title: build.iconic('ban') + 'Make Private', fn: () => album.setPublic(albumID, false) } + ] - basicContext.show(items, e.originalEvent); - $('.basicContext input#link').focus().select(); + basicContext.show(items, e.originalEvent) + $('.basicContext input#link').focus().select() } contextMenu.close = function() { - if (!visible.contextMenu()) return false; + if (!visible.contextMenu()) return false - basicContext.close(); + basicContext.close() - $('.photo.active, .album.active').removeClass('active'); - if (visible.multiselect()) multiselect.close(); + $('.photo.active, .album.active').removeClass('active') + if (visible.multiselect()) multiselect.close() } \ No newline at end of file