Skip to content

Instantly share code, notes, and snippets.

@sibsfinx
Created November 20, 2015 14:45
Show Gist options
  • Save sibsfinx/c673a743f8ae12abecad to your computer and use it in GitHub Desktop.
Save sibsfinx/c673a743f8ae12abecad to your computer and use it in GitHub Desktop.
Photoswipe example
window.Gallery ||= {}
((app) ->
$(document).ready ->
$pswpElement = $('.pswp')[0]
$pswpCollection = $('@pswp-collection')
$pswpCollection.each ->
collection = $(@)
$pswpLinks = collection.find('[role*="pswp-link"]')
$pswpLinks.on 'click', (e) ->
e.preventDefault()
items = _.map $pswpLinks, getItem
index = $(@).data('index') || 0
app.openPhotoSwipe $pswpElement, items, index
getItem = (link) ->
src = $(link).attr 'href'
img = new Image
img.src = src
w = img.naturalWidth
h = img.naturalHeight
img = null
{
src: src
w: w
h: h
}
app.openPhotoSwipe = ($pswpElement, items, index) ->
options =
history: false
focus: false
escKey: true
showAnimationDuration: 0
hideAnimationDuration: 0
tapToToggleControls: true
gallery = new PhotoSwipe($pswpElement, PhotoSwipeUI_Default, items, options)
gallery.init()
return
)(window.Gallery ||= {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment