Skip to content

Commit b167feb

Browse files
Refactor updating methods to improve performance and drawing time
switch intersectionObserver to a single and simple resize event.
1 parent bf2acf0 commit b167feb

File tree

3 files changed

+174
-149
lines changed

3 files changed

+174
-149
lines changed

README.md

+44-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A fast-render, lightweight plugin to turn tables responsive the right way.
66

77
## Why should you use it?
88

9-
* Has 10 customizable usefull properties.
9+
* Highly customizable page-breaks.
1010
* Won't break your table's primordial design, it uses css only to re-structure table for mobile.
1111
* Designed to attend fat-fingers concept to prevent missclicking, you can tap anywhere in the row and it will trigger the collapser.
1212
* You can maintain all previous functions working anywhere inside the elements of the table. (ie: a dropdown in table headers)
@@ -43,11 +43,10 @@ First, add <b>shrink</b> class to the table you want to be shrinked
4343
```html
4444
<table class="shrink">
4545
```
46-
Next, instantiate the plugin right after the DOM finished rendering.
46+
Next, start the plugin right after the DOM finished rendering.
4747
```javascript
4848
options = {
4949
useZebra: false // i don't like zebras
50-
useObserver: false // turned off observer because i really don't like zebras
5150
}
5251

5352
$("table.shrink").tableShrinker(options)
@@ -89,22 +88,17 @@ Below there's the options explanation and some hints of use.
8988
#### useZebra
9089
###### default: true
9190
Table rows inside wrapper became striped.
92-
#### useObserver
93-
###### default: true
94-
update Zebra whenever a new cell becomes visible in the wrapper.
95-
<br/>
96-
not supported for older browsers check compatibility [here](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#Browser_compatibility).
9791
#### useTransitions
9892
###### default: true
9993
Animate when collapsing the wrapper.
10094
#### transitionSpeed
10195
###### default: 300
10296
name says it all.
10397
#### ignoreWhenHit
104-
###### default: 'button, a, .btn'
105-
If you have a share button on each row you might want to ignore it.
98+
###### default: 'input, button, a, .btn'
99+
If you have a customized radiobutton or selectbox on each row you might want to ignore them too. you can add then to this selector.
106100
<br>
107-
so if any tap/click event hit one of these elements it's event propagation is stoped, this way buttons can keep their functionality inside the table.
101+
so if any tap/click event hit any of these elements it's event propagation is stoped, and they keep their functionality inside the shrinked table container.
108102
#### showToggle
109103
###### default: true
110104
You can disable the toggle icon and still show/hide the shrinked content by hiting the anywhere in the row (except for the ignoreWhenHit elements).
@@ -123,17 +117,22 @@ If true, forces all shrinked elements to be visible on window first load, else i
123117

124118

125119

126-
### Hints
127-
#### Load Collapsed
128-
129-
To start with all rows collapsed is to add "load-collapsed" class to the table.
130-
120+
### Quick Tips
121+
#### Classname Property Controls
122+
You can add "shrink-[property-name]" classes to each individual table to control their behaviour separately, this way you can call the plugin constructor just once. just remember to not override their defaults on options array.
123+
<br>
124+
- shrink-use-zebra
125+
- shrink-show-toggle-all
126+
- shrink-show-toggle
127+
- shrink-load-collapsed
128+
For example:
131129
```html
132-
<table class="shrink load-collapsed">
130+
<table class="shrink shrink-load-collapsed ">
133131
(...)
134132
</table>
135133
```
136134

135+
137136
#### Instant Load
138137
The table can be instantly rendered at the first graphic engine loop of the browser by adding the same <b>shrink-XX</b> and <b>shrinkable</b> classes that you used on the table headers to every table cell
139138
<br>
@@ -166,7 +165,7 @@ There's no impact in performance speed, the only downside of this is that if you
166165

167166

168167
#### Larger than desktops
169-
If you want to show more data in the same table but even desktops width can't handle, just keep adding columns with <br>shrink-xl</br>
168+
If you want to show more data in the same table but even desktops width can't handle, just keep adding columns with <b>shrink-xl</b>
170169

171170
```html
172171
(...)
@@ -178,6 +177,28 @@ If you want to show more data in the same table but even desktops width can't ha
178177
<br>
179178

