diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 7766952..cb7a84d 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -34,6 +34,22 @@ const MARK_NEW = 1; const MARK_UPDATED = 2; /** + * A responsive table class; hide table cell on narrow devices. + * + * Indicates that a column has medium priority and thus can be hidden on narrow + * width devices and shown on medium+ width devices (i.e. tablets and desktops). + */ +const RESPONSIVE_PRIORITY_MEDIUM = 'priority-medium'; + +/** + * A responsive table class; only show table cell on wide devices. + * + * Indicates that a column has low priority and thus can be hidden on narrow + * and medium viewports and shown on wide devices (i.e. desktops). + */ +const RESPONSIVE_PRIORITY_LOW = 'priority-low'; + +/** * @} End of "defgroup content_flags". */ @@ -1759,6 +1775,14 @@ function theme_breadcrumb($variables) { * - "field": The database field represented in the table column (required * if user is to be able to sort on this column). * - "sort": A default sort order for this column ("asc" or "desc"). + * - "class": An array of values for the 'class' attribute. In particular, + * the least important columns that can be hidden on narrow and medium + * width screens should have a 'priority-low' class, referenced with the + * RESPONSIVE_PRIORITY_LOW constant. Columns that should be shown on + * medium+ wide screens should be marked up with a class of + * 'priority-medium', referenced by with the RESPONSIVE_PRIORITY_MEDIUM + * constant. Themes may hide columns with one of these two classes on + * narrow viewports to save horizontal space. * - Any HTML attributes, such as "colspan", to apply to the column header * cell. * - rows: An array of table rows. Every row is an array of cells, or an @@ -1829,6 +1853,7 @@ function theme_table($variables) { $caption = $variables['caption']; $colgroups = $variables['colgroups']; $sticky = $variables['sticky']; + $responsive = $variables['responsive']; $empty = $variables['empty']; // Add sticky headers, if applicable. @@ -1838,6 +1863,15 @@ function theme_table($variables) { // This is needed to target tables constructed by this function. $attributes['class'][] = 'sticky-enabled'; } + // If the table has headers and it should react responsively to columns hidden + // with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM + // and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors. + if (count($header) && $responsive) { + drupal_add_library('system', 'drupal.tableresponsive'); + // Add 'responsive-enabled' class to the table to identify it for JS. + // This is needed to target tables constructed by this function. + $attributes['class'][] = 'responsive-enabled'; + } $output = '