Thursday 14 March 2013

Phonegap photoswipe with download option script



(function(window, PhotoSwipe){

document.addEventListener('DOMContentLoaded', function(){

var
options = {

getImageCaption: function(el){

var captionText, captionEl, captionTextSRC;

// Get the caption from the alt tag
if (el.nodeName === "IMG"){
captionText = el.getAttribute('alt');
captionTextSRC = el.getAttribute("src");
}
var i, j, childEl;
for (i=0, j=el.childNodes.length; i childEl = el.childNodes[i];
if (el.childNodes[i].nodeName === 'IMG'){
captionText = childEl.getAttribute('alt');
captionTextSRC = childEl.getAttribute("src");
}
}




// Return a DOM element with custom styling
captionEl = document.createElement('div');
captionEl.style.cssText = 'background: red; font-weight: bold; padding: 5px;';
captionEl.appendChild(document.createTextNode("Download"));
//console.log('JJJJJJJJJJJJ'+ captionTextSRC);
//captionEl.onclick = testing;
//var fileTransfer = new FileTransfer();
captionEl.onclick = (function() {
//navigator.notification.alert("Loasdasdsaddsdsdsdgin Successfull");
var fileTransfer = new FileTransfer();
fileTransfer.download(
    captionTextSRC,
    "file://sdcard/"+captionText,
    function(entry) {
       navigator.notification.alert("download complete: " + entry.fullPath);
    },
    function(error) {
       navigator.notification.alert("download error source " + error.source);
        navigator.notification.alert("download error target " + error.target);
        navigator.notification.alert("upload error code" + error.code);
    });

});


//captionEl.appendChild(document.createTextNode(captionText));
return captionEl;

// Alternatively you can just pass back a string. However, any HTML
// markup will be escaped

}

},
instance = PhotoSwipe.attach( window.document.querySelectorAll('#Gallery a'), options );

}, false);


}(window, window.Code.PhotoSwipe));


function testing()
{
navigator.notification.alert("Login Successfull");
}

No comments:

Post a Comment