Browse Source

Front-end rewrite #275

Tobias Reich 9 years ago
parent
commit
b4d356f7e4
6 changed files with 433 additions and 410 deletions
  1. 0 0
      dist/main.js
  2. 8 2
      src/scripts/album.js
  3. 98 96
      src/scripts/albums.js
  4. 260 250
      src/scripts/lychee.js
  5. 1 1
      src/scripts/photo.js
  6. 66 61
      src/scripts/search.js

File diff suppressed because it is too large
+ 0 - 0
dist/main.js


+ 8 - 2
src/scripts/album.js

@@ -63,9 +63,15 @@ album = {
 
 				album.json = data;
 
+				// Calculate delay
 				durationTime = (new Date().getTime() - startTime);
-				if (durationTime>300) waitTime = 0; else if (refresh) waitTime = 0; else waitTime = 300 - durationTime;
-				if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
+				if (durationTime>300)	waitTime = 0;
+				else					waitTime = 300 - durationTime;
+
+				// Skip delay when refresh is true
+				// Skip delay when opening a blank Lychee
+				if (refresh===true)											waitTime = 0;
+				if (!visible.albums()&&!visible.photo()&&!visible.album())	waitTime = 0;
 
 				setTimeout(function() {
 

+ 98 - 96
src/scripts/albums.js

@@ -3,109 +3,111 @@
  * @copyright	2014 by Tobias Reich
  */
 
-albums = {
-
-	json: null,
-
-	load: function() {
-
-		var startTime,
-			durationTime,
-			waitTime;
-
-		lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomOut");
-		lychee.animate(".divider", "fadeOut");
-
-		startTime = new Date().getTime();
-
-		if(albums.json===null) {
-
-			lychee.api("getAlbums", function(data) {
-
-				/* Smart Albums */
-				data.unsortedAlbum = {
-					id: 0,
-					title: "Unsorted",
-					sysdate: data.unsortedNum + " photos",
-					unsorted: "1",
-					thumb0: data.unsortedThumb0,
-					thumb1: data.unsortedThumb1,
-					thumb2: data.unsortedThumb2
-				};
-
-				data.starredAlbum = {
-					id: "f",
-					title: "Starred",
-					sysdate: data.starredNum + " photos",
-					star: "1",
-					thumb0: data.starredThumb0,
-					thumb1: data.starredThumb1,
-					thumb2: data.starredThumb2
-				};
-
-				data.publicAlbum = {
-					id: "s",
-					title: "Public",
-					sysdate: data.publicNum + " photos",
-					public: "1",
-					thumb0: data.publicThumb0,
-					thumb1: data.publicThumb1,
-					thumb2: data.publicThumb2
-				};
-
-				data.recentAlbum = {
-					id: "r",
-					title: "Recent",
-					sysdate: data.recentNum + " photos",
-					recent: "1",
-					thumb0: data.recentThumb0,
-					thumb1: data.recentThumb1,
-					thumb2: data.recentThumb2
-				};
-
-				albums.json = data;
-
-				durationTime = (new Date().getTime() - startTime);
-				if (durationTime>300) waitTime = 0; else waitTime = 300 - durationTime;
-				if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
-				if (visible.album()&&lychee.content.html()==="") waitTime = 0;
-
-				setTimeout(function() {
-					view.header.mode("albums");
-					view.albums.init();
-					lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
-				}, waitTime);
-			});
-
-		} else {
+albums = {}
+
+albums.json = null;
+
+albums.load = function() {
+
+	var startTime,
+		durationTime,
+		waitTime;
+
+	lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomOut');
+	lychee.animate('.divider', 'fadeOut');
+
+	startTime = new Date().getTime();
+
+	if (albums.json===null) {
+
+		lychee.api('getAlbums', function(data) {
+
+			/* Smart Albums */
+			data.unsortedAlbum = {
+				id:			0,
+				title:		'Unsorted',
+				sysdate:	data.unsortedNum + ' photos',
+				unsorted: 	'1',
+				thumb0:		data.unsortedThumb0,
+				thumb1:		data.unsortedThumb1,
+				thumb2:		data.unsortedThumb2
+			};
+
+			data.starredAlbum = {
+				id:			'f',
+				title:		'Starred',
+				sysdate:	data.starredNum + ' photos',
+				star:		'1',
+				thumb0:		data.starredThumb0,
+				thumb1:		data.starredThumb1,
+				thumb2:		data.starredThumb2
+			};
+
+			data.publicAlbum = {
+				id:			's',
+				title:		'Public',
+				sysdate:	data.publicNum + ' photos',
+				public:		'1',
+				thumb0:		data.publicThumb0,
+				thumb1:		data.publicThumb1,
+				thumb2:		data.publicThumb2
+			};
+
+			data.recentAlbum = {
+				id:			'r',
+				title:		'Recent',
+				sysdate:	data.recentNum + ' photos',
+				recent:		'1',
+				thumb0:		data.recentThumb0,
+				thumb1:		data.recentThumb1,
+				thumb2:		data.recentThumb2
+			};
+
+			albums.json = data;
+
+			// Calculate delay
+			durationTime = (new Date().getTime() - startTime);
+			if (durationTime>300)	waitTime = 0;
+			else					waitTime = 300 - durationTime;
+
+			// Skip delay when opening a blank Lychee
+			if (!visible.albums()&&!visible.photo()&&!visible.album())	waitTime = 0;
+			if (visible.album()&&lychee.content.html()==='')			waitTime = 0;
 
 			setTimeout(function() {
-				view.header.mode("albums");
+				view.header.mode('albums');
 				view.albums.init();
-				lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
-			}, 300);
+				lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomIn');
+			}, waitTime);
+		});
 
-		}
-	},
+	} else {
 
-	parse: function(album) {
+		setTimeout(function() {
+			view.header.mode('albums');
+			view.albums.init();
+			lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomIn');
+		}, 300);
 
-		if (album.password&&lychee.publicMode) {
-			album.thumb0 = "src/images/password.svg";
-			album.thumb1 = "src/images/password.svg";
-			album.thumb2 = "src/images/password.svg";
-		} else {
-			if (!album.thumb0) album.thumb0 = "src/images/no_images.svg";
-			if (!album.thumb1) album.thumb1 = "src/images/no_images.svg";
-			if (!album.thumb2) album.thumb2 = "src/images/no_images.svg";
-		}
-
-	},
+	}
+}
+
+albums.parse = function(album) {
+
+	if (album.password&&lychee.publicMode) {
+		album.thumb0 = 'src/images/password.svg';
+		album.thumb1 = 'src/images/password.svg';
+		album.thumb2 = 'src/images/password.svg';
+	} else {
+		if (!album.thumb0) album.thumb0 = 'src/images/no_images.svg';
+		if (!album.thumb1) album.thumb1 = 'src/images/no_images.svg';
+		if (!album.thumb2) album.thumb2 = 'src/images/no_images.svg';
+	}
 
-	refresh: function() {
+}
 
-		albums.json = null;
+albums.refresh = function() {
 
-	}
+	albums.json = null;
 
-};
+}

+ 260 - 250
src/scripts/lychee.js

@@ -3,373 +3,383 @@
  * @copyright	2014 by Tobias Reich
  */
 
-var lychee = {
+lychee = {
 
-	title: "",
-	version: "2.7.0",
-	version_code: "020700",
+	title:			'',
+	version:		'2.7.0',
+	version_code:	'020700',
 
-	api_path: "php/api.php",
-	update_path: "http://lychee.electerious.com/version/index.php",
-	updateURL: "https://github.com/electerious/Lychee",
-	website: "http://lychee.electerious.com",
+	api_path:		'php/api.php',
+	update_path:	'http://lychee.electerious.com/version/index.php',
+	updateURL:		'https://github.com/electerious/Lychee',
+	website:		'http://lychee.electerious.com',
 
-	publicMode: false,
-	viewMode: false,
-	debugMode: false,
+	publicMode:		false,
+	viewMode:		false,
+	debugMode:		false,
 
-	username: "",
-	checkForUpdates: false,
-	sorting: "",
-	location: "",
+	checkForUpdates:false,
+	username:		'',
+	sorting:		'',
+	location:		'',
 
-	dropbox: false,
-	dropboxKey: '',
+	dropbox:		false,
+	dropboxKey:		'',
 
-	loadingBar: $("#loading"),
-	header: $("header"),
-	content: $("#content"),
-	imageview: $("#imageview"),
-	infobox: $("#infobox"),
+	loadingBar:		$('#loading'),
+	header:			$('header'),
+	content:		$('#content'),
+	imageview:		$('#imageview'),
+	infobox:		$('#infobox')
 
-	init: function() {
+}
 
-		var params;
+lychee.init = function() {
 
-		params = "init&version=" + lychee.version_code;
-		lychee.api(params, function(data) {
+	var params;
 
-			if (data.loggedIn!==true) {
-				lychee.setMode("public");
-			} else {
-				lychee.username = data.config.username || '';
-				lychee.sorting = data.config.sorting || '';
-				lychee.dropboxKey = data.config.dropboxKey || '';
-				lychee.location = data.config.location || '';
-			}
+	params = 'init&version=' + lychee.version_code;
+	lychee.api(params, function(data) {
 
-			// No configuration
-			if (data==="Warning: No configuration!") {
-				lychee.header.hide();
-				lychee.content.hide();
-				$("body").append(build.no_content("cog"));
-				settings.createConfig();
-				return true;
-			}
+		if (data.loggedIn!==true) {
+			lychee.setMode('public');
+		} else {
+			lychee.username		= data.config.username		|| '';
+			lychee.sorting		= data.config.sorting		|| '';
+			lychee.dropboxKey	= data.config.dropboxKey	|| '';
+			lychee.location		= data.config.location		|| '';
+		}
 
-			// No login
-			if (data.config.login===false) {
-				settings.createLogin();
-			}
+		// No configuration
+		if (data==='Warning: No configuration!') {
+			lychee.header.hide();
+			lychee.content.hide();
+			$('body').append(build.no_content('cog'));
+			settings.createConfig();
+			return true;
+		}
+
+		// No login
+		if (data.config.login===false) {
+			settings.createLogin();
+		}
 
-			lychee.checkForUpdates = data.config.checkForUpdates;
-			$(window).bind("popstate", lychee.load);
-			lychee.load();
+		lychee.checkForUpdates = data.config.checkForUpdates;
+		$(window).bind('popstate', lychee.load);
+		lychee.load();
 
-		});
+	});
 
-	},
+}
 
-	api: function(params, callback, loading) {
+lychee.api = function(params, callback) {
 
-		if (loading===undefined) loadingBar.show();
+	loadingBar.show();
 
-		$.ajax({
-			type: "POST",
-			url: lychee.api_path,
-			data: "function=" + params,
-			dataType: "text",
-			success: function(data) {
+	$.ajax({
+		type:		'POST',
+		url:		lychee.api_path,
+		data:		'function=' + params,
+		dataType:	'text',
+		success: function(data) {
 
-				setTimeout(function() { loadingBar.hide() }, 100);
+			setTimeout(function() { loadingBar.hide() }, 100);
 
-				if (typeof data==="string"&&data.substring(0, 7)==="Error: ") {
+			// Catch errors
+			if (typeof data==='string'&&
+				data.substring(0, 7)==='Error: ') {
 					lychee.error(data.substring(7, data.length), params, data);
 					upload.close(true);
 					return false;
-				}
+			}
 
-				if (data==="1") data = true;
-				else if (data==="") data = false;
+			// Convert 1 to true and an empty string to false
+			if (data==='1')		data = true;
+			else if (data==='')	data = false;
 
-				if (typeof data==="string"&&data.substring(0, 1)==="{"&&data.substring(data.length-1, data.length)==="}") data = $.parseJSON(data);
+			// Convert to JSON if string start with '{' and ends with '}'
+			if (typeof data==='string'&&
+				data.substring(0, 1)==='{'&&
+				data.substring(data.length-1, data.length)==='}') data = $.parseJSON(data);
 
-				if (lychee.debugMode) console.log(data);
+			// Output response when debug mode is enabled
+			if (lychee.debugMode) console.log(data);
 
-				callback(data);
+			callback(data);
 
-			},
-			error: function(jqXHR, textStatus, errorThrown) {
+		},
+		error: function(jqXHR, textStatus, errorThrown) {
 
-				lychee.error("Server error or API not found.", params, errorThrown);
-				upload.close(true);
+			lychee.error('Server error or API not found.', params, errorThrown);
+			upload.close(true);
 
-			}
-		});
+		}
+	});
+
+}
 
-	},
+lychee.login = function() {
 
-	login: function() {
+	var user		= $('input#username').val(),
+		password	= md5($('input#password').val()),
+		params;
 
-		var user = $("input#username").val(),
-			password = md5($("input#password").val()),
-			params;
+	params = 'login&user=' + user + '&password=' + password;
+	lychee.api(params, function(data) {
 
-		params = "login&user=" + user + "&password=" + password;
-		lychee.api(params, function(data) {
+		if (data===true) {
 
-			if (data===true) {
+			// Use 'try' to catch a thrown error when Safari is in private mode
+			try { localStorage.setItem('lychee_username', user); }
+			catch (err) {}
 
-				// Use 'try' to catch a thrown error when Safari is in private mode
-				try { localStorage.setItem("lychee_username", user); }
-				catch (err) {}
+			window.location.reload();
 
-				window.location.reload();
+		} else {
 
-			} else {
+			// Show error and reactive button
+			$('#password').val('').addClass('error').focus();
+			$('.message .button.active').removeClass('pressed');
 
-				// Show error and reactive button
-				$("#password").val("").addClass("error").focus();
-				$(".message .button.active").removeClass("pressed");
+		}
 
-			}
+	});
 
-		});
+}
 
-	},
+lychee.loginDialog = function() {
 
-	loginDialog: function() {
+	var local_username;
 
-		var local_username;
+	$('body').append(build.signInModal());
+	$('#username').focus();
 
-		$("body").append(build.signInModal());
-		$("#username").focus();
-		if (localStorage) {
-			local_username = localStorage.getItem("lychee_username");
-			if (local_username!==null) {
-				if (local_username.length>0) $("#username").val(local_username);
-				$("#password").focus();
-			}
+	if (localStorage) {
+		local_username = localStorage.getItem('lychee_username');
+		if (local_username!==null) {
+			if (local_username.length>0) $('#username').val(local_username);
+			$('#password').focus();
 		}
-		if (lychee.checkForUpdates==="1") lychee.getUpdate();
+	}
 
-	},
+	if (lychee.checkForUpdates==='1') lychee.getUpdate();
 
-	logout: function() {
+}
 
-		lychee.api("logout", function() {
-			window.location.reload();
-		});
+lychee.logout = function() {
 
-	},
+	lychee.api('logout', function() {
+		window.location.reload();
+	});
 
-	goto: function(url) {
+}
 
-		if (url===undefined) url = "#";
-		else url = "#" + url;
+lychee.goto = function(url) {
 
-		history.pushState(null, null, url);
-		lychee.load();
+	if (url===undefined)	url = '#';
+	else					url = '#' + url;
 
-	},
+	history.pushState(null, null, url);
+	lychee.load();
 
-	load: function() {
+}
 
-		var albumID = "",
-			photoID = "",
-			hash = document.location.hash.replace("#", "").split("/");
+lychee.load = function() {
 
-		$(".no_content").remove();
-		contextMenu.close();
-		multiselect.close();
+	var albumID	= '',
+		photoID	= '',
+		hash	= document.location.hash.replace('#', '').split('/');
 
-		if (hash[0]!==undefined) albumID = hash[0];
-		if (hash[1]!==undefined) photoID = hash[1];
+	$('.no_content').remove();
+	contextMenu.close();
+	multiselect.close();
 
-		if (albumID&&photoID) {
+	if (hash[0]!==undefined) albumID = hash[0];
+	if (hash[1]!==undefined) photoID = hash[1];
 
-			// Trash data
-			photo.json = null;
+	if (albumID&&photoID) {
 
-			// Show Photo
-			if (lychee.content.html()===""||($("#search").length&&$("#search").val().length!==0)) {
+		// Trash data
+		photo.json = null;
+
+		// Show Photo
+		if (lychee.content.html()===''||
+			($('#search').length&&$('#search').val().length!==0)) {
 				lychee.content.hide();
 				album.load(albumID, true);
-			}
-			photo.load(photoID, albumID);
+		}
+		photo.load(photoID, albumID);
 
-		} else if (albumID) {
+	} else if (albumID) {
 
-			// Trash data
-			photo.json = null;
+		// Trash data
+		photo.json = null;
 
-			// Show Album
-			if (visible.photo()) view.photo.hide();
-			if (album.json&&albumID==album.json.id) view.album.title();
-			else album.load(albumID);
+		// Show Album
+		if (visible.photo()) view.photo.hide();
+		if (album.json&&albumID==album.json.id) view.album.title();
+		else album.load(albumID);
 
-		} else {
+	} else {
 
-			// Trash data
-			album.json = null;
-			photo.json = null;
-			search.code = "";
+		// Trash data
+		album.json = null;
+		photo.json = null;
+		search.code = '';
 
-			// Show Albums
-			if (visible.album()) view.album.hide();
-			if (visible.photo()) view.photo.hide();
-			albums.load();
+		// Show Albums
+		if (visible.album()) view.album.hide();
+		if (visible.photo()) view.photo.hide();
+		albums.load();
 
-		}
+	}
 
-	},
+}
 
-	getUpdate: function() {
+lychee.getUpdate = function() {
 
-		$.ajax({
-			url: lychee.update_path,
-			success: function(data) { if (parseInt(data)>parseInt(lychee.version_code)) $("#version span").show(); }
-		});
+	$.ajax({
+		url: lychee.update_path,
+		success: function(data) { if (parseInt(data)>parseInt(lychee.version_code)) $('#version span').show(); }
+	});
 
-	},
+}
 
-	setTitle: function(title, editable) {
+lychee.setTitle = function(title, editable) {
 
-		if (lychee.title==="") lychee.title = document.title;
+	if (lychee.title==='')	lychee.title = document.title;
 
-		if (title==="Albums") document.title = lychee.title;
-		else document.title = lychee.title + " - " + title;
+	if (title==='Albums')	document.title = lychee.title;
+	else					document.title = lychee.title + ' - ' + title;
 
-		if (editable) $("#title").addClass("editable");
-		else $("#title").removeClass("editable");
+	if (editable)	$('#title').addClass('editable');
+	else			$('#title').removeClass('editable');
 
-		$("#title").html(title);
+	$('#title').html(title);
 
-	},
+}
 
-	setMode: function(mode) {
+lychee.setMode = function(mode) {
 
-		$("#button_settings, #button_settings, #button_search, #search, #button_trash_album, #button_share_album, .button_add, .button_divider").remove();
-		$("#button_trash, #button_move, #button_share, #button_star").remove();
+	$('#button_settings, #button_settings, #button_search, #search, #button_trash_album, #button_share_album, .button_add, .button_divider').remove();
+	$('#button_trash, #button_move, #button_share, #button_star').remove();
 
-		$(document)
-			.on("mouseenter", "#title.editable", function() { $(this).removeClass("editable") })
-			.off("click", "#title.editable")
-			.off("touchend", "#title.editable")
-			.off("contextmenu", ".photo")
-			.off("contextmenu", ".album")
-			.off("drop");
+	$(document)
+		.on('mouseenter',	'#title.editable', function() { $(this).removeClass('editable') })
+		.off('click',		'#title.editable')
+		.off('touchend',	'#title.editable')
+		.off('contextmenu',	'.photo')
+		.off('contextmenu',	'.album')
+		.off('drop');
 
-		Mousetrap
-			.unbind(['u', 'ctrl+u'])
-			.unbind(['s', 'ctrl+s'])
-			.unbind(['r', 'ctrl+r'])
-			.unbind(['d', 'ctrl+d'])
-			.unbind(['t', 'ctrl+t'])
-			.unbind(['command+backspace', 'ctrl+backspace']);
+	Mousetrap
+		.unbind(['u', 'ctrl+u'])
+		.unbind(['s', 'ctrl+s'])
+		.unbind(['r', 'ctrl+r'])
+		.unbind(['d', 'ctrl+d'])
+		.unbind(['t', 'ctrl+t'])
+		.unbind(['command+backspace', 'ctrl+backspace']);
 
-		if (mode==="public") {
+	if (mode==='public') {
 
-			$("header #button_signin, header #hostedwith").show();
-			lychee.publicMode = true;
+		$('header #button_signin, header #hostedwith').show();
+		lychee.publicMode = true;
 
-		} else if (mode==="view") {
+	} else if (mode==='view') {
 
-			Mousetrap.unbind('esc');
-			$("#button_back, a#next, a#previous").remove();
-			$(".no_content").remove();
+		Mousetrap.unbind('esc');
+		$('#button_back, a#next, a#previous').remove();
+		$('.no_content').remove();
 
-			lychee.publicMode = true;
-			lychee.viewMode = true;
+		lychee.publicMode	= true;
+		lychee.viewMode		= true;
 
-		}
+	}
 
-	},
+}
 
-	animate: function(obj, animation) {
+lychee.animate = function(obj, animation) {
 
-		var animations = [
-			["fadeIn", "fadeOut"],
-			["contentZoomIn", "contentZoomOut"]
-		];
+	var animations = [
+		['fadeIn', 'fadeOut'],
+		['contentZoomIn', 'contentZoomOut']
+	];
 
-		if (!obj.jQuery) obj = $(obj);
+	if (!obj.jQuery) obj = $(obj);
 
-		for (var i = 0; i < animations.length; i++) {
-			for (var x = 0; x < animations[i].length; x++) {
-				if (animations[i][x]==animation) {
-					obj.removeClass(animations[i][0] + " " + animations[i][1]).addClass(animation);
-					return true;
-				}
+	for (var i = 0; i < animations.length; i++) {
+		for (var x = 0; x < animations[i].length; x++) {
+			if (animations[i][x]==animation) {
+				obj.removeClass(animations[i][0] + ' ' + animations[i][1]).addClass(animation);
+				return true;
 			}
 		}
+	}
 
-		return false;
-
-	},
-
-	escapeHTML: function(s) {
+	return false;
 
-		return s.replace(/&/g, '&amp;')
-				.replace(/"/g, '&quot;')
-				.replace(/</g, '&lt;')
-				.replace(/>/g, '&gt;');
+}
 
-	},
+lychee.escapeHTML = function(s) {
 
-	loadDropbox: function(callback) {
+	return s.replace(/&/g, '&amp;')
+			.replace(/"/g, '&quot;')
+			.replace(/</g, '&lt;')
+			.replace(/>/g, '&gt;');
 
-		if (!lychee.dropbox&&lychee.dropboxKey) {
+}
 
-			loadingBar.show();
+lychee.loadDropbox = function(callback) {
 
-			var g = document.createElement("script"),
-				s = document.getElementsByTagName("script")[0];
+	if (!lychee.dropbox&&lychee.dropboxKey) {
 
-			g.src = "https://www.dropbox.com/static/api/1/dropins.js";
-			g.id = "dropboxjs";
-			g.type = "text/javascript";
-			g.async = "true";
-			g.setAttribute("data-app-key", lychee.dropboxKey);
-			g.onload = g.onreadystatechange = function() {
-				var rs = this.readyState;
-				if (rs&&rs!=="complete"&&rs!=="loaded") return;
-				lychee.dropbox = true;
-				loadingBar.hide();
-				callback();
-			};
-			s.parentNode.insertBefore(g, s);
+		loadingBar.show();
 
-		} else if (lychee.dropbox&&lychee.dropboxKey) {
+		var g = document.createElement('script'),
+			s = document.getElementsByTagName('script')[0];
 
+		g.src	= 'https://www.dropbox.com/static/api/1/dropins.js';
+		g.id	= 'dropboxjs';
+		g.type	= 'text/javascript';
+		g.async = 'true';
+		g.setAttribute('data-app-key', lychee.dropboxKey);
+		g.onload = g.onreadystatechange = function() {
+			var rs = this.readyState;
+			if (rs&&rs!=='complete'&&rs!=='loaded') return;
+			lychee.dropbox = true;
+			loadingBar.hide();
 			callback();
+		};
+		s.parentNode.insertBefore(g, s);
 
-		} else {
+	} else if (lychee.dropbox&&lychee.dropboxKey) {
 
-			settings.setDropboxKey(callback);
+		callback();
 
-		}
+	} else {
 
-	},
+		settings.setDropboxKey(callback);
 
-	removeHTML: function(html) {
+	}
 
-		var tmp = document.createElement("DIV");
-		tmp.innerHTML = html;
-		return tmp.textContent || tmp.innerText;
+}
 
-	},
+lychee.removeHTML = function(html) {
 
-	error: function(errorThrown, params, data) {
+	var tmp = document.createElement('DIV');
+	tmp.innerHTML = html;
+	return tmp.textContent || tmp.innerText;
 
-		console.error({
-			description: errorThrown,
-			params: params,
-			response: data
-		});
+}
 
-		loadingBar.show("error", errorThrown);
+lychee.error = function(errorThrown, params, data) {
 
-	}
+	console.error({
+		description:	errorThrown,
+		params:			params,
+		response:		data
+	});
+
+	loadingBar.show('error', errorThrown);
 
-};
+}

+ 1 - 1
src/scripts/photo.js

@@ -158,7 +158,7 @@ photo.duplicate = function(photoIDs) {
 	lychee.api(params, function(data) {
 
 		if (data!==true) lychee.error(null, params, data);
-		else album.load(album.getID(), false);
+		else album.load(album.getID());
 
 	});
 

+ 66 - 61
src/scripts/search.js

@@ -3,93 +3,98 @@
  * @copyright	2014 by Tobias Reich
  */
 
-search = {
+search = {}
 
-	code: null,
+search.code = null;
 
-	find: function(term) {
+search.find = function(term) {
 
-		var params,
-			albumsData = "",
-			photosData = "",
-			code;
+	var params,
+		albumsData = '',
+		photosData = '',
+		code;
 
-		clearTimeout($(window).data("timeout"));
-		$(window).data("timeout", setTimeout(function() {
+	clearTimeout($(window).data('timeout'));
+	$(window).data('timeout', setTimeout(function() {
 
-			if ($("#search").val().length!==0) {
+		if ($('#search').val().length!==0) {
 
-				params = "search&term=" + term;
-				lychee.api(params, function(data) {
+			params = 'search&term=' + term;
+			lychee.api(params, function(data) {
 
-					if (data&&data.albums) {
-						albums.json = { content: data.albums };
-						$.each(albums.json.content, function() {
-							albums.parse(this);
-							albumsData += build.album(this);
-						});
-					}
+				// Build albums
+				if (data&&data.albums) {
+					albums.json = { content: data.albums };
+					$.each(albums.json.content, function() {
+						albums.parse(this);
+						albumsData += build.album(this);
+					});
+				}
 
-					if (data&&data.photos) {
-						album.json = { content: data.photos };
-						$.each(album.json.content, function() {
-							photosData += build.photo(this);
-						});
-					}
+				// Build photos
+				if (data&&data.photos) {
+					album.json = { content: data.photos };
+					$.each(album.json.content, function() {
+						photosData += build.photo(this);
+					});
+				}
 
-					if (albumsData===""&&photosData==="") code = "error";
-					else if (albumsData==="") code = build.divider("Photos")+photosData;
-					else if (photosData==="") code = build.divider("Albums")+albumsData;
-					else code = build.divider("Photos")+photosData+build.divider("Albums")+albumsData;
+				// 1. No albums and photos found
+				// 2. Only photos found
+				// 3. Only albums found
+				// 4. Albums and photos found
+				if (albumsData===''&&photosData==='')	code = 'error';
+				else if (albumsData==='')				code = build.divider('Photos') + photosData;
+				else if (photosData==='')				code = build.divider('Albums') + albumsData;
+				else									code = build.divider('Photos') + photosData + build.divider('Albums') + albumsData;
 
-					if (search.code!==md5(code)) {
+				// Only refresh view when search results are different
+				if (search.code!==md5(code)) {
 
-						$(".no_content").remove();
+					$('.no_content').remove();
 
-						lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomOut");
-						lychee.animate(".divider", "fadeOut");
+					lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomOut');
+					lychee.animate('.divider', 'fadeOut');
 
-						search.code = md5(code);
+					search.code = md5(code);
 
-						setTimeout(function() {
+					setTimeout(function() {
 
-							if (code==="error") $("body").append(build.no_content("search"));
-							else {
-								lychee.content.html(code);
-								lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
-								$("img[data-type!='svg']").retina();
-							}
+						if (code==='error') $('body').append(build.no_content('search'));
+						else {
+							lychee.content.html(code);
+							lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomIn');
+							$('img[data-type!="svg"]').retina();
+						}
 
-						}, 300);
+					}, 300);
 
-					}
+				}
 
-				});
+			});
 
-			} else search.reset();
+		} else search.reset();
 
-		}, 250));
+	}, 250));
 
-	},
+}
 
-	reset: function() {
+search.reset = function() {
 
-		$("#search").val("");
-		$(".no_content").remove();
+	$('#search').val('');
+	$('.no_content').remove();
 
-		if (search.code!=="") {
+	if (search.code!=='') {
 
-			// Trash data
-			albums.json = null;
-			album.json = null;
-			photo.json = null;
-			search.code = "";
+		// Trash data
+		albums.json	= null;
+		album.json	= null;
+		photo.json	= null;
+		search.code	= '';
 
-			lychee.animate(".divider", "fadeOut");
-			albums.load();
-
-		}
+		lychee.animate('.divider', 'fadeOut');
+		albums.load();
 
 	}
 
-};
+}

Some files were not shown because too many files changed in this diff