3 doLog = function(aTextToLog, type){
4 var aLog = $('<div>',{class:"log "+type,html:aTextToLog});
5 aLog.hide().prependTo($log).show('fast').delay(10000).hide('fast', function() {
9 var $main = $("#Changing");
10 var $metaNav = $("#metaNav");
11 var $log = $("#userLog");
13 /****************************************************/
14 /**** AJAX UTILITIES FOR REQUESTS ****/
15 /****************************************************/
16 String.prototype.decodeHTML = function() {
17 return $("<div>", {html: "" + this}).html();
19 var loadPage_request = null;
20 afterLoad = function(html, textStatus, XMLHttpRequest) {
21 loadPage_request = null;
22 if (textStatus == "error") {
23 doLog('Sorry! And error occur when loading page content','error');
25 new_content = $($.parseHTML(html)).find('#Changing>*');
26 $main.hide().empty().append(new_content).fadeIn();
28 new_menu = $($.parseHTML(html)).find('#metaNav>*');
29 $metaNav.empty().append(new_menu);
31 var newTitle = html.match(/<title>(.*?)<\/title>/);
32 if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
34 if (typeof (Piwik) == 'object') {
35 piwikTracker = Piwik.getAsyncTracker();
36 if (typeof (piwikTracker.trackPageView) == 'function') {
37 piwikTracker.setDocumentTitle(document.title);
38 piwikTracker.setCustomUrl(window.location.href);
39 piwikTracker.trackPageView();
44 Quite UGLY but needed for styling the whole body with ID
45 Feel free to correct and find a better way
46 According to this link the probles is that $(html).filter('body').Attr('id') will not work!
47 http://www.devnetwork.net/viewtopic.php?f=13&t=117065
49 if(sectionName = $(html).find('[data-section]').attr('data-section')){
50 $('body').attr('id',sectionName);
52 var bodyID = html.match(/<body id="(.*?)">/);
53 if(bodyID){$('body').attr('id',bodyID[1].trim());}
55 $("#Changing").css({'min-height':$(window).height()});
56 $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
60 function afterLoadError(xhr, text, error) {
61 afterLoad(xhr.responseText, 'error', xhr);
64 $(window).on("popstate", function(e) {
65 if (e.originalEvent.state !== null) {loadPage(location.href);}
68 loadPage = function(href) {
69 history.pushState({}, '', href);
70 if (loadPage_request !== null) {
71 loadPage_request.abort();
73 loadPage_request = $.ajax({
76 error: afterLoadError,
79 $.fn.ajaxifyClick = function(params) {
80 this.each(function() {
81 $(this).unbind('click');
82 $(this).bind('click',function(){
83 $(this).addClass('loading');
84 var href = $(this).attr("href");
85 /* this checks the link points to a local document, be
86 * it because it's just a path, or because the server
87 * part points to the same domain */
89 doLog('No href attributes, unable to load content','error');
90 $("#All a, #All area").removeClass('loading');
92 }else if (!$(this).attr('target') && (
93 href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
98 $(this).attr('target','_blanck');
99 $("#All a, #All area").removeClass('loading');
105 /****************************************************/
106 /**** AUDIOPLAYER ****/
107 /****************************************************/
112 //TODO: mini icon version for player, (playpause only)
113 $('#togglePlayer').on('click',function(e) {
115 if($(this).is('.icon-double-angle-left')){
116 $("#player").fadeOut('fast',function(){
117 $("#player-container").toggleClass('minimized');
118 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
121 $("#player").fadeIn('fast',function(){
122 $("#player-container").toggleClass('minimized');
123 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
129 $('#WhatsOnAir').on('load',function(){
130 var WhatsOnAir = $(this);
131 $.getJSON('/onair.json', function(onair) {
132 WhatsOnAir.fadeOut();
133 if(onair.data.episode || onair.data.emission){
134 var onairContainer = $('<span>');
135 if(onair.data.emission){
136 $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
138 if(onair.data.episode){
139 $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
141 WhatsOnAir.empty().append(onairContainer);
142 } else if (onair.data.nonstop) {
143 result = onair.data.nonstop.title;
144 WhatsOnAir.html('<span>' + result + '</span>');
146 else{WhatsOnAir.html('<span>Unknown (Probably Non-Stop)</span>');}
150 $('#RefreshWhatsOnAir').on('activate',function(e){
151 $(this).addClass('spinning');
152 $('#WhatsOnAir').addClass('active');
153 $('#WhatsOnAir').trigger('load');
154 timer = setInterval( "$('#WhatsOnAir').trigger('load');", interval);
155 }).on('deactivate',function(e){
156 $(this).removeClass('spinning');
157 $('#WhatsOnAir').removeClass('active');
158 clearInterval(timer);
159 }).on('click',function(e){
160 $(this).toggleClass('spinning');
161 if($(this).is('.spinning')){
162 $(this).trigger('activate');
163 }else{$(this).trigger('deactivate');}
166 $("#DirectStreamPanikControler").on('click',function(e) {
168 var stream = $('#DirectStreamPanik').get(0);
169 if (stream.paused == false){
176 $('#DirectStreamPanik').on('play',function(){
177 $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
178 $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
179 $('#RefreshWhatsOnAir').trigger('activate');
180 }).on('pause',function(){
181 //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
182 $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
183 $('#RefreshWhatsOnAir').trigger('deactivate');
185 if($('#player-container').offset()){
187 topPosition = $('#player-container').offset().top;
188 $(window).bind('scroll load',function (event) {
189 //$('#player-container').removeClass('fixed');
190 var y = $(this).scrollTop() - $('#Player').height() + $('#metaNav').height() +5;
191 if (topPosition!== 0 && y >= topPosition) {
192 $('#Player').css({'min-height':$('#Player').height()});
193 $('#player-container').addClass('fixed').removeClass('normal');
195 $('#Player').css({'min-height':'auto'});
196 $('#player-container').removeClass('fixed').addClass('normal');
201 var $localList = $('#localList').playlist({
202 controlContainer: $('<div>',{class:"playListControls label"}).sortable(),
203 playlistContainer: $('<ol>',{id:"myPlaylist",class:"custom"}).sortable(),
204 onLoad:function(self){
205 $('#toggleList').on('click',function(){
206 self.playlistContainer.toggleClass('deploy');
208 $('#emptyList').on('click',function(){
209 self.playlistContainer.empty();
214 self.playlistContainer.scrollTo(self.isActive, 800 );
215 self.isActive.find('audio').attr('preload',"preload")
218 onPlay:function(self){
219 $('#DirectStreamPanik')[0].pause();
220 self.playlistContainer.scrollTo(self.isActive, 800 );
222 onAdd:function(self){
223 //self.isLastAdd[0].scrollIntoView();
224 self.isLastAdd.find('a').ajaxifyClick();
225 self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
228 onUpdate:function(self){
229 //doLog(JSON.stringify(self.playlist, null, '\t'));
230 if(self.playlist.length >= 1){
232 $('#Player').addClass('withPlaylist');
235 $('#Player').removeClass('withPlaylist');
241 $("#All a, #All area").removeClass('loading');
242 $("#All a, #All area").ajaxifyClick();
243 $("#search-form").unbind('submit').on('submit', function(event) {
244 event.preventDefault();
245 $(this).addClass('loading');
246 loadPage($(this).attr('action') + '/?' + $(this).serialize());
248 $(".tabs").each(function() {
250 var about= $($(this).attr("data-tab-about"));
251 var current = $(this).find("[data-tab].active")[0];
252 var dftShowSelector = current?".active":":first";
253 var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
254 $(this).find("[data-tab]").each(function() {
255 $(this).on('click load',function (e) {
257 self.find(".active").removeClass("active");
258 $(this).addClass("active");
259 about.find("[data-tabbed]").hide();
260 $($(this).attr("data-tab")).fadeIn();
264 activeTab.trigger('load');
266 $('[data-player-action]').on('click',function(){
267 var audio = $('#'+$(this).attr('data-player-audio'));
268 if($(this).attr('data-player-action') == "registerAudio"){
269 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
270 }else if($(this).attr('data-player-action') == "playAudio"){
271 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' will play soon.','ok'));
272 $localList.playlist("playLast");
274 $localList.playlist($(this).attr('data-player-action'));
277 $('[data-player-control]').each(function(){
278 var audio = $('#'+$(this).attr('data-player-audio'));
279 $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
282 $('[data-highlight]').on('check',function(){
283 $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
284 }).on('uncheck',function(){
285 $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
286 }).on('click',function(){
287 $(this).toggleClass('icon-check icon-check-empty');
288 if($(this).hasClass('icon-check')){$(this).trigger('check');
289 }else{ $(this).trigger('uncheck');}
291 $('[data-highlight].icon-check-empty').each(function(){
292 $(this).trigger('uncheck');
294 $('[data-toggle]').on('check',function(){
295 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
296 }).on('uncheck',function(){
297 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
298 }).on('click',function(){
299 $(this).toggleClass('icon-check icon-check-empty');
300 if($(this).hasClass('icon-check')){$(this).trigger('check');
301 }else{ $(this).trigger('uncheck');}
303 $('[data-toggle].icon-check-empty').each(function(){
304 $(this).trigger('uncheck');
306 if ($('input#id_q').val() == '') {
307 $('input#id_q').focus();