$.fn.extend({ JPager: function (cfg, pageIndex, pageSize) { if (cfg && pageIndex > 0 && pageSize>0) { var token = "#" this.attr("id"); this.empty(); var pageFirst = function () { $(token).JPager(cfg, 1, pageSize); };
var pagePre = function () { $(token).JPager(cfg, pageIndex - 1, pageSize); };
var pageLast = function () { $(token).JPager(cfg, parseInt($("#_tot").val()), pageSize); };
var pageNext = function () { $(token).JPager(cfg, pageIndex 1, pageSize); };
var pageNumber = function () { $(token).JPager(cfg, parseInt($(this).text()), pageSize); };
var pageGo = function () { var index = parseInt($("#_pos").val()); var total = parseInt($("#_tot").val()); if (index) { if (index > total) { $(token).JPager(cfg, total, pageSize); } else if (index < 1) { $(token).JPager(cfg, 1, pageSize); } else { $(token).JPager(cfg, index, pageSize); } } }; var checkGoNumber = function () { if (!Number(this.value)) { this.value = ""; } else { this.value = Number(this.value); } }; var initCustomer = function (recordCount) { if (cfg.customer) { if (cfg.customer.template) { var t = cfg.customer.template; t = t.replace(/%total%/gi, Math.ceil(recordCount / pageSize)).replace(/%current%/gi, pageIndex).replace(/%recordCount%/gi, recordCount).replace(/%pageSize%/gi, pageSize); if (cfg.customer.position == "right") { $("#_right").after(t); } else { $("#_left").before(t); } } } };
var changeState = function (total) { if (pageIndex == 1) { $("#_first").attr("class", "unable"); $("#_pre").attr("class", "unable"); } else { $("#_first").bind("click", pageFirst).attr("class", "number"); $("#_pre").bind("click", pagePre).attr("class", "number"); } if (pageIndex == total) { $("#_last").attr("class", "unable"); $("#_next").attr("class", "unable"); } else { $("#_last").bind("click", pageLast).attr("class", "number"); $("#_next").bind("click", pageNext).attr("class", "number"); } }; var initNumber = function (total, count, current) { if (total > 0 && count > 0) { if (current < 1) { current = 1; } if (current > total) { current = total; } var endIndex = total; var startIndex = 1; var temp = current Math.floor(count / 2); if (temp < total) { if (temp < count) { endIndex = count; } else { startIndex = temp - count 1; endIndex = temp; } } else { if (total > count) { startIndex = total - count 1; } } $("#_number").empty(); for (var i = startIndex; i <= endIndex; i ) { var html = $("").text(i).bind("click", pageNumber); if (i == current) { $("#_number").append(html.attr("class", "selected")); } else { $("#_number").append(html.attr("class", "number")); } } } };
var initPager = function (data) { if ($.isArray(data.SearchResult) && data.RecordCount > 0) { $(token).append("首页上一页下一页末页"); var total = Math.ceil(data.RecordCount / pageSize); $("#_tot").val(total); $("#_pos").bind("blur", checkGoNumber); $("#_to").bind("click", pageGo);