Created
September 30, 2011 15:47
-
-
Save danlynn/1254172 to your computer and use it in GitHub Desktop.
Description
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Rewraps the elements in a table to the specified 'width'. If 'elements' | |
| * is provided then populates the innerHTML of the cells of the specified | |
| * 'table' using the data in the 'elements' array instead of re-using the | |
| * elements already in the table. | |
| * | |
| * rewrapTableToWidth($('#myTable'), $(window).width()) | |
| */ | |
| function rewrapTableToWidth(table, width, elements) { | |
| table = typeof(table[0]) != "undefined" ? table[0] : table; | |
| elements = typeof(elements) != 'undefined' ? elements : null; | |
| var cols = 0; | |
| do { | |
| rewrapTableToCols(table, ++cols, elements); | |
| if (table.rows[0].cells.length < cols) | |
| break; | |
| } while (table.offsetWidth < width); | |
| rewrapTableToCols(table, (cols-1 < 1 ? 1 : cols-1), elements); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment