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 new_menu = $($.parseHTML(html)).find('#metaNav>*');
60 $metaNav.empty().append(new_menu);
62 var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
63 if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
66 Quite UGLY but needed for styling the whole body with ID
67 Feel free to correct and find a better way
68 According to this link the probles is that $(html).filter('body').Attr('id') will not work!
69 http://www.devnetwork.net/viewtopic.php?f=13&t=117065
71 if(sectionName = $(html).find('[data-section]').attr('data-section')){
72 $('body').attr('id',sectionName);
74 var bodyID = html.match(/<body id="(.*?)">/);
75 if(bodyID){$('body').attr('id',bodyID[1].trim());}
77 $("#Changing").css({'min-height':$(window).height()});
78 $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
81 if (typeof (Piwik) == 'object') {
82 piwikTracker = Piwik.getAsyncTracker();
83 if (typeof (piwikTracker.trackPageView) == 'function') {
84 piwikTracker.setDocumentTitle(document.title);
85 piwikTracker.setCustomUrl(window.location.href);
86 piwikTracker.trackPageView();
92 function afterLoadError(xhr, text, error) {
93 afterLoad(xhr.responseText, 'error', xhr);
96 $(window).on("popstate", function(e) {
97 if (e.originalEvent.state !== null) {loadPage(location.href, false);}
100 loadPage = function(href, push_state) {
101 if (push_state !== false) {
102 history.pushState({}, '', href);
104 if (loadPage_request !== null) {
105 loadPage_request.abort();
107 loadPage_request = $.ajax({
110 error: afterLoadError,
113 $.fn.ajaxifyClick = function(params) {
114 this.each(function() {
115 $(this).unbind('click');
116 $(this).bind('click',function(e){
117 var href = $(this).attr("href");
119 window.open(href, '_blank');
122 $(this).addClass('loading');
123 /* this checks the link points to a local document, be
124 * it because it's just a path, or because the server
125 * part points to the same domain */
127 doLog('No href attributes, unable to load content','error');
128 $("#All a, #All area").removeClass('loading');
130 }else if (!$(this).attr('target') && (
131 href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
136 $(this).attr('target','_blanck');
137 $("#All a, #All area").removeClass('loading');
143 /****************************************************/
144 /**** AUDIOPLAYER ****/
145 /****************************************************/
149 var ticker_interval = null;
151 //TODO: mini icon version for player, (playpause only)
152 $('#togglePlayer').on('click',function(e) {
154 if($(this).is('.icon-double-angle-left')){
155 $("#player").fadeOut('fast',function(){
156 $("#player-container").toggleClass('minimized');
157 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
160 $("#player").fadeIn('fast',function(){
161 $("#player-container").toggleClass('minimized');
162 $('#togglePlayer').toggleClass('icon-double-angle-left icon-double-angle-right');
168 $('#WhatsOnAir').on('load',function(){
169 var WhatsOnAir = $(this);
170 $.getJSON('/onair.json', function(onair) {
171 WhatsOnAir.fadeOut();
172 if(onair.data.episode || onair.data.emission){
173 var onairContainer = $('<span>');
174 if(onair.data.emission){
175 $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
177 if(onair.data.episode){
178 $('<span> - </span>').appendTo(onairContainer);
179 $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
181 WhatsOnAir.empty().append(onairContainer);
182 } else if (onair.data.nonstop) {
183 result = onair.data.nonstop.title;
184 WhatsOnAir.html('<span>' + result + '</span>');
186 else{WhatsOnAir.html('<span>Unknown (Probably Non-Stop)</span>');}
190 $('#RefreshWhatsOnAir').on('activate',function(e){
191 $(this).addClass('spinning');
192 $('#WhatsOnAir').addClass('active');
193 $('#WhatsOnAir').trigger('load');
194 timer = setInterval( "$('#WhatsOnAir').trigger('load');", interval);
195 }).on('deactivate',function(e){
196 $(this).removeClass('spinning');
197 $('#WhatsOnAir').removeClass('active');
198 clearInterval(timer);
199 }).on('click',function(e){
200 $(this).toggleClass('spinning');
201 if($(this).is('.spinning')){
202 $(this).trigger('activate');
203 }else{$(this).trigger('deactivate');}
206 $("#DirectStreamPanikControler").on('click',function(e) {
208 var stream = $('#DirectStreamPanik').get(0);
209 if (stream.paused == false){
216 $('#DirectStreamPanik').on('play',function(){
217 $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
218 $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
219 $('#RefreshWhatsOnAir').trigger('activate');
220 }).on('pause',function(){
221 //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
222 $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
223 $('#RefreshWhatsOnAir').trigger('deactivate');
225 if($('#player-container').offset()){
227 topPosition = $('#player-container').offset().top;
228 $(window).bind('scroll load',function (event) {
229 //$('#player-container').removeClass('fixed');
230 var y = $(this).scrollTop() + $('#metaNav').height() - $('#Player').height() + 10;
231 if (topPosition!== 0 && y >= topPosition) {
232 $('#Player').css({'min-height':$('#Player').height()});
233 $('#player-container').addClass('fixed').removeClass('normal');
235 $('#Player').css({'min-height':'auto'});
236 $('#player-container').removeClass('fixed').addClass('normal');
241 var $localList = $('#localList').playlist({
242 controlContainer: $('<div>',{class:"playListControls"}).sortable(),
243 playlistContainer: $('<ol>',{id:"myPlaylist",class:"custom"}).sortable(),
244 onLoad:function(self){
245 $('#toggleList').on('click',function(){
246 self.playlistContainer.toggleClass('deploy');
248 $('#emptyList').on('click',function(){
253 self.playlistContainer.scrollTo(self.isActive, 800 );
254 self.isActive.find('audio').attr('preload',"preload")
256 self.controlButtons['playpause'].addClass('resymbol');
258 onPlay:function(self){
259 $('#DirectStreamPanik')[0].pause();
260 self.playlistContainer.scrollTo(self.isActive, 800 );
262 onAdd:function(self){
263 //self.isLastAdd[0].scrollIntoView();
264 self.isLastAdd.find('a').ajaxifyClick();
265 self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
268 onUpdate:function(self){
269 //doLog(JSON.stringify(self.playlist, null, '\t'));
270 if(self.playlist.length >= 1){
272 $('#Player').addClass('withPlaylist').removeClass('withoutPlaylist');
275 $('#Player').removeClass('withPlaylist').addClass('withoutPlaylist');
281 $("#All a, #All area").removeClass('loading');
282 $("#All a, #All area").ajaxifyClick();
283 $("#search-form").unbind('submit').on('submit', function(event) {
284 event.preventDefault();
285 $(this).addClass('loading');
286 console.log('action:', $(this).attr('action') + '?' + $(this).serialize());
287 loadPage($(this).attr('action') + '?' + $(this).serialize());
289 $(".tabs").each(function() {
291 var about= $($(this).attr("data-tab-about"));
292 var current = $(this).find("[data-tab].active")[0];
293 var dftShowSelector = current?".active":":first";
294 var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
295 $(this).find("[data-tab]").each(function() {
296 $(this).on('click load',function (e) {
298 self.find(".active").removeClass("active");
299 $(this).addClass("active");
300 about.find("[data-tabbed]").hide();
301 $($(this).attr("data-tab")).fadeIn();
305 activeTab.trigger('load');
307 $('[data-player-action]').on('click',function(){
308 var audio = $('#'+$(this).attr('data-player-audio'));
309 if($(this).attr('data-player-action') == "registerAudio"){
310 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' has been added to your playlist.','ok'));
311 }else if($(this).attr('data-player-action') == "playAudio"){
312 $localList.playlist("registerAudio",audio,doLog(audio.attr('title')+' will play soon.','ok'));
313 $localList.playlist("playLast");
315 $localList.playlist($(this).attr('data-player-action'));
318 $('[data-player-control]').each(function(){
319 var audio = $('#'+$(this).attr('data-player-audio'));
320 $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
323 $('[data-highlight]').on('check',function(){
324 $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
325 }).on('uncheck',function(){
326 $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
327 }).on('click',function(){
328 $(this).toggleClass('icon-check icon-check-empty');
329 if($(this).hasClass('icon-check')){$(this).trigger('check');
330 }else{ $(this).trigger('uncheck');}
332 $('[data-highlight].icon-check-empty').each(function(){
333 $(this).trigger('uncheck');
335 $('[data-toggle]').on('check',function(){
336 /* make sure all other unchecked items are hidden */
337 $('[data-toggle].icon-check-empty').each(function() {
338 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
340 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
341 }).on('uncheck',function(){
342 $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
343 if ($('[data-toggle].icon-check').length == 0) {
344 /* special case the situation where all toggles
345 * are unchecked, as we want that to mean
346 * "everything", not "nothing".
348 $('[data-toggle].icon-check-empty').each(function() {
349 $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
352 }).on('click',function(){
353 $(this).toggleClass('icon-check icon-check-empty');
354 if($(this).hasClass('icon-check')){$(this).trigger('check');
355 }else{ $(this).trigger('uncheck');}
357 $('[data-toggle].icon-check-empty').each(function(){
358 $(this).trigger('uncheck');
361 initial_enabled_toggles = {};
362 if (typeof(urlParams.q) == 'string') {
363 urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
365 $('[data-toggle]').each(function() {
366 if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
367 $(this).trigger('click');
371 if ($('input#id_q').val() == '') {
372 $('input#id_q').focus();
375 $('#ticker li:not(:first)');
376 if (ticker_interval) clearInterval(ticker_interval);
378 $('#ticker li:first').animate({'opacity':0}, 200, function () {
379 $(this).appendTo($('#ticker')).css('opacity', 1);
382 $("#roller button").on('click',function(e){
383 clearInterval(ticker_interval);
385 $($(this).attr('data-about')).prependTo('#ticker');
388 ticker_interval = setInterval(function(){tick(); }, 20000);/**/