Skip to content

Commit

Permalink
experimental: use MutationObserver to auto reflow when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoryak committed Jan 5, 2015
1 parent aec5e54 commit 172e6f6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jquery.floatThead v1.2.9
jquery.floatThead v1.2.10
=================

Float the table header without special css. This plugin assumes nothing about your table markup and "just works" without losing your events or styles. Supports floating the header while scrolling within the window or while scrolling within a container with overflow. Plays nice with AngularJS and datatables. My cat loves it.
Expand Down Expand Up @@ -32,7 +32,7 @@ Download / Install:

#### Download

[Latest Release](https://github.com/mkoryak/floatThead/archive/v1.2.9.zip)
[Latest Release](https://github.com/mkoryak/floatThead/archive/v1.2.10.zip)

Inside of that zip the following javascript files are of interest to you:

Expand Down Expand Up @@ -73,6 +73,8 @@ Features:
- Works on any table
- Requires no special css
- Works with [datatables](http://datatables.net) out of the box
- Screen reader support
- Plays nicely with angularjs

Requirements:
-------------
Expand Down Expand Up @@ -109,6 +111,14 @@ Watch for it.

Change Log
----------
### 1.2.10
- play nicely with angularjs if it modifies the DOM behind the scenes
- screen reader support via `enableAria` option
- https://github.com/mkoryak/floatThead/issues/122 - better default options for ie
- https://github.com/mkoryak/floatThead/issues/121 - header layout bug
- https://github.com/mkoryak/floatThead/issues/128 - issues with scrollbar size detection in certain layouts
- https://github.com/mkoryak/floatThead/issues/127 - destroy not removing some elements

### 1.2.9
- **Deprecated the `cellTag` option**, use `headerCellSelector` instead (see docs)
- https://github.com/mkoryak/floatThead/issues/101 - **huge** performance improvement
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery.floatThead",
"version": "1.2.9",
"version": "1.2.10",
"homepage": "http://mkoryak.github.io/floatThead/",
"authors": [
"Misha Koryak"
Expand Down
9 changes: 6 additions & 3 deletions dist/jquery.floatThead-slim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @preserve jQuery.floatThead 1.2.10dev - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @preserve jQuery.floatThead 1.2.10 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @license MIT

/* @author Misha Koryak
Expand Down Expand Up @@ -38,6 +38,8 @@
floatWrapperClass: 'floatThead-wrapper',
floatContainerClass: 'floatThead-container',
copyTableClass: true, //copy 'class' attribute from table into the floated table so that the styles match.
enableAria: false, //will copy header text from the floated header back into the table for screen readers. Might cause the css styling to be off. beware!
autoReflow: false, //(undocumeted) - use MutationObserver api to reflow automatically when internal table DOM changes
debug: false //print possible issues (that don't prevent script loading) to console, if console exists.
};

Expand Down Expand Up @@ -164,6 +166,7 @@
if(!$table.is('table')){
throw new Error('jQuery.floatThead must be run on a table element. ex: $("table").floatThead();');
}
canObserveMutations = opts.autoReflow && canObserveMutations; //option defaults to false!
var $header = $table.find('thead:first');
var $tbody = $table.find('tbody:first');
if($header.length == 0){
Expand Down Expand Up @@ -204,7 +207,7 @@
existingColGroup = false;
}
var $fthRow = $('<fthrow style="display:table-row;border-spacing:0;height:0;border-collapse:collapse"/>'); //created unstyled elements
var $floatContainer = $('<div style="overflow: hidden;"></div>');
var $floatContainer = $('<div style="overflow: hidden;" aria-hidden="true"></div>');
var floatTableHidden = false; //this happens when the table is hidden and we do magic when making it visible
var $newHeader = $("<thead/>");
var $sizerRow = $('<tr class="size-row"/>');
Expand Down Expand Up @@ -340,7 +343,7 @@
lastColumnCount = count;
var cells = [], cols = [], psuedo = [], content;
for(var x = 0; x < count; x++){
if ( content = $headerColumns.eq(x).text() ) {
if (opts.enableAria && (content = $headerColumns.eq(x).text()) ) {
cells.push('<th scope="col" class="floatThead-col">' + content + '</th>');
} else {
cells.push('<th class="floatThead-col"/>');
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.floatThead-slim.min.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions dist/jquery.floatThead.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @preserve jQuery.floatThead 1.2.10dev - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @preserve jQuery.floatThead 1.2.10 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
// @license MIT

/* @author Misha Koryak
Expand Down Expand Up @@ -38,6 +38,8 @@
floatWrapperClass: 'floatThead-wrapper',
floatContainerClass: 'floatThead-container',
copyTableClass: true, //copy 'class' attribute from table into the floated table so that the styles match.
enableAria: false, //will copy header text from the floated header back into the table for screen readers. Might cause the css styling to be off. beware!
autoReflow: false, //(undocumeted) - use MutationObserver api to reflow automatically when internal table DOM changes
debug: false //print possible issues (that don't prevent script loading) to console, if console exists.
};

Expand Down Expand Up @@ -164,6 +166,7 @@
if(!$table.is('table')){
throw new Error('jQuery.floatThead must be run on a table element. ex: $("table").floatThead();');
}
canObserveMutations = opts.autoReflow && canObserveMutations; //option defaults to false!
var $header = $table.find('thead:first');
var $tbody = $table.find('tbody:first');
if($header.length == 0){
Expand Down Expand Up @@ -204,7 +207,7 @@
existingColGroup = false;
}
var $fthRow = $('<fthrow style="display:table-row;border-spacing:0;height:0;border-collapse:collapse"/>'); //created unstyled elements
var $floatContainer = $('<div style="overflow: hidden;"></div>');
var $floatContainer = $('<div style="overflow: hidden;" aria-hidden="true"></div>');
var floatTableHidden = false; //this happens when the table is hidden and we do magic when making it visible
var $newHeader = $("<thead/>");
var $sizerRow = $('<tr class="size-row"/>');
Expand Down Expand Up @@ -340,7 +343,7 @@
lastColumnCount = count;
var cells = [], cols = [], psuedo = [], content;
for(var x = 0; x < count; x++){
if ( content = $headerColumns.eq(x).text() ) {
if (opts.enableAria && (content = $headerColumns.eq(x).text()) ) {
cells.push('<th scope="col" class="floatThead-col">' + content + '</th>');
} else {
cells.push('<th class="floatThead-col"/>');
Expand Down Expand Up @@ -777,7 +780,6 @@
return this;
};
})(jQuery);

/* jQuery.floatThead.utils - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
* License: MIT
*
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.floatThead.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions jquery.floatThead.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
floatContainerClass: 'floatThead-container',
copyTableClass: true, //copy 'class' attribute from table into the floated table so that the styles match.
enableAria: false, //will copy header text from the floated header back into the table for screen readers. Might cause the css styling to be off. beware!
autoReflow: false, //(undocumeted) - use MutationObserver api to reflow automatically when internal table DOM changes
debug: false //print possible issues (that don't prevent script loading) to console, if console exists.
};

Expand Down Expand Up @@ -165,6 +166,7 @@
if(!$table.is('table')){
throw new Error('jQuery.floatThead must be run on a table element. ex: $("table").floatThead();');
}
canObserveMutations = opts.autoReflow && canObserveMutations; //option defaults to false!
var $header = $table.find('thead:first');
var $tbody = $table.find('tbody:first');
if($header.length == 0){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "floatthead",
"version": "1.2.9",
"version": "1.2.10",
"description": "fixed table header plugin that works",
"filename": "jquery.floatThead.js",
"dependencies": {},
Expand Down

0 comments on commit 172e6f6

Please sign in to comment.