--- /dev/null
+var urlParams;
+var connection;
+
+(window.onpopstate = function () {
+ var match,
+ pl = /\+/g, // Regex for replacing addition symbol with a space
+ search = /([^&=]+)=?([^&]*)/g,
+ decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
+ query = window.location.search.substring(1);
+
+ urlParams = {};
+ while (match = search.exec(query))
+ urlParams[decode(match[1])] = decode(match[2]);
+})();
+
+$(function() {
+
+ doLog = function(aTextToLog, type){
+ var aLog = $('<div>',{'class':"log "+type,html:aTextToLog});
+ aLog.hide().prependTo($log).show('fast').delay(3000).hide('fast', function() {
+ $(this).remove();
+ });
+ }
+ var $main = $("#Changing");
+ var $metaNav = $("#metaNav");
+ var $log = $("#userLog");
+
+ /****************************************************/
+ /**** AJAX UTILITIES FOR REQUESTS ****/
+ /****************************************************/
+ String.prototype.decodeHTML = function() {
+ return $("<div>", {html: "" + this}).html();
+ };
+ var loadPage_request = null;
+ afterLoad = function(html, textStatus, XMLHttpRequest) {
+ $('#loading-page').addClass('fade');
+ loadPage_request = null;
+ if (textStatus == "error") {
+ doLog('Sorry! And error occur when loading page content','error');
+ }
+ if (connection) { connection.disconnect(); }
+ new_html = $.parseHTML(html);
+ new_content = $(new_html).find('#Changing>*');
+ $main.hide().empty().append(new_content).show();
+
+ /* calling onpopstate here is necessary to get urlParams to be
+ * updated */
+ window.onpopstate();
+
+ canonical_href_node = $.grep($(new_html), function(elem, idx) {
+ return (elem.nodeName === "LINK" && elem.attributes['rel'].value == "canonical");
+ })[0];
+ if (canonical_href_node) {
+ canonical_href = canonical_href_node.attributes['href'].value;
+ try { history.replaceState({}, '', canonical_href); } catch(ex) {};
+ }
+
+ new_menu = $($.parseHTML(html)).find('#metaNav>*');
+ $metaNav.empty().append(new_menu);
+
+ var newTitle = html?html.match(/<title>(.*?)<\/title>/):'';
+ if(newTitle){document.title = newTitle[1].trim().decodeHTML();}
+
+ $.scrollTo('#Changing',1000,{offset:-$('#metaNav').height()+2});
+ init();
+
+ if (typeof (Piwik) == 'object') {
+ piwikTracker = Piwik.getAsyncTracker();
+ if (typeof (piwikTracker.trackPageView) == 'function') {
+ piwikTracker.setDocumentTitle(document.title);
+ piwikTracker.setCustomUrl(window.location.href);
+ piwikTracker.trackPageView();
+ $('.audio a').each(function() {
+ piwikTracker.addListener(this);
+ });
+ }
+ }
+
+ };
+
+ function afterLoadError(xhr, text, error) {
+ afterLoad(xhr.responseText, 'error', xhr);
+ };
+
+ $(window).on("popstate", function(e) {
+ loadPage(location.href, false);
+ });
+
+ loadPage = function(href, push_state) {
+ if (push_state !== false) {
+ history.pushState({}, '', href);
+ }
+ if (loadPage_request !== null) {
+ loadPage_request.abort();
+ }
+ $('#loading-page').remove();
+ $('<div id="loading-page"></div>').prependTo($('#All'));
+ loadPage_request = $.ajax({
+ url: href,
+ success: afterLoad,
+ error: afterLoadError,
+ dataType: 'html'});
+ };
+ $.fn.ajaxifyClick = function(params) {
+ if ($('#df-wpr-sidebar').length > 0) {
+ /* this is fiber sidebar, it doesn't work well with
+ * seamless page loading */
+ return;
+ }
+ this.each(function() {
+ $(this).unbind('click');
+ $(this).bind('click',function(e){
+ var href = $(this).attr("href");
+ if (e.which == 2) {
+ window.open(href, '_blank');
+ return false;
+ }
+ if (href.match('\.(pdf|odt|ods|doc|xls|docx|xlsx|rtf|zip|rss|atom)$')) {
+ /* open files */
+ window.location = href;
+ return false;
+ }
+ $(this).addClass('loading');
+ /* this checks the link points to a local document, be
+ * it because it's just a path, or because the server
+ * part points to the same domain */
+ if (!href) {
+ doLog('No href attributes, unable to load content','error');
+ $("#All a, #All area").removeClass('loading');
+ return false;
+ }else if (!$(this).attr('target') && (
+ href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
+ )) {
+ loadPage(href);
+ return false;
+ }else{
+ $(this).attr('target','_blank');
+ $(this).attr('rel', 'noopener');
+ $("#All a, #All area").removeClass('loading');
+ return true;
+ }
+ });
+ });
+ };
+ /****************************************************/
+ /**** AUDIOPLAYER ****/
+ /****************************************************/
+
+ var timer = null;
+ var ticker_interval = null;
+ $('#WhatsOnAir').on('load',function(){
+ var WhatsOnAir = $(this);
+ $.getJSON('/onair.json', function(onair) {
+ var onairContainer = $('<span>');
+ if(onair.data.episode || onair.data.emission) {
+ if(onair.data.emission){
+ $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
+ }
+ if(onair.data.episode){
+ $('<span> - </span>').appendTo(onairContainer);
+ $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
+ }
+ } else if (onair.data.nonstop) {
+ if (onair.data.nonstop.url) {
+ onairContainer = $('<a href="' + onair.data.nonstop.url + '">' + onair.data.nonstop.title + '</a>');
+ } else {
+ onairContainer = $('<span>' + onair.data.nonstop.title + '</span>');
+ }
+ if (onair.data.track_title) {
+ $('<span> - </span>').appendTo(onairContainer);
+ $('<span class="nonstop-track-title">' + onair.data.track_title + '</span>').appendTo(onairContainer);
+ if (onair.data.track_artist) {
+ $('<span> </span>').appendTo(onairContainer)
+ $('<span class="nonstop-track-artist">(' + onair.data.track_artist + ')</span>').appendTo(onairContainer);
+ }
+ }
+ }
+ else {
+ onairContainer = $('<span>Unknown (Probably Non-Stop)</span>');
+ }
+ if (onair.data.emission && onair.data.emission.chat) {
+ $('#CurrentlyChatting a').attr('href', onair.data.emission.chat);
+ $('#CurrentlyChatting').show();
+ } else {
+ $('#CurrentlyChatting').hide();
+ }
+ var current_html = WhatsOnAir.html();
+ var new_html = '<span>' + onairContainer.html() + '</span>';
+ if (new_html !== current_html) {
+ WhatsOnAir.fadeOut();
+ WhatsOnAir.empty().append(onairContainer);
+ WhatsOnAir.fadeIn();
+ }
+ });
+ });
+ $('#WhatsOnAir').trigger('load');
+ var refresh_onair_interval = 25000;
+ setInterval("$('#WhatsOnAir').trigger('load');", refresh_onair_interval);
+ $("#DirectStreamPanikControler").on('click',function(e) {
+ e.preventDefault();
+ var stream = $('#DirectStreamPanik').get(0);
+ if (stream.paused == false){
+ stream.pause();
+ }else{
+ if (typeof (_paq) == 'object') {
+ _paq.push(['trackEvent', 'Audio', 'Play Stream']);
+ }
+ stream.play();
+ }
+ return false;
+ });
+ $('#DirectStreamPanik').on('play',function(){
+ $('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
+ $('#streamSymbol').removeClass('icon-volume-up').addClass('icon-pause');
+ }).on('pause',function(){
+ //$('audio:not(#DirectStreamPanik)').each(function(){this.pause();});
+ $('#streamSymbol').addClass('icon-volume-up').removeClass('icon-pause');
+ });
+ if($('#player-container').offset()){
+ var topPosition = 0;
+ topPosition = $('#mainHeader > div').offset().top + $('#mainHeader > div').height();
+ $(window).bind('scroll load',function (event) {
+ //$('#player-container').removeClass('fixed');
+ var y = $(this).scrollTop() + 60;
+ if (topPosition!== 0 && y >= topPosition) {
+ $('#player-container').addClass('fixed').removeClass('normal');
+ } else {
+ $('#player-container').removeClass('fixed').addClass('normal');
+ }
+ });
+ }
+
+ var $localList = $('#localList').playlist({
+ controlContainer: $('<div>',{'class':"playListControls"}).sortable(),
+ playlistContainer: $('<ol>',{id:"myPlaylist",'class':"custom"}).sortable(),
+ onLoad:function(self){
+ $('#toggleList').on('click',function(){
+ self.playlistContainer.toggleClass('deploy');
+ });
+ $('#emptyList').on('click',function(){
+ self._reset();
+ });
+
+ if(self.isActive){
+ self.playlistContainer.scrollTo(self.isActive, 800 );
+ self.isActive.find('audio').attr('preload',"preload")
+ }
+ self.controlButtons['playpause'].addClass('resymbol');
+ },
+ onPlay:function(self){
+ $('#DirectStreamPanik')[0].pause();
+ self.playlistContainer.scrollTo(self.isActive, 800 );
+ },
+ onAdd:function(self){
+ //self.isLastAdd[0].scrollIntoView();
+ self.isLastAdd.find('a').ajaxifyClick();
+ self.playlistContainer.scrollTo(self.isLastAdd, 800).delay(1000).scrollTo(self.isActive, 800 ).clearQueue();
+
+ if (typeof (_paq) == 'object') {
+ _paq.push(['trackEvent', 'Audio', 'Add to playlist']);
+ }
+ },
+ onUpdate:function(self){
+ //doLog(JSON.stringify(self.playlist, null, '\t'));
+ if(self.playlist.length >= 1){
+ self.element.show();
+ $('#Player').addClass('withPlaylist').removeClass('withoutPlaylist');
+ }else{
+ self.element.hide();
+ $('#Player').removeClass('withPlaylist').addClass('withoutPlaylist');
+ }
+ }
+ });
+
+ init = function() {
+ $("#All a, #All area").removeClass('loading');
+ $("#All a, #All area").ajaxifyClick();
+ $("#search-form").unbind('submit').on('submit', function(event) {
+ event.preventDefault();
+ $(this).addClass('loading');
+ loadPage($(this).attr('action') + '?' + $(this).serialize());
+ });
+ $(".tabs").each(function() {
+ var self = $(this);
+ var about= $($(this).attr("data-tab-about"));
+ var current = $(this).find("[data-tab].active")[0];
+ var dftShowSelector = current?".active":":first";
+ var activeTab = $(this).find("[data-tab]"+dftShowSelector+"").addClass("active");
+ $(this).find("[data-tab]").each(function() {
+ $(this).on('click load',function (e) {
+ e.preventDefault();
+ self.find(".active").removeClass("active");
+ $(this).addClass("active");
+ about.find("[data-tabbed]").hide();
+ $($(this).attr("data-tab")).fadeIn();
+
+ });
+ });
+ activeTab.trigger('load');
+ });
+ $('[data-player-action]').on('click',function(){
+ var audio = $('audio[data-sound-id=' + $(this).attr('data-sound-id') + ']');
+ var sound_id = audio.data('sound-id');
+ if($(this).attr('data-player-action') == "registerAudio"){
+ $localList.playlist("registerAudio",audio);
+ }else if($(this).attr('data-player-action') == "playAudio"){
+ if ($(this).hasClass('icon-play-sign')) {
+ $localList.playlist("registerAudio",audio);
+ $localList.playlist("playSoundId", sound_id);
+ if ($(this).parent().find('.icon-pause').length) {
+ $(this).hide();
+ $(this).parent().find('.icon-pause').show();
+ }
+ } else {
+ $localList.playlist('pauseSounds');
+ }
+ }else if ($(this).attr('data-player-action') == "pauseSounds") {
+ if ($(this).parent().find('.icon-play-sign').length) {
+ $(this).hide();
+ $(this).parent().find('.icon-play-sign').show();
+ }
+ $localList.playlist($(this).attr('data-player-action'));
+ }else{
+ $localList.playlist($(this).attr('data-player-action'));
+ }
+ });
+ $('[data-player-control]').each(function(){
+ var audio = $('audio[data-sound-id=' + $(this).attr('data-sound-id') + ']');
+ $localList.playlist("bindControl",$(this).attr('data-player-control'),audio,$(this));
+ });
+
+ $('[data-highlight]').on('check',function(){
+ $($(this).attr('data-about')).find($(this).attr('data-highlight')).addClass('highlighted').removeClass('normal');
+ }).on('uncheck',function(){
+ $($(this).attr('data-about')).find($(this).attr('data-highlight')).removeClass('highlighted').addClass('normal');
+ }).on('click',function(){
+ $(this).toggleClass('icon-check icon-check-empty');
+ if($(this).hasClass('icon-check')){$(this).trigger('check');
+ }else{ $(this).trigger('uncheck');}
+ });
+ $('[data-highlight].icon-check-empty').each(function(){
+ $(this).trigger('uncheck');
+ });
+ $('[data-toggle]').on('check',function(){
+ /* make sure all other unchecked items are hidden */
+ $('[data-toggle].icon-check-empty').each(function() {
+ $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
+ });
+ $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
+ }).on('uncheck',function(){
+ $($(this).attr('data-about')).find($(this).attr('data-toggle')).hide();
+ if ($('[data-toggle].icon-check').length == 0) {
+ /* special case the situation where all toggles
+ * are unchecked, as we want that to mean
+ * "everything", not "nothing".
+ */
+ $('[data-toggle].icon-check-empty').each(function() {
+ $($(this).attr('data-about')).find($(this).attr('data-toggle')).show();
+ });
+ }
+ }).on('click',function(){
+ $(this).toggleClass('icon-check icon-check-empty');
+ if($(this).hasClass('icon-check')){$(this).trigger('check');
+ }else{ $(this).trigger('uncheck');}
+ });
+ $('[data-toggle].icon-check-empty').each(function(){
+ $(this).trigger('uncheck');
+ });
+
+ initial_enabled_toggles = {};
+ if (typeof(urlParams.q) == 'string') {
+ urlParams.q.split('|').forEach(function(a) { initial_enabled_toggles[a] = 1; })
+ }
+ $('[data-toggle]').each(function() {
+ if ($(this).data('toggle').substring(1) in initial_enabled_toggles) {
+ $(this).trigger('click');
+ }
+ });
+
+ $('[data-popup-href]').on('click', function() {
+ $.ajax({
+ url: $(this).data('popup-href'),
+ success: function (html, textStatus, jqXhr) {
+ $(html).appendTo($('body'));
+ }
+ });
+ return false;
+ });
+
+ if ($('#search-form.big input#id_q').val() == '') {
+ $('#search-form.big input#id_q').focus();
+ }
+
+ $('#ticker li:not(:first)');
+ if (ticker_interval) clearInterval(ticker_interval);
+ function tick(){
+ $('#ticker li:first').animate({'opacity':0}, 200, function () {
+ $(this).appendTo($('#ticker')).css('opacity', 1);
+ });
+ }
+ $("#roller button").on('click',function(e){
+ clearInterval(ticker_interval);
+ e.preventDefault();
+ $($(this).attr('data-about')).prependTo('#ticker');
+ return false;
+ });
+ ticker_interval = setInterval(function(){tick(); }, 20000);/**/
+
+ function navsearch_click(event) {
+ event.preventDefault();
+ var query = $('#nav-search input').val();
+ var form = $('#nav-search form');
+ var href = '';
+ if (query == '') {
+ href = $(form).attr('action');
+ } else {
+ href = $(form).attr('action') + '?' + $(form).serialize();
+ }
+ if (event.which == 2) {
+ window.open(href, '_blank');
+ } else {
+ $(this).addClass('loading');
+ loadPage(href);
+ }
+ return false;
+ }
+ $('#nav-search a').unbind('click').on('click', navsearch_click);
+ $('#nav-search form').unbind('submit').on('submit', navsearch_click);
+
+ if ($('.bg-title').length) {
+ var bg_title = $('<span id="bg-title" aria-hidden="true"></span>');
+ bg_title.text($('.bg-title').text());
+ $('#Changing').append(bg_title);
+ }
+ $('[data-toggle-img]').bind('click', function() {
+ var src = $(this).data('toggle-img');
+ $(this).data('toggle-img', $(this).attr('src'));
+ $(this).attr('src', src);
+ $(this).toggleClass('right marged');
+ });
+
+ $('#Main #Emission-tabs-detail audio, div.soundcell audio').each(function(index, audio) {
+ var audio_src = $(audio).find('source')[0];
+ var sound_id = $(audio).data('sound-id');
+ var $waveform = $(audio).next();
+ $.getJSON(audio_src.src.replace('.ogg', '.waveform.json'), function(data) {
+ $waveform.empty();
+ $waveform.append('<i class="duration">' + $waveform.data('duration-string') + '</i>');
+ $.each(data, function(k, val) {
+ var val = val * 0.5;
+ $waveform.append('<span data-tick-index="' + k + '" style="height: ' + val + 'px;"></span>');
+ });
+ $waveform.show();
+ $waveform.find('span').on('click', function() {
+ /* if there's been something loaded */
+ var matching_audio = $('audio[data-sound-id=' + sound_id + ']');
+ if (matching_audio.length == 0) return;
+ matching_audio = matching_audio[0];
+ if (matching_audio.paused || matching_audio.ended) {
+ $(this).parents('.sound').find('.icon-play-sign').click();
+ return;
+ }
+ /* try to set time */
+ var total_duration = parseFloat($waveform.data('duration'));
+ var nb_ticks = $(this).parent().find('span').length;
+ var tick_index = $(this).data('tick-index');
+ matching_audio.currentTime = total_duration * tick_index / nb_ticks;
+ });
+ });
+ });
+
+ $('#nav-language span').click(function() {
+ document.cookie = 'panikweb_language=' + $(this).data('lang') + '; path=/';
+ window.location = window.location;
+ return false;
+ });
+
+ if ($('.sound + .content .text ').length) {
+ var text_content = $('.sound + .content .text')[0];
+ text_content.innerHTML = text_content.innerHTML.replace(
+ /[0-9][0-9]+:[0-9][0-9]/g,
+ function(x) { return '<span class="timestamp">' + x + "</span>"; });
+ $(text_content).find('span.timestamp').on('click', function() {
+ var $waveform = $('div.waveform').first();
+ var sound_id = $waveform.prev().data('sound-id');
+ var total_duration = parseFloat($waveform.data('duration'));
+ var nb_ticks = $waveform.find('span').length;
+ var timestamp = $(this).text().split(':');
+ var timestamp_position = timestamp[0] * 60 + timestamp[1] * 1;
+ var tick_idx = parseInt(nb_ticks * timestamp_position / total_duration);
+ // play, then set rough position
+ $('.episode.detail .icon-play-sign').first().trigger('click');
+ var matching_audio = $('audio[data-sound-id=' + sound_id + ']');
+ matching_audio[0].currentTime = timestamp_position;
+ });
+ }
+
+ if (document.cookie.indexOf('panikdb=on') != -1) {
+ panikdb_path = null;
+ if (window.location.pathname.indexOf('/emissions/') == 0) {
+ panikdb_path = window.location.pathname;
+ } else if (window.location.pathname.indexOf('/news/') == 0) {
+ panikdb_path = '/emissions' + window.location.pathname;
+ }
+ if (panikdb_path) {
+ $('<a id="panikdb" href="http://panikdb.radiopanik.org' + panikdb_path + '">Voir dans PanikDB</a>').appendTo($main);
+ }
+ }
+
+ $('.gallery').each(function() {
+ var $gallery = $(this);
+ $gallery.find('span.image').on('click', function() {
+ if ($(this).find('img').hasClass('portrait')) {
+ $(this).parents('.gallerycell').addClass('portrait');
+ } else {
+ $(this).parents('.gallerycell').removeClass('portrait');
+ }
+ $gallery.find('div.first img').attr('src', $(this).data('image-large'));
+ $gallery.find('div.first span.gallery-legend').text($(this).find('img').attr('title') || '');
+ $gallery.find('div.first').show('fade');
+ return false;
+ });
+ $gallery.find('div.first').on('click', function() { $(this).toggle('fade'); return false; });
+ });
+
+ /* CHAT */
+ if ($('#chat').length) {
+ $('#player').addClass('on-chat-page');
+ var moderator = ($('#panikdb').length > 0);
+ var $msg = $('input#msg');
+ var $send = $('button#send');
+ var chat_roster = Object();
+
+ if (moderator) {
+ $('#chat').addClass('moderation');
+ $('#chat').on('click', 'span.from', function() {
+ var name = $(this).text();
+ if (confirm('Kick ' + name + ' ?')) {
+ var muc = $('div#chat').data('chatroom');
+ connection.muc.kick(muc + '@conf.panik', name,
+ 'no reason',
+ function(iq) {
+ },
+ function(iq) {
+ doLog('error kicking', 'error');
+ }
+ );
+ }
+ });
+ }
+
+ $('.nick input').on('keydown', function(ev) {
+ if (ev.keyCode == 13) {
+ $('.nick button').trigger('click');
+ return false;
+ }
+ return true;
+ });
+
+ $('.nick button').on('click', function() {
+ window.localStorage['pa-nick'] = $('.nick input').val();
+ var nick = window.localStorage['pa-nick'];
+ $('.commands .prompt').text(nick + '>');
+
+ connection = new Strophe.Connection("/http-bind");
+ connection.connect('im.panik', null, function(status, error) {
+ if (status == Strophe.Status.CONNECTING) {
+ $('.nick').show();
+ $('.commands').hide();
+ //console.log('Strophe is connecting.');
+ } else if (status == Strophe.Status.CONNFAIL) {
+ $('.nick').show();
+ $('.commands').hide();
+ //console.log('Strophe failed to connect.');
+ } else if (status == Strophe.Status.DISCONNECTING) {
+ $('.nick').show();
+ $('.commands').hide();
+ //console.log('Strophe is disconnecting.');
+ } else if (status == Strophe.Status.DISCONNECTED) {
+ $('.nick').show();
+ $('.commands').hide();
+ //console.log('Strophe is disconnected.');
+ } else if (status == Strophe.Status.CONNECTED) {
+ //console.log('Strophe is connected');
+ $('.nick').hide();
+ $('.commands').show();
+ var jid = nick;
+ var muc = $('div#chat').data('chatroom');
+ connection.muc.join(muc + '@conf.panik', jid,
+ function(msg) {
+ var from = msg.attributes.from.value.replace(/.*\//, '');
+ var klass = '';
+ if (from == jid) {
+ klass = 'msg-out';
+ } else {
+ klass = 'msg-in';
+ }
+ var new_msg = $('<div class="msg new ' + klass + '"><span class="from">' + from + '</span> <span class="content">' + msg.textContent + '</span></div>').prependTo($('#chat'));
+ new_msg[0].offsetHeight; /* trigger reflow */
+ new_msg.removeClass('new');
+ $('div#chat div:nth-child(20)').remove()
+ return true;
+ },
+ function(pres) {
+ var nick = $('.nick input').val()
+ var muc = $('div#chat').data('chatroom');
+ if (pres.getElementsByTagName('status').length == 1 &&
+ pres.getElementsByTagName('status')[0].attributes &&
+ pres.getElementsByTagName('status')[0].attributes.code &&
+ pres.getElementsByTagName('status')[0].attributes.code.value == '307') {
+ /* kicked */
+ var kicked = pres.getElementsByTagName('item')[0].attributes.nick.value;
+ var new_msg = $('<div class="msg info new"><span class="content">' + kicked + ' a été mis dehors.</span></div>').prependTo($('#chat'));
+ new_msg[0].offsetHeight; /* trigger reflow */
+ new_msg.removeClass('new');
+ if (kicked == nick) {
+ connection.disconnect();
+ $('div.nick').css('visibility', 'hidden');
+ }
+ }
+ if (pres.getElementsByTagName('conflict').length == 1) {
+ $('.nick input').val(nick + '_');
+ connection.disconnect();
+ $('.nick button').trigger('click');
+ }
+ return true;
+ },
+ function(roster) {
+ if (chat_roster[nick] == true) {
+ for (contact in roster) {
+ if (chat_roster[contact] !== true) {
+ var new_msg = $('<div class="msg info new"><span class="content">' + contact + ' est dans la place.</span></div>').prependTo($('#chat'));
+ new_msg[0].offsetHeight; /* trigger reflow */
+ new_msg.removeClass('new');
+ }
+ }
+ }
+ chat_roster = Object();
+ for (contact in roster) {
+ chat_roster[contact] = true;
+ }
+ return true;
+ }
+ );
+ }
+ });
+
+ });
+
+ function send() {
+ var text = $msg.val();
+ var muc = $('div#chat').data('chatroom');
+ connection.muc.message(muc + '@conf.panik', null, text);
+ $msg.val('');
+ return true;
+ }
+ $send.click(send);
+ $msg.keydown(function(ev) {
+ if (ev.keyCode == 13) {
+ send();
+ return false;
+ }
+ return true;
+ });
+
+ if (window.localStorage['pa-nick'] !== undefined) {
+ $('.nick input').val(window.localStorage['pa-nick']);
+ $('.nick button').click();
+ }
+
+ $(window).on('beforeunload', function() {
+ if (connection) { connection.disconnect(); }
+ });
+
+ } else {
+ $('#player').removeClass('on-chat-page');
+ }
+ }
+ init();
+
+ if (! document.createElement('audio').canPlayType('audio/ogg') &&
+ document.createElement('audio').canPlayType('audio/aac') ) {
+ $('#ogg-m3u').hide().removeClass('resymbol');
+ $('#aac-m3u').addClass('resymbol').show();
+ }
+
+ var konami = new Konami('/party');
+
+ $(document).on('panik:play', function(ev, data) {
+ var $page_audio_controls = $('#Main').find('div.audio[data-sound-id="' + data.sound_id + '"]');
+ $page_audio_controls.find('.icon-play-sign').removeClass('icon-play-sign').addClass('icon-pause');
+ });
+
+ $(document).on('panik:pause', function(ev, data) {
+ var $page_audio_controls = $('#Main').find('div.audio[data-sound-id="' + data.sound_id + '"]');
+ $page_audio_controls.find('.icon-pause').removeClass('icon-pause').addClass('icon-play-sign');
+ });
+
+
+ $(document).on('panik:timeupdate', function(ev, data) {
+ var $page_audio_controls = $('#Main').find('div.audio[data-sound-id="' + data.sound_id + '"]');
+ $page_audio_controls.find('.icon-play-sign').removeClass('icon-play-sign').addClass('icon-pause');
+ $waveform = $('#Main div.waveform[data-sound-id="' + data.sound_id + '"]');
+ var elems = $waveform.find('span');
+ var total_elems = elems.length;
+ var done = total_elems * data.position;
+ $waveform.find('span').each(function(k, elem) {
+ if (k < done) {
+ $(elem).addClass('done').removeClass('current');
+ } else {
+ $(elem).removeClass('done');
+ }
+ });
+ $waveform.find('span.done:last').addClass('current');
+ });
+
+ $("body").keydown(function(e) {
+ var $visible_element = $('div.first:visible img');
+ if ($visible_element.length == 0) {
+ return true;
+ }
+ if ($visible_element.length > 1) {
+ /* remove all but last */
+ $visible_element.parent().find('img:not(:last)').remove();
+ }
+ var $visible_element = $('div.first:visible img');
+ var img_url = $visible_element.attr('src');
+ var all_img = $('div.gallery span[data-image-large] img');
+ var active_img = $('div.gallery span[data-image-large="' + img_url + '"] img');
+ var idx = all_img.index(active_img);
+ if (e.which == 37) { // left
+ idx--;
+ if (idx == -1) {
+ idx = all_img.length-1;
+ }
+ } else if (e.which == 39) { // right
+ idx++;
+ if (idx == all_img.length) {
+ idx = 0;
+ }
+ } else if (e.which == 27) { // escape
+ $visible_element.parent().toggle('fade');
+ return true;
+ } else {
+ return true;
+ }
+ /* create a new <img> with the new image but opacity 0, then display
+ * it using a css transition */
+ if (e.which == 37) { $visible_element.css('transform-origin', 'bottom right'); }
+ if (e.which == 39) { $visible_element.css('transform-origin', 'bottom left'); }
+ var new_img = $visible_element.clone().appendTo($visible_element.parent());
+ $(new_img).css('opacity', 0).attr('src', $(all_img[idx]).parent().data('image-large'));
+ $(new_img).css('transform', 'scale(0, 1)');
+ $(new_img)[0].offsetHeight; /* trigger reflow */
+ $(new_img).css('opacity', 1).css('transform', 'scale(1)');
+ $(new_img).parents('.gallery').find('span.gallery-legend').text($(all_img[idx]).attr('title') || '');
+ if ($(all_img[idx]).hasClass('portrait')) {
+ if (! $(new_img).parents('.gallerycell').hasClass('portrait')) {
+ $visible_element.parent().find('img:not(:last)').remove();
+ $(new_img).parents('.gallerycell').addClass('portrait');
+ }
+ } else {
+ if ($(new_img).parents('.gallerycell').hasClass('portrait')) {
+ $visible_element.parent().find('img:not(:last)').remove();
+ $(new_img).parents('.gallerycell').removeClass('portrait');
+ }
+ }
+ return false;
+ });
+});