2 (window.onpopstate = function () {
4 pl = /\+/g, // Regex for replacing addition symbol with a space
5 search = /([^&=]+)=?([^&]*)/g,
6 decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
7 query = window.location.search.substring(1);
10 while (match = search.exec(query))
11 urlParams[decode(match[1])] = decode(match[2]);
16 doLog = function(aTextToLog, type){
17 var aLog = $('<div>',{'class':"log "+type,html:aTextToLog});
18 aLog.hide().prependTo($log).show('fast').delay(3000).hide('fast', function() {
22 var $main = $("#Changing");
23 var $metaNav = $("#metaNav");
24 var $log = $("#userLog");
27 my: "center bottom-5",
29 using: function( position, feedback ) {
30 $( this ).css( position );
33 .addClass( feedback.vertical )
34 .addClass( feedback.horizontal )
40 $('.newsRoll').tooltip(tooltip_options);
41 $('#metaNav').tooltip(tooltip_options);
43 $('body').css({'min-height':$(window).height() + $('#Commons').height()});
44 /****************************************************/
45 /**** AJAX UTILITIES FOR REQUESTS ****/
46 /****************************************************/
47 String.prototype.decodeHTML = function() {
48 return $("<div>", {html: "" + this}).html();
50 var loadPage_request = null;
51 afterLoad = function(html, textStatus, XMLHttpRequest) {
52 loadPage_request = null;
53 if (textStatus == "error") {
54 doLog('Sorry! And error occur when loading page content','error');
56 new_html = $.parseHTML(html);
57 new_content = $(new_html).find('#Changing>*');
58 $main.hide().empty().append(new_content).show();
60 /* calling onpopstate here is necessary to get urlParams to be
64 canonical_href_node = $.grep($(new_html), function(elem, idx) {
65 return (elem.nodeName === "LINK" && elem.attributes['rel'].value == "canonical");
67 if (canonical_href_node) {
68 canonical_href = canonical_href_node.attributes['href'].value;
69 history.replaceState({}, '', canonical_href);
72 new_menu = $($.parseHTML(html)).find('#metaNav>*');
73 $metaNav.empty().append(new_menu);
75 var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
76 if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
79 Quite UGLY but needed for styling the whole body with ID
80 Feel free to correct and find a better way
81 According to this link the probles is that $(html).filter('body').Attr('id') will not work!
82 http://www.devnetwork.net/viewtopic.php?f=13&t=117065
84 if(sectionName = $(html).find('[data-section]').attr('data-section')){
85 $('body').attr('id',sectionName);
87 var bodyID = html.match(/<body id="(.*?)">/);
88 if(bodyID){$('body').attr('id',bodyID[1].trim());}
90 $("#Changing").css({'min-height':$(window).height()});
91 $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
94 if (typeof (Piwik) == 'object') {
95 piwikTracker = Piwik.getAsyncTracker();
96 if (typeof (piwikTracker.trackPageView) == 'function') {
97 piwikTracker.setDocumentTitle(document.title);
98 piwikTracker.setCustomUrl(window.location.href);
99 piwikTracker.trackPageView();
100 $('.audio a').each(function() {
101 piwikTracker.addListener(this);
108 function afterLoadError(xhr, text, error) {
109 afterLoad(xhr.responseText, 'error', xhr);
112 $(window).on("popstate", function(e) {
113 if (e.originalEvent.state !== null) {loadPage(location.href, false);}
116 loadPage = function(href, push_state) {
117 if (push_state !== false) {
118 history.pushState({}, '', href);
120 if (loadPage_request !== null) {
121 loadPage_request.abort();
123 loadPage_request = $.ajax({
126 error: afterLoadError,
129 $.fn.ajaxifyClick = function(params) {
130 if ($('#df-wpr-sidebar').length > 0) {
131 /* this is fiber sidebar, it doesn't work well with
132 * seamless page loading */
135 this.each(function() {
136 $(this).unbind('click');
137 $(this).bind('click',function(e){
138 var href = $(this).attr("href");
139 if (href.match('\.(pdf|odt|ods|doc|xls|docx|xlsx|rtf)$')) {
141 window.open(href, '_blank');
145 window.open(href, '_blank');
148 $(this).addClass('loading');
149 /* this checks the link points to a local document, be
150 * it because it's just a path, or because the server
151 * part points to the same domain */
153 doLog('No href attributes, unable to load content','error');
154 $("#All a, #All area").removeClass('loading');
156 }else if (!$(this).attr('target') && (
157 href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
162 $(this).attr('target','_blank');
163 $("#All a, #All area").removeClass('loading');
169 /****************************************************/
170 /**** AUDIOPLAYER ****/
171 /****************************************************/
174 var refresh_onair_interval = 25000;
175 var ticker_interval = null;
177 //TODO: mini icon version for player, (playpause only)
178 $('#togglePlayer').on('click',function(e) {
180 if($(this).is('.icon-double-angle-left')){
181 $("#player").fadeOut('fast',function(){
182 $("#player-container").toggleClass('minimized');
183 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
186 $("#player").fadeIn('fast',function(){
187 $("#player-container").toggleClass('minimized');
188 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
194 $('#WhatsOnAir').on('load',function(){
195 var WhatsOnAir = $(this);
196 $('#RefreshWhatsOnAir').addClass('spinning');
197 $.getJSON('/onair.json', function(onair) {
198 setTimeout(function() { $('#RefreshWhatsOnAir').removeClass('spinning'); }, 5000);
199 var onairContainer = $('<span>');
200 if(onair.data.episode || onair.data.emission) {
201 if(onair.data.emission){
202 $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
204 if(onair.data.episode){
205 $('<span> - </span>').appendTo(onairContainer);
206 $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
208 } else if (onair.data.nonstop) {
209 onairContainer = $('<span>' + onair.data.nonstop.title + '</span>');
210 if (onair.data.track_title) {
211 $('<span> - </span>').appendTo(onairContainer);
212 $('<span class="nonstop-track-title">' + onair.data.track_title + '</span>').appendTo(onairContainer);
213 if (onair.data.track_artist) {
214 $('<span> </span>').appendTo(onairContainer)
215 $('<span class="nonstop-track-artist">(' + onair.data.track_artist + ')</span>').appendTo(onairContainer);
220 onairContainer = $('<span>Unknown (Probably Non-Stop)</span>');
222 var current_html = WhatsOnAir.html();
223 var new_html = '<span>' + onairContainer.html() + '</span>';
224 if (new_html !== current_html) {
225 WhatsOnAir.fadeOut();
226 WhatsOnAir.empty().append(onairContainer);
231 $('#RefreshWhatsOnAir').on('activate',function(e){
232 $('#WhatsOnAir').trigger('load');
233 timer = setInterval( "$('#WhatsOnAir').trigger('load');", refresh_onair_interval);
234 }).on('deactivate',function(e){
235 $(this).removeClass('spinning');
236 $('#WhatsOnAir').removeClass('active');
237 clearInterval(timer);
238 }).on('click',function(e){
239 $(this).toggleClass('active');
240 if($(this).is('.active')){
241 $(this).trigger('deactivate');
243 $(this).trigger('activate');
246 }).trigger('activate');
247 $("#DirectStreamPanikControler").on('click',function(e) {
249 var stream = $('#DirectStreamPanik').get(0);
250 if (stream.paused == false){
253 if (typeof (_paq) == 'object') {
254 _paq.push(['trackEvent', 'Audio', 'Play Stream']);
260 $('#DirectStreamPanik').on('play',function(){
261 $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
262 $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
263 $('#RefreshWhatsOnAir').trigger('activate');
264 }).on('pause',function(){
265 //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
266 $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
268 if($('#player-container').offset()){
270 topPosition = $('#mainHeader > div').offset().top + $('#mainHeader > div').height();
271 $(window).bind('scroll load',function (event) {
272 //$('#player-container').removeClass('fixed');
273 var y = $(this).scrollTop() + 40;
274 if (topPosition!== 0 && y >= topPosition) {
275 $('#player-container').addClass('fixed').removeClass('normal');
277 $('#player-container').removeClass('fixed').addClass('normal');
282 var $localList = $('#localList').playlist({
283 controlContainer: $('<div>',{'class':"playListControls"}).sortable(),
284 playlistContainer: $('<ol>',{id:"myPlaylist",'class':"custom"}).sortable(),
285 onLoad:function(self){
286 $('#toggleList').on('click',function(){
287 self.playlistContainer.toggleClass('deploy');
289 $('#emptyList').on('click',function(){
294 self.playlistContainer.scrollTo(self.isActive, 800 );
295 self.isActive.find('audio').attr('preload',"preload")
297 self.controlButtons['playpause'].addClass('resymbol');
299 onPlay:function(self){
300 $('#DirectStreamPanik')[0].pause();
301 self.playlistContainer.scrollTo(self.isActive, 800 );
303 onAdd:function(self){
304 //self.isLastAdd[0].scrollIntoView();
305 self.isLastAdd.find('a').ajaxifyClick();
306 self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
308 if (typeof (_paq) == 'object') {
309 _paq.push(['trackEvent', 'Audio', 'Add to playlist']);
312 onUpdate:function(self){
313 //doLog(JSON.stringify(self.playlist, null, '\t'));
314 if(self.playlist.length >= 1){
316 $('#Player').addClass('withPlaylist').removeClass('withoutPlaylist');
319 $('#Player').removeClass('withPlaylist').addClass('withoutPlaylist');
325 $("#All a, #All area").removeClass('loading');
326 $("#All a, #All area").ajaxifyClick();
327 $("#search-form").unbind('submit').on('submit', function(event) {
328 event.preventDefault();
329 $(this).addClass('loading');
330 loadPage($(this).attr('action') + '?' + $(this).serialize());
332 $(".tabs").each(function() {
334 var about= $($(this).attr("data-tab-about"));
335 var current = $(this).find("[data-tab].active")[0];
336 var dftShowSelector = current?".active":":first";
337 var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
338 $(this).find("[data-tab]").each(function() {
339 $(this).on('click load',function (e) {
341 self.find(".active").removeClass("active");
342 $(this).addClass("active");
343 about.find("[data-tabbed]").hide();
344 $($(this).attr("data-tab")).fadeIn();
348 activeTab.trigger('load');
350 $('[data-player-action]').on('click',function(){
351 var audio = $('#'+$(this).attr('data-player-audio'));
352 var sound_id = audio.data('sound-id');
353 if($(this).attr('data-player-action') == "registerAudio"){
354 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
355 }else if($(this).attr('data-player-action') == "playAudio"){
356 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' will play soon.','ok'));
357 $localList.playlist("playSoundId", sound_id);
358 if ($(this).parent().find('.icon-pause').length) {
360 $(this).parent().find('.icon-pause').show();
362 }else if ($(this).attr('data-player-action') == "pauseSounds") {
363 if ($(this).parent().find('.icon-play-sign').length) {
365 $(this).parent().find('.icon-play-sign').show();
367 $localList.playlist($(this).attr('data-player-action'));
369 $localList.playlist($(this).attr('data-player-action'));
372 $('[data-player-control]').each(function(){
373 var audio = $('#'+$(this).attr('data-player-audio'));
374 $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
377 $('[data-highlight]').on('check',function(){
378 $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
379 }).on('uncheck',function(){
380 $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
381 }).on('click',function(){
382 $(this).toggleClass('icon-check icon-check-empty');
383 if($(this).hasClass('icon-check')){$(this).trigger('check');
384 }else{ $(this).trigger('uncheck');}
386 $('[data-highlight].icon-check-empty').each(function(){
387 $(this).trigger('uncheck');
389 $('[data-toggle]').on('check',function(){
390 /* make sure all other unchecked items are hidden */
391 $('[data-toggle].icon-check-empty').each(function() {
392 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
394 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
395 }).on('uncheck',function(){
396 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
397 if ($('[data-toggle].icon-check').length == 0) {
398 /* special case the situation where all toggles
399 * are unchecked, as we want that to mean
400 * "everything", not "nothing".
402 $('[data-toggle].icon-check-empty').each(function() {
403 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
406 }).on('click',function(){
407 $(this).toggleClass('icon-check icon-check-empty');
408 if($(this).hasClass('icon-check')){$(this).trigger('check');
409 }else{ $(this).trigger('uncheck');}
411 $('[data-toggle].icon-check-empty').each(function(){
412 $(this).trigger('uncheck');
415 initial_enabled_toggles = {};
416 if (typeof(urlParams.q) == 'string') {
417 urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
419 $('[data-toggle]').each(function() {
420 if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
421 $(this).trigger('click');
425 $('[data-popup-href]').on('click', function() {
427 url: $(this).data('popup-href'),
428 success: function (html, textStatus, jqXhr) {
429 $(html).appendTo($('body'));
435 if ($('input#id_q').val() == '') {
436 $('input#id_q').focus();
439 $('#ticker li:not(:first)');
440 if (ticker_interval) clearInterval(ticker_interval);
442 $('#ticker li:first').animate({'opacity':0}, 200, function () {
443 $(this).appendTo($('#ticker')).css('opacity', 1);
446 $("#roller button").on('click',function(e){
447 clearInterval(ticker_interval);
449 $($(this).attr('data-about')).prependTo('#ticker');
452 ticker_interval = setInterval(function(){tick(); }, 20000);/**/
454 function navsearch_click(event) {
455 event.preventDefault();
456 var query = $('#nav-search input').val();
457 var form = $('#nav-search form');
460 href = $(form).attr('action');
462 href = $(form).attr('action') + '?' + $(form).serialize();
464 if (event.which == 2) {
465 window.open(href, '_blank');
467 $(this).addClass('loading');
472 $('#nav-search a').unbind('click').on('click', navsearch_click);
473 $('#nav-search form').unbind('submit').on('submit', navsearch_click);
475 $('[data-toggle-img]').bind('click', function() {
476 var src = $(this).data('toggle-img');
477 $(this).data('toggle-img', $(this).attr('src'));
478 $(this).attr('src', src);
479 $(this).toggleClass('right marged');
482 $('#Main #Emission-tabs-detail audio, div.soundcell audio').each(function(index, audio) {
483 var audio_src = $(audio).find('source')[0];
484 var sound_id = $(audio).data('sound-id');
485 var $waveform = $(audio).next();
486 $.getJSON(audio_src.src.replace('.ogg', '.waveform.json'), function(data) {
488 $waveform.append('<i class="duration">' + $waveform.data('duration-string') + '</i>');
489 $.each(data, function(k, val) {
491 $waveform.append('<span data-tick-index="' + k + '" style="height: ' + val + 'px;"></span>');
494 $waveform.find('span').on('click', function() {
495 /* if there's been something loaded */
496 var matching_audio = $('audio[data-sound-id=' + sound_id + ']');
497 if (matching_audio.length == 0) return;
498 matching_audio = matching_audio[0];
499 if (matching_audio.paused || matching_audio.ended) {
503 /* try to set time */
504 var total_duration = parseFloat($waveform.data('duration'));
505 var nb_ticks = $(this).parent().find('span').length;
506 var tick_index = $(this).data('tick-index');
507 matching_audio.currentTime = total_duration * tick_index / nb_ticks;
512 $('#nav-language span').click(function() {
513 document.cookie = 'panikweb_language=' + $(this).data('lang') + '; path=/';
514 window.location = window.location;
518 if (document.cookie.indexOf('panikdb=on') != -1) {
520 if (window.location.pathname.indexOf('/emissions/') == 0) {
521 panikdb_path = window.location.pathname;
522 } else if (window.location.pathname.indexOf('/news/') == 0) {
523 panikdb_path = '/emissions' + window.location.pathname;
526 $('<a id="panikdb" href="http://panikdb.radiopanik.org' + panikdb_path + '">Voir dans PanikDB</a>').appendTo($main);
530 $('.gallery').each(function() {
531 var $gallery = $(this);
532 $gallery.find('span.image').on('click', function() {
533 if ($(this).find('img').hasClass('portrait')) {
534 $(this).parents('.gallerycell').addClass('portrait');
536 $(this).parents('.gallerycell').removeClass('portrait');
538 $gallery.find('div.first img').attr('src', $(this).data('image-large'));
539 $gallery.find('div.first span.gallery-legend').text($(this).find('img').attr('title'));
540 $gallery.find('div.first').show('fade');
543 $gallery.find('div.first').on('click', function() { $(this).toggle('fade'); return false; });
549 if (! document.createElement('audio').canPlayType('audio/ogg') &&
550 document.createElement('audio').canPlayType('audio/aac') ) {
551 $('#ogg-m3u').hide().removeClass('resymbol');
552 $('#aac-m3u').addClass('resymbol').show();
555 var konami = new Konami('/party');
557 $(document).on('panik:timeupdate', function(ev, data) {
558 $waveform = $('#Main div.waveform[data-sound-id="' + data.sound_id + '"]');
559 var elems = $waveform.find('span');
560 var total_elems = elems.length;
561 var done = total_elems * data.position;
562 $waveform.find('span').each(function(k, elem) {
564 $(elem).addClass('done').removeClass('current');
566 $(elem).removeClass('done');
569 $waveform.find('span.done:last').addClass('current');
572 $("body").keydown(function(e) {
573 var $visible_element = $('div.first:visible img');
574 if ($visible_element.length == 0) {
577 if ($visible_element.length > 1) {
578 /* remove all but last */
579 $visible_element.parent().find('img:not(:last)').remove();
581 var $visible_element = $('div.first:visible img');
582 var img_url = $visible_element.attr('src');
583 var all_img = $('div.gallery span[data-image-large] img');
584 var active_img = $('div.gallery span[data-image-large="' + img_url + '"] img');
585 var idx = all_img.index(active_img);
586 if (e.which == 37) { // left
589 idx = all_img.length-1;
591 } else if (e.which == 39) { // right
593 if (idx == all_img.length) {
596 } else if (e.which == 27) { // escape
597 $visible_element.parent().toggle('fade');
602 /* create a new <img> with the new image but opacity 0, then display
603 * it using a css transition */
604 if (e.which == 37) { $visible_element.css('transform-origin', 'bottom right'); }
605 if (e.which == 39) { $visible_element.css('transform-origin', 'bottom left'); }
606 var new_img = $visible_element.clone().appendTo($visible_element.parent());
607 $(new_img).css('opacity', 0).attr('src', $(all_img[idx]).parent().data('image-large'));
608 $(new_img).css('transform', 'scale(0, 1)');
609 $(new_img)[0].offsetHeight; /* trigger reflow */
610 $(new_img).css('opacity', 1).css('transform', 'scale(1)');
611 $(new_img).parents('.gallery').find('span.gallery-legend').text($(all_img[idx]).attr('title'));
612 if ($(all_img[idx]).hasClass('portrait')) {
613 if (! $(new_img).parents('.gallerycell').hasClass('portrait')) {
614 $visible_element.parent().find('img:not(:last)').remove();
615 $(new_img).parents('.gallerycell').addClass('portrait');
618 if ($(new_img).parents('.gallerycell').hasClass('portrait')) {
619 $visible_element.parent().find('img:not(:last)').remove();
620 $(new_img).parents('.gallerycell').removeClass('portrait');