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:
parent
7a42b450db
commit
1550b37c79
108
media/js/jquery.dataTables.js
vendored
108
media/js/jquery.dataTables.js
vendored
@ -9905,41 +9905,26 @@
|
|||||||
*/
|
*/
|
||||||
"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 ) )
|
||||||
{
|
{
|
||||||
fnCallbackDraw( oSettings );
|
fnCallbackDraw( oSettings );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Store the next and previous elements in the oSettings object as they can be very
|
|
||||||
* useful for automation - particularly testing
|
|
||||||
*/
|
|
||||||
nPrevious = document.createElement( 'a' );
|
|
||||||
nNext = document.createElement( 'a' );
|
|
||||||
if ( oSettings.bJUI )
|
|
||||||
{
|
|
||||||
nNextInner = document.createElement('span');
|
|
||||||
nNextInner.className = oSettings.oClasses.sPageJUINext;
|
|
||||||
nNext.appendChild( nNextInner );
|
|
||||||
|
|
||||||
nPreviousInner = document.createElement('span');
|
|
||||||
nPreviousInner.className = oSettings.oClasses.sPageJUIPrev;
|
|
||||||
nPrevious.appendChild( nPreviousInner );
|
|
||||||
}
|
|
||||||
|
|
||||||
nPrevious.className = oSettings.oClasses.sPagePrevDisabled;
|
|
||||||
nNext.className = oSettings.oClasses.sPageNextDisabled;
|
|
||||||
|
|
||||||
nPrevious.setAttribute('tabindex', '0');
|
var sAppend = (!oSettings.bJUI) ?
|
||||||
nNext.setAttribute('tabindex', '0');
|
'<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"></a>'+
|
||||||
|
'<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"></a>'
|
||||||
|
:
|
||||||
|
'<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
|
||||||
|
'<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
|
||||||
|
$(nPaging).append( sAppend );
|
||||||
|
|
||||||
nPrevious.title = oSettings.oLanguage.oPaginate.sPrevious;
|
var els = $('a', nPaging);
|
||||||
nNext.title = oSettings.oLanguage.oPaginate.sNext;
|
var nPrevious = els[0],
|
||||||
|
nNext = els[1]
|
||||||
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,37 +10006,30 @@
|
|||||||
*/
|
*/
|
||||||
"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 ) )
|
||||||
{
|
{
|
||||||
fnCallbackDraw( oSettings );
|
fnCallbackDraw( oSettings );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -21,41 +21,26 @@ $.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 ) )
|
||||||
{
|
{
|
||||||
fnCallbackDraw( oSettings );
|
fnCallbackDraw( oSettings );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Store the next and previous elements in the oSettings object as they can be very
|
|
||||||
* useful for automation - particularly testing
|
|
||||||
*/
|
|
||||||
nPrevious = document.createElement( 'a' );
|
|
||||||
nNext = document.createElement( 'a' );
|
|
||||||
if ( oSettings.bJUI )
|
|
||||||
{
|
|
||||||
nNextInner = document.createElement('span');
|
|
||||||
nNextInner.className = oSettings.oClasses.sPageJUINext;
|
|
||||||
nNext.appendChild( nNextInner );
|
|
||||||
|
|
||||||
nPreviousInner = document.createElement('span');
|
|
||||||
nPreviousInner.className = oSettings.oClasses.sPageJUIPrev;
|
|
||||||
nPrevious.appendChild( nPreviousInner );
|
|
||||||
}
|
|
||||||
|
|
||||||
nPrevious.className = oSettings.oClasses.sPagePrevDisabled;
|
|
||||||
nNext.className = oSettings.oClasses.sPageNextDisabled;
|
|
||||||
|
|
||||||
nPrevious.setAttribute('tabindex', '0');
|
var sAppend = (!oSettings.bJUI) ?
|
||||||
nNext.setAttribute('tabindex', '0');
|
'<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"></a>'+
|
||||||
|
'<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"></a>'
|
||||||
|
:
|
||||||
|
'<a tabindex="0" title="'+oLang.sPrevious+'" class="'+oSettings.oClasses.sPagePrevDisabled+'"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
|
||||||
|
'<a tabindex="0" title="'+oLang.sNext+'" class="'+oSettings.oClasses.sPageNextDisabled+'"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
|
||||||
|
$(nPaging).append( sAppend );
|
||||||
|
|
||||||
nPrevious.title = oSettings.oLanguage.oPaginate.sPrevious;
|
var els = $('a', nPaging);
|
||||||
nNext.title = oSettings.oLanguage.oPaginate.sNext;
|
var nPrevious = els[0],
|
||||||
|
nNext = els[1]
|
||||||
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,37 +122,30 @@ $.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 ) )
|
||||||
{
|
{
|
||||||
fnCallbackDraw( oSettings );
|
fnCallbackDraw( oSettings );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user