Ticket #5434: 0005-0001-Fix-for-issue-5434-Lightbox-effect-for-images.patch

File 0005-0001-Fix-for-issue-5434-Lightbox-effect-for-images.patch, 4.8 KB (added by Saksham Agrawal, 8 years ago)
  • new file mediagoblin/static/css/lightbox.css

    From 9be04a0063196ff4ffdd819434032b8a36cd72db Mon Sep 17 00:00:00 2001
    From: saksham1115 <saksham115@gmail.com>
    Date: Thu, 3 Mar 2016 20:20:53 +0530
    Subject: [PATCH 5/5] 0001 Fix for issue #5434 : Lightbox effect for images
    
    ---
     mediagoblin/static/css/lightbox.css                | 21 +++++++
     mediagoblin/static/js/lightbox.js                  | 70 ++++++++++++++++++++++
     .../templates/mediagoblin/user_pages/media.html    |  6 +-
     3 files changed, 96 insertions(+), 1 deletion(-)
     create mode 100644 mediagoblin/static/css/lightbox.css
     create mode 100644 mediagoblin/static/js/lightbox.js
    
    diff --git a/mediagoblin/static/css/lightbox.css b/mediagoblin/static/css/lightbox.css
    new file mode 100644
    index 0000000..e4fa4c4
    - +  
     1body {
     2    height: 100%;
     3}
     4.overlay {
     5    position: absolute;
     6    top: 0;
     7    left: 0;
     8    height: 100%;
     9    width: 100%;
     10    opacity: 0;
     11    filter: alpha(opacity=0);
     12    z-index: 50;
     13    cursor: pointer;
     14}
     15.box {
     16    position: absolute;
     17    opacity: 0;
     18    filter: alpha(opacity=0);
     19    left: -9999em;
     20    z-index: 51;
     21}
  • new file mediagoblin/static/js/lightbox.js

    diff --git a/mediagoblin/static/js/lightbox.js b/mediagoblin/static/js/lightbox.js
    new file mode 100644
    index 0000000..8d7bf31
    - +  
     1$(document).ready(function() {
     2    $(".lightbox").click(function() {
     3        overlayLink = $(this).attr("href");  //Getting the link for the media
     4        window.startOverlay(overlayLink);
     5        return false;
     6    });
     7});
     8
     9function startOverlay(overlayLink) {
     10
     11    // Adding elements to the page
     12    $("body")
     13        .append('<div class="overlay"></div><div class="box"></div>')
     14        .css({
     15            "overflow-y": "hidden"
     16        });
     17
     18    // To create the lightbox effect
     19    $(".container").animate({
     20        "opacity": "0.2"
     21    }, 300, "linear");
     22
     23    var imgWidth = $(".box img").width();
     24    var imgHeight = $(".box img").height();
     25
     26    //adding the image to the box
     27
     28    $(".box").html('<img height=100% width=100% src="' + overlayLink + '" alt="" />');
     29    //Position
     30    $(".box img").load(function() {
     31        var imgWidth = $(".box img").width();
     32        var imgHeight = $(".box img").height();
     33        if (imgHeight > screen.height - 170) imgHeight = screen.height - 170;
     34        if (imgWidth > screen.width - 300) imgWidth = screen.width - 300;
     35        $(".box")
     36            .css({
     37                "position": "absolute",
     38                "top": "50%",
     39                "left": "50%",
     40                "height": imgHeight + 10,
     41                "width": imgWidth + 10,
     42                "border": "5px solid white",
     43                "margin-top": -(imgHeight / 2),
     44                "margin-left": -(imgWidth / 2) //to position it in the middle
     45            })
     46            .animate({
     47                "opacity": "1"
     48            }, 400, "linear");
     49
     50        //To remove
     51        window.closeOverlay();
     52    });
     53}
     54
     55function closeOverlay() {
     56    // allow users to be able to close the lightbox
     57    $(".overlay").click(function() {
     58        $(".box, .overlay").animate({
     59            "opacity": "0"
     60        }, 200, "linear", function() {
     61            $(".box, .overlay").remove();
     62        });
     63        $(".container").animate({
     64            "opacity": "1"
     65        }, 200, "linear");
     66        $("body").css({
     67            "overflow-y": "scroll"
     68        });
     69    });
     70}
  • mediagoblin/templates/mediagoblin/user_pages/media.html

    diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html
    index 1a35414..37e1db8 100644
    a b  
    2525{% block mediagoblin_head %}
    2626<!--[if lte IE 8]><link rel="stylesheet"
    2727    href="{{ request.staticdirect('/extlib/leaflet/leaflet.ie.css') }}" /><![endif]-->
     28
     29 <link rel="stylesheet" type="text/css" href="{{ request.staticdirect('/css/lightbox.css') }}">
    2830  <script type="text/javascript"
    2931          src="{{ request.staticdirect('/js/comment_show.js') }}"></script>
    3032  <script type="text/javascript"
    3133          src="{{ request.staticdirect('/js/keyboard_navigation.js') }}"></script>
     34  <script type="text/javascript"
     35          src="{{ request.staticdirect('/js/lightbox.js') }}"></script>
    3236
    3337  {% template_hook("location_head") %}
    3438  {% template_hook("media_head") %}
     
    5761         #}
    5862        {% if media.media_files.has_key('medium') %}
    5963          <a href="{{ request.app.public_store.file_url(
    60                         media.media_files['original']) }}">
     64                        media.media_files['original']) }}" class="lightbox">
    6165            <img class="media_image"
    6266                 src="{{ display_media }}"
    6367                 alt="{% trans media_title=media.title -%}