I'm working on a 3 columns photo website (responsive), and I'm parsing the img src
from XML. I need to prepend HTML code every 3 elements so my photo wall respects my responsive class.
I just found a cheap solution, repeating the XML loop (for
). Do you have an advice to give me, to do it right, to improve my code?
$(document).ready(function(){
xmldata=new Array(); //initialise array for XML data
$.ajax({ //get the XML data
url: "xml/gallery.xml", //URL to get the data from
success: function(data) { //if we succeed, set everything up. We don't expect failure.
$(data).find("image").each(function()
{
xmldata.push($(this)); //add item into array
});
totalNum = xmldata.length;
gallery_images();
}
});
});
function gallery_images(){
for (var i = 0; i <= 2; i++) {
data=xmldata[i];
img_src=$(data).attr("src");
href=$(data).attr("href");
title1=$(data).attr("title1");
client=$(data).attr("client");
var video_gallery_html = '';
video_gallery_html += '<article class="col span_8"><div class="title_div span_24 ">';
video_gallery_html += ' <a href="#"> <img src="images/linea.png" alt="line_divisor" /></a>';
video_gallery_html += ' <h1 class="title_item col span_12 _left">DENIS ROVIRA</h1>';
video_gallery_html += ' <h3 class="title_more col span_12 _right">See all projects</h3></div><!-- title_div -->';
video_gallery_html += ' <a href="#"> <img src="'+ img_src +'" alt="image_item" /></a>';
video_gallery_html += ' <p>Nescafe Gold</p></article><!-- span_8 -->';
$(".videos_container").prepend(video_gallery_html);
};
for (var i = 3; i <= 5; i++) {
data=xmldata[i];
img_src=$(data).attr("src");
href=$(data).attr("href");
title1=$(data).attr("title1");
client=$(data).attr("client");
var video_gallery_html2 = '';
video_gallery_html2 += '<article class="col span_8"><div class="title_div span_24 ">';
video_gallery_html2 += ' <a href="#"> <img src="images/linea.png" alt="line_divisor" /></a>';
video_gallery_html2 += ' <h1 class="title_item col span_12 _left">DENIS ROVIRA</h1>';
video_gallery_html2 += ' <h3 class="title_more col span_12 _right">See all projects</h3></div><!-- title_div -->';
video_gallery_html2 += ' <a href="#"> <img src="'+ img_src +'" alt="image_item" /></a>';
video_gallery_html2 += ' <p>Nescafe Gold</p></article><!-- span_8 -->';
$(".videos_container2").prepend(video_gallery_html2);
};
}