Switch to basicContext

This commit is contained in:
Tobias Reich 2014-11-01 23:58:01 +01:00
parent 94e40d24bd
commit 2bfa6e4fe1
3 changed files with 163 additions and 318 deletions

View File

@ -5,260 +5,171 @@
contextMenu = { contextMenu = {
fns: null,
show: function(items, mouse_x, mouse_y, orientation) {
contextMenu.close();
$("body")
.css("overflow", "hidden")
.append(build.contextMenu(items));
// Do not leave the screen
if ((mouse_x+$(".contextmenu").outerWidth(true))>$("html").width()) orientation = "left";
if ((mouse_y+$(".contextmenu").outerHeight(true))>$("html").height()) mouse_y -= (mouse_y+$(".contextmenu").outerHeight(true)-$("html").height());
if (mouse_x>$(document).width()) mouse_x = $(document).width();
if (mouse_x<0) mouse_x = 0;
if (mouse_y>$(document).height()) mouse_y = $(document).height();
if (mouse_y<0) mouse_y = 0;
if (orientation==="left") mouse_x -= $(".contextmenu").outerWidth(true);
if (mouse_x===null||
mouse_x===undefined||
isNaN(mouse_x)||
mouse_y===null||
mouse_y===undefined||
isNaN(mouse_y)) {
mouse_x = "10px";
mouse_y = "10px";
}
$(".contextmenu").css({
"top": mouse_y,
"left": mouse_x,
"opacity": 0.98
});
},
add: function(e) { add: function(e) {
var mouse_x = e.pageX, var items = [
mouse_y = e.pageY - $(document).scrollTop(), { type: 'item', title: 'Upload Photo', icon: 'icon-picture', fn: function() { $('#upload_files').click() } },
items; { type: 'separator' },
{ type: 'item', title: 'Import from Link', icon: 'icon-link', fn: upload.start.url },
{ type: 'item', title: 'Import from Dropbox', icon: 'icon-folder-open', fn: upload.start.dropbox },
{ type: 'item', title: 'Import from Server', icon: 'icon-hdd', fn: upload.start.server },
{ type: 'separator' },
{ type: 'item', title: 'New Album', icon: 'icon-folder-close', fn: album.add }
];
context.show(items, e);
upload.notify(); upload.notify();
contextMenu.fns = [
function() { $("#upload_files").click() },
function() { upload.start.url() },
function() { upload.start.dropbox() },
function() { upload.start.server() },
function() { album.add() }
];
items = [
["<a class='icon-picture'></a> Upload Photo", 0],
["separator", -1],
["<a class='icon-link'></a> Import from Link", 1],
["<a class='icon-folder-open'></a> Import from Dropbox", 2],
["<a class='icon-hdd'></a> Import from Server", 3],
["separator", -1],
["<a class='icon-folder-close'></a> New Album", 4]
];
contextMenu.show(items, mouse_x, mouse_y, "left");
}, },
settings: function(e) { settings: function(e) {
var mouse_x = e.pageX, var items = [
mouse_y = e.pageY - $(document).scrollTop(), { type: 'item', title: 'Change Login', icon: 'icon-user', fn: settings.setLogin },
items; { type: 'item', title: 'Change Sorting', icon: 'icon-sort', fn: settings.setSorting },
{ type: 'item', title: 'Set Dropbox', icon: 'icon-folder-open', fn: settings.setDropboxKey },
contextMenu.fns = [ { type: 'separator' },
function() { settings.setLogin() }, { type: 'item', title: 'About Lychee', icon: 'icon-info-sign', fn: function() { window.open(lychee.website) } },
function() { settings.setSorting() }, { type: 'item', title: 'Diagnostics', icon: 'icon-dashboard', fn: function() { window.open('plugins/check/') } },
function() { settings.setDropboxKey() }, { type: 'item', title: 'Show Log', icon: 'icon-list', fn: function() { window.open('plugins/displaylog/') } },
function() { window.open(lychee.website); }, { type: 'separator' },
function() { window.open("plugins/check/"); }, { type: 'item', title: 'Sign Out', icon: 'icon-signout', fn: lychee.logout }
function() { window.open("plugins/displaylog/"); },
function() { lychee.logout() }
]; ];
items = [ context.show(items, e);
["<a class='icon-user'></a> Change Login", 0],
["<a class='icon-sort'></a> Change Sorting", 1],
["<a class='icon-folder-open'></a> Set Dropbox", 2],
["separator", -1],
["<a class='icon-info-sign'></a> About Lychee", 3],
["<a class='icon-dashboard'></a> Diagnostics", 4],
["<a class='icon-list'></a> Show Log", 5],
["separator", -1],
["<a class='icon-signout'></a> Sign Out", 6]
];
contextMenu.show(items, mouse_x, mouse_y, "right");
}, },
album: function(albumID, e) { album: function(albumID, e) {
var mouse_x = e.pageX, if (albumID==='0'||albumID==='f'||albumID==='s'||albumID==='r') return false;
mouse_y = e.pageY - $(document).scrollTop(),
items;
if (albumID==="0"||albumID==="f"||albumID==="s"||albumID==="r") return false; var items = [
{ type: 'item', title: 'Rename', icon: 'icon-edit', fn: function() { album.setTitle([albumID]) } },
contextMenu.fns = [ { type: 'item', title: 'Delete', icon: 'icon-trash', fn: function() { album.delete([albumID]) } }
function() { album.setTitle([albumID]) },
function() { album.delete([albumID]) }
]; ];
items = [ $('.album[data-id="' + albumID + '"]').addClass('active');
["<a class='icon-edit'></a> Rename", 0],
["<a class='icon-trash'></a> Delete", 1]
];
contextMenu.show(items, mouse_x, mouse_y, "right"); context.show(items, e, function() {
$('.photo.active, .album.active').removeClass('active');
$(".album[data-id='" + albumID + "']").addClass("active"); context.close();
});
}, },
albumMulti: function(albumIDs, e) { albumMulti: function(albumIDs, e) {
var mouse_x = e.pageX,
mouse_y = e.pageY - $(document).scrollTop(),
items;
multiselect.stopResize(); multiselect.stopResize();
contextMenu.fns = [ var items = [
function() { album.setTitle(albumIDs) }, { type: 'item', title: 'Rename All', icon: 'icon-edit', fn: function() { album.setTitle(albumIDs) } },
function() { album.delete(albumIDs) }, { type: 'item', title: 'Delete All', icon: 'icon-trash', fn: function() { album.delete(albumIDs) } }
]; ];
items = [ context.show(items, e, function() {
["<a class='icon-edit'></a> Rename All", 0], context.close();
["<a class='icon-trash'></a> Delete All", 1] $('.photo.active, .album.active').removeClass('active');
]; if (visible.multiselect()) multiselect.close();
});
contextMenu.show(items, mouse_x, mouse_y, "right");
}, },
photo: function(photoID, e) { photo: function(photoID, e) {
var mouse_x = e.pageX, var items = [
mouse_y = e.pageY - $(document).scrollTop(), { type: 'item', title: 'Star', icon: 'icon-star', fn: function() { photo.setStar([photoID]) } },
items; { type: 'item', title: 'Tags', icon: 'icon-tags', fn: function() { photo.editTags([photoID]) } },
{ type: 'separator' },
contextMenu.fns = [ { type: 'item', title: 'Rename', icon: 'icon-edit', fn: function() { photo.setTitle([photoID]) } },
function() { photo.setStar([photoID]) }, { type: 'item', title: 'Duplicate', icon: 'icon-copy', fn: function() { photo.duplicate([photoID]) } },
function() { photo.editTags([photoID]) }, { type: 'item', title: 'Move', icon: 'icon-folder-open', fn: function() { contextMenu.move([photoID], e) } },
function() { photo.setTitle([photoID]) }, { type: 'item', title: 'Delete', icon: 'icon-trash', fn: function() { photo.delete([photoID]) } }
function() { photo.duplicate([photoID]) },
function() { contextMenu.move([photoID], e, "right") },
function() { photo.delete([photoID]) }
]; ];
items = [ $('.photo[data-id="' + photoID + '"]').addClass('active');
["<a class='icon-star'></a> Star", 0],
["<a class='icon-tags'></a> Tags", 1],
["separator", -1],
["<a class='icon-edit'></a> Rename", 2],
["<a class='icon-copy'></a> Duplicate", 3],
["<a class='icon-folder-open'></a> Move", 4],
["<a class='icon-trash'></a> Delete", 5]
];
contextMenu.show(items, mouse_x, mouse_y, "right"); context.show(items, e, function() {
context.close();
$(".photo[data-id='" + photoID + "']").addClass("active"); $('.photo.active, .album.active').removeClass('active');
});
}, },
photoMulti: function(photoIDs, e) { photoMulti: function(photoIDs, e) {
var mouse_x = e.pageX,
mouse_y = e.pageY - $(document).scrollTop(),
items;
multiselect.stopResize(); multiselect.stopResize();
contextMenu.fns = [ var items = [
function() { photo.setStar(photoIDs) }, { type: 'item', title: 'Star All', icon: 'icon-star', fn: function() { photo.setStar(photoIDs) } },
function() { photo.editTags(photoIDs) }, { type: 'item', title: 'Tag All', icon: 'icon-tags', fn: function() { photo.editTags(photoIDs) } },
function() { photo.setTitle(photoIDs) }, { type: 'separator' },
function() { photo.duplicate(photoIDs) }, { type: 'item', title: 'Rename All', icon: 'icon-edit', fn: function() { photo.setTitle(photoIDs) } },
function() { contextMenu.move(photoIDs, e, "right") }, { type: 'item', title: 'Duplicate All', icon: 'icon-copy', fn: function() { photo.duplicate(photoIDs) } },
function() { photo.delete(photoIDs) } { type: 'item', title: 'Move All', icon: 'icon-folder-open', fn: function() { contextMenu.move(photoIDs, e) } },
{ type: 'item', title: 'Delete All', icon: 'icon-trash', fn: function() { photo.delete(photoIDs) } }
]; ];
items = [ context.show(items, e, function() {
["<a class='icon-star'></a> Star All", 0], context.close();
["<a class='icon-tags'></a> Tag All", 1], $('.photo.active, .album.active').removeClass('active');
["separator", -1], if (visible.multiselect()) multiselect.close();
["<a class='icon-edit'></a> Rename All", 2], });
["<a class='icon-copy'></a> Duplicate All", 3],
["<a class='icon-folder-open'></a> Move All", 4],
["<a class='icon-trash'></a> Delete All", 5]
];
contextMenu.show(items, mouse_x, mouse_y, "right");
}, },
photoMore: function(photoID, e) { photoMore: function(photoID, e) {
var mouse_x = e.pageX, var items = [
mouse_y = e.pageY - $(document).scrollTop(), { type: 'item', title: 'Full Photo', icon: 'icon-resize-full', fn: function() { window.open(photo.getDirectLink()) } },
items; { type: 'item', title: 'Download', icon: 'icon-circle-arrow-down', fn: function() { photo.getArchive(photoID) } }
contextMenu.fns = [
function() { window.open(photo.getDirectLink()) },
function() { photo.getArchive(photoID) }
]; ];
items = [["<a class='icon-resize-full'></a> Full Photo", 0]]; // Remove download-item when
if ((album.json&&album.json.downloadable&&album.json.downloadable==="1"&&lychee.publicMode)||!lychee.publicMode) items.push(["<a class='icon-circle-arrow-down'></a> Download", 1]); // 1) In public mode
// 2) Downloadable not 1 or not found
if (!(album.json&&album.json.downloadable&&album.json.downloadable==='1')&&
lychee.publicMode===true) items.splice(1, 1);
contextMenu.show(items, mouse_x, mouse_y, "right"); context.show(items, e);
}, },
move: function(photoIDs, e, orientation) { move: function(photoIDs, e) {
var mouse_x = e.pageX, var items = [];
mouse_y = e.pageY - $(document).scrollTop(),
items = [];
contextMenu.close(true); // Show Unsorted when unsorted is not the current album
if (album.getID()!=='0') {
if (album.getID()!=="0") {
items = [ items = [
["Unsorted", 0, "photo.setAlbum([" + photoIDs + "], 0)"], { type: 'item', title: 'Unsorted', fn: function() { photo.setAlbum([photoIDs], 0) } },
["separator", -1] { type: 'separator' }
]; ];
} }
lychee.api("getAlbums", function(data) { lychee.api('getAlbums', function(data) {
if (data.num===0) { if (data.num===0) {
items = [["New Album", 0, "album.add()"]];
// Show 'Add album' when no album available
items = [
{ type: 'item', title: 'New Album', fn: album.add }
];
} else { } else {
// Generate list of albums
$.each(data.content, function(index) { $.each(data.content, function(index) {
if (this.id!=album.getID()) items.push([this.title, 0, "photo.setAlbum([" + photoIDs + "], " + this.id + ")"]); var that = this;
if (that.id!=album.getID()) items.push({ type: 'item', title: that.title, fn: function() { photo.setAlbum([photoIDs], that.id) } });
}); });
} }
if (!visible.photo()) contextMenu.show(items, mouse_x, mouse_y, "right"); context.show(items, e);
else contextMenu.show(items, mouse_x, mouse_y, "left");
}); });
@ -266,70 +177,40 @@ contextMenu = {
sharePhoto: function(photoID, e) { sharePhoto: function(photoID, e) {
var mouse_x = e.pageX, var link = photo.getViewLink(photoID);
mouse_y = e.pageY, if (photo.json.public==='2') link = location.href;
items,
link = "";
mouse_y -= $(document).scrollTop(); var items = [
{ type: 'item', title: '<input readonly id="link" value="' + link + '">', fn: function() {}, class: 'noHover' },
contextMenu.fns = [ { type: 'separator' },
function() { photo.setPublic(photoID) }, { type: 'item', title: 'Make Private', icon: 'icon-eye-close', fn: function() { photo.setPublic(photoID) } },
function() { photo.share(photoID, 0) }, { type: 'separator' },
function() { photo.share(photoID, 1) }, { type: 'item', title: 'Twitter', icon: 'icon-twitter', fn: function() { photo.share(photoID, 0) } },
function() { photo.share(photoID, 2) }, { type: 'item', title: 'Facebook', icon: 'icon-facebook', fn: function() { photo.share(photoID, 1) } },
function() { photo.share(photoID, 3) }, { type: 'item', title: 'Mail', icon: 'icon-envelope', fn: function() { photo.share(photoID, 2) } },
function() { window.open(photo.getDirectLink()) } { type: 'item', title: 'Dropbox', icon: 'icon-hdd', fn: function() { photo.share(photoID, 3) } },
{ type: 'item', title: 'Direct Link', icon: 'icon-link', fn: function() { window.open(photo.getDirectLink()) } }
]; ];
link = photo.getViewLink(photoID); context.show(items, e);
if (photo.json.public==="2") link = location.href; $('.context input#link').focus().select();
items = [
["<input readonly id='link' value='" + link + "'>", -1],
["separator", -1],
["<a class='icon-eye-close'></a> Make Private", 0],
["separator", -1],
["<a class='icon-twitter'></a> Twitter", 1],
["<a class='icon-facebook'></a> Facebook", 2],
["<a class='icon-envelope'></a> Mail", 3],
["<a class='icon-hdd'></a> Dropbox", 4],
["<a class='icon-link'></a> Direct Link", 5]
];
contextMenu.show(items, mouse_x, mouse_y, "left");
$(".contextmenu input").focus().select();
}, },
shareAlbum: function(albumID, e) { shareAlbum: function(albumID, e) {
var mouse_x = e.pageX, var items = [
mouse_y = e.pageY, { type: 'item', title: '<input readonly id="link" value="' + location.href + '">', fn: function() {}, class: 'noHover' },
items; { type: 'separator' },
{ type: 'item', title: 'Make Private', icon: 'icon-eye-close', fn: function() { album.setPublic(albumID) } },
mouse_y -= $(document).scrollTop(); { type: 'separator' },
{ type: 'item', title: 'Twitter', icon: 'icon-twitter', fn: function() { album.share(0) } },
contextMenu.fns = [ { type: 'item', title: 'Facebook', icon: 'icon-facebook', fn: function() { album.share(1) } },
function() { album.setPublic(albumID) }, { type: 'item', title: 'Mail', icon: 'icon-envelope', fn: function() { album.share(2) } }
function() { album.share(0) },
function() { album.share(1) },
function() { album.share(2) },
function() { password.remove(albumID) }
]; ];
items = [ context.show(items, e);
["<input readonly id='link' value='" + location.href + "'>", -1], $('.context input#link').focus().select();
["separator", -1],
["<a class='icon-eye-close'></a> Make Private", 0],
["separator", -1],
["<a class='icon-twitter'></a> Twitter", 1],
["<a class='icon-facebook'></a> Facebook", 2],
["<a class='icon-envelope'></a> Mail", 3],
];
contextMenu.show(items, mouse_x, mouse_y, "left");
$(".contextmenu input").focus().select();
}, },
@ -337,10 +218,7 @@ contextMenu = {
if (!visible.contextMenu()) return false; if (!visible.contextMenu()) return false;
contextMenu.fns = []; context.close();
$(".contextmenu_bg, .contextmenu").remove();
$("body").css("overflow", "auto");
if (leaveSelection!==true) { if (leaveSelection!==true) {
$(".photo.active, .album.active").removeClass("active"); $(".photo.active, .album.active").removeClass("active");

View File

@ -55,7 +55,7 @@ visible.signin = function() {
} }
visible.contextMenu = function() { visible.contextMenu = function() {
if ($('.contextmenu').length>0) return true; if ($('.contextContainer').length>0) return true;
else return false; else return false;
} }

View File

@ -2,90 +2,57 @@
* @copyright 2014 by Tobias Reich * @copyright 2014 by Tobias Reich
*/ */
.contextmenu_bg { /* Context ------------------------------------------------*/
position: fixed; .context {
height: 100%; padding: 5px 0 6px;
width: 100%;
z-index: 1000;
}
.contextmenu {
position: fixed;
top: 0px;
left: 0px;
padding: 5px 0px 6px 0px;
background: linear-gradient(to bottom, #444 0%, #2f2f2f 100%); background: linear-gradient(to bottom, #444 0%, #2f2f2f 100%);
border: 1px solid rgba(0,0,0,0.5); border: 1px solid rgba(0, 0, 0, .5);
border-bottom: 1px solid rgba(0,0,0,.7); border-bottom: 1px solid rgba(0, 0, 0, .6);
border-radius: 5px; border-radius: 5px;
box-shadow: 0px 3px 4px rgba(0,0,0,0.25), inset 0px 1px 0px rgba(255,255,255, .1); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15), inset 0px 1px 0px rgba(255, 255, 255, .08);
opacity: 0;
z-index: 1001;
transition: none; /* Item ------------------------------------------------*/
} tr {
margin-bottom: 2px;
/* Items ------------------------------------------------*/
.contextmenu tr {
font-size: 14px;
color: #eee; color: #eee;
text-shadow: 0px -1px 0px rgba(0,0,0,.2); font-size: 14px;
cursor: pointer; text-shadow: 0 -1px 0px rgba(0, 0, 0, .2);
}
.contextmenu tr:hover { &.separator {
background: linear-gradient(to bottom, #6a84f2, #4967F0); background-color: rgba(0, 0, 0, .2);
} border-bottom: 1px solid rgba(255, 255, 255, .1);
.contextmenu tr.no_hover:hover { }
cursor: inherit;
background-color: inherit;
background-image: none;
}
.contextmenu tr.separator {
float: left;
height: 1px;
width: 100%;
background-color: #1f1f1f;
border-bottom: 1px solid #4c4c4c;
margin: 5px 0px;
cursor: inherit;
}
.contextmenu tr.separator:hover {
background-color: #222;
background-image: none;
}
.contextmenu tr td {
padding: 7px 30px 6px 12px;
white-space: nowrap;
transition: none;
}
.contextmenu tr:hover td {
color: #fff;
box-shadow: inset 0px 1px 0px rgba(255,255,255,.05);
text-shadow: 0px -1px 0px rgba(0,0,0,.2);
}
.contextmenu tr.no_hover:hover td {
box-shadow: none;
}
.contextmenu tr a {
float: left;
width: 10px;
margin-right: 10px;
text-align: center;
} }
/* Direct Link Input ------------------------------------------------*/ tr td {
.contextmenu #link { padding: 7px 25px 6px 12px;
float: right; min-width: auto;
width: 140px; color: #fff;
margin: -1px -18px -2px -1px; border-radius: 0;
transition: none;
&:hover {
background: linear-gradient(to bottom, #6a84f2, #4967F0);
}
}
/* Link ------------------------------------------------*/
input#link {
width: 100%;
margin: -2px 0 -1px -2px;
padding: 5px 7px 6px 7px; padding: 5px 7px 6px 7px;
background-color: #444; background-color: #444;
color: #fff; color: #fff;
border: none; border: 1px solid rgba(0, 0, 0, .4);
border: 1px solid rgba(0, 0, 0, .5); box-shadow: 0px 1px 0px rgba(255, 255, 255, .05);
box-shadow: 0px 1px 0px rgba(255,255,255,.08);
outline: none; outline: none;
border-radius: 5px; border-radius: 3px;
} }
.contextmenu tr a#link_icon {
padding-top: 4px; /* No Hover ------------------------------------------------*/
} tr.noHover td:hover {
background: none;
cursor: default;
}
}