180179

180+
#### Blank Header
181+
You can use a blank header to add a full-width column, perphaps you want to shrink just a single button.. in this case:
182+
```html
183+
<thead>
184+
<tr>
185+
<th> User-ID </th>
186+
<th> Username </th>
187+
<th class="shrink-xs"> </th> <!-- blank headers -->
188+
</tr>
189+
</thead>
190+
<tbody>
191+
<tr>
192+
<td> #0001 </td>
193+
<td> Foo </td>
194+
<td> <!-- this becomes full width when shrinked -->
195+
<button type='button'> Click me! </button> <!-- you can customize the container of this cell to go full width too in your own css -->
196+
</td>
197+
</tr>
198+
</tbody>
199+
```
200+
201+
181202
#### Collapsable Chained Tables
182203
To add a collapsable table row you can combine the previous 'XL' hint and the chained() method.
183204

@@ -186,24 +207,24 @@ To add a collapsable table row you can combine the previous 'XL' hint and the ch
186207
<tr>
187208
<th> User-ID </th>
188209
<th> Username </th>
189-
<th class="shrink-xl"> </th> <!-- blank headers for the user data table cell (optional) -->
210+
<th class="shrink-xl"> </th> <!-- shrink-xl / blank headers -->
190211
</tr>
191212
</thead>
192213
<tbody>
193214
<tr>
194215
<td> #0001 </td>
195216
<td> Foo </td>
196-
<td class="shrink-xl">
197-
<table class="shrink"> <!-- table with a bunch of Foo's user data -->
217+
<td>
218+
<table class="shrink"> <!-- start shrinked / full width table -->
198219
(...)
199220
</table>
200221
</td>
201222
</tr>
202223
<tr>
203224
<td> #0002 </td>
204225
<td> Bar </td>
205-
<td class="shrink-xl">
206-
<table class="shrink"> <!-- table with a bunch of Bar's user data -->
226+
<td>
227+
<table class="shrink"> <!-- start shrinked / full width table -->
207228
(...)
208229
</table>
209230
</td>

jquery.table-shrinker.css

