47ac1d75ec47b107ef8b7a06839c1d48acd23701
1 // © Benoît PIN 2006-2013
7 /* Ajax for everything : if an click event has not been intercepted before */
13 var reProtocol
= /^\s*[a-z]+:/;
15 AjaxLinkHandler = function() {
17 addListener(document
.body
, 'click', function(evt
){self
.handleClick(evt
);});
18 addListener(window
, 'popstate', function(evt
){self
.handlePopState(evt
);});
21 AjaxLinkHandler
.prototype.handleClick = function(evt
){
22 var target
= getTargetedObject(evt
);
23 while (target
.nodeName
!= 'A') {
24 target
= target
.parentNode
;
25 if (target
== document
.body
)
34 var m
= reProtocol
.exec(target
.getAttribute('href', 2));
37 if (protocol
== location
.protocol
)
43 url
= absolute_url() + '/' + target
.getAttribute('href', 2);
47 var query
= target
.search
;
48 if ((query
&& query
.search("noajax=1") != -1) || target
.name
== 'noajax')
55 AjaxLinkHandler
.prototype.handlePopState = function (evt
, extra
) {
57 this.loadUrl(evt
.state
, true);
60 AjaxLinkHandler
.prototype.loadUrl = function(url
, noPush
) {
62 var ajaxParams
='ajax=1&_browserObjectUrl=' + escape(absolute_url());
63 var urlQueryStart
= url
.indexOf('?');
64 if (urlQueryStart
!= -1)
65 url
+= '&' + ajaxParams
;
67 url
+= '?' + ajaxParams
;
70 var fi
= new FragmentImporter(url
);
74 window
.location
.href
= rawUrl
;
78 history
.pushState(rawUrl
, '', rawUrl
)
81 function ajaxSubmitFormHandler(evt
) {
82 var target
= getTargetedObject(evt
);
83 if (target
.nodeName
== 'INPUT' && (target
.type
== 'submit' || target
.type
== 'image')) {
85 while (form
!= document
) {
86 form
= form
.parentNode
;
87 if (form
.nodeName
== 'FORM') {
88 var fm
= new FormManager(form
, document
.getElementById("mainCell"));
89 fm
.submitButton
= target
;
96 function _addRootHandlers() {
97 if ((AJAX_CONFIG
& 1) == 1 && history
.pushState
!== undefined) {
98 window
.linkHandler
= new AjaxLinkHandler(200);
100 if ((AJAX_CONFIG
& 2) == 2) {
101 addListener(document
, 'click', ajaxSubmitFormHandler
);
105 registerStartupFunction(_addRootHandlers
);