Projet

Général

Profil

0001-a11y-add-support-for-foldable-folding-cells-38192.patch

Frédéric Péters, 17 décembre 2019 11:34

Télécharger (2,13 ko)

Voir les différences:

Subject: [PATCH] a11y: add support for foldable/folding cells (#38192)

 combo/public/static/js/combo.public.js | 34 +++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)
combo/public/static/js/combo.public.js
213 213
    $(checkboxes[checkboxes.length-1]).parents('tr').next().find('td:nth-child(' + (column_index+1) + ')').addClass('clickable');
214 214
  }
215 215

  
216
  $('body').on('click', 'div.cell.foldable > div > h2:first-child, div.cell.foldable > div > picture', function() {
217
      $(this).parents('div.foldable').toggleClass('folded');
216
  /* foldable/folded support */
217
  function prepare_foldable(cell) {
218
    var $cell = $(cell);
219
    if (! $cell.is('.foldable')) {
220
      return;
221
    }
222
    var $cell_title = $cell.find('> div > h2:first-child');
223
    $cell_title.attr('tabindex', '0');
224
    $cell_title.attr('role', 'button');
225
    function set_aria_expanded() {
226
      if ($cell.is('.folded')) {
227
        $cell_title.attr('aria-expanded', 'false');
228
      } else {
229
        $cell_title.attr('aria-expanded', 'true');
230
      }
231
    }
232
    set_aria_expanded();
233
    $cell.find('> div > h2:first-child').on('keydown', function(ev) {
234
      if (ev.keyCode == 13 || ev.keyCode == 32) {  // enter || space
235
        $(this).trigger('click');
236
        return false;
237
      }
238
    });
239
    $cell.find('> div > h2:first-child, > div > picture').on('click', function() {
240
      $cell.toggleClass('folded');
241
      set_aria_expanded();
218 242
      return false;
219
  });
243
    });
244
  }
245

  
246
  $('div.cell.foldable').each(function(i, cell) { prepare_foldable(cell); });
247
  $(document).on('combo:cell-loaded', function(ev, cell) { prepare_foldable(cell); });
220 248

  
221 249
  /* add a scrolled class to body once the user scrolled the page a bit */
222 250
  $(window).on('scroll', function() {
223
-