Merge pull request #104 from Anderezekial/patch-4

Update input.js
pull/107/head
Allan Jardine 10 years ago
commit ce10e4342a

@ -33,8 +33,8 @@ $.fn.dataTableExt.oPagination.input = {
nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext; nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext;
nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast; nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast;
nFirst.className = "paginate_button first"; nFirst.className = "paginate_button first disabled";
nPrevious.className = "paginate_button previous"; nPrevious.className = "paginate_button previous disabled";
nNext.className="paginate_button next"; nNext.className="paginate_button next";
nLast.className = "paginate_button last"; nLast.className = "paginate_button last";
nOf.className = "paginate_of"; nOf.className = "paginate_of";
@ -61,54 +61,66 @@ $.fn.dataTableExt.oPagination.input = {
nPaging.appendChild( nNext ); nPaging.appendChild( nNext );
nPaging.appendChild( nLast ); nPaging.appendChild( nLast );
$(nFirst).click( function () { $(nFirst).click( function ()
oSettings.oApi._fnPageChange( oSettings, "first" ); {
fnCallbackDraw( oSettings ); var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
$(nFirst).addClass('disabled'); if (iCurrentPage != 1)
$(nPrevious).addClass('disabled'); {
$(nNext).removeClass('disabled'); oSettings.oApi._fnPageChange( oSettings, "first" );
$(nLast).removeClass('disabled'); fnCallbackDraw( oSettings );
$(nFirst).addClass('disabled');
$(nPrevious).addClass('disabled');
$(nNext).removeClass('disabled');
$(nLast).removeClass('disabled');
}
} ); } );
$(nPrevious).click( function() { $(nPrevious).click( function()
oSettings.oApi._fnPageChange( oSettings, "previous" ); {
fnCallbackDraw( oSettings );
var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
if (iCurrentPage == 1) if (iCurrentPage != 1)
{ {
$(nFirst).addClass('disabled'); oSettings.oApi._fnPageChange(oSettings, "previous");
$(nPrevious).addClass('disabled'); fnCallbackDraw(oSettings);
} if (iCurrentPage == 2)
else {
{ $(nFirst).addClass('disabled');
$(nNext).removeClass('disabled'); $(nPrevious).addClass('disabled');
$(nLast).removeClass('disabled'); }
$(nNext).removeClass('disabled');
$(nLast).removeClass('disabled');
} }
} ); } );
$(nNext).click( function() { $(nNext).click( function()
oSettings.oApi._fnPageChange( oSettings, "next" ); {
fnCallbackDraw( oSettings );
var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
if (iCurrentPage == (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength))) if (iCurrentPage != (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength)))
{
$(nNext).addClass('disabled');
$(nLast).addClass('disabled');
}
else
{ {
oSettings.oApi._fnPageChange(oSettings, "next");
fnCallbackDraw(oSettings);
if (iCurrentPage == (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1))
{
$(nNext).addClass('disabled');
$(nLast).addClass('disabled');
}
$(nFirst).removeClass('disabled'); $(nFirst).removeClass('disabled');
$(nPrevious).removeClass('disabled'); $(nPrevious).removeClass('disabled');
} }
} ); } );
$(nLast).click( function() { $(nLast).click( function()
oSettings.oApi._fnPageChange( oSettings, "last" ); {
fnCallbackDraw( oSettings ); var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
$(nFirst).removeClass('disabled'); if (iCurrentPage != (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength)))
$(nPrevious).removeClass('disabled'); {
$(nNext).addClass('disabled'); oSettings.oApi._fnPageChange(oSettings, "last");
$(nLast).addClass('disabled'); fnCallbackDraw(oSettings);
$(nFirst).removeClass('disabled');
$(nPrevious).removeClass('disabled');
$(nNext).addClass('disabled');
$(nLast).addClass('disabled');
}
} ); } );
$(nInput).keyup( function (e) { $(nInput).keyup( function (e) {
@ -126,29 +138,33 @@ $.fn.dataTableExt.oPagination.input = {
if ( this.value === "" || this.value.match(/[^0-9]/) ) if ( this.value === "" || this.value.match(/[^0-9]/) )
{ {
/* Nothing entered or non-numeric character */ /* Nothing entered or non-numeric character */
this.value = this.value.replace(/[^\d]/g, ''); // don't even allow anything but digits
return; return;
} }
var iNewStart = oSettings._iDisplayLength * (this.value - 1); var iNewStart = oSettings._iDisplayLength * (this.value - 1);
var iEndPosition = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength; if (iNewStart < 0)
if (iNewStart < 0)
{ {
iNewStart = 0; iNewStart = 0;
} }
if (iNewStart > oSettings.fnRecordsDisplay()) if (iNewStart > oSettings.fnRecordsDisplay())
{ {
iNewStart = iEndPosition; iNewStart = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
} }
if (iNewStart == 0) if (iNewStart == 0)
{ {
$(nFirst).addClass('disabled'); $(nFirst).addClass('disabled');
$(nPrevious).addClass('disabled'); $(nPrevious).addClass('disabled');
$(nNext).removeClass('disabled');
$(nLast).removeClass('disabled');
} }
else if (iNewStart == iEndPosition) else if (iNewStart == ((Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength))
{ {
$(nNext).addClass('disabled'); $(nNext).addClass('disabled');
$(nLast).addClass('disabled'); $(nLast).addClass('disabled');
$(nFirst).removeClass('disabled');
$(nPrevious).removeClass('disabled');
} }
else else
{ {
@ -165,6 +181,13 @@ $.fn.dataTableExt.oPagination.input = {
/* Take the brutal approach to cancelling text selection */ /* Take the brutal approach to cancelling text selection */
$('span', nPaging).bind( 'mousedown', function () { return false; } ); $('span', nPaging).bind( 'mousedown', function () { return false; } );
$('span', nPaging).bind( 'selectstart', function () { return false; } ); $('span', nPaging).bind( 'selectstart', function () { return false; } );
// If we can't page anyway, might as well not show it
var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
if(iPages <= 1)
{
$(nPaging).hide();
}
}, },
@ -177,14 +200,21 @@ $.fn.dataTableExt.oPagination.input = {
var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength); var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p; var an = oSettings.aanFeatures.p;
for ( var i=0, iLen=an.length ; i<iLen ; i++ ) if (iPages <= 1) // hide paging when we can't page
{
$(an).hide();
}
else
{ {
var spans = an[i].getElementsByTagName('span'); /* Loop over each instance of the pager */
var inputs = an[i].getElementsByTagName('input'); for (var i = 0, iLen = an.length ; i < iLen ; i++)
spans[3].innerHTML = " of "+iPages; {
inputs[0].value = iCurrentPage; var spans = an[i].getElementsByTagName('span');
var inputs = an[i].getElementsByTagName('input');
spans[3].innerHTML = " of " + iPages;
inputs[0].value = iCurrentPage;
}
} }
} }
}; };

Loading…
Cancel
Save