Merge pull request #2366 from lijunle/jquery-pjax

Definition for jquery.pjax plugin.
This commit is contained in:
Masahiro Wakame
2014-06-19 16:35:20 +09:00
3 changed files with 205 additions and 1 deletions
+3 -1
View File
@@ -157,9 +157,11 @@ All definitions files include a header with the author and editors, so at some p
* [jQuery.joyride](http://zurb.com/playground/jquery-joyride-feature-tour-plugin) (by [Vincent Bortone](https://github.com/vbortone))
* [jQuery.jSignature](https://github.com/willowsystems/jSignature) (by [Patrick Magee](https://github.com/pjmagee))
* [jQuery.noty](http://needim.github.io/noty/) (by [Aaron King](https://github.com/kingdango/))
* [jQuery.pickadate](https://github.com/amsul/pickadate.js) (by [Theodore Brown](https://github.com/theodorejb))
* [jQuery.payment](http://needim.github.io/noty/) (by [Eric J. Smith](https://github.com/ejsmith/))
* [jQuery.pickadate](https://github.com/amsul/pickadate.js) (by [Theodore Brown](https://github.com/theodorejb))
* [jQuery.pjax](https://github.com/defunkt/jquery-pjax) (by [Junle Li](https://github.com/lijunle))
* [jQuery.pnotify](http://sciactive.github.io/pnotify/) (by [David Sichau](https://github.com/DavidSichau/))
* [jQuery.postMessage](http://benalman.com/projects/jquery-postmessage-plugin/) (by [Junle Li](https://github.com/lijunle))
* [jQuery.scrollTo](https://github.com/flesler/jquery.scrollTo) (by [Neil Stalker](https://github.com/nestalk/))
* [jQuery.simplePagination](https://github.com/flaviusmatis/simplePagination.js) (by [Natan Vivo](https://github.com/nvivo/))
* [jquery.superLink](http://james.padolsey.com/demos/plugins/jQuery/superLink/superlink.jquery.js) (by [Blake Niemyjski](https://github.com/niemyjski))
+60
View File
@@ -0,0 +1,60 @@
/// <reference path="jquery.pjax.d.ts" />
/// <reference path="../jquery/jquery.d.ts" />
function test_fn_pjax() {
$(document).pjax("a");
$(document).pjax("a", "#pjax-container");
$(document).pjax("a", { push: true });
$(document).pjax("a", "#pjax-container", { push: true });
}
function test_pjax() {
$.pjax();
$.pjax({
url: "hello.html",
container: "#main"
});
}
function test_click() {
var event = $.Event("click");
$.pjax.click(event, "#pjax-container");
$.pjax.click(event, { container: "#pjax-container" });
$.pjax.click(event, "#pjax-container", { push: true });
}
function test_submit() {
var event = $.Event("submit");
$.pjax.submit(event, "#pjax-container");
$.pjax.submit(event, { container: "#pjax-container" });
$.pjax.submit(event, "#pjax-container", { push: true });
}
function test_enable() {
$.pjax.enable();
}
function test_disable() {
$.pjax.disable();
}
function test_reload() {
$.pjax.reload();
}
function test_defauluts() {
$.pjax.defaults = {
timeout: 650,
push: true,
replace: false,
type: 'GET',
dataType: 'html',
scrollTo: 0,
maxCacheLength: 20,
version: $.noop
};
}
function test_support() {
console.log($.support.pjax);
}
+142
View File
@@ -0,0 +1,142 @@
// Type definitions for jquery-pjax
// Project: https://github.com/defunkt/jquery-pjax
// Definitions by: Junle Li <https://github.com/lijunle>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
interface PjaxSettings extends JQueryAjaxSettings {
/**
* A jQuery selector indicates where to stick the response body. E.g., $(container).html(xhr.responseBody).
* If it is not defined, the `data-pjax` attribute of the link will be treated as container.
* If such an attribute is not defined too, the context will be treated as container.
*/
container?: string;
/**
* Whether to pushState the URL. Defaults to true.
*/
push?: boolean;
/**
* Whether to replaceState the URL. Defaults to false.
*/
replace?: boolean;
}
interface JQuery {
/**
* Tell PJAX to listen links with delegation selector that, when click on them, fetches the href with ajax into the container.
* Tries to make sure the back button and ctrl+click work the way you'd expect.
* If `options.container` is not defined, the `data-pjax` attribute of the link will be treated as container.
* If such an attribute is not defined too, the context runs with this statement will be treated as container.
* @param delegationSelector The selector to limit which links PJAX should listen on.
* @param options PJAX settings, which is a superset of jQuery AJAX settings. It includes the following specific options:
* - container: a jQuery selector indicates where to stick the response body. E.g., $(container).html(xhr.responseBody).
* - push: a boolean indicates whether to pushState the URL. Default is true.
* - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false.
* @return Returns the jQuery object
*/
pjax(delegationSelector: string, options?: PjaxSettings): JQuery;
/**
* Tell PJAX to listen links with delegation selector that, when click on them, fetches the href with ajax into the container.
* Tries to make sure the back button and ctrl+click work the way you'd expect.
* If `options.container` is not defined, the `data-pjax` attribute of the link will be treated as container.
* If such an attribute is not defined too, the context runs with this statement will be treated as container.
* @param delegationSelector The selector to limit which links PJAX should listen on.
* @param containerSelector A jQuery selector indicates where to stick the response body. E.g., $(containerSelector).html(xhr.responseBody).
* @param options PJAX settings, which is a superset of jQuery AJAX settings. It includes the following specific options:
* - container: a jQuery selector indicates where to stick the response body. The `containerSelector` parameter has priority.
* - push: a boolean indicates whether to pushState the URL. Default is true.
* - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false.
* @return Returns the jQuery object
*/
pjax(delegationSelector: string, containerSelector?: string, options?: PjaxSettings): JQuery;
}
interface JQueryStatic {
pjax: PjaxStatic;
}
interface PjaxStatic {
/**
* PJAX default settings.
*/
defaults: PjaxSettings;
/**
* Loads a URL with ajax, puts the response body inside a container, then pushState()'s the loaded URL.
* Works just like $.ajax in that it accepts a jQuery ajax settings object (with keys like url, type, data, etc).
* @param options PJAX settings, which is a superset of jQuery AJAX settings. It includes the following specific options:
* - container: a jQuery selector indicates where to stick the response body. E.g., $(container).html(xhr.responseBody).
* - push: a boolean indicates whether to pushState the URL. Default is true.
* - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false.
*/
(options?: PjaxSettings): JQueryXHR;
/**
* PJAX on click handler.
* @param event A jQuery click event.
* @param options PJAX settings, which is a superset of jQuery AJAX settings. It includes the following specific options:
* - container: a jQuery selector indicates where to stick the response body. E.g., $(container).html(xhr.responseBody).
* - push: a boolean indicates whether to pushState the URL. Default is true.
* - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false.
*/
click(event: JQueryEventObject, options?: PjaxSettings): void;
/**
* PJAX on click handler.
* @param event A jQuery click event.
* @param containerSelector A jQuery selector indicates where to stick the response body. E.g., $(containerSelector).html(xhr.responseBody).
* @param options PJAX settings, which is a superset of jQuery AJAX settings. It includes the following specific options:
* - container: a jQuery selector indicates where to stick the response body. The `containerSelector` parameter has priority.
* - push: a boolean indicates whether to pushState the URL. Default is true.
* - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false.
*/
click(event: JQueryEventObject, containerSelector?: string, options?: PjaxSettings): void;
/**
* PJAX on form submit handler
* @param event A jQuery click event.
* @param options PJAX settings, which is a superset of jQuery AJAX settings. It includes the following specific options:
* - container: a jQuery selector indicates where to stick the response body. E.g., $(container).html(xhr.responseBody).
* - push: a boolean indicates whether to pushState the URL. Default is true.
* - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false.
*/
submit(event: JQueryEventObject, options?: PjaxSettings): void;
/**
* PJAX on form submit handler
* @param event A jQuery click event.
* @param containerSelector A jQuery selector indicates where to stick the response body. E.g., $(containerSelector).html(xhr.responseBody).
* @param options PJAX settings, which is a superset of jQuery AJAX settings. It includes the following specific options:
* - container: a jQuery selector indicates where to stick the response body. The `containerSelector` parameter has priority.
* - push: a boolean indicates whether to pushState the URL. Default is true.
* - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false.
*/
submit(event: JQueryEventObject, containerSelector?: string, options?: PjaxSettings): void;
/**
* Install pjax functions on $.pjax to enable pushState behavior. Does nothing if already enabled.
*/
enable(): void;
/**
* Disable pushState behavior.
* This is the case when a browser doesn't support pushState. It is sometimes useful to disable pushState for debugging on a modern browser.
*/
disable(): void;
/**
* Reload current page with pjax.
*/
reload(): JQueryXHR;
}
interface JQuerySupport {
/**
* A boolean value indicates if pjax is supported by the browser.
*/
pjax: boolean;
}