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_content = $($.parseHTML(html)).find('#Changing>*');
57 $main.hide().empty().append(new_content).show();
59 /* calling onpopstate here is necessary to get urlParams to be
63 new_menu = $($.parseHTML(html)).find('#metaNav>*');
64 $metaNav.empty().append(new_menu);
66 var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
67 if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
70 Quite UGLY but needed for styling the whole body with ID
71 Feel free to correct and find a better way
72 According to this link the probles is that $(html).filter('body').Attr('id') will not work!
73 http://www.devnetwork.net/viewtopic.php?f=13&t=117065
75 if(sectionName = $(html).find('[data-section]').attr('data-section')){
76 $('body').attr('id',sectionName);
78 var bodyID = html.match(/<body id="(.*?)">/);
79 if(bodyID){$('body').attr('id',bodyID[1].trim());}
81 $("#Changing").css({'min-height':$(window).height()});
82 $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
85 if (typeof (Piwik) == 'object') {
86 piwikTracker = Piwik.getAsyncTracker();
87 if (typeof (piwikTracker.trackPageView) == 'function') {
88 piwikTracker.setDocumentTitle(document.title);
89 piwikTracker.setCustomUrl(window.location.href);
90 piwikTracker.trackPageView();
96 function afterLoadError(xhr, text, error) {
97 afterLoad(xhr.responseText, 'error', xhr);
100 $(window).on("popstate", function(e) {
101 if (e.originalEvent.state !== null) {loadPage(location.href, false);}
104 loadPage = function(href, push_state) {
105 if (push_state !== false) {
106 history.pushState({}, '', href);
108 if (loadPage_request !== null) {
109 loadPage_request.abort();
111 loadPage_request = $.ajax({
114 error: afterLoadError,
117 $.fn.ajaxifyClick = function(params) {
118 this.each(function() {
119 $(this).unbind('click');
120 $(this).bind('click',function(e){
121 var href = $(this).attr("href");
123 window.open(href, '_blank');
126 $(this).addClass('loading');
127 /* this checks the link points to a local document, be
128 * it because it's just a path, or because the server
129 * part points to the same domain */
131 doLog('No href attributes, unable to load content','error');
132 $("#All a, #All area").removeClass('loading');
134 }else if (!$(this).attr('target') && (
135 href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
140 $(this).attr('target','_blanck');
141 $("#All a, #All area").removeClass('loading');
147 /****************************************************/
148 /**** AUDIOPLAYER ****/
149 /****************************************************/
153 var ticker_interval = null;
155 //TODO: mini icon version for player, (playpause only)
156 $('#togglePlayer').on('click',function(e) {
158 if($(this).is('.icon-double-angle-left')){
159 $("#player").fadeOut('fast',function(){
160 $("#player-container").toggleClass('minimized');
161 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
164 $("#player").fadeIn('fast',function(){
165 $("#player-container").toggleClass('minimized');
166 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
172 $('#WhatsOnAir').on('load',function(){
173 var WhatsOnAir = $(this);
174 $.getJSON('/onair.json', function(onair) {
175 WhatsOnAir.fadeOut();
176 if(onair.data.episode || onair.data.emission){
177 var onairContainer = $('<span>');
178 if(onair.data.emission){
179 $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
181 if(onair.data.episode){
182 $('<span> - </span>').appendTo(onairContainer);
183 $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
185 WhatsOnAir.empty().append(onairContainer);
186 } else if (onair.data.nonstop) {
187 result = onair.data.nonstop.title;
188 WhatsOnAir.html('<span>' + result + '</span>');
190 else{WhatsOnAir.html('<span>Unknown (Probably Non-Stop)</span>');}
194 $('#RefreshWhatsOnAir').on('activate',function(e){
195 $(this).addClass('spinning');
196 $('#WhatsOnAir').addClass('active');
197 $('#WhatsOnAir').trigger('load');
198 timer = setInterval( "$('#WhatsOnAir').trigger('load');", interval);
199 }).on('deactivate',function(e){
200 $(this).removeClass('spinning');
201 $('#WhatsOnAir').removeClass('active');
202 clearInterval(timer);
203 }).on('click',function(e){
204 $(this).toggleClass('spinning');
205 if($(this).is('.spinning')){
206 $(this).trigger('activate');
207 }else{$(this).trigger('deactivate');}
210 $("#DirectStreamPanikControler").on('click',function(e) {
212 var stream = $('#DirectStreamPanik').get(0);
213 if (stream.paused == false){
220 $('#DirectStreamPanik').on('play',function(){
221 $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
222 $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
223 $('#RefreshWhatsOnAir').trigger('activate');
224 }).on('pause',function(){
225 //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
226 $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
227 $('#RefreshWhatsOnAir').trigger('deactivate');
229 if($('#player-container').offset()){
231 topPosition = $('#mainHeader > div').offset().top + $('#mainHeader > div').height();
232 $(window).bind('scroll load',function (event) {
233 //$('#player-container').removeClass('fixed');
234 var y = $(this).scrollTop() + 40;
235 if (topPosition!== 0 && y >= topPosition) {
236 $('#player-container').addClass('fixed').removeClass('normal');
238 $('#player-container').removeClass('fixed').addClass('normal');
243 var $localList = $('#localList').playlist({
244 controlContainer: $('<div>',{'class':"playListControls"}).sortable(),
245 playlistContainer: $('<ol>',{id:"myPlaylist",'class':"custom"}).sortable(),
246 onLoad:function(self){
247 $('#toggleList').on('click',function(){
248 self.playlistContainer.toggleClass('deploy');
250 $('#emptyList').on('click',function(){
255 self.playlistContainer.scrollTo(self.isActive, 800 );
256 self.isActive.find('audio').attr('preload',"preload")
258 self.controlButtons['playpause'].addClass('resymbol');
260 onPlay:function(self){
261 $('#DirectStreamPanik')[0].pause();
262 self.playlistContainer.scrollTo(self.isActive, 800 );
264 onAdd:function(self){
265 //self.isLastAdd[0].scrollIntoView();
266 self.isLastAdd.find('a').ajaxifyClick();
267 self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
270 onUpdate:function(self){
271 //doLog(JSON.stringify(self.playlist, null, '\t'));
272 if(self.playlist.length >= 1){
274 $('#Player').addClass('withPlaylist').removeClass('withoutPlaylist');
277 $('#Player').removeClass('withPlaylist').addClass('withoutPlaylist');
283 $("#All a, #All area").removeClass('loading');
284 $("#All a, #All area").ajaxifyClick();
285 $("#search-form").unbind('submit').on('submit', function(event) {
286 event.preventDefault();
287 $(this).addClass('loading');
288 loadPage($(this).attr('action') + '?' + $(this).serialize());
290 $(".tabs").each(function() {
292 var about= $($(this).attr("data-tab-about"));
293 var current = $(this).find("[data-tab].active")[0];
294 var dftShowSelector = current?".active":":first";
295 var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
296 $(this).find("[data-tab]").each(function() {
297 $(this).on('click load',function (e) {
299 self.find(".active").removeClass("active");
300 $(this).addClass("active");
301 about.find("[data-tabbed]").hide();
302 $($(this).attr("data-tab")).fadeIn();
306 activeTab.trigger('load');
308 $('[data-player-action]').on('click',function(){
309 var audio = $('#'+$(this).attr('data-player-audio'));
310 if($(this).attr('data-player-action') == "registerAudio"){
311 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
312 }else if($(this).attr('data-player-action') == "playAudio"){
313 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' will play soon.','ok'));
314 $localList.playlist("playLast");
316 $localList.playlist($(this).attr('data-player-action'));
319 $('[data-player-control]').each(function(){
320 var audio = $('#'+$(this).attr('data-player-audio'));
321 $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
324 $('[data-highlight]').on('check',function(){
325 $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
326 }).on('uncheck',function(){
327 $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
328 }).on('click',function(){
329 $(this).toggleClass('icon-check icon-check-empty');
330 if($(this).hasClass('icon-check')){$(this).trigger('check');
331 }else{ $(this).trigger('uncheck');}
333 $('[data-highlight].icon-check-empty').each(function(){
334 $(this).trigger('uncheck');
336 $('[data-toggle]').on('check',function(){
337 /* make sure all other unchecked items are hidden */
338 $('[data-toggle].icon-check-empty').each(function() {
339 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
341 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
342 }).on('uncheck',function(){
343 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
344 if ($('[data-toggle].icon-check').length == 0) {
345 /* special case the situation where all toggles
346 * are unchecked, as we want that to mean
347 * "everything", not "nothing".
349 $('[data-toggle].icon-check-empty').each(function() {
350 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
353 }).on('click',function(){
354 $(this).toggleClass('icon-check icon-check-empty');
355 if($(this).hasClass('icon-check')){$(this).trigger('check');
356 }else{ $(this).trigger('uncheck');}
358 $('[data-toggle].icon-check-empty').each(function(){
359 $(this).trigger('uncheck');
362 initial_enabled_toggles = {};
363 if (typeof(urlParams.q) == 'string') {
364 urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
366 $('[data-toggle]').each(function() {
367 if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
368 $(this).trigger('click');
372 if ($('input#id_q').val() == '') {
373 $('input#id_q').focus();
376 $('#ticker li:not(:first)');
377 if (ticker_interval) clearInterval(ticker_interval);
379 $('#ticker li:first').animate({'opacity':0}, 200, function () {
380 $(this).appendTo($('#ticker')).css('opacity', 1);
383 $("#roller button").on('click',function(e){
384 clearInterval(ticker_interval);
386 $($(this).attr('data-about')).prependTo('#ticker');
389 ticker_interval = setInterval(function(){tick(); }, 20000);/**/
391 function navsearch_click(event) {
392 event.preventDefault();
393 var query = $('#nav-search input').val();
394 var form = $('#nav-search form');
397 href = $(form).attr('action');
399 href = $(form).attr('action') + '?' + $(form).serialize();
401 if (event.which == 2) {
402 window.open(href, '_blank');
404 $(this).addClass('loading');
409 $('#nav-search a').unbind('click').on('click', navsearch_click);
410 $('#nav-search form').unbind('submit').on('submit', navsearch_click);
412 if (document.cookie.indexOf('panikdb=on') != -1) {
414 if (window.location.pathname.indexOf('/emissions/') == 0) {
415 panikdb_path = window.location.pathname;
416 } else if (window.location.pathname.indexOf('/news/') == 0) {
417 panikdb_path = '/emissions' + window.location.pathname;
420 $('<a id="panikdb" href="http://panikdb.radiopanik.org' + panikdb_path + '">Voir dans PanikDB</a>').appendTo($main);
425 var konami = new Konami('/party');