Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image counter in viewer #4

Open
Brintaman opened this issue Mar 14, 2014 · 2 comments
Open

Image counter in viewer #4

Brintaman opened this issue Mar 14, 2014 · 2 comments

Comments

@Brintaman
Copy link

Hi!
First of all, gamma gallery is awesome!
I'm trying to add a counter in the photo viewer that shows "current image / total images"
To accomplish this i put a variable for Gamma.itemsCount; in the gamma-single-view. But I don't think a function exists to grab the id of the current image.
I tried writing a function that grabs it from the url hash but because the page doesn't reload when sliding trough the photo's this only works after refreshing. It also won't work if i bind the function on a hashchange event.
Does anyone have any ideas?

Thanks in advance!

@danyx23
Copy link

danyx23 commented Mar 25, 2014

I tried something similar and got it to work - I don't have time to clean the code and push it to github right now, but if you want to try: Insite the _layout = function($item) {} method there is a part where it iterates over the items and sets the image sources and source. There, you can set the description like this:

description = $picEl.data( 'description' ) + " " + (itemIndex+1) + " of " + Gamma.itemsCount;

HTH!

@Brintaman
Copy link
Author

Thanks for the reply! I found an alternative way to solve this but your method is way better. I'll implement your example instead of my solution :)

For reference I'll post my method as well.

In gamma.js I added:

$(".gamma-gallery li").each(function(i,el){

// increment item numbering
var current_item = i + 1;

// total length
var listItems = $(".gamma-gallery").children();
var totaal_foto = listItems.length;

// put div and data attribute to variables
var div = el.firstElementChild;
var tekst = div.dataset.description;
delete div.dataset.description;


// add the counter to the variable with data attribute, and add it to the div
var counter = tekst.concat("<div class='counter'><p>" + current_item + " / " + totaal_foto +"</p></div>");
div.dataset.description = counter;

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants