Browse Source

added zoom feature.

Signed-off-by: root <root@ipekatrinadei.ipe.kit.edu>
root 6 years ago
parent
commit
059aa5ac52

+ 16 - 1
static/fossil/css/style.css

@@ -238,7 +238,10 @@ hr {
 	border-radius: 10px;
 }
 
-.photowrapper img {
+.photowrapper #img-front,
+.photowrapper #img-top,
+.photowrapper #placeholder-left,
+.photowrapper #img-preview {
     margin-top: 15px;
     width: 100%;
     height: 100%;
@@ -372,3 +375,15 @@ hr {
 #placeholder-left:-moz-full-screen { cursor:zoom-out; width: auto; }
 #placeholder-left:-ms-fullscreen { cursor:zoom-out; width: auto; }
 #placeholder-left:fullscreen { cursor:zoom-out; width: auto; }
+
+#test {  
+    position: absolute;
+    top: 10px;
+    right: 10px;
+    border: 1px solid red; 
+    display: block; 
+    background: #FFF; 
+    z-index: 2147483647;
+}
+
+

+ 1 - 1
static/fossil/js/jquery.ez-plus.js

@@ -1942,7 +1942,7 @@ if (typeof Object.create !== 'function') {
 
     $.fn.ezPlus.options = {
         attrImageZoomSrc: 'zoom-image', // attribute to plugin use for zoom
-        borderColour: '#888',
+        borderColour: '#C91921',
         borderSize: 4,
         constrainSize: false,  //in pixels the dimensions you want to constrain on
         constrainType: false,  //width or height

+ 338 - 0
static/fossil/js/jquery.fullscreenslides.js

@@ -0,0 +1,338 @@
+/*
+ * Copyright Eike Send: http://eike.se/nd
+ * License: MIT / GPLv2
+ * 
+ * This is a jQuery plugin to generate full screen galleries.
+ *
+ * https://github.com/eikes/jquery.fullscreen.js
+ */
+;
+/* 
+ * It assumes that your images are wrapped in links like this:
+ * 
+ * <a href="image-1-large.jpg" rel="gallery-1" title="woot">
+ *   <img src="image-1-small"/>
+ * </a>
+ * <a href="image-2-large.jpg" rel="gallery-1" title="woot">
+ *   <img src="image-2-small"/>
+ * </a>
+ * <a href="image-3-large.jpg" rel="gallery-1" title="woot">
+ *   <img src="image-3-small"/>
+ * </a>
+ * 
+ * You would then call it like this:
+ * 
+ * <script src="http://code.jquery.com/jquery.js"></script>
+ * <script src="fullscreenslides.js"></script>
+ * <script>
+ *  $(function(){
+ *    $("img").fullscreenslides();
+ *    
+ *    // You can then use the container:
+ *    var $container = $('#fullscreenSlideshowContainer');
+ *    
+ *    // Bind to events:
+ *    $container
+ *      .bind("init", function() { 
+ *
+ *        // Do something like adding a logo and adding a UI
+ *        $container
+ *          .append('<div class="ui" id="fullscreen-close">&times;</div>')
+ *          .append('<div class="ui" id="fullscreen-loader"></div>')
+ *          .append('<div class="ui" id="fullscreen-prev">&larr;</div>')
+ *          .append('<div class="ui" id="fullscreen-next">&rarr;</div>');
+ *
+ *        $('#fullscreen-prev').click(function(){
+ *          // You can trigger events as well:
+ *          $container.trigger("prevSlide");
+ *        });
+ *        $('#fullscreen-next').click(function(){
+ *          // You can trigger events as well:
+ *          $container.trigger("nextSlide");
+ *        });
+ *        $('#fullscreen-close').click(function(){
+ *          // You can trigger events as well:
+ *          $container.trigger("close");
+ *        });
+ *
+ *      })
+ *      .bind("startLoading", function() { 
+ *        // show spinner
+ *      })
+ *      .bind("stopLoading", function() { 
+ *        // hide spinner
+ *      })
+ *      .bind("startOfSlide", function(event, slide) { 
+ *        // show Caption, notice the slide element
+ *      })
+ *      .bind("stopLoading", function(event, slide) { 
+ *        // hide caption
+ *      })
+ *    
+ *  });
+ * </script>
+ * 
+ */
+
+(function($){
+  
+  var $container;
+
+  var attachEvents = function(){
+    
+    // deal with resizing the browser window and resize container
+    $container.bind("updateSize orientationchange", function(event) {
+      $container.height($(window).height());
+      updateSlideSize();
+    });
+    
+    // privat function to update the image size and position of a slide
+    var updateSlideSize = function(slide) {
+      if (slide === undefined) {
+        var slide = $container.data("currentSlide");
+      }
+      if (slide && slide.$img) {
+        var wh = $(window).height();
+        var ww = $(window).width();
+        // compare the window aspect ratio to the image aspect ratio
+        // to use either maximum width or height
+        if ((ww / wh) > (slide.$img.width() / slide.$img.height())) {
+          slide.$img.css({
+            "height" : wh + "px",
+            "width"  : "auto"
+          });
+        } else {
+          slide.$img.css({
+            "height" : "auto",
+            "width"  : ww + "px"
+          });
+        }
+        // update margins to position in the center
+        slide.$img.css({
+          "margin-left" : "-" + (0.5 * slide.$img.width()) + "px",
+          "margin-top"  : "-" + (0.5 * slide.$img.height()) + "px"
+        });
+      }
+    }
+    
+    $(window).bind("resize", function(){
+      //todo: throttle
+      $container.trigger("updateSize");
+    });
+    
+    // Show individual slides
+    var isLoading = false;
+    $container.bind("showSlide", function(event, newSlide) {
+      if (!isLoading) {
+        var oldSlide = $container.data("currentSlide");
+        // if it is not loaded yet then initialize the dom object and load it
+        if (!("$img" in newSlide)) {
+          isLoading = true;
+          $container.trigger("startLoading");
+          newSlide.$img = $('<img class="slide">')
+            .css({
+              "position"    : "absolute",
+              "left"        : "50%",
+              "top"         : "50%"
+            })
+            .hide()
+            // on load get the images dimensions and show it
+            .load(function(){
+              isLoading = false;
+              $container.trigger("stopLoading");
+              updateSlideSize(newSlide);
+              changeSlide(oldSlide, newSlide);
+            })
+            .error(function(){
+              isLoading = false;
+              newSlide.error = true;
+              $container
+                .trigger("stopLoading")
+                .trigger("error", newSlide);
+            })
+            .attr("src", newSlide.image);
+          $container.append(newSlide.$img);
+        } else {
+          changeSlide(oldSlide, newSlide);
+        }
+      }
+    });
+    
+    $container.bind("prevSlide nextSlide", function(event) {
+      var nextID,
+          slides = $container.data("slides"),
+          currentSlide = $container.data("currentSlide"),
+          currentID = currentSlide && currentSlide.id || 0;
+      if (event.type == "nextSlide") {
+        nextID = (currentID + 1) % slides.length;
+      } else {
+        nextID = (currentID - 1 + slides.length) % slides.length;
+      }
+      $container.trigger("showSlide", slides[nextID]);
+    });
+    
+    // privat function to change between slides
+    var changeSlide = function(oldSlide, newSlide) {
+      if (oldSlide !== undefined) {
+        $container.trigger("endOfSlide", oldSlide);
+        oldSlide.$img.fadeOut();
+      }
+      if (newSlide.$img && !newSlide.error) {
+        newSlide.$img.fadeIn(function(){
+          $container.trigger("startOfSlide", newSlide);
+        });
+      } else {
+        $container.trigger("startOfSlide", newSlide);
+      }
+      $container.data("currentSlide", newSlide);
+    }
+    
+    // keyboard navigation
+    var keyFunc = function(event) {
+      if (event.keyCode == 27) { // ESC
+        $container.trigger("close");
+      }
+      if (event.keyCode == 37) { // Left
+        $container.trigger("prevSlide");
+      }
+      if (event.keyCode == 39) { // Right
+        $container.trigger("nextSlide");
+      }
+    }
+    
+    // Close the viewer
+    $container.bind("close", function (){
+      var options = $container.data("options");
+      var oldSlide = $container.data("currentSlide");
+      oldSlide && oldSlide.$img && oldSlide.$img.hide();
+      $container.trigger("endOfSlide", oldSlide);
+      $(document).unbind("keydown", keyFunc);
+      // Use the fancy new FullScreenAPI:
+      if (options.useFullScreen) {
+        if (document.cancelFullScreen) {  
+          document.cancelFullScreen();  
+        } 
+        if (document.mozCancelFullScreen) {
+          $("html").css("overflow", "auto");
+          $(document).scrollTop($container.data("mozScrollTop"));
+          document.mozCancelFullScreen();
+        } 
+        if (document.webkitCancelFullScreen) {
+          document.webkitCancelFullScreen();
+        }
+        document.removeEventListener('fullscreenchange', changeFullScreenHandler);
+        document.removeEventListener('mozfullscreenchange', changeFullScreenHandler);
+        document.removeEventListener('webkitfullscreenchange', changeFullScreenHandler);
+      } else {
+        $container.data("hiddenElements").show();
+        $(window).scrollTop($container.data("originalScrollTop"));
+      }
+      $container
+        .removeData("currentSlide slides width height originalScrollTop hiddenElements")
+        .hide();
+    });
+    
+    // When ESC is pressed in full screen mode, the keypressed event is not
+    // triggered, so this here catches the exit-fullscreen event:
+    function changeFullScreenHandler(event) {
+      if ($container.data("isFullScreen")) {
+        $container.trigger("close");
+      }
+      $container.data("isFullScreen", true);
+    }
+    
+    var firstrun = true;
+    // Show a particular slide
+    $container.bind("show", function(event, rel, slide){
+      var options = $container.data("options");
+      var slideshows = $container.data("slideshows");
+      var slides = slideshows[rel];
+      $container.data("slides", slides);
+      $container.trigger("updateSize");
+      $(document).bind("keydown", keyFunc);
+      // Use the fancy new FullScreenAPI:
+      if (options.useFullScreen) {
+        con = $container[0];
+        if (con.requestFullScreen) {
+          con.requestFullScreen();
+          document.addEventListener('fullscreenchange', changeFullScreenHandler);
+        } 
+        if (con.mozRequestFullScreen) {
+          con.mozRequestFullScreen();
+          document.addEventListener('mozfullscreenchange', changeFullScreenHandler);
+          $container.data("mozScrollTop", $(document).scrollTop());
+          $("html").css("overflow", "hidden");
+        } 
+        if (con.webkitRequestFullScreen) {
+          con.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
+          document.addEventListener('webkitfullscreenchange', changeFullScreenHandler);
+        } 
+        $container.data("isFullScreen", false);
+      } 
+      if (firstrun) {
+        $container.trigger("init");
+        firstrun = false;
+      }
+      if (!options.useFullScreen) {
+        $container.data("hiddenElements", $('body > *').filter(function(){return $(this).css("display")!="none";}).hide());
+      }
+      if (!$container.data("originalScrollTop")) {
+        $container.data("originalScrollTop", $(window).scrollTop());
+      }
+      $container.show();
+      $container.trigger("showSlide", slide);
+    });
+    
+  }
+
+  $.fn.fullscreenslides = function(options) {
+    $container = $('#fullscreenSlideshowContainer');
+    if ($container.length == 0) {
+      $container = $('<div id="fullscreenSlideshowContainer">').hide();
+      $("body").append($container);
+      attachEvents();
+    }
+    // initialize variables
+    var options = $.extend({
+      "bgColor"           : "#000",
+      "useFullScreen"     : true,
+      "startSlide"        : 0
+    }, options || {});
+    // Check if fullScreenApi is available
+    options.useFullScreen = options.useFullScreen && !!(
+      $container[0].requestFullScreen ||
+      $container[0].mozRequestFullScreen ||
+      $container[0].webkitRequestFullScreen);
+    $container.data("options", options);
+    // Apply default styles
+    $container.css({
+      "position"         : "absolute",
+      "top"              : "0px",
+      "left"             : "0px",
+      "width"            : "100%",
+      "text-align"       : "center",
+      "background-color" : options.bgColor
+    });
+    var slideshows = {};
+    // Store galleries
+    this.each(function(){
+      var link = $(this).parents("a")[0];
+      if (!link.rel) link.setAttribute("rel", "__all__");
+      var slide = {
+        image: link.href,
+        title: link.title,
+        rel: link.rel
+      };
+      slide.data = $.extend({}, $(this).data(), $(link).data());
+      slideshows[slide.rel] = slideshows[slide.rel] || [];
+      slideshows[slide.rel].push(slide);
+      slide.id = slideshows[slide.rel].length - 1;
+      $(link).data("slide", slide);
+      $(link).click(function(event){
+        $container.trigger("show", [this.rel, $(this).data("slide")]);
+        event.preventDefault();
+      });
+    });
+    $container.data("slideshows", slideshows);
+  }
+})(jQuery);

+ 102 - 14
static/fossil/js/script.js

@@ -1,11 +1,69 @@
+var glob_width;
+var glob_height;
+var glob_elem;
+
+if (document.addEventListener)
+{
+    document.addEventListener('webkitfullscreenchange', exitHandler, false);
+    document.addEventListener('mozfullscreenchange', exitHandler, false);
+    document.addEventListener('fullscreenchange', exitHandler, false);
+    document.addEventListener('MSFullscreenChange', exitHandler, false);
+}
+
+function exitHandler() {
+    if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) {
+        if (!document.fullscreenElement && !document.mozFullScreenElement &&
+            !document.webkitFullscreenElement && !document.msFullscreenElement) { 
+            console.log("Exit FS");
+            //$(glob_elem).css("width", glob_width+"px");
+            //$(glob_elem).css("height", glob_height+"px");
+            $(glob_elem).css("width", "100%");
+            $(glob_elem).css("height", "100%");
+            $(glob_elem).css("background-color", "white");
+            $(glob_elem).css("color", "#000");
+            $("#front-quality-text").text("Size: 25%");
+            $("#top-quality-text").text("Size: 25%");
+            $("#left-quality-text").text("Size: 25%");
+        } else {
+            console.log("Enter FS");
+            $("#front-quality-text").text("Size: 100%");
+            $("#top-quality-text").text("Size: 100%");
+            $("#left-quality-text").text("Size: 100%");
+        }
+    }
+}
+
+
 function toggleFullscreen(elem) {
     elem = elem || document.documentElement;
+
+    var ori_width = glob_width
+    var ori_height = glob_height;
+      
+    console.log("DEBUG");
+    console.log(screen.width, screen.height, glob_width, glob_height)
+    var fs_scale;
+
     if (!document.fullscreenElement && !document.mozFullScreenElement &&
       !document.webkitFullscreenElement && !document.msFullscreenElement) { 
+      if ((ori_height*1.2) > ori_width) {
+        newWidth = screen.width * 0.5;
+        newHeight = screen.width * (ori_height/ori_width) * 0.5;
+      } else {
+        newHeight = screen.height * 0.6;
+        newWidth = screen.height * (ori_width/ori_height) * 0.6;
+      }
+      //$(elem, "img").css("height", (screen.height*0.8)+"px");
+      //$(elem, "img").css("width", (screen.width*0.8)+"px");
+      $(elem, "img").css("height", (newHeight)+"px");
+      $(elem, "img").css("width", (newWidth)+"px");
 
-      img_fullscreen = $(elem).attr("src").split("-");
-      img_fullscreen = img_fullscreen[0] + "-" + img_fullscreen[1] + img_fullscreen[2].slice(7);
-      $(elem).attr("src", img_fullscreen);
+      
+      
+      //$(elem).css("width", Math.max(screen.width, screen.height)+"px");
+      //$(elem).css("width", "90%");
+      $(elem).css("background-color", "black");
+      $(elem).css("color", "#ccc");
 
       if (elem.requestFullscreen) {
         elem.requestFullscreen();
@@ -17,10 +75,19 @@ function toggleFullscreen(elem) {
         elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
       }
     } else {
+      console.log("Set width height");
+      console.log(ori_width);
+      console.log(ori_height);
+      $(elem).css("width", "100%");
+      //$(elem).css("height", "100%");
+      //$(elem).css("width", ori_width+"px");
+      //$(elem).css("height", ori_height+"px");
+      $(elem).css("background-color", "white");
+      $(elem).css("color", "#000");
 
-      img_fullscreen = $(elem).attr("src").split("&");
-      img_fullscreen = img_fullscreen[0] + "&" + img_fullscreen[1] + "&" + img_fullscreen[2] + "-resized&" + img_fullscreen[3];
-      $(elem).attr("src", img_fullscreen);
+      //img_fullscreen = $(elem).attr("src").split("&");
+      //img_fullscreen = img_fullscreen[0] + "&" + img_fullscreen[1] + "&" + img_fullscreen[2] + "-resized&" + img_fullscreen[3];
+      //$(elem).attr("src", img_fullscreen);
 
       if (document.exitFullscreen) {
         document.exitFullscreen();
@@ -242,22 +309,39 @@ $(function() {
         $("#placeholder-left").attr("src", "img?id="+id+"&name="+name+"&type=left-resized&counter="+index.toString());
     });
 
-    /*
+
     document.getElementById("img-front").addEventListener("click", function() {
-        console.log(this);
-        toggleFullscreen(this);
+        var container = $("#photowrapper-front");
+        if (!document.fullscreenElement && !document.mozFullScreenElement &&
+            !document.webkitFullscreenElement && !document.msFullscreenElement) { 
+            glob_width = $("#photowrapper-front > img").width();
+            glob_height = $("#photowrapper-front > img").height();
+            glob_elem = $("#photowrapper-front")[0];
+        }
+        toggleFullscreen(container[0]);
     });
 
     document.getElementById('img-top').addEventListener('click', function() {
-        console.log(this);
-        toggleFullscreen(this);
+        var container = $("#photowrapper-top");
+        if (!document.fullscreenElement && !document.mozFullScreenElement &&
+            !document.webkitFullscreenElement && !document.msFullscreenElement) { 
+            glob_width = $("#photowrapper-top > img").width();
+            glob_height = $("#photowrapper-top > img").height();
+            glob_elem = $("#photowrapper-top")[0];
+        }
+        toggleFullscreen(container[0]);
     });
 
     document.getElementById('placeholder-left').addEventListener('click', function() {
-        console.log(this);
-        toggleFullscreen(this);
+        var container = $("#photowrapper-left");
+        if (!document.fullscreenElement && !document.mozFullScreenElement &&
+            !document.webkitFullscreenElement && !document.msFullscreenElement) { 
+            glob_width = $("#photowrapper-left > img").width();
+            glob_height = $("#photowrapper-left > img").height();
+            glob_elem = $("#photowrapper-left")[0];
+        }
+        toggleFullscreen(container[0]);
     });
-    */
 
     $("#img-top").ezPlus({
         zoomWindowPosition: 1,
@@ -285,4 +369,8 @@ $(function() {
         zoomWindowWidth: 300,
         zoomWindowHeight: 300
     });
+
+
 });
+
+

+ 22 - 21
templates/index.html

@@ -95,37 +95,37 @@
         </div>
 
         <div id="img-right">
-            <div class="cont">
-                <img id="front-left" class="icon" src="{{ static_url("img/icon/left-arrow.svg") }}"/>
-                <span id="image-text">Front: <span id="front-text">1</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="front-quality-text"></span></span>
-                <img id="front-right" class="icon" src="{{ static_url("img/icon/right-arrow.svg") }}"/>
-            </div>
-	        <div class="photowrapper">
+	        <div id="photowrapper-front" class="photowrapper">
+                <div class="cont">
+                    <img id="front-left" class="icon" src="{{ static_url("img/icon/left-arrow.svg") }}"/>
+                    <span id="image-text">Front: <span id="front-text">1</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="front-quality-text"></span></span>
+                    <img id="front-right" class="icon" src="{{ static_url("img/icon/right-arrow.svg") }}"/>
+                </div>
                 <img id="img-front" src="img?id={{ index }}&name={{ name }}&type=front-resized&counter=0"/>
+                <div id="slider-right"></div><div class="slice-count" id="front-count">{{ front_count }}</div>
             </div>
-            <div id="slider-right"></div><div class="slice-count" id="front-count">{{ front_count }}</div>
         </div>
         
         <div id="img-center">
-            <div class="cont">
-                <img id="top-left" class="icon" src="{{ static_url("img/icon/left-arrow.svg") }}"/>
-                <span id="image-text">Top: <span id="top-text">1</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="top-quality-text"></span></span>
-                <img id="top-right" class="icon" src="{{ static_url("img/icon/right-arrow.svg") }}"/>
-            </div>
-	        <div class="photowrapper">
+	        <div id="photowrapper-top" class="photowrapper">
+                <div class="cont">
+                    <img id="top-left" class="icon" src="{{ static_url("img/icon/left-arrow.svg") }}"/>
+                    <span id="image-text">Top: <span id="top-text">1</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="top-quality-text"></span></span>
+                    <img id="top-right" class="icon" src="{{ static_url("img/icon/right-arrow.svg") }}"/>
+                </div>
                 <img id="img-top" src="img?id={{ index }}&name={{ name }}&type=top-resized&counter=0" data-zoom-image="img?id={{ index }}&name={{ name }}&type=top-resized&counter=0" />
+	            <div id="slider-center"></div><div class="slice-count" id="top-count">{{ top_count }}</div>
             </div>
-	        <div id="slider-center"></div><div class="slice-count" id="top-count">{{ top_count }}</div>
 
-            <div class="cont">
-                <img id="left-left" class="icon" src="{{ static_url("img/icon/left-arrow.svg") }}"/>
-                <span id="image-text">Left: <span id="left-text">1</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="left-quality-text"></span></span>
-                <img id="left-right" class="icon" src="{{ static_url("img/icon/right-arrow.svg") }}"/>
-            </div>
-	        <div class="photowrapper">
+	        <div id="photowrapper-left" class="photowrapper">
+                <div class="cont">
+                    <img id="left-left" class="icon" src="{{ static_url("img/icon/left-arrow.svg") }}"/>
+                    <span id="image-text">Left: <span id="left-text">1</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="left-quality-text"></span></span>
+                    <img id="left-right" class="icon" src="{{ static_url("img/icon/right-arrow.svg") }}"/>
+                </div>
                 <img id="placeholder-left" src="img?id={{ index }}&name={{ name }}&type=left-resized&counter=0"/>
+	            <div id="slider-left"></div><div class="slice-count" id="left-count">{{ left_count }}</div>
             </div>
-	        <div id="slider-left"></div><div class="slice-count" id="left-count">{{ left_count }}</div>
 
         </div>
     </div>
@@ -135,6 +135,7 @@
 <script src="{{ static_url("js/jquery-1.12.4.min.js") }}"></script>
 <script src="{{ static_url("js/jquery-ui.min.js") }}"></script>
 <script src="{{ static_url("js/jquery.ez-plus.js") }}"></script>
+<script src="{{ static_url("js/jquery.fullscreenslides.js") }}"></script>
 <script src="{{ static_url("js/script.js") }}"></script>
 </body>
 </html>