/* * Copyright 2016, CMCC Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var serverPageTable = {}; /* Bootstrap style full number pagination control */ $.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ) { return { "iStart": oSettings._iDisplayStart, "iEnd": oSettings.fnDisplayEnd(), "iLength": oSettings._iDisplayLength, "iTotal": oSettings.fnRecordsTotal(), "iFilteredTotal": oSettings.fnRecordsDisplay(), "iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ), "iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength ) }; }; $.extend( $.fn.dataTableExt.oPagination, { "bootstrap_extended": { "fnInit": function( oSettings, nPaging, fnDraw ) { var oLang = oSettings.oLanguage.oPaginate; var oPaging = oSettings.oInstance.fnPagingInfo(); var fnClickHandler = function ( e ) { e.preventDefault(); if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) { fnDraw( oSettings ); } }; $(nPaging).append( '
' ); var els = $('a', nPaging); $(els[0]).bind('click.DT', { action: "previous" }, fnClickHandler ); $(els[1]).bind('click.DT', { action: "next" }, fnClickHandler); $('.pagination-panel-input', nPaging).bind('change.DT', function(e) { var oPaging = oSettings.oInstance.fnPagingInfo(); e.preventDefault(); var page = parseInt($(this).val()); if (page > 0 && page < oPaging.iTotalPages) { if ( oSettings.oApi._fnPageChange(oSettings, page-1) ) { fnDraw( oSettings ); } } else { $(this).val(oPaging.iPage + 1); } }); $('.pagination-panel-input', nPaging).bind('keypress.DT', function(e) { var oPaging = oSettings.oInstance.fnPagingInfo(); if (e.which == 13) { var page = parseInt($(this).val()); if (page > 0 && page < oSettings.oInstance.fnPagingInfo().iTotalPages) { if ( oSettings.oApi._fnPageChange(oSettings, page-1) ) { fnDraw( oSettings ); } } else { $(this).val(oPaging.iPage + 1); } e.preventDefault(); } }); }, "fnUpdate": function ( oSettings, fnDraw ) { var iListLength = 5; var oPaging = oSettings.oInstance.fnPagingInfo(); var an = oSettings.aanFeatures.p; var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2); if ( oPaging.iTotalPages < iListLength) { iStart = 1; iEnd = oPaging.iTotalPages; } else if ( oPaging.iPage <= iHalf ) { iStart = 1; iEnd = iListLength; } else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) { iStart = oPaging.iTotalPages - iListLength + 1; iEnd = oPaging.iTotalPages; } else { iStart = oPaging.iPage - iHalf + 1; iEnd = iStart + iListLength - 1; } for ( i=0, iLen=an.length ; i