Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Created September 15, 2012 17:56
Show Gist options
  • Save MeoMix/3729069 to your computer and use it in GitHub Desktop.
Save MeoMix/3729069 to your computer and use it in GitHub Desktop.
for (var i = 0; i < songs.length; i++){
//Wrap in a closure to preserve song index for each iteration.
//If you don't do this the contextmenu method will always have the last song.
(function(i){
var listItem = $('<li/>').appendTo(songList);
var song = songs[i];
var link = $('<a/>', {
id: song.id,
href: '#' + song.id,
text: song.name,
contextmenu: function(e){
var contextMenu = new SongListContextMenu(song);
contextMenu.show(e.pageY, e.pageX);
//Prevent default context menu display.
return false;
}
}).appendTo(listItem);
}(i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment