Skip to content

Commit

Permalink
Merge pull request #79 from isubit/LUGG-883-3
Browse files Browse the repository at this point in the history
LUGG 883 3 - Responsive table support
  • Loading branch information
angelamnr authored Feb 15, 2017
2 parents e55c571 + ba3283b commit 3b34d4e
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 0 deletions.
209 changes: 209 additions & 0 deletions css/suitcase.css
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,215 @@ html.js input.form-autocomplete {
background-position: 100% 12px;
}

/* -------------------- */
/* ## RESPONSIVE TABLES
/* -------------------- */

table.responsive-table {
margin-top: 1.5rem;
margin-bottom: 1.5rem;
border-collapse: collapse;
}

table.responsive-table,
.responsive-table tbody,
.responsive-table thead,
.responsive-table tr,
.responsive-table th,
.responsive-table td {
border: none;
border-collapse: collapse;
border-spacing: 0;
}

.responsive-table tr {
border-bottom: 1px solid #ccc;
}

.responsive-table tr:first-of-type {
border-top: 1px solid #ccc;
}

.responsive-table th,
.responsive-table td {
padding: 0.5rem 0.75rem;
border-left: 1px solid #ccc;
}
.responsive-table th:last-of-type,
.responsive-table td:last-of-type {
border-right: 1px solid #ccc;
}

.responsive-table th {
background-color: #eee;
}

/* -------------------- */
/* NO JS
/* -------------------- */

.field-items table {
display: block;
max-width: 100%;
overflow: hidden;
overflow-x: auto;
}

.field-items table tr {
width: 100%;
}

.field-items table::-webkit-scrollbar {
-webkit-appearance: none;
}

.field-items table::-webkit-scrollbar:horizontal {
height: 11px;
}

.field-items table::-webkit-scrollbar-thumb {
border-radius: 8px;
border: 2px solid white;
background-color: rgba(0, 0, 0, 0.5);
}

.field-items table::-webkit-scrollbar-track {
background-color: #fff;
border-radius: 8px;
}

@media (min-width: 801px) {
.row-header { display: none; }
.both-row-header { display: none; }
}

