From fcc7d4a78dd73cc977eeed07544fba565e127f98 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 22 Apr 2013 18:56:20 +0100 Subject: [PATCH] Internal - refactor of table information control --- media/src/core/core.info.js | 105 +++++++++++++++--------------------- 1 file changed, 44 insertions(+), 61 deletions(-) diff --git a/media/src/core/core.info.js b/media/src/core/core.info.js index 1e86bbdc..e9606143 100644 --- a/media/src/core/core.info.js +++ b/media/src/core/core.info.js @@ -4,102 +4,85 @@ * @returns {node} Information element * @memberof DataTable#oApi */ -function _fnFeatureHtmlInfo ( oSettings ) +function _fnFeatureHtmlInfo ( settings ) { - var nInfo = document.createElement( 'div' ); - nInfo.className = oSettings.oClasses.sInfo; + var + tid = settings.sTableId, + nodes = settings.aanFeatures.i; - /* Actions that are to be taken once only for this feature */ - if ( !oSettings.aanFeatures.i ) - { - /* Add draw callback */ - oSettings.aoDrawCallback.push( { + if ( ! nodes ) { + // Update display on each draw + settings.aoDrawCallback.push( { "fn": _fnUpdateInfo, "sName": "information" } ); - - /* Add id */ - nInfo.id = oSettings.sTableId+'_info'; + + // Table is described by our info div + $(settings.nTable).attr( 'aria-describedby', tid+'_info' ); } - oSettings.nTable.setAttribute( 'aria-describedby', oSettings.sTableId+'_info' ); - - return nInfo; + + return $('
', { + 'class': settings.oClasses.sInfo, + 'id': ! nodes ? tid+'_info' : null + } )[0]; } /** * Update the information elements in the display - * @param {object} oSettings dataTables settings object + * @param {object} settings dataTables settings object * @memberof DataTable#oApi */ -function _fnUpdateInfo ( oSettings ) +function _fnUpdateInfo ( settings ) { /* Show information about the table */ - if ( !oSettings.oFeatures.bInfo || oSettings.aanFeatures.i.length === 0 ) - { + var nodes = settings.aanFeatures.i; + if ( nodes.length === 0 ) { return; } var - oLang = oSettings.oLanguage, - iStart = oSettings._iDisplayStart+1, - iEnd = oSettings.fnDisplayEnd(), - iMax = oSettings.fnRecordsTotal(), - iTotal = oSettings.fnRecordsDisplay(), - sOut; - - if ( iTotal === 0 ) - { - /* Empty record set */ - sOut = oLang.sInfoEmpty; - } - else { - /* Normal record set */ - sOut = oLang.sInfo; - } + lang = settings.oLanguage, + start = settings._iDisplayStart+1, + end = settings.fnDisplayEnd(), + max = settings.fnRecordsTotal(), + total = settings.fnRecordsDisplay(), + out = total ? + lang.sInfoEmpty : + lang.sInfo; - if ( iTotal != iMax ) - { + if ( total !== max ) { /* Record set after filtering */ - sOut += ' ' + oLang.sInfoFiltered; + out += ' ' + lang.sInfoFiltered; } // Convert the macros - sOut += oLang.sInfoPostFix; - sOut = _fnInfoMacros( oSettings, sOut ); + out += lang.sInfoPostFix; + out = _fnInfoMacros( settings, out ); - if ( oLang.fnInfoCallback !== null ) - { - sOut = oLang.fnInfoCallback.call( oSettings.oInstance, - oSettings, iStart, iEnd, iMax, iTotal, sOut ); + var callback = lang.fnInfoCallback; + if ( callback !== null ) { + out = callback.call( settings.oInstance, + settings, start, end, max, total, out + ); } - var n = oSettings.aanFeatures.i; - for ( var i=0, iLen=n.length ; i