2 * This work is licensed under a Creative Commons Attribution 3.0 License
\r
3 * (http://creativecommons.org/licenses/by/3.0/).
\r
6 * to Share - to copy, distribute and transmit the work
\r
7 * to Remix - to adapt the work
\r
8 * Under the following conditions:
\r
9 * Attribution. You must attribute the work in the manner specified
\r
10 * by the author or licensor (but not in any way that suggests that
\r
11 * they endorse you or your use of the work).
\r
13 * For any reuse or distribution, you must make clear to others the license
\r
14 * terms of this work. The best way to do this is with a link to the
\r
15 * Creative Commons web page.
\r
17 * Any of the above conditions can be waived if you get permission from
\r
18 * the copyright holder. Nothing in this license impairs or restricts
\r
19 * the author's moral rights.
\r
23 * Your fair dealing and other rights are in no way affected by the above.
\r
24 * This is a human-readable summary of the Legal Code (the full license).
\r
26 * The author of this work is Vlad Bailescu (http://vlad.bailescu.ro). No
\r
27 * warranty or support will be provided for this work, although updates
\r
28 * might be made available at http://vlad.bailescu.ro/javascript/tablekit .
\r
30 * Licence code and basic description provided by Creative Commons.
\r
33 Object.extend(TableKit.options || {}, {
\r
34 // If true table width gets recalculated on column resize
\r
36 // If true table width will be kept constant on column resize
\r
40 Object.extend(TableKit.Resizable, {
\r
41 resize : function(table, index, w) {
\r
42 // This part is taken from Andrew Tetlaw's original TableKit.Resizable.resize
\r
44 if(typeof index === 'number') {
\r
45 if(!table || (table.tagName && table.tagName !== "TABLE")) {return;}
\r
47 index = Math.min(table.rows[0].cells.length, index);
\r
48 index = Math.max(1, index);
\r
50 cell = (table.tHead && table.tHead.rows.length > 0) ? $(table.tHead.rows[table.tHead.rows.length-1].cells[index]) : $(table.rows[0].cells[index]);
\r
53 table = table ? $(table) : cell.up('table');
\r
54 index = TableKit.getCellIndex(cell);
\r
56 // And now, for the fun stuff
\r
57 // Read the new options values for the given table
\r
58 var op = TableKit.option('trueResize keepWidth minWidth', table.id);
\r
59 // Took also the minWidth as we're gonna use it later anyway
\r
60 var pad = parseInt(cell.getStyle('paddingLeft'),10) + parseInt(cell.getStyle('paddingRight'),10);
\r
61 // Improvement: add cell border to padding as width incorporates both
\r
62 pad += parseInt(cell.getStyle('borderLeftWidth'),10) + parseInt(cell.getStyle('borderRightWidth'),10);
\r
63 w = Math.max(w-pad, op.minWidth); // This will also be used later
\r
64 if (!op.trueResize) {
\r
65 // Original resize method
\r
66 cell.setStyle({'width' : w + 'px'}); // Using previously read minWidth instead of the old way
\r
69 var delta = (w + pad - parseInt(cell.getWidth()));
\r
70 if (!op.keepWidth) {
\r
71 // We'll be updating the table width
\r
72 var tableWidth = parseInt(table.getWidth()) + delta;
\r
73 cell.setStyle({'width' : w + 'px'});
\r
74 table.setStyle({'width' : tableWidth + 'px'});
\r
76 // Let's see what we have to do to keep the table width constant
\r
77 var cells = TableKit.getHeaderCells(table);
\r
78 if (index < 0 || index > cells.length) { return; }
\r
80 if (index == cells.length - 1) { // Rightmost cell
\r
81 nbour = cells[index - 1];
\r
82 } else { // Left or inner cell
\r
83 nbour = cells[index + 1];
\r
85 var nbourWidth = parseInt(nbour.getWidth());
\r
86 var nbourPad = parseInt(nbour.getStyle('paddingLeft'),10) + parseInt(nbour.getStyle('paddingRight'),10);
\r
87 var proposedNbourWidth = nbourWidth - nbourPad - delta;
\r
89 if (proposedNbourWidth < op.minWidth) {
\r
90 // Don't be mean to neighbours. Step off their porch.
\r
91 newNbourWidth = Math.min(nbourWidth - nbourPad, op.minWidth);
\r
92 w -= newNbourWidth - proposedNbourWidth;
\r
94 newNbourWidth = proposedNbourWidth;
\r
96 nbour.setStyle({'width' : newNbourWidth + 'px'});
\r
97 cell.setStyle({'width' : w + 'px'});
\r