views:

132

answers:

2

Here is the home page for the popular jquery-plugin galleria. I need to insert the download link to the right bottom corner for the active image. Now there is available statistic like (3/10), which indicates the current number from list. Maybe someone already did this. What is the fastest way?


UPD: using the gearsdigital's idea I wrote the code:

var gallery = Galleria.get(0);

gallery.bind(Galleria.IMAGE, function(e) {
    imgHandle = e.imageTarget;
    console.log(imgHandle);
    console.log(imgHandle.attr('href'));
    //$('.galleria-counter').append('<a href="'+imgHandle.attr('src')+'">Download</a>');
});

The first log line shows up something like:

<img width="584" height="438" src="http://....jpg" style="display: block; position: relative; left: 0px; top: -4px; opacity: 1;">

But how to get the src location, I see the error that attr function isn't available.

A: 

I would try to get the current Source-Attribute from the current image and append this as link.

//Untested. This is just a suggestion :)
currentImageSource = $('.galleria-image img').attr('src');  
$('.galleria-counter').append('<a href="'+currentImageSource+'">Download</a>');

But a link like this will open the image separatly and not download ordinary. If you want a "real" Download you have to put this image in an zip archive.

$('.galleria-counter').append('<a href="'+currentImageSource+'.zip">Download</a>');

This will produce something like that: http://www.example.com/galleria/img/mygreatimage.jpg.zip

Works for me:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Example</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;&lt;/script&gt;

        <script type="text/javascript">
            $(document).ready(function() {

                currentImageSource = $('.container img').attr('src');  
                $('.placeholder').append('<a href="'+currentImageSource+'">Download</a>');

            });

        </script>
    </head>

    <body>
        <div class="container">
            <h2>Get img src</h2>
            <img src="http://www.duba.at/wp-content/uploads/2007/08/bild_0570000.jpg" witdh="200" height="220"/>
        </div>

        <div class="placeholder">
            <h2>Append Here</h2>
        </div>

    </body>
</html>
gearsdigital
Look at update, please.
Ockonal
+1  A: 

your getting the imgHandle from a DOMEvent, not a jquery object.

As attr is part of the jQuery object you need to transfer the dom object to a jquery object.

gallery.bind(Galleria.IMAGE, function(e) {
    imgHandle = $(e.imageTarget); //Wrap it here

   alert(imghandle.attr('href'))

    //$('.galleria-counter').append('<a href="'+imgHandle.attr('src')+'">Download</a>');
});
RobertPitt