@media (max-width: 800px) {

/* -------------------- */
/* NONE
/* -------------------- */

.responsive-table.table-none { display: table; min-width: 75%; }

.responsive-table.table-none tr { border-bottom: 3px solid #bbb; }
.responsive-table.table-none td {
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
display: block;
}

.responsive-table.table-none td:last-of-type { border-bottom: none; }

/* -------------------- */
/* FIRST ROW
/* -------------------- */

.responsive-table.table-row { display: table; min-width: 75%; }

.responsive-table.table-row th { display: none; }

.responsive-table.table-row tr {
display: block;
border-bottom: 3px solid #bbb;
}

.responsive-table.table-row tr:first-of-type { border-bottom: 0; }

.responsive-table.table-row td {
display: flex;
padding: 0;
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
}

.responsive-table.table-row td:last-of-type { border-bottom: none; }

.cell-content {
display: block;
flex: 1 1 50%;
padding: 0.5rem 0.75rem;
}

.row-header {
display: block;
flex: 0 1 45%;
padding: 0.5rem 0.75rem;
font-weight: 500;
background: #eee;
}

.table-row tr { border-bottom: 3px solid #bbb; }

/* -------------------- */
/* FIRST COL
/* -------------------- */

.responsive-table.table-col { display: table; min-width: 75%; }

.responsive-table.table-col th,
.responsive-table.table-col td { display: block; }

.responsive-table.table-col th { border-bottom: 1px solid #bbb; }

.responsive-table.table-col tr {
display: block;
border-bottom: 1px solid #ddd;
}

.responsive-table.table-col td {
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
display: block;
}

.responsive-table.table-col td:last-of-type { border-bottom: none; }

/* -------------------- */
/* BOTH
/* -------------------- */

.responsive-table.table-both { display: table; min-width: 75%; }

.responsive-table.table-both th,
.responsive-table.table-both td { display: block; }

.responsive-table.table-both th { border-bottom: 1px solid #bbb; }

.responsive-table.table-both tr {
display: block;
border-bottom: 3px solid #bbb;
}

.responsive-table.table-both tr:first-of-type { display: none; }

.responsive-table.table-both tr:first-of-type th:first-of-type { display: none; }

.responsive-table.table-both tr:nth-of-type(2) { border-top: 1px solid #ddd; }

.responsive-table.table-both td {
display: flex;
padding: 0;
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
}

.responsive-table.table-both td:last-of-type { border-bottom: none; }

.both-cell-content {
display: block;
flex: 1 1 50%;
padding: 0.5rem 0.75rem;
}

.both-row-header {
display: block;
flex: 0 1 45%;
padding: 0.5rem 0.75rem;
font-weight: 500;
background: #eee;
}
}

/* -------------------- */
/* ## MEGAPANELS
/* -------------------- */
Expand Down
78 changes: 78 additions & 0 deletions js/suitcase_responsive_tables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
(function ($) {

$(document).ready(function() {

// Just tables in content
var table = $('.field-items table');

/* ---------------------
First, check the table
structure and assign classes.
--------------------- */

/* ----- None ----- */
table.addClass('table-none');

/* ----- Row ----- */
var rowsHeader = $(table.has('tr:first-of-type th:nth-of-type(2)'));
rowsHeader.attr('class', 'table-row');

/* ----- Col ----- */
var colHeader = $(table.has('tr:nth-of-type(2) th:nth-of-type(1)'));
colHeader.attr('class', 'table-col');

/* ----- Both ----- */
var bothHeader = $(table.has('tr:nth-of-type(1) th:nth-of-type(2)').has('tr:nth-of-type(2) th:nth-of-type(1)'));
bothHeader.attr('class', 'table-both');

/* --- Colspan or Rowspan --- */
var tdColFreeze = $(table.has('td[colspan]'));
var thColFreeze = $(table.has('th[colspan]'));
var tdRowFreeze = $(table.has('td[rowspan]'));
var thRowFreeze = $(table.has('th[rowspan]'));
tdColFreeze.attr('class', 'table-freeze');
thColFreeze.attr('class', 'table-freeze');
tdRowFreeze.attr('class', 'table-freeze');
thRowFreeze.attr('class', 'table-freeze');

/* --- All Responsive Tables --- */
table.addClass('responsive-table');

/* ---------------------
Now apply any jQuery needed
to make the tables responsive
--------------------- */

/* ----- Row ----- */
// Wrap cell content in a span for flexbox.
$('.table-row td').wrapInner('<span class="cell-content"></span>');

// Cycle through each row...
$('.table-row tr').each(function() {
// And cycle through each td in that row...
$(this).find('td').each(function(i) {
// Find the content of the closest th...
var rowHeader = $(this).closest('.table-row').find('tr th')[i].innerHTML;
// And add it as a span in the td.
$(this).prepend('<span class="row-header" aria-hidden="true">' + rowHeader + '</span>')
});
});

/* ----- BOTH ----- */
// Wrap cell content in a span for flexbox.
$('.table-both td').wrapInner('<span class="both-cell-content"></span>');

// Cycle through each row...
$('.table-both tr').each(function() {
// And cycle through each td in that row...
$(this).find('td').each(function(i) {

// Find the content of the closest th...
var rowHeader = $(this).closest('.table-both').find('tr th:not(:first-of-type)')[i].innerHTML;
// And add it as a span in the td.
$(this).prepend('<span class="both-row-header" aria-hidden="true">' + rowHeader + '</span>')
});
});
});

})(jQuery);
5 changes: 5 additions & 0 deletions suitcase_interim.info
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ settings[alpha_libraries][suitcase_gridheight] = 'suitcase_gridheight'
settings[alpha_libraries][suitcase_jquery_smart_menu] = 'suitcase_jquery_smart_menu'
settings[alpha_libraries][suitcase_smart_menu_init] = 'suitcase_smart_menu_init'
settings[alpha_libraries][suitcase_image_floats] = 'suitcase_image_floats'
settings[alpha_libraries][suitcase_responsive_tables] = 'suitcase_responsive_tables'
settings[alpha_css][alpha-reset.css] = 'alpha-reset.css'
settings[alpha_css][alpha-mobile.css] = 'alpha-mobile.css'
settings[alpha_css][alpha-alpha.css] = 'alpha-alpha.css'
Expand Down Expand Up @@ -412,3 +413,7 @@ libraries[suitcase_image_floats][name] = 'Suitcase Image Floats'
libraries[suitcase_image_floats][description] = 'Provides a javascript library that adds a class to floated images'
libraries[suitcase_image_floats][js][0][file] = 'suitcase_image_floats.js'
libraries[suitcase_image_floats][js][0][options][weight] = '30'
libraries[suitcase_responsive_tables][name] = 'Suitcase Responsive Tables'
libraries[suitcase_responsive_tables][description] = 'Support for table display on mobile devices'
libraries[suitcase_responsive_tables][js][0][file] = 'suitcase_responsive_tables.js'
libraries[suitcase_responsive_tables][js][0][options][weight] = '30'

0 comments on commit 3b34d4e

Please sign in to comment.