﻿/***********************************************************************************************jPager v 1.1.2 10/26/2010 - written by Eric Rolnicki Description: simple pager will intercept page links and turn them into ajax links also can work with buttons for a form Dependencies: 	jquery lib v 1.2.6+ Useage: useage $(".page").jPager("#content-to-get", "content-to-replace", [{additionalAjaxParms}]); or $("#myForm :button").jPager("#content-to-get", "content-to-replace", [{additionalAjaxParms}]);- see below for ctor options***********************************************************************************************/(function ($) {jQuery.fn.jPager = function (payload, target, options) {var trigger = this;var isButton = $(this).is("button");if (isButton)$(this).closest("form").submit(function () { return false; });var opts = $.extend({}, $.fn.jPager.defaults, options);$(trigger).live(opts.triggerEvent, function (e) {e.preventDefault();var url = opts.url.length > 0 ? opts.url : isButton ? $(this).closest("form").attr("action") : $(this).attr("href");var data = isButton ? ($(this).attr("name").length) ?$(this).attr("name") + "=" + $(this).attr("value") + "&" + $(this).closest("form").serialize() : $(this).closest("form").serialize() : opts.data;var type = isButton ? $(this).closest("form").attr("method") : opts.type;if (url) {$.ajax({url: url,async: opts.async,beforeSend: opts.beforeSend,cache: opts.cache,complete: opts.complete,contentType: opts.contentType,data: data,dataType: opts.dataType,error: opts.error,password: opts.password,timeout: opts.timeout,type: type,username: opts.username,success: function (rspnse) {if (opts.dataType = "html") {var $data = $("<div>" + rspnse.replace(/<script(.|\s)*?\/script>/gi, "") + "</div>");$(target).html($(payload, $data).html());if (type == "GET") window.location.hash = data.length > 0 ? url + "?" + data : url;}else {$(target).html(opts.parseJson($.parseJSON(rspnse)));}}});}return false;});};$.fn.jPager.defaults = {triggerEvent: 'click',async: true,beforeSend: function (XMLHttpRequest) { },cache: true,complete: function (XMLHttpRequest, textStatus) { },contentType: "application/x-www-form-urlencoded",data: "",dataType: "html",error: function (XMLHttpRequest, textStatus, errorThrown) { },parseJson: function (rawJson) { },password: "",timeout: 5000,type: "GET",url: "",username: ""};})(jQuery);
