Browse Source

Updated init.js (ES2015)

Tobias Reich 8 years ago
parent
commit
1987286efc
2 changed files with 76 additions and 82 deletions
  1. 0 0
      dist/main.js
  2. 76 82
      src/scripts/init.js

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


+ 76 - 82
src/scripts/init.js

@@ -1,134 +1,128 @@
 /**
- * @description	This module is used for bindings.
- * @copyright	2015 by Tobias Reich
+ * @description This module is used for bindings.
+ * @copyright   2015 by Tobias Reich
  */
 
 $(document).ready(function() {
 
-	/* Event Name */
-	var eventName = lychee.getEventName();
+	// Event Name
+	let eventName = lychee.getEventName()
 
-	/* Set API error handler */
-	api.onError = lychee.error;
+	// Set API error handler
+	api.onError = lychee.error
 
-	/* Multiselect */
-	multiselect.bind();
+	// Multiselect
+	multiselect.bind()
 
-	/* Header */
-	header.bind();
+	// Header
+	header.bind()
 
-	/* Image View */
+	// Image View
 	lychee.imageview
-		.on(eventName, '.arrow_wrapper--previous',	photo.previous)
-		.on(eventName, '.arrow_wrapper--next',		photo.next);
+		.on(eventName, '.arrow_wrapper--previous', photo.previous)
+		.on(eventName, '.arrow_wrapper--next',     photo.next)
 
-	/* Keyboard */
+	// Keyboard
 	Mousetrap
-		.bind('left',			function() { if (visible.photo()) $('#imageview a#previous').click() })
-		.bind('right',			function() { if (visible.photo()) $('#imageview a#next').click() })
-		.bind('u',	function() { $('#upload_files').click() })
-		.bind(['s', 'f'], function(e) {
-			if (visible.photo())		header.dom('#button_star').click();
-			else if (visible.albums())	header.dom('#search').focus();
-			return false;
+		.bind('left', function() {
+			if (visible.photo()) { $('#imageview a#previous').click(); return false }
 		})
-		.bind('r', function(e) {
-			e.preventDefault();
-			if (visible.album())		album.setTitle(album.getID());
-			else if (visible.photo())	photo.setTitle([photo.getID()]);
+		.bind('right', function() {
+			if (visible.photo()) { $('#imageview a#next').click(); return false }
 		})
-		.bind('d', function(e) {
-			e.preventDefault();
-			if (visible.photo())		photo.setDescription(photo.getID());
-			else if (visible.album())	album.setDescription(album.getID());
+		.bind('u', function() {
+			if (!visible.photo()) { $('#upload_files').click(); return false }
 		})
-		.bind('t', function(e) {
-			if (visible.photo()) {
-				e.preventDefault();
-				photo.editTags([photo.getID()]);
-			}
+		.bind(['s', 'f'], function() {
+			if (visible.photo())       { header.dom('#button_star').click(); return false }
+			else if (visible.albums()) { header.dom('#search').focus(); return false }
+		})
+		.bind('r', function() {
+			if (visible.album())      { album.setTitle(album.getID()); return false }
+			else if (visible.photo()) { photo.setTitle([photo.getID()]); return false }
+		})
+		.bind('d', function() {
+			if (visible.photo())      { photo.setDescription(photo.getID()); return false }
+			else if (visible.album()) { album.setDescription(album.getID()); return false }
+		})
+		.bind('t', function() {
+			if (visible.photo()) { photo.editTags([photo.getID()]); return false }
 		})
 		.bind('i', function() {
-			if (visible.multiselect())		return false;
-			else							sidebar.toggle();
+			if (!visible.multiselect()) { sidebar.toggle(); return false }
 		})
 		.bind(['command+backspace', 'ctrl+backspace'], function() {
-			if (visible.photo()&&!visible.message())		photo.delete([photo.getID()]);
-			else if (visible.album()&&!visible.message())	album.delete([album.getID()]);
+			if (visible.photo() && !visible.message())      { photo.delete([photo.getID()]); return false }
+			else if (visible.album() && !visible.message()) { album.delete([album.getID()]); return false }
 		})
 		.bind(['command+a', 'ctrl+a'], function() {
-			if (visible.album()&&!visible.message())		multiselect.selectAll();
-			else if (visible.albums()&&!visible.message())	multiselect.selectAll();
-		});
+			if (visible.album() && !visible.message())       { multiselect.selectAll(); return false }
+			else if (visible.albums() && !visible.message()) { multiselect.selectAll(); return false }
+		})
 
 	Mousetrap.bindGlobal('enter', function() {
-		if (basicModal.visible()===true) basicModal.action();
-	});
-
-	Mousetrap.bindGlobal(['esc', 'command+up'], function(e) {
-		e.preventDefault();
-		if (basicModal.visible()===true)							basicModal.cancel();
-		else if (visible.contextMenu())								contextMenu.close();
-		else if (visible.photo())									lychee.goto(album.getID());
-		else if (visible.album())									lychee.goto('');
-		else if (visible.albums()&&$('#search').val().length!==0)	search.reset();
-	});
-
+		if (basicModal.visible()===true) basicModal.action()
+	})
+
+	Mousetrap.bindGlobal(['esc', 'command+up'], function() {
+		if (basicModal.visible()===true)                            basicModal.cancel()
+		else if (visible.contextMenu())                             contextMenu.close()
+		else if (visible.photo())                                   lychee.goto(album.getID())
+		else if (visible.album())                                   lychee.goto('')
+		else if (visible.albums() && $('#search').val().length!==0) search.reset()
+		return false
+	})
 
 	if (eventName==='touchend') {
 
 		$(document)
 
-			/* Fullscreen on mobile */
+			// Fullscreen on mobile
 			.on('touchend', '#image', function(e) {
-				if (swipe.obj==null||(swipe.offset>=-5&&swipe.offset<=5)) {
-					if (visible.header())	header.hide(e, 0);
-					else					header.show();
+				if (swipe.obj==null || (swipe.offset>=-5&&swipe.offset<=5)) {
+					if (visible.header()) header.hide(e, 0)
+					else                  header.show()
 				}
 			})
 
-			/* Swipe on mobile */
-			.swipe().on('swipeStart',	function() { if (visible.photo()) swipe.start($('#image')) })
-			.swipe().on('swipeMove',	function(e) { if (visible.photo()) swipe.move(e.swipe) })
-			.swipe().on('swipeEnd',		function(e) { if (visible.photo()) swipe.stop(e.swipe, photo.previous, photo.next) });
+			// Swipe on mobile
+			.swipe().on('swipeStart', function() { if (visible.photo()) swipe.start($('#image')) })
+			.swipe().on('swipeMove',  function(e) { if (visible.photo()) swipe.move(e.swipe) })
+			.swipe().on('swipeEnd',   function(e) { if (visible.photo()) swipe.stop(e.swipe, photo.previous, photo.next) })
 
 	}
 
-	/* Document */
+	// Document
 	$(document)
 
-		/* Login */
-		.on('keyup', '#password', function() { if ($(this).val().length>0) $(this).removeClass('error') })
-
-		/* Navigation */
+		// Navigation
 		.on('click', '.album', function() { lychee.goto($(this).attr('data-id')) })
 		.on('click', '.photo', function() { lychee.goto(album.getID() + '/' + $(this).attr('data-id')) })
 
-		/* Context Menu */
+		// Context Menu
 		.on('contextmenu', '.photo', function(e) { contextMenu.photo(photo.getID(), e) })
 		.on('contextmenu', '.album', function(e) { contextMenu.album(album.getID(), e) })
 
-		/* Upload */
-		.on('change', '#upload_files',				function() { basicModal.close(); upload.start.local(this.files) })
-		.on('dragover',								function(e) { e.preventDefault(); }, false)
-		.on('drop', function(e) {
+		// Upload
+		.on('change', '#upload_files', function() { basicModal.close(); upload.start.local(this.files) })
 
-			e.stopPropagation();
-			e.preventDefault();
+		// Drag and Drop upload
+		.on('dragover', function() { return false }, false)
+		.on('drop', function(e) {
 
 			// Close open overlays or views which are correlating with the upload
-			if (visible.photo())		lychee.goto(album.getID());
-			if (visible.contextMenu())	contextMenu.close();
+			if (visible.photo())       lychee.goto(album.getID())
+			if (visible.contextMenu()) contextMenu.close()
 
 			// Detect if dropped item is a file or a link
-			if (e.originalEvent.dataTransfer.files.length>0)				upload.start.local(e.originalEvent.dataTransfer.files);
-			else if (e.originalEvent.dataTransfer.getData('Text').length>3)	upload.start.url(e.originalEvent.dataTransfer.getData('Text'));
+			if (e.originalEvent.dataTransfer.files.length>0)                upload.start.local(e.originalEvent.dataTransfer.files)
+			else if (e.originalEvent.dataTransfer.getData('Text').length>3) upload.start.url(e.originalEvent.dataTransfer.getData('Text'))
 
-			return true;
+			return false
 
-		});
+		})
 
-	/* Init */
-	lychee.init();
+	// Init
+	lychee.init()
 
-});
+})

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