Fixing Galley Script Code To Show Icon A or Icon B According to Previous User Selection In Different Pages

Web, Mobile & Software Dev Web Development Posted 3 years ago

Fixed Price

Budget: $30
Delivery by April 6, 2013

Start Date

April 3, 2013


We are in need of a very urgent simple fix to an existing project.

The script is an images gallery with zipping and downloading cart. Each thumb on each gallery has a checkmark button. When the button is checked, the big picture related to the thumb is sent to a zipping and downloading cart; if unchecked, it is deleted from the zipping and downloading cart. When the user is done with his selections, he can zip and download the content of the zipping and downloading cart. When a gallery initially loads, each checkmark button is greyed; when selected it becomes red. The user can select pictures on a gallery and then load another gallery and select more pictures on that one, before zipping and downloading.

Imagine this case scenario:

user checks 3 thumbs on gallery A;  so now 3 images are sent to cart via $session and $post; user loads gallery B and checks 2 thumbs on gallery B sending them to the cart; now the cart has 5 images ready to be zipped and downloaded; however, the user decides to return to gallery A and see if he wants to select some more thumbs from there;

when it goes back to gallery A, the previously selected thumbs should have a selected checkmark icon, while instead right now the script shows all thumbs unselected any time a gallery is loaded, although some images have been selected and sent to cart.

So basically, when a gallery is loaded we need to read the cart, see if any image from that gallery is in the cart and show the selected checkmark on the related thumb.

The script is a mix of js, ajax and php and we can address to the right part of code which needs to be modified.

Right now the above is coded, but there seems to be a sync problem for which when the user go back to a previous gallery where they selected some images, some images are not red checked anymore, especially when these images are on the bottom of the gallery; it seems like while the code checks if an image was selected, it does it faster than the page load and therefore it cannot match all selected images paths correctly returning undefined paths for images on the bottom of the loading list.

This is part of the code where the magic should happen, so maybe it can help you better to figure out what the problem is and how to fix it:

boxes = $("#myDiv>div>div").children('div');

if(i<(boxes.length-2)) {
my_a = $("<a href='#'></a>");
check_me_div  = $("<div class='check_me' rel='-1'></div>");

check_me_div.append (my_a);
var thumb_parent = $(this).children();

                        var $datenumber = selected_images;
$.each($datenumber, function(idx, val) {
if (val == thumb_parent.children().find("img").attr("src")) {
var tick_icon = thumb_parent.find("div.check_me")
tick_icon.attr("rel", i);
tick_icon.addClass("clicked ");
return false;

my_a.bind ("click", function(e){
current_index = $(this).parent().parent().parent().index();
if ($(this).parent().attr("class").indexOf ("clicked") > -1){
$(this).parent().attr ("rel",-1);
                                                                var lastItem = $(this).parent().parent().find("img").attr("src");
var index = selected_images.indexOf(lastItem);
selected_images.splice(index, 1);

else {
$(this).parent().attr ("rel",current_index);
$(this).parent().addClass("clicked ");
selected_images[selected_images.length] = $(this).parent().parent().find("img").attr("src");

if (selected_images.length == 0)
$(".download_link").html("Select Images for donwloading");
else {
$(".download_link").html("Download <b>" + selected_images.length + "</b> image" +

((selected_images.length == 1) ? "" : "s" ) );



We have three full, larger projects assignments ready for the person who will fix this by quick and smartly and we can offer ongoing work on a weekly basis.

  • Other Skills:

Activity on this Job

Last Viewed by Client: 3 years ago

Hired: 1

About the Client

(4.57) 4 reviews

Firenze 09:31 AM

6 Jobs Posted
67% Hire Rate, 1 Open Job

$334 Total Spent
4 Hires, 0 Active

Member Since Jun 15, 2011