1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-01 13:24:10 +01:00

Tidy up the pagination functions a bit - lass code and easier to understand

This commit is contained in:
Allan Jardine 2011-12-07 18:33:59 +00:00
parent 7a42b450db
commit 1550b37c79
2 changed files with 86 additions and 130 deletions

View File

@ -9905,7 +9905,8 @@
*/ */
"fnInit": function ( oSettings, nPaging, fnCallbackDraw ) "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{ {
var nPrevious, nNext, nPreviousInner, nNextInner; var oLang = oSettings.oLanguage.oPaginate;
var oClasses = oSettings.oClasses;
var fnClickHandler = function ( e ) { var fnClickHandler = function ( e ) {
if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) ) if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
{ {
@ -9913,33 +9914,17 @@
} }
}; };
/* Store the next and previous elements in the oSettings object as they can be very var sAppend = (!oSettings.bJUI) ?
* useful for automation - particularly testing '<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"></a>'+
*/ '<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"></a>'
nPrevious = document.createElement( 'a' ); :
nNext = document.createElement( 'a' ); '<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
if ( oSettings.bJUI ) '<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
{ $(nPaging).append( sAppend );
nNextInner = document.createElement('span');
nNextInner.className = oSettings.oClasses.sPageJUINext;
nNext.appendChild( nNextInner );
nPreviousInner = document.createElement('span'); var els = $('a', nPaging);
nPreviousInner.className = oSettings.oClasses.sPageJUIPrev; var nPrevious = els[0],
nPrevious.appendChild( nPreviousInner ); nNext = els[1]
}
nPrevious.className = oSettings.oClasses.sPagePrevDisabled;
nNext.className = oSettings.oClasses.sPageNextDisabled;
nPrevious.setAttribute('tabindex', '0');
nNext.setAttribute('tabindex', '0');
nPrevious.title = oSettings.oLanguage.oPaginate.sPrevious;
nNext.title = oSettings.oLanguage.oPaginate.sNext;
nPaging.appendChild( nPrevious );
nPaging.appendChild( nNext );
$(nPrevious) $(nPrevious)
.bind( 'click.DT', { action: "previous" }, fnClickHandler ) .bind( 'click.DT', { action: "previous" }, fnClickHandler )
@ -9959,9 +9944,9 @@
/* ID the first elements only */ /* ID the first elements only */
if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" ) if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
{ {
nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' ); nPaging.id = oSettings.sTableId+'_paginate';
nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' ); nPrevious.id = oSettings.sTableId+'_previous';
nNext.setAttribute( 'id', oSettings.sTableId+'_next' ); nNext.id = oSettings.sTableId+'_next';
} }
}, },
@ -9979,19 +9964,19 @@
return; return;
} }
/* Loop over each instance of the pager */ var oClasses = oSettings.oClasses;
var an = oSettings.aanFeatures.p; var an = oSettings.aanFeatures.p;
/* Loop over each instance of the pager */
for ( var i=0, iLen=an.length ; i<iLen ; i++ ) for ( var i=0, iLen=an.length ; i<iLen ; i++ )
{ {
if ( an[i].childNodes.length !== 0 ) if ( an[i].childNodes.length !== 0 )
{ {
an[i].childNodes[0].className = an[i].childNodes[0].className = ( oSettings._iDisplayStart === 0 ) ?
( oSettings._iDisplayStart === 0 ) ? oClasses.sPagePrevDisabled : oClasses.sPagePrevEnabled;
oSettings.oClasses.sPagePrevDisabled : oSettings.oClasses.sPagePrevEnabled;
an[i].childNodes[1].className = an[i].childNodes[1].className = ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ? oClasses.sPageNextDisabled : oClasses.sPageNextEnabled;
oSettings.oClasses.sPageNextDisabled : oSettings.oClasses.sPageNextEnabled;
} }
} }
} }
@ -10021,11 +10006,8 @@
*/ */
"fnInit": function ( oSettings, nPaging, fnCallbackDraw ) "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{ {
var nFirst = document.createElement( 'a' ); var oLang = oSettings.oLanguage.oPaginate;
var nPrevious = document.createElement( 'a' ); var oClasses = oSettings.oClasses;
var nList = document.createElement( 'span' );
var nNext = document.createElement( 'a' );
var nLast = document.createElement( 'a' );
var fnClickHandler = function ( e ) { var fnClickHandler = function ( e ) {
if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) ) if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
{ {
@ -10033,25 +10015,21 @@
} }
}; };
nFirst.innerHTML = oSettings.oLanguage.oPaginate.sFirst; $(nPaging).append(
nPrevious.innerHTML = oSettings.oLanguage.oPaginate.sPrevious; '<a class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'">'+oLang.sFirst+'</a>'+
nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext; '<a class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'">'+oLang.sPrevious+'</a>'+
nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast; '<span></span>'+
'<a class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+'</a>'+
var oClasses = oSettings.oClasses; '<a class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+'</a>'
nFirst.className = oClasses.sPageButton+" "+oClasses.sPageFirst; );
nPrevious.className = oClasses.sPageButton+" "+oClasses.sPagePrevious; var els = $('a', nPaging);
nNext.className= oClasses.sPageButton+" "+oClasses.sPageNext; var nFirst = els[0],
nLast.className = oClasses.sPageButton+" "+oClasses.sPageLast; nPrev = els[1],
nNext = els[2],
nPaging.appendChild( nFirst ); nLast = els[3];
nPaging.appendChild( nPrevious );
nPaging.appendChild( nList );
nPaging.appendChild( nNext );
nPaging.appendChild( nLast );
$(nFirst).bind( 'click.DT', { action: "first" }, fnClickHandler ); $(nFirst).bind( 'click.DT', { action: "first" }, fnClickHandler );
$(nPrevious).bind( 'click.DT', { action: "previous" }, fnClickHandler ); $(nPrev).bind( 'click.DT', { action: "previous" }, fnClickHandler );
$(nNext).bind( 'click.DT', { action: "next" }, fnClickHandler ); $(nNext).bind( 'click.DT', { action: "next" }, fnClickHandler );
$(nLast).bind( 'click.DT', { action: "last" }, fnClickHandler ); $(nLast).bind( 'click.DT', { action: "last" }, fnClickHandler );
@ -10063,11 +10041,11 @@
/* ID the first elements only */ /* ID the first elements only */
if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" ) if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
{ {
nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' ); nPaging.id = oSettings.sTableId+'_paginate';
nFirst.setAttribute( 'id', oSettings.sTableId+'_first' ); nFirst.id =oSettings.sTableId+'_first';
nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' ); nPrev.id =oSettings.sTableId+'_previous';
nNext.setAttribute( 'id', oSettings.sTableId+'_next' ); nNext.id =oSettings.sTableId+'_next';
nLast.setAttribute( 'id', oSettings.sTableId+'_last' ); nLast.id =oSettings.sTableId+'_last';
} }
}, },

