From 0bffb5432c20e54a6ca155df12f37acf2c985efc Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sun, 19 Oct 2014 14:29:09 +0200 Subject: [PATCH] Code adjustments --- src/scripts/view/main.js | 82 ++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/src/scripts/view/main.js b/src/scripts/view/main.js index c3b5588..dddc30e 100644 --- a/src/scripts/view/main.js +++ b/src/scripts/view/main.js @@ -5,95 +5,97 @@ * @copyright 2014 by Tobias Reich */ -var header = $("header"), - headerTitle = $("#title"), - imageview = $("#imageview"), - api_path = "php/api.php", - infobox = $("#infobox"); +var header = $('header'), + headerTitle = $('#title'), + imageview = $('#imageview'), + api_path = 'php/api.php', + infobox = $('#infobox'); $(document).ready(function(){ /* Event Name */ - if (mobileBrowser()) event_name = "touchend"; - else event_name = "click"; + if (mobileBrowser()) event_name = 'touchend'; + else event_name = 'click'; /* Window */ $(window).keydown(key); /* Infobox */ - $(document).on(event_name, "#infobox .header a", function() { hideInfobox() }); - $(document).on(event_name, "#infobox_overlay", function() { hideInfobox() }); - $("#button_info").on(event_name, function() { showInfobox() }); + $(document).on(event_name, '#infobox .header a', function() { hideInfobox() }); + $(document).on(event_name, '#infobox_overlay', function() { hideInfobox() }); + $('#button_info').on(event_name, function() { showInfobox() }); /* Direct Link */ - $("#button_direct").on(event_name, function() { + $('#button_direct').on(event_name, function() { - link = $("#imageview #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, ""); - window.open(link,"_newtab"); + link = $('#imageview #image').css('background-image').replace(/"/g,'').replace(/url\(|\)$/ig, ''); + window.open(link,'_newtab'); }); - loadPhotoInfo(gup("p")); + loadPhotoInfo(gup('p')); }); -function key(e) { +key = function(e) { code = (e.keyCode ? e.keyCode : e.which); if (code===27&&visibleInfobox()) { hideInfobox(); e.preventDefault(); } } -function visibleInfobox() { +visibleInfobox = function() { - if (parseInt(infobox.css("right").replace("px", ""))<0) return false; + if (parseInt(infobox.css('right').replace('px', ''))<0) return false; else return true; } -function isPhotoSmall(photo) { +isPhotoSmall = function(photo) { - size = [ - ["width", false], - ["height", false] - ]; + size = { + width: false, + height: false + }; - if (photo.width<$(window).width()-60) size["width"] = true; - if (photo.height<$(window).height()-100) size["height"] = true; + if (photo.width<$(window).width()-60) size.width = true; + if (photo.height<$(window).height()-100) size.height = true; - if (size["width"]&&size["height"]) return true; + if (size.width&&size.height) return true; else return false; } -function showInfobox() { +showInfobox = function() { - $("body").append("
"); - infobox.addClass("active"); + $('body').append("
"); + infobox.addClass('active'); } -function hideInfobox() { +hideInfobox = function() { - $("#infobox_overlay").removeClass("fadeIn").addClass("fadeOut"); - setTimeout(function() { $("#infobox_overlay").remove() }, 300); - infobox.removeClass("active"); + $('#infobox_overlay').removeClass('fadeIn').addClass('fadeOut'); + setTimeout(function() { $('#infobox_overlay').remove() }, 300); + infobox.removeClass('active'); } -function loadPhotoInfo(photoID) { +loadPhotoInfo = function(photoID) { - params = "function=getPhoto&photoID=" + photoID + "&albumID=0&password=''"; - $.ajax({type: "POST", url: api_path, data: params, dataType: "json", success: function(data) { + params = 'function=getPhoto&photoID=' + photoID + '&albumID=0&password=""'; + $.ajax({type: 'POST', url: api_path, data: params, dataType: 'json', success: function(data) { - if (!data.title) data.title = "Untitled"; - document.title = "Lychee - " + data.title; + if (!data.title) data.title = 'Untitled'; + document.title = 'Lychee - ' + data.title; headerTitle.html(data.title); - imageview.attr("data-id", photoID); + imageview.attr('data-id', photoID); + if (isPhotoSmall(data)) imageview.html("
"); else imageview.html("
"); - imageview.removeClass("fadeOut").addClass("fadeIn").show(); + + imageview.removeClass('fadeOut').addClass('fadeIn').show(); infobox.html(build.infoboxPhoto(data, true)).show(); @@ -101,7 +103,7 @@ function loadPhotoInfo(photoID) { } -function ajaxError(jqXHR, textStatus, errorThrown) { +ajaxError = function(jqXHR, textStatus, errorThrown) { console.log(jqXHR); console.log(textStatus);