What I want to do is to save the link of photo into an array and than pass it to the photoswiper so that my photo can be viewed by photoswiper.
Unfortunitely, the jquery xml parse can't change the global variable. I can change the value of the global variable inside the parseXml(xml) function. Then I can pass the link to the function(window, PhotoSwipe).
var cars = new Array();
var carcar;
$(document).ready(function()
{
$.ajax({
type: "GET",
url: "http://www.utravel.com.hk/mobile-app/news-photo-xml.php?id=3256",
dataType: "xml",
success: function(xml) { parseXml(xml); }
});
});
function parseXml(xml)
{
$(xml).find("item").each(function()
{
carcar="http://www.utravel.com.hk/cms/news_photo/original/"+$(this).find("photo").text().substring(5);
cars.push(carcar);
});
}
(function(window, PhotoSwipe){
document.addEventListener('DOMContentLoaded', function(){
var
options = {
preventHide: true,
getImageSource: function(obj){
return obj.url;
},
getImageCaption: function(obj){
return obj.caption;
}
},
instance = PhotoSwipe.attach(
[
{ url: 'cars[0]', caption: 'Image 001'},
{ url: 'cars[1]', caption: 'Image 002'},
{ url: 'cars[2]', caption: 'Image 003'},
],
options
);
instance.show(0);
}, false);
}(window, window.Code.PhotoSwipe));