var $$ = jQuery.noConflict(); var jRecorderCurrentPlaylist = ""; $$(document).ready( function() { var $$ = jQuery.noConflict(); //$$("#jRecPlaylistsWrapper, #jRecSongsWrapper, #jRecPlaylistsSongsWrapper").equalizeCols(); $$.post("http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/mtrPodcastsProcessor.php", {action : 'getPlaylists'}, function(response) { var playlist = ""; redoPlaylists(response); loadPlaylist(); $$("#jRecBtnNewPlaylist").click( function() { $$(this).hide(); $$(this).after('\
\ \ \ \
\ '); //$$("#jRecPlaylistsWrapper, #jRecSongsWrapper, #jRecPlaylistsSongsWrapper").equalizeCols(); // Insert actions for the buttons created above $$("#jRecRemoveMe .jRecSaveBtn").click(function() { $$.post("http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php", { action : 'createPlaylist', playlist : $$("#jRecNewPlaylistName").val() }, function(response) { // Get an updated sorted list of the playlists $$.post("http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/mtrPodcastsProcessor.php", { action : 'getPlaylists' }, function(response) { // Remove the inserted elements $$("#jRecPlaylists li").remove(); redoPlaylists(response); $$("#jRecRemoveMe").remove(); $$("#jRecBtnNewPlaylist").show(); } ); } ); // end $$.post }); $$("#jRecRemoveMe .jRecCancelBtn").click(function() { $$("#jRecRemoveMe").remove(); $$("#jRecBtnNewPlaylist").show(); }); $$("#jRecRemoveMe #jRecNewPlaylistName").blur(function() { $$(this).val( slugify( $$(this).val() ) ); }); return false; } ); // end .click // Add some more functionality to the recorder's save button $$("#jRecSaveButton").click(function() { var obj = $$("#jRecPlaylist").get(0); var selectedPlaylistValue = obj.options[obj.selectedIndex].value; // If we are recording to the playlist we are also looking at, // auto update the list with recordings with the new one if (jRecorderCurrentPlaylist == selectedPlaylistValue) { loadPlaylist(); } return false; }); } // end function(response) ); // end $$.post } // end document ready inline function ); // end document ready function function slugify(t) { t = t.replace(//g, "a"); t = t.replace(//g, "b"); t = t.replace(//g, "v"); t = t.replace(//g, "g"); t = t.replace(//g, "d"); t = t.replace(//g, "e"); t = t.replace(//g, "j"); t = t.replace(//g, "z"); t = t.replace(//g, "i"); t = t.replace(//g, "i"); t = t.replace(//g, "k"); t = t.replace(//g, "l"); t = t.replace(//g, "m"); t = t.replace(//g, "n"); t = t.replace(//g, "o"); t = t.replace(//g, "p"); t = t.replace(//g, "r"); t = t.replace(//g, "s"); t = t.replace(//g, "t"); t = t.replace(//g, "u"); t = t.replace(//g, "f"); t = t.replace(//g, "h"); t = t.replace(//g, "c"); t = t.replace(//g, "ch"); t = t.replace(//g, "sh"); t = t.replace(//g, "sht"); t = t.replace(//g, "i"); t = t.replace(//g, "y"); t = t.replace(//g, "yu"); t = t.replace(//g, "ya"); t = t.replace(//g, "a"); t = t.replace(//g, "b"); t = t.replace(//g, "v"); t = t.replace(//g, "g"); t = t.replace(//g, "d"); t = t.replace(//g, "e"); t = t.replace(//g, "j"); t = t.replace(//g, "z"); t = t.replace(//g, "i"); t = t.replace(//g, "i"); t = t.replace(//g, "k"); t = t.replace(//g, "l"); t = t.replace(//g, "m"); t = t.replace(//g, "n"); t = t.replace(//g, "o"); t = t.replace(//g, "p"); t = t.replace(//g, "r"); t = t.replace(//g, "s"); t = t.replace(//g, "t"); t = t.replace(//g, "u"); t = t.replace(//g, "f"); t = t.replace(//g, "h"); t = t.replace(//g, "c"); t = t.replace(//g, "ch"); t = t.replace(//g, "sh"); t = t.replace(//g, "sht"); t = t.replace(//g, "i"); t = t.replace(//g, "y"); t = t.replace(//g, "yu"); t = t.replace(//g, "ya"); t = t.replace(/[^a-zA-Z0-9\ _-]/g, ""); //t = t.replace(/\s/g, "-"); t = t.replace(/\s/g, "_"); //t = t.replace(/-+/g, "-"); t = t.replace(/-+/g, "_"); t = t.replace(/_+/g, "_"); t = t.replace(/[_-]*$/, ""); //t = t.toLowerCase(); return t; } function fixZebra(tableName) { var $$ = jQuery.noConflict(); // Fix the zebra coloring $$("#" + tableName + " tr:nth-child(odd)").addClass("odd"); $$("#" + tableName + " tr:even").removeClass("odd"); $$("#" + tableName + " tr:even").addClass("even"); } function redoPlaylists(response) { var $$ = jQuery.noConflict(); // Repopulate the playlists list $$("#jRecPlaylists").html(""); var playlists = response.split("\n"); for (var i = 0; i < playlists.length; i++) { var playlist = $$.trim(playlists[i]); if (playlist.length == 0) { playlists.splice(i--, 1); continue; } if (jRecorderCurrentPlaylist == "" && i == 0) jRecorderCurrentPlaylist = playlist; var trClass = (i % 2 == 0) ? ' even ' : ' odd '; var aClass = (playlist == jRecorderCurrentPlaylist) ? ' class="current" ' : ''; var html = ' \ \ \ ' + playlist + ' \ \ \
\
\ \ '; $$("#jRecPlaylists").append(html); } // Needed this line here for Safari //$$("#jRecPlaylistsWrapper, #jRecSongsWrapper, #jRecPlaylistsSongsWrapper").equalizeCols(); $$("#jRecPlaylists a").click(function() { jRecorderCurrentPlaylist = $$(this).text(); loadPlaylist(); $$("#jRecPlaylists a").removeClass("current"); $$(this).addClass("current"); return false; }); // EDIT $$(".jRecPlaylistEdit").click(function() { var old = $$(this).parent().parent().attr("id"); var obj = $$(this).parent().parent().find(".text"); obj.find("a").hide(); obj.append(''); $$("#jRecEditedPlaylist").focus(); // for some reason this line is ignored unless .select() is added or a second line $$("#jRecEditedPlaylist").focus(); $$("#jRecEditedPlaylist").blur( function() { var r = confirm("!!! WARNING !!!\n\r\n\rIf you have used any recordings from this playlist in a post or in the sidebar widget, \n\ryou will have to modify the playlist name there as well, or the recording there will not be available for playback."); if (!r) { $$("#jRecEditedPlaylist").remove(); obj.find("a").show(); return; } var newPlaylist = slugify($$(this).val()); $$.post("http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php", { action : 'editPlaylist', oldName : old, newName : newPlaylist }, function(response) { if (response != "OK") { alert(response); return false; } $$("#jRecEditedPlaylist").remove(); obj.find("a").text(newPlaylist); obj.find("a").show(); if (jRecorderCurrentPlaylist == old) { jRecorderCurrentPlaylist = newPlaylist; } jRecorderLoadPlaylists(); } ); }); return false; }); // DELETE $$(".jRecPlaylistDelete").click(function() { var r = confirm("!!! WARNING !!!\n\r\n\rIf you delete this playlist, all recordings in it will be deleted as well.\n\r\n\rDo you want to proceed?"); if (!r) return; var pl = $$(this).parent().parent().attr("id"); var obj = $$(this).parent().parent(); $$.post("http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php", { action : 'deletePlaylist', playlist : pl }, function(response) { if (response != "OK") { alert(response); return false; } obj.remove(); if (pl == jRecorderCurrentPlaylist) { jRecorderCurrentPlaylist = $$("#jRecPlaylists tr:first").find(".text a").text(); $$("#jRecPlaylists tr:first").find(".text a").addClass("current"); loadPlaylist(); } jRecorderLoadPlaylists(); } ); return false; }); // (bug fix) IE 7 seems to add empty LI elements, so remove them $$("#jRecPlaylists li").each( function(i) { if ($$(this).text() == "") { $$(this).remove(); } } ); //$$("#jRecPlaylistsWrapper, #jRecSongsWrapper, #jRecPlaylistsSongsWrapper").equalizeCols(); // Reload the playlists in the applet jRecorderLoadPlaylists(); } // Loads the recordings inside a playlist and builds a table from the entries function loadPlaylist() { var $$ = jQuery.noConflict(); $$.post("http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php", { action : 'loadRecordings', playlist : jRecorderCurrentPlaylist }, function(response) { var songs = response.split("\n"); $$("#jRecSongsTable tbody tr").remove(); var anyFound = false; for (var i = 0; i < songs.length; i++) { if ($$.trim(songs[i]) == "") continue; // Separate the song name from its status (pipe separated) var arr2 = songs[i].split("|"); var songName = arr2[0]; var songStatus = arr2[1]; if ($$.trim(songStatus) == "") songStatus = "on"; var songUrl = "http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/flash/xspf_player_button.swf?&song_url={song_url}&song_title={song_title}&"; songUrl = songUrl.replace(/{song_url}/, 'http://radiodrama.de/blog4/blog42/wp-content/mtr-podcasts/' + songName); songUrl = songUrl.replace(/{song_title}/, songName); anyFound = true; $$("#jRecSongsTable tbody").append('\ \ \
\ \ ' + songName + '\ \ \ \ \ \ \ \ \ \ \ \ \
\
\
\ \ \ '); } if (!anyFound || songs.length == 0) { $$("#jRecSongsTable tbody").html('Playlist is empty.'); return; } // Make columns equally tall //$$("#jRecPlaylistsWrapper, #jRecSongsWrapper, #jRecPlaylistsSongsWrapper").equalizeCols(); // Add zebra coloring fixZebra("jRecSongsTable"); // STATUS $$(".jRecSongStatus").click( function() { var status = true; var statusStr = "on"; if ($$(this).hasClass("jRecSongStatus-on")) { status = false; statusStr = "off"; } var row = $$(this).parents("tr:first").get(0); var url = "http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php"; $$.post(url, { action : 'setSongStatus', id : row.id.replace(/\D*/, ''), playlist : jRecorderCurrentPlaylist, status : statusStr }, function(response) { if (response != "OK") { alert(response); return false; } }); $$(this).removeClass("jRecSongStatus-on"); $$(this).removeClass("jRecSongStatus-off"); if (status) { $$(this).addClass("jRecSongStatus-on"); } else { $$(this).addClass("jRecSongStatus-off"); } return false; } ); /********************** NEEDED IF FLASH PLAYER WILL BE CONTROLLED VIA JAVASCRIPT // PLAY $$(".jRecSongPlay").click( function() { if ($$(this).hasClass("jRecSongStop")) { $$(this).removeClass("jRecSongStop"); // TODO Stop playback return; } $$(this).addClass("jRecSongStop"); // TODO Start playback // var rec = $$(this).find("span").text(); // jRecorder.jsPlay(rec, "jRecRestorePlayButton"); } ); **************************/ // MOVE DOWN $$(".jRecSongDown").click( function() { var ct = $$(this).parents("tr:first"); // stub class used as a selector if (ct.next().hasClass("nosort")) { return; } ct.before(ct.next()); var navID = ct.get(0).id.replace(/n/, ''); var url = "http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php"; $$.post(url, { action: 'sortSong', id: navID.replace(/\D*/, ''), direction: 'down', playlist : jRecorderCurrentPlaylist }, function() { }); fixZebra("jRecSongsTable"); return false; } ); // MOVE UP $$(".jRecSongUp").click( function() { var ct = $$(this).parents("tr:first"); // stub class used as a selector if (ct.prev().hasClass("nosort")) { return; } ct.after(ct.prev()); var navID = ct.get(0).id.replace(/n/, ''); var url = "http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php"; $$.post(url, { action: 'sortSong', id: navID.replace(/\D*/, ''), direction: 'up', playlist : jRecorderCurrentPlaylist }, function() { }); fixZebra("jRecSongsTable"); return false; } ); // DELETE $$(".jRecSongDelete").click( function() { r = confirm("Are you sure you want to delete this?"); if(!r) return false; var row = $$(this).parents("tr:first").get(0); var url = "http://radiodrama.de/blog4/blog42/wp-content/plugins/mtr-podcast-recorder/php/jrecorder_ajax.php"; $$.post( url, { action: 'deleteSong', playlist: jRecorderCurrentPlaylist, id: row.id.replace(/\D*/, '') }, function(r) { $$(row).remove(); fixZebra("jRecSongsTable"); }); return false; } ); } ); } function jRecRestorePlayButton() { alert("restore play button"); }