diff --git a/.datatables-commit-sync b/.datatables-commit-sync index 6f2e54f5..f6bab65c 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -1961e26b6a8d8de91c784da88091899cd478dd4c +589cef0c08c3206e5fa86f114188fcd58a3f0eb8 diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 5cf2b6a3..9f01d546 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -2948,450 +2948,434 @@ /** * Add any control elements for the table - specifically scrolling - * @param {object} oSettings dataTables settings object + * @param {object} settings dataTables settings object * @returns {node} Node to add to the DOM * @memberof DataTable#oApi */ - function _fnFeatureHtmlTable ( oSettings ) + function _fnFeatureHtmlTable ( settings ) { - /* Check if scrolling is enabled or not - if not then leave the DOM unaltered */ - if ( oSettings.oScroll.sX === "" && oSettings.oScroll.sY === "" ) - { - return oSettings.nTable; + var scroll = settings.oScroll; + + if ( scroll.sX === '' && scroll.sY === '' ) { + return; + } + + var scrollX = scroll.sX; + var scrollY = scroll.sY; + var classes = settings.oClasses; + var table = $(settings.nTable); + var caption = table.children('caption'); + var captionSide = caption.length ? caption[0]._captionSide : null; + var headerClone = $( table[0].cloneNode(false) ); + var footerClone = $( table[0].cloneNode(false) ); + var footer = table.children('tfoot'); + var _div = '
'; + var size = function ( s ) { + return !s ? null : _fnStringToCss( s ); + }; + + if ( ! footer.length ) { + footer = null; } /* * The HTML structure that we want to generate in this function is: - * div - nScroller - * div - nScrollHead - * div - nScrollHeadInner - * table - nScrollHeadTable - * thead - nThead - * div - nScrollBody - * table - oSettings.nTable - * thead - nTheadSize - * tbody - nTbody - * div - nScrollFoot - * div - nScrollFootInner - * table - nScrollFootTable - * tfoot - nTfoot + * div - scroller + * div - scroll head + * div - scroll head inner + * table - scroll head table + * thead - thead + * div - scroll body + * table - table (master table) + * thead - thead clone for sizing + * tbody - tbody + * div - scroll foot + * div - scroll foot inner + * table - scroll foot table + * tfoot - tfoot */ - var - nScroller = document.createElement('div'), - nScrollHead = document.createElement('div'), - nScrollHeadInner = document.createElement('div'), - nScrollBody = document.createElement('div'), - nScrollFoot = document.createElement('div'), - nScrollFootInner = document.createElement('div'), - nScrollHeadTable = oSettings.nTable.cloneNode(false), - nScrollFootTable = oSettings.nTable.cloneNode(false), - nThead = oSettings.nTable.getElementsByTagName('thead')[0], - nTfoot = oSettings.nTable.getElementsByTagName('tfoot').length === 0 ? null : - oSettings.nTable.getElementsByTagName('tfoot')[0], - oClasses = oSettings.oClasses; + var scroller = $( _div, { 'class': classes.sScrollWrapper } ) + .append( + $(_div, { 'class': classes.sScrollHead } ) + .css( { + overflow: 'hidden', + position: 'relative', + border: 0, + width: scrollX ? size(scrollX) : '100%' + } ) + .append( + $(_div, { 'class': classes.sScrollHeadInner } ) + .css( { + 'box-sizing': 'content-box', + width: scroll.sXInner || '100%' + } ) + .append( + headerClone + .removeAttr('id') + .css( 'margin-left', 0 ) + .append( + table.children('thead') + ) + ) + ) + .append( captionSide === 'top' ? caption : null ) + ) + .append( + $(_div, { 'class': classes.sScrollBody } ) + .css( { + overflow: 'auto', + height: size( scrollY ), + width: size( scrollX ) + } ) + .append( table ) + ); - nScrollHead.appendChild( nScrollHeadInner ); - nScrollFoot.appendChild( nScrollFootInner ); - nScrollBody.appendChild( oSettings.nTable ); - nScroller.appendChild( nScrollHead ); - nScroller.appendChild( nScrollBody ); - nScrollHeadInner.appendChild( nScrollHeadTable ); - nScrollHeadTable.appendChild( nThead ); - if ( nTfoot !== null ) - { - nScroller.appendChild( nScrollFoot ); - nScrollFootInner.appendChild( nScrollFootTable ); - nScrollFootTable.appendChild( nTfoot ); + if ( footer ) { + scroller.append( + $(_div, { 'class': classes.sScrollFoot } ) + .css( { + overflow: 'hidden', + border: 0, + width: scrollX ? size(scrollX) : '100%' + } ) + .append( + $(_div, { 'class': classes.sScrollFootInner } ) + .append( + footerClone + .removeAttr('id') + .css( 'margin-left', 0 ) + .append( + table.children('tfoot') + ) + ) + ) + .append( captionSide === 'bottom' ? caption : null ) + ); } - nScroller.className = oClasses.sScrollWrapper; - nScrollHead.className = oClasses.sScrollHead; - nScrollHeadInner.className = oClasses.sScrollHeadInner; - nScrollBody.className = oClasses.sScrollBody; - nScrollFoot.className = oClasses.sScrollFoot; - nScrollFootInner.className = oClasses.sScrollFootInner; + var children = scroller.children(); + var scrollHead = children[0]; + var scrollBody = children[1]; + var scrollFoot = footer ? children[2] : null; - if ( oSettings.oScroll.bAutoCss ) - { - nScrollHead.style.overflow = "hidden"; - nScrollHead.style.position = "relative"; - nScrollFoot.style.overflow = "hidden"; - nScrollBody.style.overflow = "auto"; - } + // When the body is scrolled, then we also want to scroll the headers + if ( scrollX ) { + $(scrollBody).scroll( function (e) { + var scrollLeft = this.scrollLeft; - nScrollHead.style.border = "0"; - nScrollHead.style.width = "100%"; - nScrollFoot.style.border = "0"; - $(nScrollHeadInner).css('box-sizing', 'content-box'); - nScrollHeadInner.style.width = oSettings.oScroll.sXInner !== "" ? - oSettings.oScroll.sXInner : "100%"; /* will be overwritten */ + scrollHead.scrollLeft = scrollLeft; - /* Modify attributes to respect the clones */ - nScrollHeadTable.removeAttribute('id'); - nScrollHeadTable.style.marginLeft = "0"; - oSettings.nTable.style.marginLeft = "0"; - if ( nTfoot !== null ) - { - nScrollFootTable.removeAttribute('id'); - nScrollFootTable.style.marginLeft = "0"; - } - - /* Move caption elements from the body to the header, footer or leave where it is - * depending on the configuration. Note that the DTD says there can be only one caption */ - var nCaption = $(oSettings.nTable).children('caption'); - if ( nCaption.length > 0 ) - { - nCaption = nCaption[0]; - if ( nCaption._captionSide === "top" ) - { - nScrollHeadTable.appendChild( nCaption ); - } - else if ( nCaption._captionSide === "bottom" && nTfoot ) - { - nScrollFootTable.appendChild( nCaption ); - } - } - - /* - * Sizing - */ - /* When x-scrolling add the width and a scroller to move the header with the body */ - if ( oSettings.oScroll.sX !== "" ) - { - nScrollHead.style.width = _fnStringToCss( oSettings.oScroll.sX ); - nScrollBody.style.width = _fnStringToCss( oSettings.oScroll.sX ); - - if ( nTfoot !== null ) - { - nScrollFoot.style.width = _fnStringToCss( oSettings.oScroll.sX ); - } - - /* When the body is scrolled, then we also want to scroll the headers */ - $(nScrollBody).scroll( function (e) { - nScrollHead.scrollLeft = this.scrollLeft; - - if ( nTfoot !== null ) - { - nScrollFoot.scrollLeft = this.scrollLeft; + if ( footer ) { + scrollFoot.scrollLeft = scrollLeft; } } ); } - /* When yscrolling, add the height */ - if ( oSettings.oScroll.sY !== "" ) - { - nScrollBody.style.height = _fnStringToCss( oSettings.oScroll.sY ); - } + settings.nScrollHead = scrollHead; + settings.nScrollBody = scrollBody; + settings.nScrollFoot = scrollFoot; - /* Redraw - align columns across the tables */ - oSettings.aoDrawCallback.push( { + // On redraw - align columns + settings.aoDrawCallback.push( { "fn": _fnScrollDraw, "sName": "scrolling" } ); - oSettings.nScrollHead = nScrollHead; - oSettings.nScrollFoot = nScrollFoot; - - return nScroller; + return scroller[0]; } + /** - * Update the various tables for resizing. It's a bit of a pig this function, but - * basically the idea to: + * Update the header, footer and body tables for resizing - i.e. column + * alignment. + * + * Welcome to the most horrible function DataTables. The process that this + * function follows is basically: * 1. Re-create the table inside the scrolling div * 2. Take live measurements from the DOM - * 3. Apply the measurements + * 3. Apply the measurements to align the columns * 4. Clean up - * @param {object} o dataTables settings object - * @returns {node} Node to add to the DOM + * + * @param {object} settings dataTables settings object * @memberof DataTable#oApi */ - function _fnScrollDraw ( o ) + function _fnScrollDraw ( settings ) { + // Given that this is such a monster function, a lot of variables are use + // to try and keep the minimised size as small as possible var - nScrollHeadInner = o.nScrollHead.getElementsByTagName('div')[0], - nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0], - nScrollBody = o.nTable.parentNode, - i, iLen, j, jLen, anHeadToSize, anHeadSizers, anFootSizers, anFootToSize, oStyle, iVis, - nTheadSize, nTfootSize, - iWidth, aApplied=[], aAppliedFooter=[], iSanityWidth, - nScrollFootInner = (o.nTFoot !== null) ? o.nScrollFoot.getElementsByTagName('div')[0] : null, - nScrollFootTable = (o.nTFoot !== null) ? nScrollFootInner.getElementsByTagName('table')[0] : null, - ie67 = o.oBrowser.bScrollOversize, + scroll = settings.oScroll, + scrollX = scroll.sX, + scrollXInner = scroll.sXInner, + scrollY = scroll.sY, + barWidth = scroll.iBarWidth, + divHeader = $(settings.nScrollHead), + divHeaderStyle = divHeader[0].style, + divHeaderInner = divHeader.children('div'), + divHeaderInnerStyle = divHeaderInner[0].style, + divHeaderTable = divHeaderInner.children('table'), + divBodyEl = settings.nScrollBody, + divBody = $(divBodyEl), + divBodyStyle = divBodyEl.style, + divFooter = $(settings.nScrollFoot), + divFooterInner = divFooter.children('div'), + divFooterTable = divFooterInner.children('table'), + header = $(settings.nTHead), + table = $(settings.nTable), + tableEl = table[0], + tableStyle = tableEl.style, + footer = settings.nTFoot ? $(settings.nTFoot) : null, + browser = settings.oBrowser, + ie67 = browser.bScrollOversize, + headerTrgEls, footerTrgEls, + headerSrcEls, footerSrcEls, + headerCopy, footerCopy, + headerWidths=[], footerWidths=[], + idx, correction, sanityWidth, zeroOut = function(nSizer) { - oStyle = nSizer.style; - oStyle.paddingTop = "0"; - oStyle.paddingBottom = "0"; - oStyle.borderTopWidth = "0"; - oStyle.borderBottomWidth = "0"; - oStyle.height = 0; + var style = nSizer.style; + style.paddingTop = "0"; + style.paddingBottom = "0"; + style.borderTopWidth = "0"; + style.borderBottomWidth = "0"; + style.height = 0; }; /* * 1. Re-create the table inside the scrolling div */ - /* Remove the old minimised thead and tfoot elements in the inner table */ - $(o.nTable).children('thead, tfoot').remove(); + // Remove the old minimised thead and tfoot elements in the inner table + table.children('thead, tfoot').remove(); - /* Clone the current header and footer elements and then place it into the inner table */ - nTheadSize = $(o.nTHead).clone()[0]; - o.nTable.insertBefore( nTheadSize, o.nTable.childNodes[0] ); - anHeadToSize = o.nTHead.getElementsByTagName('tr'); - anHeadSizers = nTheadSize.getElementsByTagName('tr'); - $('th, td', nTheadSize).removeAttr('tabindex'); + // Clone the current header and footer elements and then place it into the inner table + headerCopy = header.clone().prependTo( table ); + headerTrgEls = header.find('tr'); // original header is in its own table + headerSrcEls = headerCopy.find('tr'); + headerCopy.find('th, td').removeAttr('tabindex'); - if ( o.nTFoot !== null ) - { - nTfootSize = $(o.nTFoot).clone()[0]; - o.nTable.insertBefore( nTfootSize, o.nTable.childNodes[1] ); - anFootToSize = o.nTFoot.getElementsByTagName('tr'); - anFootSizers = nTfootSize.getElementsByTagName('tr'); + if ( footer ) { + footerCopy = footer.clone().prependTo( table ); + footerTrgEls = footer.find('tr'); // the original tfoot is in its own table and must be sized + footerSrcEls = footerCopy.find('tr'); } + /* * 2. Take live measurements from the DOM - do not alter the DOM itself! */ - /* Remove old sizing and apply the calculated column widths - * Get the unique column headers in the newly created (cloned) header. We want to apply the - * calculated sizes to this header - */ - if ( o.oScroll.sX === "" ) + // Remove old sizing and apply the calculated column widths + // Get the unique column headers in the newly created (cloned) header. We want to apply the + // calculated sizes to this header + if ( ! scrollX ) { - nScrollBody.style.width = '100%'; - nScrollHeadInner.parentNode.style.width = '100%'; + divBodyStyle.width = '100%'; + divHeader[0].style.width = '100%'; } - var nThs = _fnGetUniqueThs( o, nTheadSize ); - for ( i=0, iLen=nThs.length ; i