Projet

Général

Profil

0001-misc-display-sidepage-instantaneously-60180.patch

Frédéric Péters, 02 janvier 2022 16:44

Télécharger (5,92 ko)

Voir les différences:

Subject: [PATCH] misc: display sidepage instantaneously (#60180)

 gadjo/static/js/gadjo.js | 98 +++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 46 deletions(-)
gadjo/static/js/gadjo.js
1 1
var gadjo_js = gadjo_js || {};
2 2
(function () {
3
    if (gadjo_js.loaded) return
3
    if (gadjo_js.loaded) return;
4 4
    gadjo_js.loaded = true;
5 5
    var $ = jQuery;
6 6
    var popup_script_loaded = {};
......
289 289
        }
290 290
    }
291 291

  
292
    $(function() {
293
      var cookie_domain = window.location.hostname.split('.').slice(1).join('.');
292
    var cookie_domain = window.location.hostname.split('.').slice(1).join('.');
294 293

  
295
      function readCookie(name) { /* http://www.quirksmode.org/js/cookies.html */
296
        var nameEQ = name + "=";
297
        var ca = document.cookie.split(';');
298
        for(var i=0;i < ca.length;i++) {
299
          var c = ca[i];
300
          while (c.charAt(0)==' ') c = c.substring(1,c.length);
301
          if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
302
        }
303
        return null;
294
    function readCookie(name) { /* http://www.quirksmode.org/js/cookies.html */
295
      var nameEQ = name + "=";
296
      var ca = document.cookie.split(';');
297
      for(var i=0;i < ca.length;i++) {
298
        var c = ca[i];
299
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
300
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
304 301
      }
302
      return null;
303
    }
305 304

  
306
      function set_sidepage_status(sidepage_status) {
307
        storage.sidepage_status = sidepage_status;
308
        if (cookie_domain) {
309
          var date = new Date();
310
          date.setTime(date.getTime() + (10 * 86400 * 1000)); /* a long week */
311
          document.cookie = 'gadjo_sidepage_status=' + sidepage_status +
312
                            '; expires=' + date.toGMTString() +
313
                            (window.location.protocol == "https:" && "; Secure" || "") +
314
                            '; sameSite=Strict' +
315
                            '; domain=.' + cookie_domain +
316
                            '; path=/';
317
        }
305
    function set_sidepage_status(sidepage_status) {
306
      storage.sidepage_status = sidepage_status;
307
      if (cookie_domain) {
308
        var date = new Date();
309
        date.setTime(date.getTime() + (10 * 86400 * 1000)); /* a long week */
310
        document.cookie = 'gadjo_sidepage_status=' + sidepage_status +
311
                          '; expires=' + date.toGMTString() +
312
                          (window.location.protocol == "https:" && "; Secure" || "") +
313
                          '; sameSite=Strict' +
314
                          '; domain=.' + cookie_domain +
315
                          '; path=/';
318 316
      }
319
      function get_sidepage_status() {
320
        if (window.location.protocol == 'file:') {
321
          /* don't open sidepage when loading from a file:// */
322
          return 'collapsed';
323
        }
324
        var sidepage_status = null;
325
        if (cookie_domain) {
326
          sidepage_status = readCookie('gadjo_sidepage_status');
327
        } else {
328
          sidepage_status = storage.sidepage_status;
317
    }
318
    function get_sidepage_status() {
319
      if (window.location.protocol == 'file:') {
320
        /* don't open sidepage when loading from a file:// */
321
        return 'collapsed';
322
      }
323
      var sidepage_status = null;
324
      if (cookie_domain) {
325
        sidepage_status = readCookie('gadjo_sidepage_status');
326
      } else {
327
        sidepage_status = storage.sidepage_status;
328
      }
329
      if (!sidepage_status &&
330
              typeof(GADJO_DEFAULT_SIDEPAGE_STATUS) !== "undefined") {
331
        return GADJO_DEFAULT_SIDEPAGE_STATUS;
332
      }
333
      return sidepage_status;
334
    }
335
    document.addEventListener('DOMContentLoaded', function() {
336
      if (document.body.dataset.gadjo === 'true' && document.getElementById('sidepage')) {
337
        document.body.setAttribute('data-has-sidepage', 'true');
338
        if (storage.gadjo_sidebar_menu) {
339
          $('#sidepage-menu').empty().append($(storage.gadjo_sidebar_menu));
329 340
        }
330
        if (!sidepage_status &&
331
                typeof(GADJO_DEFAULT_SIDEPAGE_STATUS) !== "undefined") {
332
          return GADJO_DEFAULT_SIDEPAGE_STATUS;
341
        if (window.innerWidth > 760 && get_sidepage_status() == 'expanded') {
342
          document.body.className += ' sidepage-expanded';
333 343
        }
334
        return sidepage_status;
335 344
      }
345
    });
336 346

  
347
    $(function() {
337 348
      $(document).on('click.gadjo', 'a[rel=popup], a[data-popup]', displayPopup);
338 349
      if ($('#sidepage').length) {
339 350
        var sidepage_button = $('#sidepage #applabel');
......
350 361
            $(window).trigger('gadjo:sidepage-toggled');
351 362
          }, 500);
352 363
        });
353
        if ($(window).width() > 760) {
354
          if (get_sidepage_status() == 'expanded') {
355
            $('body').toggleClass('sidepage-expanded');
356
          }
357
        }
358 364
      }
359 365
    });
360 366
    $(function () { /* foldable elements with memory */
......
382 388
    });
383 389
    $(function () {
384 390
      if ($('body').data('gadjo')) {
385
        if ($('#sidepage').length == 1) {
386
          $('body').attr('data-has-sidepage', 'true');
387
        }
388 391
        /* add × to close notification messages */
389 392
        $('.messages > li').each(function(idx, elem) {
390 393
          var elem = $('<a aria-hidden="true" class="close">×</a>');
......
418 421
        return false;
419 422
      });
420 423
    });
424
    $(document).on('publik:menu-loaded', function() {
425
      storage.gadjo_sidebar_menu = document.getElementById('sidepage-menu').innerHTML;
426
    });
421 427
})();
422
-