]> git.0d.be Git - panikweb-esperanzah.git/commitdiff
sync bits of specifics.js with panik
authorFrédéric Péters <fpeters@0d.be>
Thu, 4 Aug 2022 12:42:31 +0000 (14:42 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 4 Aug 2022 12:42:31 +0000 (14:42 +0200)
panikweb_esperanzah/static/js/specifics.js

index c663a556152e47dd0c7c6d916729ac8f5b329cbe..b1f62771d92a5fece40d89ca2381a2f95af4aab5 100644 (file)
@@ -120,6 +120,19 @@ $(function() {
                        return;
                }
                this.each(function() {
+                       if ($(this).parents('.leaflet-control').length) {
+                               // don't touch leaflet control links
+                               return;
+                       }
+                       var href = $(this).attr("href");
+                       if (!href || href.match('\.(ogg|mp3|pdf|odt|ods|doc|xls|docx|xlsx|rtf|zip|rss|atom)$')) {
+                               // don't touch empty <a> or links to downloadable files
+                               return;
+                       }
+                       if ($(this).attr('target')) {
+                               // don't touch links with an explicit target
+                               return;
+                       }
                        $(this).unbind('click');
                        $(this).bind('click',function(e){
                                var href = $(this).attr("href");
@@ -127,11 +140,6 @@ $(function() {
                                        window.open(href, '_blank');
                                        return false;
                                }
-                               if (href.match('\.(ogg|mp3|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
@@ -143,7 +151,11 @@ $(function() {
                                }else if (!$(this).attr('target') && (
                                                href.indexOf(document.domain) > -1 ||href.indexOf(':') === -1 || href.indexOf(':') > 5
                                        )) {
-                                       loadPage(href);
+                                       if ($(this).data('replace')) {
+                                               loadPage(href, false, $(this).data('replace'));
+                                       } else {
+                                               loadPage(href);
+                                       }
                                        return false;
                                }else{
                                        $(this).attr('target','_blank');
@@ -165,6 +177,7 @@ $(function() {
                $.getJSON('/onair.json', function(onair) {
                        var onairContainer = $('<span>');
                        if(onair.data.episode || onair.data.emission) {
+                               $('body').removeClass('nothing-playing');
                                if(onair.data.emission){
                                        $('<a>',{href:onair.data.emission.url,html:onair.data.emission.title}).appendTo(onairContainer).ajaxifyClick();
                                }
@@ -173,6 +186,7 @@ $(function() {
                                        $('<a>',{href:onair.data.episode.url,html:onair.data.episode.title}).appendTo(onairContainer).ajaxifyClick();
                                }
                        } else if (onair.data.nonstop) {
+                               $('body').removeClass('nothing-playing');
                                if (onair.data.nonstop.url) {
                                        onairContainer = $('<a href="' + onair.data.nonstop.url + '">' + onair.data.nonstop.title + '</a>');
                                } else {
@@ -188,6 +202,7 @@ $(function() {
                                }
                        }
                        else {
+                               $('body').addClass('nothing-playing');
                                onairContainer = $('<span>Toute la musique du festival</span>');
                        }
                        if (onair.data.emission && onair.data.emission.chat) {
@@ -203,6 +218,15 @@ $(function() {
                                WhatsOnAir.empty().append(onairContainer);
                                WhatsOnAir.fadeIn();
                        }
+                       // update grid
+                       var cell_slug = (onair.data.emission && onair.data.emission.slug) || (
+                               onair.data.nonstop && onair.data.nonstop.slug);
+                       var $current_cell = $('.program li.current');
+                       if ($current_cell.data('program-slug') !== cell_slug &&
+                           $current_cell.next().data('program-slug') === cell_slug) {
+                               $current_cell.removeClass('current').addClass('past');
+                               $current_cell.next().removeClass('future').addClass('current');
+                       }
                });
        });
         $('#WhatsOnAir').trigger('load');
@@ -294,24 +318,53 @@ $(function() {
                        $(this).addClass('loading');
                        loadPage($(this).attr('action') + '?' + $(this).serialize());
                });
+               // custom loading behaviour for week on homepage
+               // (studioneau-only for now)
+               $('#week .week-arrow a').unbind('click').on('click', function(event) {
+                       $.ajax({
+                               url: $(this).attr('href'),
+                               dataType: 'html',
+                               success: function(html, textStatus, jqXhr) {
+                                       var $new_week = $(html);
+                                       var $new_program_tabs = $new_week.find('.program.tabs');
+                                       var $new_program_content = $new_week.find($new_program_tabs.attr('data-tab-about'));
+                                       var $old_program_content = $($('.program.tabs').attr('data-tab-about'));
+                                       $('.program.tabs').replaceWith($new_program_tabs);
+                                       $old_program_content.replaceWith($new_program_content);
+                                       init();
+                                       $(document).trigger('panikweb:week-change');
+                               }
+                       });
+                       return false;
+               });
                $(".tabs").each(function() {
                        var self = $(this);
-                       var about= $($(this).attr("data-tab-about"));
+                       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) {  
+                           $(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();  
-               
-                           });  
+                               self.find(".active").removeClass("active");
+                               $(this).addClass("active");
+                               var new_active = $($(this).attr("data-tab"));
+                               if (! new_active.is(':visible')) {
+                                 about.find("[data-tabbed]").hide();
+                                 $($(this).attr("data-tab")).show();
+                               }
+                           });
                        });  
                        activeTab.trigger('load');
                });
+               // disable week tab buttons if there's nothing (but nonstop) on the day
+               // (studioneau-only for now)
+               $('.program div[data-tabbed]').each(function(idx, elem) {
+                       if ($(elem).find('a[href]').length == 0) {
+                               // nothing this day
+                               $('button[data-tab="#' + $(elem).attr('id') + '"]').attr('disabled', 'disabled');
+                       }
+               });
                $('[data-player-action]').on('click',function(){
                        var audio = $('#'+$(this).attr('data-player-audio'));
                        var sound_id = audio.data('sound-id');
@@ -549,14 +602,13 @@ $(function() {
                });
 
                 /* CHAT */
-                if ($('#chat').length) {
+                if ($('#chat').length && ! $('#player.on-chat-page').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) {
+                    function enable_moderation() {
                       $('#chat').addClass('moderation');
                       $('#chat').on('click', 'span.from', function() {
                         var name = $(this).text();
@@ -585,7 +637,7 @@ $(function() {
                     $('.nick button').on('click', function() {
                       window.localStorage['pa-nick'] = $('.nick input').val();
                       var nick = window.localStorage['pa-nick'];
-                      $('.commands .prompt').text(nick + '>');
+                      $('.commands .prompt').text(nick);
 
                       connection = new Strophe.Connection("/http-bind");
                       connection.connect('im.panik', null, function(status, error) {
@@ -613,6 +665,7 @@ $(function() {
                             var muc = $('div#chat').data('chatroom');
                             connection.muc.join(muc + '@conf.panik', jid,
                                     function(msg) {
+                                        if (! msg.textContent) return true;
                                         var from = msg.attributes.from.value.replace(/.*\//, '');
                                         var klass = '';
                                         if (from == jid) {
@@ -629,24 +682,35 @@ $(function() {
                                     function(pres) {
                                             var nick = $('.nick input').val()
                                             var muc = $('div#chat').data('chatroom');
-                                            if (pres.getElementsByTagName('status').length == 1 &&
+                                            if (pres.getElementsByTagName('status').length &&
                                                 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');
+                                              try {
+                                                var kicked = pres.getElementsByTagName('item')[0].attributes.nick.value;
+                                              } catch (error) {
+                                                var kicked = pres.attributes.from.value.split('/')[1];
+                                              }
                                               if (kicked == nick) {
                                                 connection.disconnect();
                                                 $('div.nick').css('visibility', 'hidden');
+                                                var new_msg = $('<div class="msg info new"><span class="content">You have been kicked out.</span></div>').prependTo($('#chat'));
+                                              } else {
+                                                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 (pres.getElementsByTagName('conflict').length == 1) {
                                               $('.nick input').val(nick + '_');
                                               connection.disconnect();
-                                              $('.nick button').trigger('click');
+                                              if (nic.indexOf('__') == -1) {
+                                                // auto reconnect unless nick
+                                                // has already been altered
+                                                // after conflicts.
+                                                $('.nick button').trigger('click');
+                                              }
                                             }
                                             return true;
                                     },
@@ -654,7 +718,7 @@ $(function() {
                                             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'));
+                                                                var new_msg = $('<div class="msg info new joined"><span class="content">' + contact + ' est dans la place.</span></div>').prependTo($('#chat'));
                                                                 new_msg[0].offsetHeight; /* trigger reflow */
                                                                 new_msg.removeClass('new');
                                                         }
@@ -674,7 +738,24 @@ $(function() {
 
                     function send() {
                         var text = $msg.val();
+                        if (! text) {
+                            $msg.focus();
+                            return true;
+                        }
                         var muc = $('div#chat').data('chatroom');
+                        if (text.startsWith('/auth')) {
+                            $msg.val('');
+                            /* ideally it would trigger some code on the server
+                             * to check the password and elevate priviledges in
+                             * prosody. It doesn't, this is security theater.
+                             */
+                            $.getJSON('/media/chat.json', function(chat_info) {
+                              if (text.split(' ')[1] == chat_info.secret) {
+                                enable_moderation();
+                              }
+                            });
+                            return true;
+                        }
                         connection.muc.message(muc + '@conf.panik', null, text);
                         $msg.val('');
                         return true;
@@ -690,14 +771,16 @@ $(function() {
 
                     if (window.localStorage['pa-nick'] !== undefined) {
                       $('.nick input').val(window.localStorage['pa-nick']);
-                      $('.nick button').click();
+                      if ($('#chat[data-global]').length == 0) {
+                        $('.nick button').click();
+                      }
                     }
 
                     $(window).on('beforeunload', function() {
-                        if (connection) { connection.disconnect(); }
+                        if (connection && $('#chat[data-global]').length == 0) { connection.disconnect(); }
                     });
 
-                } else {
+                } else if ($('#chat').length == 0) {
                     $('#player').removeClass('on-chat-page');
                 }
        }