annotate DataTables-1.9.4/media/src/core/core.scrolling.js @ 7:0f2b740536fb draft

Uploaded
author saskia-hiltemann
date Mon, 21 Aug 2017 09:16:07 -0400
parents ac5f9272033b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2 * Add any control elements for the table - specifically scrolling
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 * @param {object} oSettings dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 * @returns {node} Node to add to the DOM
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 function _fnFeatureHtmlTable ( oSettings )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 /* Check if scrolling is enabled or not - if not then leave the DOM unaltered */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10 if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 return oSettings.nTable;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16 * The HTML structure that we want to generate in this function is:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 * div - nScroller
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 * div - nScrollHead
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 * div - nScrollHeadInner
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 * table - nScrollHeadTable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 * thead - nThead
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22 * div - nScrollBody
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 * table - oSettings.nTable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 * thead - nTheadSize
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25 * tbody - nTbody
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26 * div - nScrollFoot
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 * div - nScrollFootInner
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 * table - nScrollFootTable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 * tfoot - nTfoot
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 nScroller = document.createElement('div'),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 nScrollHead = document.createElement('div'),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 nScrollHeadInner = document.createElement('div'),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 nScrollBody = document.createElement('div'),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 nScrollFoot = document.createElement('div'),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37 nScrollFootInner = document.createElement('div'),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 nScrollHeadTable = oSettings.nTable.cloneNode(false),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 nScrollFootTable = oSettings.nTable.cloneNode(false),
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40 nThead = oSettings.nTable.getElementsByTagName('thead')[0],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41 nTfoot = oSettings.nTable.getElementsByTagName('tfoot').length === 0 ? null :
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 oSettings.nTable.getElementsByTagName('tfoot')[0],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 oClasses = oSettings.oClasses;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 nScrollHead.appendChild( nScrollHeadInner );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 nScrollFoot.appendChild( nScrollFootInner );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 nScrollBody.appendChild( oSettings.nTable );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 nScroller.appendChild( nScrollHead );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 nScroller.appendChild( nScrollBody );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 nScrollHeadInner.appendChild( nScrollHeadTable );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 nScrollHeadTable.appendChild( nThead );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 if ( nTfoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 nScroller.appendChild( nScrollFoot );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 nScrollFootInner.appendChild( nScrollFootTable );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56 nScrollFootTable.appendChild( nTfoot );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 nScroller.className = oClasses.sScrollWrapper;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 nScrollHead.className = oClasses.sScrollHead;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 nScrollHeadInner.className = oClasses.sScrollHeadInner;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 nScrollBody.className = oClasses.sScrollBody;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 nScrollFoot.className = oClasses.sScrollFoot;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 nScrollFootInner.className = oClasses.sScrollFootInner;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 if ( oSettings.oScroll.bAutoCss )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68 nScrollHead.style.overflow = "hidden";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 nScrollHead.style.position = "relative";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 nScrollFoot.style.overflow = "hidden";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 nScrollBody.style.overflow = "auto";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 nScrollHead.style.border = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 nScrollHead.style.width = "100%";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 nScrollFoot.style.border = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 nScrollHeadInner.style.width = oSettings.oScroll.sXInner !== "" ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 oSettings.oScroll.sXInner : "100%"; /* will be overwritten */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 /* Modify attributes to respect the clones */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 nScrollHeadTable.removeAttribute('id');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82 nScrollHeadTable.style.marginLeft = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 oSettings.nTable.style.marginLeft = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 if ( nTfoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 nScrollFootTable.removeAttribute('id');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 nScrollFootTable.style.marginLeft = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 /* Move caption elements from the body to the header, footer or leave where it is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 * depending on the configuration. Note that the DTD says there can be only one caption */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 var nCaption = $(oSettings.nTable).children('caption');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 if ( nCaption.length > 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95 nCaption = nCaption[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 if ( nCaption._captionSide === "top" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
98 nScrollHeadTable.appendChild( nCaption );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
99 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
100 else if ( nCaption._captionSide === "bottom" && nTfoot )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
101 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
102 nScrollFootTable.appendChild( nCaption );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
103 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
104 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
105
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
106 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
107 * Sizing
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
108 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
109 /* When x-scrolling add the width and a scroller to move the header with the body */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
110 if ( oSettings.oScroll.sX !== "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
111 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
112 nScrollHead.style.width = _fnStringToCss( oSettings.oScroll.sX );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
113 nScrollBody.style.width = _fnStringToCss( oSettings.oScroll.sX );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
114
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
115 if ( nTfoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
116 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
117 nScrollFoot.style.width = _fnStringToCss( oSettings.oScroll.sX );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
118 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
119
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
120 /* When the body is scrolled, then we also want to scroll the headers */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
121 $(nScrollBody).scroll( function (e) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
122 nScrollHead.scrollLeft = this.scrollLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
123
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
124 if ( nTfoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
125 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
126 nScrollFoot.scrollLeft = this.scrollLeft;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
127 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
128 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
129 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
130
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
131 /* When yscrolling, add the height */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
132 if ( oSettings.oScroll.sY !== "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
133 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
134 nScrollBody.style.height = _fnStringToCss( oSettings.oScroll.sY );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
135 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
136
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
137 /* Redraw - align columns across the tables */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
138 oSettings.aoDrawCallback.push( {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
139 "fn": _fnScrollDraw,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
140 "sName": "scrolling"
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
141 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
142
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
143 /* Infinite scrolling event handlers */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
144 if ( oSettings.oScroll.bInfinite )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
145 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
146 $(nScrollBody).scroll( function() {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
147 /* Use a blocker to stop scrolling from loading more data while other data is still loading */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
148 if ( !oSettings.bDrawing && $(this).scrollTop() !== 0 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
149 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
150 /* Check if we should load the next data set */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
151 if ( $(this).scrollTop() + $(this).height() >
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
152 $(oSettings.nTable).height() - oSettings.oScroll.iLoadGap )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
153 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
154 /* Only do the redraw if we have to - we might be at the end of the data */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
155 if ( oSettings.fnDisplayEnd() < oSettings.fnRecordsDisplay() )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
156 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
157 _fnPageChange( oSettings, 'next' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
158 _fnCalculateEnd( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
159 _fnDraw( oSettings );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
160 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
161 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
162 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
163 } );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
164 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
165
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
166 oSettings.nScrollHead = nScrollHead;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
167 oSettings.nScrollFoot = nScrollFoot;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
168
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
169 return nScroller;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
170 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
171
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
172
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
173 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
174 * Update the various tables for resizing. It's a bit of a pig this function, but
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
175 * basically the idea to:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
176 * 1. Re-create the table inside the scrolling div
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
177 * 2. Take live measurements from the DOM
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
178 * 3. Apply the measurements
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
179 * 4. Clean up
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
180 * @param {object} o dataTables settings object
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
181 * @returns {node} Node to add to the DOM
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
182 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
183 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
184 function _fnScrollDraw ( o )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
185 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
186 var
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
187 nScrollHeadInner = o.nScrollHead.getElementsByTagName('div')[0],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
188 nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
189 nScrollBody = o.nTable.parentNode,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
190 i, iLen, j, jLen, anHeadToSize, anHeadSizers, anFootSizers, anFootToSize, oStyle, iVis,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
191 nTheadSize, nTfootSize,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
192 iWidth, aApplied=[], aAppliedFooter=[], iSanityWidth,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
193 nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
194 nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
195 ie67 = o.oBrowser.bScrollOversize,
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
196 zeroOut = function(nSizer) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
197 oStyle = nSizer.style;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
198 oStyle.paddingTop = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
199 oStyle.paddingBottom = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
200 oStyle.borderTopWidth = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
201 oStyle.borderBottomWidth = "0";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
202 oStyle.height = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
203 };
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
204
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
205 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
206 * 1. Re-create the table inside the scrolling div
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
207 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
208
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
209 /* Remove the old minimised thead and tfoot elements in the inner table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
210 $(o.nTable).children('thead, tfoot').remove();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
211
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
212 /* Clone the current header and footer elements and then place it into the inner table */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
213 nTheadSize = $(o.nTHead).clone()[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
214 o.nTable.insertBefore( nTheadSize, o.nTable.childNodes[0] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
215 anHeadToSize = o.nTHead.getElementsByTagName('tr');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
216 anHeadSizers = nTheadSize.getElementsByTagName('tr');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
217
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
218 if ( o.nTFoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
219 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
220 nTfootSize = $(o.nTFoot).clone()[0];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
221 o.nTable.insertBefore( nTfootSize, o.nTable.childNodes[1] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
222 anFootToSize = o.nTFoot.getElementsByTagName('tr');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
223 anFootSizers = nTfootSize.getElementsByTagName('tr');
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
224 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
225
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
226 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
227 * 2. Take live measurements from the DOM - do not alter the DOM itself!
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
228 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
229
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
230 /* Remove old sizing and apply the calculated column widths
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
231 * Get the unique column headers in the newly created (cloned) header. We want to apply the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
232 * calculated sizes to this header
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
233 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
234 if ( o.oScroll.sX === "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
235 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
236 nScrollBody.style.width = '100%';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
237 nScrollHeadInner.parentNode.style.width = '100%';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
238 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
239
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
240 var nThs = _fnGetUniqueThs( o, nTheadSize );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
241 for ( i=0, iLen=nThs.length ; i<iLen ; i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
242 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
243 iVis = _fnVisibleToColumnIndex( o, i );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
244 nThs[i].style.width = o.aoColumns[iVis].sWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
245 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
246
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
247 if ( o.nTFoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
248 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
249 _fnApplyToChildren( function(n) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
250 n.style.width = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
251 }, anFootSizers );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
252 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
253
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
254 // If scroll collapse is enabled, when we put the headers back into the body for sizing, we
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
255 // will end up forcing the scrollbar to appear, making our measurements wrong for when we
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
256 // then hide it (end of this function), so add the header height to the body scroller.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
257 if ( o.oScroll.bCollapse && o.oScroll.sY !== "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
258 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
259 nScrollBody.style.height = (nScrollBody.offsetHeight + o.nTHead.offsetHeight)+"px";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
260 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
261
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
262 /* Size the table as a whole */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
263 iSanityWidth = $(o.nTable).outerWidth();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
264 if ( o.oScroll.sX === "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
265 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
266 /* No x scrolling */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
267 o.nTable.style.width = "100%";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
268
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
269 /* I know this is rubbish - but IE7 will make the width of the table when 100% include
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
270 * the scrollbar - which is shouldn't. When there is a scrollbar we need to take this
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
271 * into account.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
272 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
273 if ( ie67 && ($('tbody', nScrollBody).height() > nScrollBody.offsetHeight ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
274 $(nScrollBody).css('overflow-y') == "scroll") )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
275 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
276 o.nTable.style.width = _fnStringToCss( $(o.nTable).outerWidth() - o.oScroll.iBarWidth);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
277 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
278 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
279 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
280 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
281 if ( o.oScroll.sXInner !== "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
282 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
283 /* x scroll inner has been given - use it */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
284 o.nTable.style.width = _fnStringToCss(o.oScroll.sXInner);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
285 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
286 else if ( iSanityWidth == $(nScrollBody).width() &&
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
287 $(nScrollBody).height() < $(o.nTable).height() )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
288 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
289 /* There is y-scrolling - try to take account of the y scroll bar */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
290 o.nTable.style.width = _fnStringToCss( iSanityWidth-o.oScroll.iBarWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
291 if ( $(o.nTable).outerWidth() > iSanityWidth-o.oScroll.iBarWidth )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
292 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
293 /* Not possible to take account of it */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
294 o.nTable.style.width = _fnStringToCss( iSanityWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
295 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
296 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
297 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
298 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
299 /* All else fails */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
300 o.nTable.style.width = _fnStringToCss( iSanityWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
301 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
302 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
303
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
304 /* Recalculate the sanity width - now that we've applied the required width, before it was
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
305 * a temporary variable. This is required because the column width calculation is done
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
306 * before this table DOM is created.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
307 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
308 iSanityWidth = $(o.nTable).outerWidth();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
309
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
310 /* We want the hidden header to have zero height, so remove padding and borders. Then
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
311 * set the width based on the real headers
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
312 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
313
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
314 // Apply all styles in one pass. Invalidates layout only once because we don't read any
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
315 // DOM properties.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
316 _fnApplyToChildren( zeroOut, anHeadSizers );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
317
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
318 // Read all widths in next pass. Forces layout only once because we do not change
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
319 // any DOM properties.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
320 _fnApplyToChildren( function(nSizer) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
321 aApplied.push( _fnStringToCss( $(nSizer).width() ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
322 }, anHeadSizers );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
323
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
324 // Apply all widths in final pass. Invalidates layout only once because we do not
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
325 // read any DOM properties.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
326 _fnApplyToChildren( function(nToSize, i) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
327 nToSize.style.width = aApplied[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
328 }, anHeadToSize );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
329
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
330 $(anHeadSizers).height(0);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
331
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
332 /* Same again with the footer if we have one */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
333 if ( o.nTFoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
334 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
335 _fnApplyToChildren( zeroOut, anFootSizers );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
336
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
337 _fnApplyToChildren( function(nSizer) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
338 aAppliedFooter.push( _fnStringToCss( $(nSizer).width() ) );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
339 }, anFootSizers );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
340
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
341 _fnApplyToChildren( function(nToSize, i) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
342 nToSize.style.width = aAppliedFooter[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
343 }, anFootToSize );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
344
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
345 $(anFootSizers).height(0);
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
346 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
347
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
348 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
349 * 3. Apply the measurements
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
350 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
351
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
352 /* "Hide" the header and footer that we used for the sizing. We want to also fix their width
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
353 * to what they currently are
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
354 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
355 _fnApplyToChildren( function(nSizer, i) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
356 nSizer.innerHTML = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
357 nSizer.style.width = aApplied[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
358 }, anHeadSizers );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
359
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
360 if ( o.nTFoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
361 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
362 _fnApplyToChildren( function(nSizer, i) {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
363 nSizer.innerHTML = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
364 nSizer.style.width = aAppliedFooter[i];
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
365 }, anFootSizers );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
366 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
367
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
368 /* Sanity check that the table is of a sensible width. If not then we are going to get
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
369 * misalignment - try to prevent this by not allowing the table to shrink below its min width
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
370 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
371 if ( $(o.nTable).outerWidth() < iSanityWidth )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
372 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
373 /* The min width depends upon if we have a vertical scrollbar visible or not */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
374 var iCorrection = ((nScrollBody.scrollHeight > nScrollBody.offsetHeight ||
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
375 $(nScrollBody).css('overflow-y') == "scroll")) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
376 iSanityWidth+o.oScroll.iBarWidth : iSanityWidth;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
377
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
378 /* IE6/7 are a law unto themselves... */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
379 if ( ie67 && (nScrollBody.scrollHeight >
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
380 nScrollBody.offsetHeight || $(nScrollBody).css('overflow-y') == "scroll") )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
381 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
382 o.nTable.style.width = _fnStringToCss( iCorrection-o.oScroll.iBarWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
383 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
384
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
385 /* Apply the calculated minimum width to the table wrappers */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
386 nScrollBody.style.width = _fnStringToCss( iCorrection );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
387 o.nScrollHead.style.width = _fnStringToCss( iCorrection );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
388
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
389 if ( o.nTFoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
390 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
391 o.nScrollFoot.style.width = _fnStringToCss( iCorrection );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
392 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
393
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
394 /* And give the user a warning that we've stopped the table getting too small */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
395 if ( o.oScroll.sX === "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
396 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
397 _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
398 " misalignment. The table has been drawn at its minimum possible width." );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
399 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
400 else if ( o.oScroll.sXInner !== "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
401 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
402 _fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
403 " misalignment. Increase the sScrollXInner value or remove it to allow automatic"+
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
404 " calculation" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
405 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
406 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
407 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
408 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
409 nScrollBody.style.width = _fnStringToCss( '100%' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
410 o.nScrollHead.style.width = _fnStringToCss( '100%' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
411
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
412 if ( o.nTFoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
413 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
414 o.nScrollFoot.style.width = _fnStringToCss( '100%' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
415 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
416 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
417
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
418
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
419 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
420 * 4. Clean up
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
421 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
422 if ( o.oScroll.sY === "" )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
423 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
424 /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
425 * the scrollbar height from the visible display, rather than adding it on. We need to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
426 * set the height in order to sort this. Don't want to do it in any other browsers.
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
427 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
428 if ( ie67 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
429 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
430 nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+o.oScroll.iBarWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
431 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
432 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
433
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
434 if ( o.oScroll.sY !== "" && o.oScroll.bCollapse )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
435 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
436 nScrollBody.style.height = _fnStringToCss( o.oScroll.sY );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
437
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
438 var iExtra = (o.oScroll.sX !== "" && o.nTable.offsetWidth > nScrollBody.offsetWidth) ?
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
439 o.oScroll.iBarWidth : 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
440 if ( o.nTable.offsetHeight < nScrollBody.offsetHeight )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
441 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
442 nScrollBody.style.height = _fnStringToCss( o.nTable.offsetHeight+iExtra );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
443 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
444 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
445
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
446 /* Finally set the width's of the header and footer tables */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
447 var iOuterWidth = $(o.nTable).outerWidth();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
448 nScrollHeadTable.style.width = _fnStringToCss( iOuterWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
449 nScrollHeadInner.style.width = _fnStringToCss( iOuterWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
450
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
451 // Figure out if there are scrollbar present - if so then we need a the header and footer to
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
452 // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
453 var bScrolling = $(o.nTable).height() > nScrollBody.clientHeight || $(nScrollBody).css('overflow-y') == "scroll";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
454 nScrollHeadInner.style.paddingRight = bScrolling ? o.oScroll.iBarWidth+"px" : "0px";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
455
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
456 if ( o.nTFoot !== null )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
457 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
458 nScrollFootTable.style.width = _fnStringToCss( iOuterWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
459 nScrollFootInner.style.width = _fnStringToCss( iOuterWidth );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
460 nScrollFootInner.style.paddingRight = bScrolling ? o.oScroll.iBarWidth+"px" : "0px";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
461 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
462
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
463 /* Adjust the position of the header in case we loose the y-scrollbar */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
464 $(nScrollBody).scroll();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
465
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
466 /* If sorting or filtering has occurred, jump the scrolling back to the top */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
467 if ( o.bSorted || o.bFiltered )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
468 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
469 nScrollBody.scrollTop = 0;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
470 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
471 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
472
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
473
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
474 /**
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
475 * Apply a given function to the display child nodes of an element array (typically
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
476 * TD children of TR rows
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
477 * @param {function} fn Method to apply to the objects
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
478 * @param array {nodes} an1 List of elements to look through for display children
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
479 * @param array {nodes} an2 Another list (identical structure to the first) - optional
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
480 * @memberof DataTable#oApi
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
481 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
482 function _fnApplyToChildren( fn, an1, an2 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
483 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
484 var index=0, i=0, iLen=an1.length;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
485 var nNode1, nNode2;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
486
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
487 while ( i < iLen )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
488 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
489 nNode1 = an1[i].firstChild;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
490 nNode2 = an2 ? an2[i].firstChild : null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
491 while ( nNode1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
492 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
493 if ( nNode1.nodeType === 1 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
494 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
495 if ( an2 )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
496 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
497 fn( nNode1, nNode2, index );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
498 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
499 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
500 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
501 fn( nNode1, index );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
502 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
503 index++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
504 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
505 nNode1 = nNode1.nextSibling;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
506 nNode2 = an2 ? nNode2.nextSibling : null;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
507 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
508 i++;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
509 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
510 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
511