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");
25 $( document ).tooltip({
27 my: "center bottom-5",
29 using: function( position, feedback ) {
30 $( this ).css( position );
33 .addClass( feedback.vertical )
34 .addClass( feedback.horizontal )
39 $('body').css({'min-height':$(window).height() + $('#Commons').height()});
40 /****************************************************/
41 /**** AJAX UTILITIES FOR REQUESTS ****/
42 /****************************************************/
43 String.prototype.decodeHTML = function() {
44 return $("<div>", {html: "" + this}).html();
46 var loadPage_request = null;
47 afterLoad = function(html, textStatus, XMLHttpRequest) {
48 loadPage_request = null;
49 if (textStatus == "error") {
50 doLog('Sorry! And error occur when loading page content','error');
52 new_content = $($.parseHTML(html)).find('#Changing>*');
53 $main.hide().empty().append(new_content).show();
56 new_menu = $($.parseHTML(html)).find('#metaNav>*');
57 $metaNav.empty().append(new_menu);
59 var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
60 if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
63 Quite UGLY but needed for styling the whole body with ID
64 Feel free to correct and find a better way
65 According to this link the probles is that $(html).filter('body').Attr('id') will not work!
66 http://www.devnetwork.net/viewtopic.php?f=13&t=117065
68 if(sectionName = $(html).find('[data-section]').attr('data-section')){
69 $('body').attr('id',sectionName);
71 var bodyID = html.match(/<body id="(.*?)">/);
72 if(bodyID){$('body').attr('id',bodyID[1].trim());}
74 $("#Changing").css({'min-height':$(window).height()});
75 $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
78 if (typeof (Piwik) == 'object') {
79 piwikTracker = Piwik.getAsyncTracker();
80 if (typeof (piwikTracker.trackPageView) == 'function') {
81 piwikTracker.setDocumentTitle(document.title);
82 piwikTracker.setCustomUrl(window.location.href);
83 piwikTracker.trackPageView();
89 function afterLoadError(xhr, text, error) {
90 afterLoad(xhr.responseText, 'error', xhr);
93 $(window).on("popstate", function(e) {
94 if (e.originalEvent.state !== null) {loadPage(location.href);}
97 loadPage = function(href) {
98 history.pushState({}, '', href);
99 if (loadPage_request !== null) {
100 loadPage_request.abort();
102 loadPage_request = $.ajax({
105 error: afterLoadError,
108 $.fn.ajaxifyClick = function(params) {
109 this.each(function() {
110 $(this).unbind('click');
111 $(this).bind('click',function(e){
112 var href = $(this).attr("href");
114 window.open(href, '_blank');
117 $(this).addClass('loading');
118 /* this checks the link points to a local document, be
119 * it because it's just a path, or because the server
120 * part points to the same domain */
122 doLog('No href attributes, unable to load content','error');
123 $("#All a, #All area").removeClass('loading');
125 }else if (!$(this).attr('target') && (
126 href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
131 $(this).attr('target','_blanck');
132 $("#All a, #All area").removeClass('loading');
138 /****************************************************/
139 /**** AUDIOPLAYER ****/
140 /****************************************************/
145 //TODO: mini icon version for player, (playpause only)
146 $('#togglePlayer').on('click',function(e) {
148 if($(this).is('.icon-double-angle-left')){
149 $("#player").fadeOut('fast',function(){
150 $("#player-container").toggleClass('minimized');
151 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
154 $("#player").fadeIn('fast',function(){
155 $("#player-container").toggleClass('minimized');
156 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
162 $('#WhatsOnAir').on('load',function(){
163 var WhatsOnAir = $(this);
164 $.getJSON('/onair.json', function(onair) {
165 WhatsOnAir.fadeOut();
166 if(onair.data.episode || onair.data.emission){
167 var onairContainer = $('<span>');
168 if(onair.data.emission){
169 $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
171 if(onair.data.episode){
172 $('<span> - </span>').appendTo(onairContainer);
173 $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
175 WhatsOnAir.empty().append(onairContainer);
176 } else if (onair.data.nonstop) {
177 result = onair.data.nonstop.title;
178 WhatsOnAir.html('<span>' + result + '</span>');
180 else{WhatsOnAir.html('<span>Unknown (Probably Non-Stop)</span>');}
184 $('#RefreshWhatsOnAir').on('activate',function(e){
185 $(this).addClass('spinning');
186 $('#WhatsOnAir').addClass('active');
187 $('#WhatsOnAir').trigger('load');
188 timer = setInterval( "$('#WhatsOnAir').trigger('load');", interval);
189 }).on('deactivate',function(e){
190 $(this).removeClass('spinning');
191 $('#WhatsOnAir').removeClass('active');
192 clearInterval(timer);
193 }).on('click',function(e){
194 $(this).toggleClass('spinning');
195 if($(this).is('.spinning')){
196 $(this).trigger('activate');
197 }else{$(this).trigger('deactivate');}
200 $("#DirectStreamPanikControler").on('click',function(e) {
202 var stream = $('#DirectStreamPanik').get(0);
203 if (stream.paused == false){
210 $('#DirectStreamPanik').on('play',function(){
211 $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
212 $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
213 $('#RefreshWhatsOnAir').trigger('activate');
214 }).on('pause',function(){
215 //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
216 $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
217 $('#RefreshWhatsOnAir').trigger('deactivate');
219 if($('#player-container').offset()){
221 topPosition = $('#player-container').offset().top;
222 $(window).bind('scroll load',function (event) {
223 //$('#player-container').removeClass('fixed');
224 var y = $(this).scrollTop() + $('#metaNav').height() - $('#Player').height() + 10;
225 if (topPosition!== 0 && y >= topPosition) {
226 $('#Player').css({'min-height':$('#Player').height()});
227 $('#player-container').addClass('fixed').removeClass('normal');
229 $('#Player').css({'min-height':'auto'});
230 $('#player-container').removeClass('fixed').addClass('normal');
235 var $localList = $('#localList').playlist({
236 controlContainer: $('<div>',{class:"playListControls"}).sortable(),
237 playlistContainer: $('<ol>',{id:"myPlaylist",class:"custom"}).sortable(),
238 onLoad:function(self){
239 $('#toggleList').on('click',function(){
240 self.playlistContainer.toggleClass('deploy');
242 $('#emptyList').on('click',function(){
247 self.playlistContainer.scrollTo(self.isActive, 800 );
248 self.isActive.find('audio').attr('preload',"preload")
250 self.controlButtons['playpause'].addClass('resymbol');
252 onPlay:function(self){
253 $('#DirectStreamPanik')[0].pause();
254 self.playlistContainer.scrollTo(self.isActive, 800 );
256 onAdd:function(self){
257 //self.isLastAdd[0].scrollIntoView();
258 self.isLastAdd.find('a').ajaxifyClick();
259 self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
262 onUpdate:function(self){
263 //doLog(JSON.stringify(self.playlist, null, '\t'));
264 if(self.playlist.length >= 1){
266 $('#Player').addClass('withPlaylist');
269 $('#Player').removeClass('withPlaylist');
275 $("#All a, #All area").removeClass('loading');
276 $("#All a, #All area").ajaxifyClick();
277 $("#search-form").unbind('submit').on('submit', function(event) {
278 event.preventDefault();
279 $(this).addClass('loading');
280 loadPage($(this).attr('action') + '/?' + $(this).serialize());
282 $(".tabs").each(function() {
284 var about= $($(this).attr("data-tab-about"));
285 var current = $(this).find("[data-tab].active")[0];
286 var dftShowSelector = current?".active":":first";
287 var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
288 $(this).find("[data-tab]").each(function() {
289 $(this).on('click load',function (e) {
291 self.find(".active").removeClass("active");
292 $(this).addClass("active");
293 about.find("[data-tabbed]").hide();
294 $($(this).attr("data-tab")).fadeIn();
298 activeTab.trigger('load');
300 $('[data-player-action]').on('click',function(){
301 var audio = $('#'+$(this).attr('data-player-audio'));
302 if($(this).attr('data-player-action') == "registerAudio"){
303 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
304 }else if($(this).attr('data-player-action') == "playAudio"){
305 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' will play soon.','ok'));
306 $localList.playlist("playLast");
308 $localList.playlist($(this).attr('data-player-action'));
311 $('[data-player-control]').each(function(){
312 var audio = $('#'+$(this).attr('data-player-audio'));
313 $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
316 $('[data-highlight]').on('check',function(){
317 $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
318 }).on('uncheck',function(){
319 $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
320 }).on('click',function(){
321 $(this).toggleClass('icon-check icon-check-empty');
322 if($(this).hasClass('icon-check')){$(this).trigger('check');
323 }else{ $(this).trigger('uncheck');}
325 $('[data-highlight].icon-check-empty').each(function(){
326 $(this).trigger('uncheck');
328 $('[data-toggle]').on('check',function(){
329 /* make sure all other unchecked items are hidden */
330 $('[data-toggle].icon-check-empty').each(function() {
331 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
333 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
334 }).on('uncheck',function(){
335 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
336 if ($('[data-toggle].icon-check').length == 0) {
337 /* special case the situation where all toggles
338 * are unchecked, as we want that to mean
339 * "everything", not "nothing".
341 $('[data-toggle].icon-check-empty').each(function() {
342 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
345 }).on('click',function(){
346 $(this).toggleClass('icon-check icon-check-empty');
347 if($(this).hasClass('icon-check')){$(this).trigger('check');
348 }else{ $(this).trigger('uncheck');}
350 $('[data-toggle].icon-check-empty').each(function(){
351 $(this).trigger('uncheck');
354 initial_enabled_toggles = {};
355 if (typeof(urlParams.q) == 'string') {
356 urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
358 $('[data-toggle]').each(function() {
359 if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
360 $(this).trigger('click');
364 if ($('input#id_q').val() == '') {
365 $('input#id_q').focus();