Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save masterkitano/1abc4c52d3791fc1cebe62dccf32601a to your computer and use it in GitHub Desktop.

Select an option

Save masterkitano/1abc4c52d3791fc1cebe62dccf32601a to your computer and use it in GitHub Desktop.

Revisions

  1. masterkitano created this gist Apr 13, 2016.
    70 changes: 70 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    $(document).ready(function()
    {

    var pswpElement = document.querySelectorAll('.pswp')[0];

    var items = [];

    $(".large-image").each(function(index)
    {
    $(this).removeClass("hidden");
    items.push({
    src: $(this).attr("src"),
    w: $(this).width(),
    h: $(this).height()
    });
    $(this).addClass("hidden");
    });

    var params = getQueryParams(document.location.toString());

    var currentGalleryID = params["pid"];

    if(currentGalleryID != null && currentGalleryID != '')
    {
    var options = {
    // optionName: 'option value'
    // for example:
    zoomEl: false,
    shareEl: false,
    index: currentGalleryID // start at first slide
    };
    var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
    gallery.init();
    }

    $(".gallery-image").click(function(){
    var options = {
    zoomEl: false,
    shareEl: false,
    // optionName: 'option value'
    // for example:
    index: parseInt($(this).attr("data-index")) // start at first slide
    };
    var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
    gallery.init();


    })

    // define options (if needed)


    // Initializes and opens PhotoSwipe


    });

    function getQueryParams(qs) {
    qs = qs.split('#')[1];

    var params = {},
    tokens,
    re = /[&]?([^=]+)=([^&]*)/g;

    while (tokens = re.exec(qs)) {
    params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
    }

    return params;
    }