2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, window) {
9 function TableResponsive(table) {
11 this.$table = $(table);
12 this.showText = Drupal.t('Show all columns');
13 this.hideText = Drupal.t('Hide lower priority columns');
15 this.$headers = this.$table.find('th');
17 this.$link = $('<button type="button" class="link tableresponsive-toggle"></button>').attr('title', Drupal.t('Show table cells that were hidden to make the table fit within a small screen.')).on('click', $.proxy(this, 'eventhandlerToggleColumns'));
19 this.$table.before($('<div class="tableresponsive-toggle-columns"></div>').append(this.$link));
21 $(window).on('resize.tableresponsive', $.proxy(this, 'eventhandlerEvaluateColumnVisibility')).trigger('resize.tableresponsive');
24 Drupal.behaviors.tableResponsive = {
25 attach: function attach(context, settings) {
26 var $tables = $(context).find('table.responsive-enabled').once('tableresponsive');
28 var il = $tables.length;
29 for (var i = 0; i < il; i++) {
30 TableResponsive.tables.push(new TableResponsive($tables[i]));
36 $.extend(TableResponsive, {
40 $.extend(TableResponsive.prototype, {
41 eventhandlerEvaluateColumnVisibility: function eventhandlerEvaluateColumnVisibility(e) {
42 var pegged = parseInt(this.$link.data('pegged'), 10);
43 var hiddenLength = this.$headers.filter('.priority-medium:hidden, .priority-low:hidden').length;
45 if (hiddenLength > 0) {
46 this.$link.show().text(this.showText);
49 if (!pegged && hiddenLength === 0) {
50 this.$link.hide().text(this.hideText);
53 eventhandlerToggleColumns: function eventhandlerToggleColumns(e) {
56 var $hiddenHeaders = this.$headers.filter('.priority-medium:hidden, .priority-low:hidden');
57 this.$revealedCells = this.$revealedCells || $();
59 if ($hiddenHeaders.length > 0) {
60 $hiddenHeaders.each(function (index, element) {
61 var $header = $(this);
62 var position = $header.prevAll('th').length;
63 self.$table.find('tbody tr').each(function () {
64 var $cells = $(this).find('td').eq(position);
67 self.$revealedCells = $().add(self.$revealedCells).add($cells);
71 self.$revealedCells = $().add(self.$revealedCells).add($header);
73 this.$link.text(this.hideText).data('pegged', 1);
75 this.$revealedCells.hide();
77 this.$revealedCells.each(function (index, element) {
79 var properties = $cell.attr('style').split(';');
82 var match = /^display\s*:\s*none$/;
83 for (var i = 0; i < properties.length; i++) {
84 var prop = properties[i];
87 var isDisplayNone = match.exec(prop);
94 $cell.attr('style', newProps.join(';'));
96 this.$link.text(this.showText).data('pegged', 0);
98 $(window).trigger('resize.tableresponsive');
103 Drupal.TableResponsive = TableResponsive;
104 })(jQuery, Drupal, window);