stacktable.js
Advanced tools
Comparing version 1.0.0 to 1.0.3
{ | ||
"name": "stacktable.js", | ||
"title": "stacktable.js", | ||
"version": "1.0.0", | ||
"version": "1.0.3", | ||
"description": "jQuery plugin for stacking tables on small screens", | ||
@@ -6,0 +6,0 @@ "main": "stacktable.js", |
@@ -7,3 +7,8 @@ # stacktable.js | ||
## Options | ||
**myClass:** Space separated classes to add to the table. | ||
**headIndex:** Use this to specify the row index of the header, in case it isn’t the first. | ||
# Legal | ||
@@ -13,2 +18,2 @@ | ||
Dual MIT & GPL license | ||
MIT License |
@@ -11,2 +11,3 @@ /** | ||
* jQuery plugin for stacking tables on small screens | ||
* Requires jQuery version 1.7 or above | ||
* | ||
@@ -17,4 +18,5 @@ */ | ||
var $tables = this, | ||
defaults = {id:'stacktable small-only',hideOriginal:true,headIndex:0}, | ||
settings = $.extend({}, defaults, options); | ||
defaults = {headIndex:0}, | ||
settings = $.extend({}, defaults, options), | ||
headIndex; | ||
@@ -28,3 +30,3 @@ // checking the "headIndex" option presence... or defaults it to 0 | ||
return $tables.each(function() { | ||
$table = $(this); | ||
var $table = $(this); | ||
if ($table.hasClass('stacktable')) { | ||
@@ -37,10 +39,14 @@ return; | ||
var markup = ''; | ||
var $caption, $topRow, headMarkup, bodyMarkup, tr_class; | ||
$table.addClass('stacktable large-only'); | ||
$caption = $table.find("caption").clone(); | ||
$topRow = $table.find('tr').eq(0); | ||
$caption = $table.find(">caption").clone(); | ||
$topRow = $table.find('>thead>tr,>tbody>tr,>tfoot>tr,>tr').eq(0); | ||
// avoid duplication when paginating | ||
$table.siblings().filter('.small-only').remove(); | ||
// using rowIndex and cellIndex in order to reduce ambiguity | ||
$table.find('tbody tr').each(function(rowIndex,value) { | ||
$table.find('>tbody>tr').each(function() { | ||
@@ -54,7 +60,7 @@ // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records | ||
// then iterate through the key/values | ||
$(this).find('td,th').each(function(cellIndex,value) { | ||
$(this).find('>td,>th').each(function(cellIndex) { | ||
if ($(this).html() !== ''){ | ||
bodyMarkup += '<tr class="' + tr_class +'">'; | ||
if ($topRow.find('td,th').eq(cellIndex).html()){ | ||
bodyMarkup += '<td class="st-key">'+$topRow.find('td,th').eq(cellIndex).html()+'</td>'; | ||
if ($topRow.find('>td,>th').eq(cellIndex).html()){ | ||
bodyMarkup += '<td class="st-key">'+$topRow.find('>td,>th').eq(cellIndex).html()+'</td>'; | ||
} else { | ||
@@ -68,8 +74,8 @@ bodyMarkup += '<td class="st-key"></td>'; | ||
markup += '<table class=" '+ table_css +' '+settings.id+'"><tbody>' + headMarkup + bodyMarkup + '</tbody></table>'; | ||
markup += '<table class=" '+ table_css +' stacktable small-only"><tbody>' + headMarkup + bodyMarkup + '</tbody></table>'; | ||
}); | ||
$table.find('tfoot tr td').each(function(rowIndex,value) { | ||
$table.find('>tfoot>tr>td').each(function(rowIndex,value) { | ||
if ($.trim($(value).text()) !== '') { | ||
markup += '<table class="'+ table_css + ' ' +settings.id+'"><tbody><tr><td>' + $(value).html() + '</td></tr></tbody></table>'; | ||
markup += '<table class="'+ table_css + ' stacktable small-only"><tbody><tr><td>' + $(value).html() + '</td></tr></tbody></table>'; | ||
} | ||
@@ -81,3 +87,2 @@ }); | ||
$table.before($stacktable); | ||
if (!settings.hideOriginal) $table.show(); | ||
}); | ||
@@ -88,4 +93,5 @@ }; | ||
var $tables = this, | ||
defaults = {id:'stacktable small-only',hideOriginal:true,headIndex:0}, | ||
settings = $.extend({}, defaults, options); | ||
defaults = {headIndex:0,displayHeader:true}, | ||
settings = $.extend({}, defaults, options), | ||
headIndex; | ||
@@ -100,13 +106,16 @@ // checking the "headIndex" option presence... or defaults it to 0 | ||
var table_css = $(this).prop('class'); | ||
var $stacktable = $('<table class="'+ table_css +' '+settings.id+'"><tbody></tbody></table>'); | ||
var $stacktable = $('<table class="'+ table_css +' stacktable small-only"><tbody></tbody></table>'); | ||
if (typeof settings.myClass !== 'undefined') $stacktable.addClass(settings.myClass); | ||
var markup = ''; | ||
var $table, $caption, $topRow, headMarkup, bodyMarkup, tr_class, displayHeader; | ||
$table = $(this); | ||
$table.addClass('stacktable large-only'); | ||
$caption = $table.find("caption").clone(); | ||
$topRow = $table.find('tr').eq(0); | ||
$caption = $table.find(">caption").clone(); | ||
$topRow = $table.find('>thead>tr,>tbody>tr,>tfoot>tr').eq(0); | ||
displayHeader = $table.data('display-header') === undefined ? settings.displayHeader : $table.data('display-header'); | ||
// using rowIndex and cellIndex in order to reduce ambiguity | ||
$table.find('tr').each(function(rowIndex,value) { | ||
$table.find('>tbody>tr, >thead>tr').each(function(rowIndex) { | ||
@@ -117,11 +126,13 @@ // declaring headMarkup and bodyMarkup, to be used for separately head and body of single records | ||
tr_class = $(this).prop('class'); | ||
// for the first row, "headIndex" cell is the head of the table | ||
if (rowIndex === 0) { | ||
// the main heading goes into the markup variable | ||
markup += '<tr class=" '+tr_class +' "><th class="st-head-row st-head-row-main" colspan="2">'+$(this).find('th,td').eq(headIndex).html()+'</th></tr>'; | ||
} | ||
else { | ||
if (displayHeader) { | ||
markup += '<tr class=" '+tr_class +' "><th class="st-head-row st-head-row-main" colspan="2">'+$(this).find('>th,>td').eq(headIndex).html()+'</th></tr>'; | ||
} | ||
} else { | ||
// for the other rows, put the "headIndex" cell as the head for that row | ||
// then iterate through the key/values | ||
$(this).find('td,th').each(function(cellIndex,value) { | ||
$(this).find('>td,>th').each(function(cellIndex) { | ||
if (cellIndex === headIndex) { | ||
@@ -132,4 +143,4 @@ headMarkup = '<tr class="'+ tr_class+'"><th class="st-head-row" colspan="2">'+$(this).html()+'</th></tr>'; | ||
bodyMarkup += '<tr class="' + tr_class +'">'; | ||
if ($topRow.find('td,th').eq(cellIndex).html()){ | ||
bodyMarkup += '<td class="st-key">'+$topRow.find('td,th').eq(cellIndex).html()+'</td>'; | ||
if ($topRow.find('>td,>th').eq(cellIndex).html()){ | ||
bodyMarkup += '<td class="st-key">'+$topRow.find('>td,>th').eq(cellIndex).html()+'</td>'; | ||
} else { | ||
@@ -151,3 +162,2 @@ bodyMarkup += '<td class="st-key"></td>'; | ||
$table.before($stacktable); | ||
if (!settings.hideOriginal) $table.show(); | ||
}); | ||
@@ -158,12 +168,13 @@ }; | ||
var $tables = this, | ||
defaults = {id:'stacktable small-only',hideOriginal:true}, | ||
defaults = {}, | ||
settings = $.extend({}, defaults, options); | ||
return $tables.each(function() { | ||
$table = $(this); | ||
var num_cols = $table.find('tr').eq(0).find('td,th').length; //first table <tr> must not contain colspans, or add sum(colspan-1) here. | ||
var $table = $(this); | ||
var $caption = $table.find(">caption").clone(); | ||
var num_cols = $table.find('>thead>tr,>tbody>tr,>tfoot>tr').eq(0).find('>td,>th').length; //first table <tr> must not contain colspans, or add sum(colspan-1) here. | ||
if(num_cols<3) //stackcolumns has no effect on tables with less than 3 columns | ||
return; | ||
var $stackcolumns = $('<table class="'+settings.id+'"></table>'); | ||
var $stackcolumns = $('<table class="stacktable small-only"></table>'); | ||
if (typeof settings.myClass !== 'undefined') $stackcolumns.addClass(settings.myClass); | ||
@@ -175,6 +186,6 @@ $table.addClass('stacktable large-only'); | ||
while (col_i < num_cols) { | ||
$table.find('tr').each(function(index,value) { | ||
$table.find('>thead>tr,>tbody>tr,>tfoot>tr').each(function(index) { | ||
var tem = $('<tr></tr>'); // todo opt. copy styles of $this; todo check if parent is thead or tfoot to handle accordingly | ||
if(index === 0) tem.addClass("st-head-row st-head-row-main"); | ||
first = $(this).find('td,th').eq(0).clone().addClass("st-key"); | ||
var first = $(this).find('>td,>th').eq(0).clone().addClass("st-key"); | ||
var target = col_i; | ||
@@ -184,3 +195,3 @@ // if colspan apply, recompute target for second cell. | ||
var i =0; | ||
$(this).find('td,th').each(function(index,value) { | ||
$(this).find('>td,>th').each(function() { | ||
var cs = $(this).attr("colspan"); | ||
@@ -193,5 +204,5 @@ if (cs) { | ||
i += cs; | ||
} else { | ||
i++; | ||
} | ||
else | ||
i++; | ||
@@ -202,3 +213,3 @@ if (i > col_i) | ||
} | ||
second = $(this).find('td,th').eq(target).clone().addClass("st-val").removeAttr("colspan"); | ||
var second = $(this).find('>td,>th').eq(target).clone().addClass("st-val").removeAttr("colspan"); | ||
tem.append(first, second); | ||
@@ -211,6 +222,4 @@ tb.append(tem); | ||
$stackcolumns.append($(tb)); | ||
$stackcolumns.prepend($caption); | ||
$table.before($stackcolumns); | ||
if (!(settings.hideOriginal)) { | ||
$table.show(); | ||
} | ||
}); | ||
@@ -217,0 +226,0 @@ }; |
Copyleft License
License(Experimental) Copyleft license information was found
Found 1 instance in 1 package
spdx disjunction for an artifact's license information
Licensespdx disjunction for an artifact's license information
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found
Found 1 instance in 1 package
spdx disjunction for an artifact's license information
Licensespdx disjunction for an artifact's license information
Found 1 instance in 1 package
18358
4
183
18
4
70