Skip to content

Instantly share code, notes, and snippets.

@joeegan
Created May 6, 2011 10:26
Show Gist options
  • Select an option

  • Save joeegan/958733 to your computer and use it in GitHub Desktop.

Select an option

Save joeegan/958733 to your computer and use it in GitHub Desktop.
downloadify
$('#downloadify').downloadify({
data: function(){
var topRowCsv = "MiC " + $('.events-title-js').text() + ",From,To,Location" + "\n";
function removeNewLineChars(str) {
return str.replace(/\r/g, "").replace(/\n/g, "");
}
var csv = "",
titles = [],
toDates = [],
fromDates = [],
locations = [];
$('.events-list li').each(function(){
$this = $(this);
titleJq = $this.find('h3 a').text().replace(',','');
toDatesJq = $this.find('.to-date-js').text();
fromDatesJq = $this.find('.from-date-js').text();
locationJq = $this.find('.location-js').text();
titles.push(removeNewLineChars(titleJq).trim());
toDates.push(removeNewLineChars(toDatesJq).trim());
fromDates.push(removeNewLineChars(fromDatesJq).trim());
locations.push(removeNewLineChars(locationJq).trim());
});
for (i=0; i < titles.length; i++) {
csv += titles[i] + "," + fromDates[i] + "," + toDates[i] + "," + locations[i] + "\n";
}
return topRowCsv + csv;
},
filename: "upcoming_events.csv",
onComplete: function(){ alert('Your file has been saved'); },
onError: function(){ alert('There was an error saving the file'); },
transparent: false,
swf: '/merc-theme/swf/downloadify.swf',
downloadImage: '/merc-theme/images/_template/buttons/download.png',
width: 100,
height: 30,
transparent: true,
append: false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment