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 /****************************************************/
44 /**** AJAX UTILITIES FOR REQUESTS ****/
45 /****************************************************/
46 String.prototype.decodeHTML = function() {
47 return $("<div>", {html: "" + this}).html();
49 var loadPage_request = null;
50 afterLoad = function(html, textStatus, XMLHttpRequest) {
51 loadPage_request = null;
52 if (textStatus == "error") {
53 doLog('Sorry! And error occur when loading page content','error');
55 new_html = $.parseHTML(html);
56 new_content = $(new_html).find('#Changing>*');
57 $main.hide().empty().append(new_content).show();
59 /* calling onpopstate here is necessary to get urlParams to be
63 canonical_href_node = $.grep($(new_html), function(elem, idx) {
64 return (elem.nodeName === "LINK" && elem.attributes['rel'].value == "canonical");
66 if (canonical_href_node) {
67 canonical_href = canonical_href_node.attributes['href'].value;
68 history.replaceState({}, '', canonical_href);
71 new_menu = $($.parseHTML(html)).find('#metaNav>*');
72 $metaNav.empty().append(new_menu);
74 var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
75 if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
78 Quite UGLY but needed for styling the whole body with ID
79 Feel free to correct and find a better way
80 According to this link the probles is that $(html).filter('body').Attr('id') will not work!
81 http://www.devnetwork.net/viewtopic.php?f=13&t=117065
83 if(sectionName = $(html).find('[data-section]').attr('data-section')){
84 $('body').attr('id',sectionName);
86 var bodyID = html.match(/<body id="(.*?)">/);
87 if(bodyID){$('body').attr('id',bodyID[1].trim());}
89 $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
92 if (typeof (Piwik) == 'object') {
93 piwikTracker = Piwik.getAsyncTracker();
94 if (typeof (piwikTracker.trackPageView) == 'function') {
95 piwikTracker.setDocumentTitle(document.title);
96 piwikTracker.setCustomUrl(window.location.href);
97 piwikTracker.trackPageView();
98 $('.audio a').each(function() {
99 piwikTracker.addListener(this);
106 function afterLoadError(xhr, text, error) {
107 afterLoad(xhr.responseText, 'error', xhr);
110 $(window).on("popstate", function(e) {
111 if (e.originalEvent.state !== null) {loadPage(location.href, false);}
114 loadPage = function(href, push_state) {
115 if (push_state !== false) {
116 history.pushState({}, '', href);
118 if (loadPage_request !== null) {
119 loadPage_request.abort();
121 loadPage_request = $.ajax({
124 error: afterLoadError,
127 $.fn.ajaxifyClick = function(params) {
128 if ($('#df-wpr-sidebar').length > 0) {
129 /* this is fiber sidebar, it doesn't work well with
130 * seamless page loading */
133 this.each(function() {
134 $(this).unbind('click');
135 $(this).bind('click',function(e){
136 var href = $(this).attr("href");
137 if (href.match('\.(pdf|odt|ods|doc|xls|docx|xlsx|rtf)$')) {
139 window.open(href, '_blank');
143 window.open(href, '_blank');
146 $(this).addClass('loading');
147 /* this checks the link points to a local document, be
148 * it because it's just a path, or because the server
149 * part points to the same domain */
151 doLog('No href attributes, unable to load content','error');
152 $("#All a, #All area").removeClass('loading');
154 }else if (!$(this).attr('target') && (
155 href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
160 $(this).attr('target','_blank');
161 $("#All a, #All area").removeClass('loading');
167 /****************************************************/
168 /**** AUDIOPLAYER ****/
169 /****************************************************/
172 var refresh_onair_interval = 25000;
173 var ticker_interval = null;
175 //TODO: mini icon version for player, (playpause only)
176 $('#togglePlayer').on('click',function(e) {
178 if($(this).is('.icon-double-angle-left')){
179 $("#player").fadeOut('fast',function(){
180 $("#player-container").toggleClass('minimized');
181 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
184 $("#player").fadeIn('fast',function(){
185 $("#player-container").toggleClass('minimized');
186 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
192 $('#WhatsOnAir').on('load',function(){
193 var WhatsOnAir = $(this);
194 $('#RefreshWhatsOnAir').addClass('spinning');
195 $.getJSON('/onair.json', function(onair) {
196 setTimeout(function() { $('#RefreshWhatsOnAir').removeClass('spinning'); }, 5000);
197 var onairContainer = $('<span>');
198 if(onair.data.episode || onair.data.emission) {
199 if(onair.data.emission){
200 $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
202 if(onair.data.episode){
203 $('<span> - </span>').appendTo(onairContainer);
204 $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
206 } else if (onair.data.nonstop) {
207 onairContainer = $('<span>' + onair.data.nonstop.title + '</span>');
208 if (onair.data.track_title) {
209 $('<span> - </span>').appendTo(onairContainer);
210 $('<span class="nonstop-track-title">' + onair.data.track_title + '</span>').appendTo(onairContainer);
211 if (onair.data.track_artist) {
212 $('<span> </span>').appendTo(onairContainer)
213 $('<span class="nonstop-track-artist">(' + onair.data.track_artist + ')</span>').appendTo(onairContainer);
218 onairContainer = $('<span>Unknown (Probably Non-Stop)</span>');
220 var current_html = WhatsOnAir.html();
221 var new_html = '<span>' + onairContainer.html() + '</span>';
222 if (new_html !== current_html) {
223 WhatsOnAir.fadeOut();
224 WhatsOnAir.empty().append(onairContainer);
229 $('#RefreshWhatsOnAir').on('activate',function(e){
230 $('#WhatsOnAir').trigger('load');
231 timer = setInterval( "$('#WhatsOnAir').trigger('load');", refresh_onair_interval);
232 }).on('deactivate',function(e){
233 $(this).removeClass('spinning');
234 $('#WhatsOnAir').removeClass('active');
235 clearInterval(timer);
236 }).on('click',function(e){
237 $(this).toggleClass('active');
238 if($(this).is('.active')){
239 $(this).trigger('deactivate');
241 $(this).trigger('activate');
244 }).trigger('activate');
245 $("#DirectStreamPanikControler").on('click',function(e) {
247 var stream = $('#DirectStreamPanik').get(0);
248 if (stream.paused == false){
251 if (typeof (_paq) == 'object') {
252 _paq.push(['trackEvent', 'Audio', 'Play Stream']);
258 $('#DirectStreamPanik').on('play',function(){
259 $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
260 $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
261 $('#RefreshWhatsOnAir').trigger('activate');
262 }).on('pause',function(){
263 //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
264 $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
266 if($('#player-container').offset()){
268 topPosition = $('#mainHeader > div').offset().top + $('#mainHeader > div').height();
269 $(window).bind('scroll load',function (event) {
270 //$('#player-container').removeClass('fixed');
271 var y = $(this).scrollTop() + 40;
272 if (topPosition!== 0 && y >= topPosition) {
273 $('#player-container').addClass('fixed').removeClass('normal');
275 $('#player-container').removeClass('fixed').addClass('normal');
280 var $localList = $('#localList').playlist({
281 controlContainer: $('<div>',{'class':"playListControls"}).sortable(),
282 playlistContainer: $('<ol>',{id:"myPlaylist",'class':"custom"}).sortable(),
283 onLoad:function(self){
284 $('#toggleList').on('click',function(){
285 self.playlistContainer.toggleClass('deploy');
287 $('#emptyList').on('click',function(){
292 self.playlistContainer.scrollTo(self.isActive, 800 );
293 self.isActive.find('audio').attr('preload',"preload")
295 self.controlButtons['playpause'].addClass('resymbol');
297 onPlay:function(self){
298 $('#DirectStreamPanik')[0].pause();
299 self.playlistContainer.scrollTo(self.isActive, 800 );
301 onAdd:function(self){
302 //self.isLastAdd[0].scrollIntoView();
303 self.isLastAdd.find('a').ajaxifyClick();
304 self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
306 if (typeof (_paq) == 'object') {
307 _paq.push(['trackEvent', 'Audio', 'Add to playlist']);
310 onUpdate:function(self){
311 //doLog(JSON.stringify(self.playlist, null, '\t'));
312 if(self.playlist.length >= 1){
314 $('#Player').addClass('withPlaylist').removeClass('withoutPlaylist');
317 $('#Player').removeClass('withPlaylist').addClass('withoutPlaylist');
323 $("#All a, #All area").removeClass('loading');
324 $("#All a, #All area").ajaxifyClick();
325 $("#search-form").unbind('submit').on('submit', function(event) {
326 event.preventDefault();
327 $(this).addClass('loading');
328 loadPage($(this).attr('action') + '?' + $(this).serialize());
330 $(".tabs").each(function() {
332 var about= $($(this).attr("data-tab-about"));
333 var current = $(this).find("[data-tab].active")[0];
334 var dftShowSelector = current?".active":":first";
335 var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
336 $(this).find("[data-tab]").each(function() {
337 $(this).on('click load',function (e) {
339 self.find(".active").removeClass("active");
340 $(this).addClass("active");
341 about.find("[data-tabbed]").hide();
342 $($(this).attr("data-tab")).fadeIn();
346 activeTab.trigger('load');
348 $('[data-player-action]').on('click',function(){
349 var audio = $('#'+$(this).attr('data-player-audio'));
350 var sound_id = audio.data('sound-id');
351 if($(this).attr('data-player-action') == "registerAudio"){
352 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
353 }else if($(this).attr('data-player-action') == "playAudio"){
354 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' will play soon.','ok'));
355 $localList.playlist("playSoundId", sound_id);
356 if ($(this).parent().find('.icon-pause').length) {
358 $(this).parent().find('.icon-pause').show();
360 }else if ($(this).attr('data-player-action') == "pauseSounds") {
361 if ($(this).parent().find('.icon-play-sign').length) {
363 $(this).parent().find('.icon-play-sign').show();
365 $localList.playlist($(this).attr('data-player-action'));
367 $localList.playlist($(this).attr('data-player-action'));
370 $('[data-player-control]').each(function(){
371 var audio = $('#'+$(this).attr('data-player-audio'));
372 $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
375 $('[data-highlight]').on('check',function(){
376 $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
377 }).on('uncheck',function(){
378 $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
379 }).on('click',function(){
380 $(this).toggleClass('icon-check icon-check-empty');
381 if($(this).hasClass('icon-check')){$(this).trigger('check');
382 }else{ $(this).trigger('uncheck');}
384 $('[data-highlight].icon-check-empty').each(function(){
385 $(this).trigger('uncheck');
387 $('[data-toggle]').on('check',function(){
388 /* make sure all other unchecked items are hidden */
389 $('[data-toggle].icon-check-empty').each(function() {
390 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
392 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
393 }).on('uncheck',function(){
394 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
395 if ($('[data-toggle].icon-check').length == 0) {
396 /* special case the situation where all toggles
397 * are unchecked, as we want that to mean
398 * "everything", not "nothing".
400 $('[data-toggle].icon-check-empty').each(function() {
401 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
404 }).on('click',function(){
405 $(this).toggleClass('icon-check icon-check-empty');
406 if($(this).hasClass('icon-check')){$(this).trigger('check');
407 }else{ $(this).trigger('uncheck');}
409 $('[data-toggle].icon-check-empty').each(function(){
410 $(this).trigger('uncheck');
413 initial_enabled_toggles = {};
414 if (typeof(urlParams.q) == 'string') {
415 urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
417 $('[data-toggle]').each(function() {
418 if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
419 $(this).trigger('click');
423 $('[data-popup-href]').on('click', function() {
425 url: $(this).data('popup-href'),
426 success: function (html, textStatus, jqXhr) {
427 $(html).appendTo($('body'));
433 if ($('input#id_q').val() == '') {
434 $('input#id_q').focus();
437 $('#ticker li:not(:first)');
438 if (ticker_interval) clearInterval(ticker_interval);
440 $('#ticker li:first').animate({'opacity':0}, 200, function () {
441 $(this).appendTo($('#ticker')).css('opacity', 1);
444 $("#roller button").on('click',function(e){
445 clearInterval(ticker_interval);
447 $($(this).attr('data-about')).prependTo('#ticker');
450 ticker_interval = setInterval(function(){tick(); }, 20000);/**/
452 function navsearch_click(event) {
453 event.preventDefault();
454 var query = $('#nav-search input').val();
455 var form = $('#nav-search form');
458 href = $(form).attr('action');
460 href = $(form).attr('action') + '?' + $(form).serialize();
462 if (event.which == 2) {
463 window.open(href, '_blank');
465 $(this).addClass('loading');
470 $('#nav-search a').unbind('click').on('click', navsearch_click);
471 $('#nav-search form').unbind('submit').on('submit', navsearch_click);
473 $('[data-toggle-img]').bind('click', function() {
474 var src = $(this).data('toggle-img');
475 $(this).data('toggle-img', $(this).attr('src'));
476 $(this).attr('src', src);
477 $(this).toggleClass('right marged');
480 $('#Main #Emission-tabs-detail audio, div.soundcell audio').each(function(index, audio) {
481 var audio_src = $(audio).find('source')[0];
482 var sound_id = $(audio).data('sound-id');
483 var $waveform = $(audio).next();
484 $.getJSON(audio_src.src.replace('.ogg', '.waveform.json'), function(data) {
486 $waveform.append('<i class="duration">' + $waveform.data('duration-string') + '</i>');
487 $.each(data, function(k, val) {
489 $waveform.append('<span data-tick-index="' + k + '" style="height: ' + val + 'px;"></span>');
492 $waveform.find('span').on('click', function() {
493 /* if there's been something loaded */
494 var matching_audio = $('audio[data-sound-id=' + sound_id + ']');
495 if (matching_audio.length == 0) return;
496 matching_audio = matching_audio[0];
497 if (matching_audio.paused || matching_audio.ended) {
501 /* try to set time */
502 var total_duration = parseFloat($waveform.data('duration'));
503 var nb_ticks = $(this).parent().find('span').length;
504 var tick_index = $(this).data('tick-index');
505 matching_audio.currentTime = total_duration * tick_index / nb_ticks;
510 $('#nav-language span').click(function() {
511 document.cookie = 'panikweb_language=' + $(this).data('lang') + '; path=/';
512 window.location = window.location;
516 if (document.cookie.indexOf('panikdb=on') != -1) {
518 if (window.location.pathname.indexOf('/emissions/') == 0) {
519 panikdb_path = window.location.pathname;
520 } else if (window.location.pathname.indexOf('/news/') == 0) {
521 panikdb_path = '/emissions' + window.location.pathname;
524 $('<a id="panikdb" href="http://panikdb.radiopanik.org' + panikdb_path + '">Voir dans PanikDB</a>').appendTo($main);
528 $('.gallery').each(function() {
529 var $gallery = $(this);
530 $gallery.find('span.image').on('click', function() {
531 if ($(this).find('img').hasClass('portrait')) {
532 $(this).parents('.gallerycell').addClass('portrait');
534 $(this).parents('.gallerycell').removeClass('portrait');
536 $gallery.find('div.first img').attr('src', $(this).data('image-large'));
537 $gallery.find('div.first span.gallery-legend').text($(this).find('img').attr('title') || '');
538 $gallery.find('div.first').show('fade');
541 $gallery.find('div.first').on('click', function() { $(this).toggle('fade'); return false; });
547 if (! document.createElement('audio').canPlayType('audio/ogg') &&
548 document.createElement('audio').canPlayType('audio/aac') ) {
549 $('#ogg-m3u').hide().removeClass('resymbol');
550 $('#aac-m3u').addClass('resymbol').show();
553 var konami = new Konami('/party');
555 $(document).on('panik:timeupdate', function(ev, data) {
556 $waveform = $('#Main div.waveform[data-sound-id="' + data.sound_id + '"]');
557 var elems = $waveform.find('span');
558 var total_elems = elems.length;
559 var done = total_elems * data.position;
560 $waveform.find('span').each(function(k, elem) {
562 $(elem).addClass('done').removeClass('current');
564 $(elem).removeClass('done');
567 $waveform.find('span.done:last').addClass('current');
570 $("body").keydown(function(e) {
571 var $visible_element = $('div.first:visible img');
572 if ($visible_element.length == 0) {
575 if ($visible_element.length > 1) {
576 /* remove all but last */
577 $visible_element.parent().find('img:not(:last)').remove();
579 var $visible_element = $('div.first:visible img');
580 var img_url = $visible_element.attr('src');
581 var all_img = $('div.gallery span[data-image-large] img');
582 var active_img = $('div.gallery span[data-image-large="' + img_url + '"] img');
583 var idx = all_img.index(active_img);
584 if (e.which == 37) { // left
587 idx = all_img.length-1;
589 } else if (e.which == 39) { // right
591 if (idx == all_img.length) {
594 } else if (e.which == 27) { // escape
595 $visible_element.parent().toggle('fade');
600 /* create a new <img> with the new image but opacity 0, then display
601 * it using a css transition */
602 if (e.which == 37) { $visible_element.css('transform-origin', 'bottom right'); }
603 if (e.which == 39) { $visible_element.css('transform-origin', 'bottom left'); }
604 var new_img = $visible_element.clone().appendTo($visible_element.parent());
605 $(new_img).css('opacity', 0).attr('src', $(all_img[idx]).parent().data('image-large'));
606 $(new_img).css('transform', 'scale(0, 1)');
607 $(new_img)[0].offsetHeight; /* trigger reflow */
608 $(new_img).css('opacity', 1).css('transform', 'scale(1)');
609 $(new_img).parents('.gallery').find('span.gallery-legend').text($(all_img[idx]).attr('title') || '');
610 if ($(all_img[idx]).hasClass('portrait')) {
611 if (! $(new_img).parents('.gallerycell').hasClass('portrait')) {
612 $visible_element.parent().find('img:not(:last)').remove();
613 $(new_img).parents('.gallerycell').addClass('portrait');
616 if ($(new_img).parents('.gallerycell').hasClass('portrait')) {
617 $visible_element.parent().find('img:not(:last)').remove();
618 $(new_img).parents('.gallerycell').removeClass('portrait');