View File

@ -21,7 +21,8 @@ $.extend( DataTable.ext.oPagination, {
*/ */
"fnInit": function ( oSettings, nPaging, fnCallbackDraw ) "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{ {
var nPrevious, nNext, nPreviousInner, nNextInner; var oLang = oSettings.oLanguage.oPaginate;
var oClasses = oSettings.oClasses;
var fnClickHandler = function ( e ) { var fnClickHandler = function ( e ) {
if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) ) if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
{ {
@ -29,33 +30,17 @@ $.extend( DataTable.ext.oPagination, {
} }
}; };
/* Store the next and previous elements in the oSettings object as they can be very var sAppend = (!oSettings.bJUI) ?
* useful for automation - particularly testing '<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"></a>'+
*/ '<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"></a>'
nPrevious = document.createElement( 'a' ); :
nNext = document.createElement( 'a' ); '<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
if ( oSettings.bJUI ) '<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
{ $(nPaging).append( sAppend );
nNextInner = document.createElement('span');
nNextInner.className = oSettings.oClasses.sPageJUINext;
nNext.appendChild( nNextInner );
nPreviousInner = document.createElement('span'); var els = $('a', nPaging);
nPreviousInner.className = oSettings.oClasses.sPageJUIPrev; var nPrevious = els[0],
nPrevious.appendChild( nPreviousInner ); nNext = els[1]
}
nPrevious.className = oSettings.oClasses.sPagePrevDisabled;
nNext.className = oSettings.oClasses.sPageNextDisabled;
nPrevious.setAttribute('tabindex', '0');
nNext.setAttribute('tabindex', '0');
nPrevious.title = oSettings.oLanguage.oPaginate.sPrevious;
nNext.title = oSettings.oLanguage.oPaginate.sNext;
nPaging.appendChild( nPrevious );
nPaging.appendChild( nNext );
$(nPrevious) $(nPrevious)
.bind( 'click.DT', { action: "previous" }, fnClickHandler ) .bind( 'click.DT', { action: "previous" }, fnClickHandler )
@ -75,9 +60,9 @@ $.extend( DataTable.ext.oPagination, {
/* ID the first elements only */ /* ID the first elements only */
if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" ) if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
{ {
nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' ); nPaging.id = oSettings.sTableId+'_paginate';
nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' ); nPrevious.id = oSettings.sTableId+'_previous';
nNext.setAttribute( 'id', oSettings.sTableId+'_next' ); nNext.id = oSettings.sTableId+'_next';
} }
}, },
@ -95,19 +80,19 @@ $.extend( DataTable.ext.oPagination, {
return; return;
} }
/* Loop over each instance of the pager */ var oClasses = oSettings.oClasses;
var an = oSettings.aanFeatures.p; var an = oSettings.aanFeatures.p;
/* Loop over each instance of the pager */
for ( var i=0, iLen=an.length ; i<iLen ; i++ ) for ( var i=0, iLen=an.length ; i<iLen ; i++ )
{ {
if ( an[i].childNodes.length !== 0 ) if ( an[i].childNodes.length !== 0 )
{ {
an[i].childNodes[0].className = an[i].childNodes[0].className = ( oSettings._iDisplayStart === 0 ) ?
( oSettings._iDisplayStart === 0 ) ? oClasses.sPagePrevDisabled : oClasses.sPagePrevEnabled;
oSettings.oClasses.sPagePrevDisabled : oSettings.oClasses.sPagePrevEnabled;
an[i].childNodes[1].className = an[i].childNodes[1].className = ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ? oClasses.sPageNextDisabled : oClasses.sPageNextEnabled;
oSettings.oClasses.sPageNextDisabled : oSettings.oClasses.sPageNextEnabled;
} }
} }
} }
@ -137,11 +122,8 @@ $.extend( DataTable.ext.oPagination, {
*/ */
"fnInit": function ( oSettings, nPaging, fnCallbackDraw ) "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{ {
var nFirst = document.createElement( 'a' ); var oLang = oSettings.oLanguage.oPaginate;
var nPrevious = document.createElement( 'a' ); var oClasses = oSettings.oClasses;
var nList = document.createElement( 'span' );
var nNext = document.createElement( 'a' );
var nLast = document.createElement( 'a' );
var fnClickHandler = function ( e ) { var fnClickHandler = function ( e ) {
if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) ) if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
{ {
@ -149,25 +131,21 @@ $.extend( DataTable.ext.oPagination, {
} }
}; };
nFirst.innerHTML = oSettings.oLanguage.oPaginate.sFirst; $(nPaging).append(
nPrevious.innerHTML = oSettings.oLanguage.oPaginate.sPrevious; '<a class="'+oClasses.sPageButton+" "+oClasses.sPageFirst+'">'+oLang.sFirst+'</a>'+
nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext; '<a class="'+oClasses.sPageButton+" "+oClasses.sPagePrevious+'">'+oLang.sPrevious+'</a>'+
nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast; '<span></span>'+
'<a class="'+oClasses.sPageButton+" "+oClasses.sPageNext+'">'+oLang.sNext+'</a>'+
var oClasses = oSettings.oClasses; '<a class="'+oClasses.sPageButton+" "+oClasses.sPageLast+'">'+oLang.sLast+'</a>'
nFirst.className = oClasses.sPageButton+" "+oClasses.sPageFirst; );
nPrevious.className = oClasses.sPageButton+" "+oClasses.sPagePrevious; var els = $('a', nPaging);
nNext.className= oClasses.sPageButton+" "+oClasses.sPageNext; var nFirst = els[0],
nLast.className = oClasses.sPageButton+" "+oClasses.sPageLast; nPrev = els[1],
nNext = els[2],
nPaging.appendChild( nFirst ); nLast = els[3];
nPaging.appendChild( nPrevious );
nPaging.appendChild( nList );
nPaging.appendChild( nNext );
nPaging.appendChild( nLast );
$(nFirst).bind( 'click.DT', { action: "first" }, fnClickHandler ); $(nFirst).bind( 'click.DT', { action: "first" }, fnClickHandler );
$(nPrevious).bind( 'click.DT', { action: "previous" }, fnClickHandler ); $(nPrev).bind( 'click.DT', { action: "previous" }, fnClickHandler );
$(nNext).bind( 'click.DT', { action: "next" }, fnClickHandler ); $(nNext).bind( 'click.DT', { action: "next" }, fnClickHandler );
$(nLast).bind( 'click.DT', { action: "last" }, fnClickHandler ); $(nLast).bind( 'click.DT', { action: "last" }, fnClickHandler );
@ -179,11 +157,11 @@ $.extend( DataTable.ext.oPagination, {
/* ID the first elements only */ /* ID the first elements only */
if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" ) if ( oSettings.sTableId !== '' && typeof oSettings.aanFeatures.p == "undefined" )
{ {
nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' ); nPaging.id = oSettings.sTableId+'_paginate';
nFirst.setAttribute( 'id', oSettings.sTableId+'_first' ); nFirst.id =oSettings.sTableId+'_first';
nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' ); nPrev.id =oSettings.sTableId+'_previous';
nNext.setAttribute( 'id', oSettings.sTableId+'_next' ); nNext.id =oSettings.sTableId+'_next';
nLast.setAttribute( 'id', oSettings.sTableId+'_last' ); nLast.id =oSettings.sTableId+'_last';
} }
}, },