+34-19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ table.shrink tr:not(.shrink-wrapper):not(.blank-row){
1515

1616
.shrink-toggle, .shrink-toggle-all{
1717
font-size: 18px;
18+
font-weight: bold;
1819
padding-right: 12px!important;
1920
padding-top: 12px!important;
2021
line-height: normal;
@@ -28,6 +29,9 @@ table.shrink tr:not(.shrink-wrapper):not(.blank-row){
2829
.shrink-toggle:hover, .shrink-toggle-all:hover{
2930
opacity: 1;
3031
}
32+
tr.shrink-row{
33+
transition: background-color 0.3s;
34+
}
3135

3236
tr.shrink-wrapper, tr.shrink-wrapper>td{
3337
max-width: 100%;
@@ -36,34 +40,35 @@ tr.shrink-wrapper, tr.shrink-wrapper>td{
3640
margin-top: 0px!important;
3741
}
3842

39-
tr.shrink-wrapper>td div.shrink-row{
43+
tr.shrink-wrapper>td div.shrinked-row{
4044
float: left;
4145
width: 100%;
4246
white-space: normal!important;
4347
padding: 0;
4448
transition: background-color 0.6s;
4549
}
4650

47-
tr.shrink-wrapper>td div.shrink-row div{
51+
tr.shrink-wrapper>td div.shrinked-row div{
4852
float: left;
4953
width: 100%;
5054
}
5155

52-
tr.shrink-wrapper>td div.shrink-row:not(.has-table)>div>div{
56+
tr.shrink-wrapper>td div.shrinked-row:not(.shrink-has-table)>div>div{
5357
padding: 4px 4px;
5458
}
5559

56-
tr.shrink-wrapper>td>div.shrink-row.has-table>div>div>div,
57-
tr.shrink-wrapper>td>div.shrink-row.has-table>div>div{
60+
tr.shrink-wrapper>td>div.shrinked-row.shrink-has-table>div>div>div,
61+
tr.shrink-wrapper>td>div.shrinked-row.shrink-has-table>div>div{
5862
width: 100%!important;
5963
}
6064

61-
tr.shrink-wrapper>td div.shrink-row.odd{background-color: rgba(0,0,0,0.1)}
62-
tr.shrink-wrapper>td div.shrink-row.even{background-color: rgba(0,0,0,0.25)}
65+
tr.collapsed {background-color: rgba(0,0,0,0.2)}
66+
tr.shrink-wrapper>td div.shrinked-row.odd{background-color: rgba(0,0,0,0.1)}
67+
tr.shrink-wrapper>td div.shrinked-row.even{background-color: rgba(0,0,0,0.25)}
6368

64-
tr.shrink-wrapper>td div.shrink-row{width: 100%}
65-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(odd){width: 25%}
66-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(even){width: 75%}
69+
tr.shrink-wrapper>td div.shrinked-row{width: 100%}
70+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(odd){width: 25%}
71+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(even){width: 75%}
6772

6873
.unshrink-xxs, .unshrink-xs, .unshrink-sm, .unshrink-md, .unshrink-lg, .unshrink-xl, .unshrinkable{ display: none!important}
6974

@@ -72,49 +77,59 @@ tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(even){width: 75%}
7277

7378
/* Large Devices, Wide Screens */
7479
@media only screen and (max-width : 1200px) {
75-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(odd){width: 17%}
76-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(even){width: 83%}
80+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(odd){width: 17%}
81+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(even){width: 83%}
7782

7883
.shrinkable{max-width: 180px}
7984
.shrink-lg{display: none!important}
8085
.unshrink-lg{display: table-cell!important}
86+
87+
.unshrink-lg .btn-shrink{width: 100%; text-align: center!important;}
8188
}
8289

8390
/* Medium Devices, Desktops */
8491
@media only screen and (max-width : 992px) {
85-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(odd){width: 23%}
86-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(even){width: 77%}
92+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(odd){width: 23%}
93+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(even){width: 77%}
8794

8895
.shrinkable{max-width: 140px}
8996
.shrink-md{display: none!important}
9097
.unshrink-md{display: table-cell!important}
98+
99+
.unshrink-md .btn-shrink{width: 100%; text-align: center!important;}
91100
}
92101

93102
/* Small Devices, Tablets */
94103
@media only screen and (max-width : 768px) {
95-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(odd){width: 35%}
96-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(even){width: 65%}
104+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(odd){width: 35%}
105+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(even){width: 65%}
97106

98107
.shrinkable{max-width: 120px}
99108
.shrink-sm{display: none!important}
100109
.unshrink-sm{display: table-cell!important}
110+
111+
.unshrink-sm .btn-shrink{width: 100%; text-align: center!important;}
101112
}
102113

103114
/* Extra Small Devices, Phones */
104115
@media only screen and (max-width : 480px) {
105-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(odd){width: 40%}
106-
tr.shrink-wrapper>td div.shrink-row>div>div:nth-child(even){width: 60%}
116+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(odd){width: 40%}
117+
tr.shrink-wrapper>td div.shrinked-row>div>div:nth-child(even){width: 60%}
107118

108119
.shrinkable{max-width: 100px}
109120
.shrink-xs{display: none!important}
110121
.unshrink-xs{display: table-cell!important}
122+
123+
.unshrink-xs .btn-shrink{width: 100%; text-align: center!important;}
111124
}
112125

113126
/* Custom, iPhone Retina */
114127
@media only screen and (max-width : 320px) {
115-
tr.shrink-wrapper>td div.shrink-row>div>div{width: 100%!important}
128+
tr.shrink-wrapper>td div.shrinked-row>div>div{width: 100%!important}
116129

117130
.shrinkable{max-width: 80px}
118131
.shrink-xxs{display: none!important}
119132
.unshrink-xxs{display: table-cell!important}
133+
134+
.unshrink-xxs .btn-shrink{width: 100%; text-align: center!important;}
120135
}

0 commit comments

Comments
 (0)