1 // © Benoît PIN 2006-2009
7 /* Ajax for everything : if an click event has not been intercepted before */
13 var reProtocol
= /^\s*[a-z]+:/;
15 AjaxLinkHandler = function(locationPollInterval
) {
16 var thisHandler
= this;
17 this.previousHash
= '#' + location
.href
;
18 location
.hash
= location
.href
;
19 setInterval(function(){thisHandler
.checkLocation();}, locationPollInterval
)
20 addListener(document
.body
, 'click', function(evt
){thisHandler
.handleClick(evt
);});
21 if (browser
.isIE55
|| browser
.isIE6up
) {
22 var ie_historyFrm
= document
.createElement('iframe');
23 ie_historyFrm
.setAttribute('src', portal_url() + '/scrape_ie_history');
24 with (ie_historyFrm
.style
) {
33 document
.body
.appendChild(ie_historyFrm
);
34 this.historyFrame
= ie_historyFrm
;
38 AjaxLinkHandler
.prototype.checkLocation = function() {
39 if ((this.previousHash
!= location
.hash
) && location
.hash
) {
40 var rawUrl
= unescape(location
.hash
.slice(1));
42 var urlHash
= rawUrl
.split('#');
44 var hash
= urlHash
[1];
46 var ajaxParams
='ajax=1&_browserObjectUrl=' + escape(absolute_url());
47 var urlQueryStart
= url
.indexOf('?');
48 if (urlQueryStart
!= -1)
49 url
+= '&' + ajaxParams
;
51 url
+= '?' + ajaxParams
;
54 var fi
= new FragmentImporter(url
);
56 var thisHandler
= this;
57 fi
.onAfterPopulate = function(){thisHandler
.loadHash('#' + hash
);};
62 window
.location
.href
= rawUrl
;
65 this.previousHash
= location
.hash
;
68 AjaxLinkHandler
.prototype.handleClick = function(evt
){
69 var target
= getTargetedObject(evt
);
70 while (target
.nodeName
!= 'A') {
71 target
= target
.parentNode
;
72 if (target
== document
.body
)
76 // prevent click glitches from IE :((
77 if (browser
.isIE55
|| browser
.isIE6up
) {
78 if (_disableRootClickHandler
)
81 _disableRootClickHandler
= true;
82 setTimeout("_disableRootClickHandler=false", 100);
90 var m
= reProtocol
.exec(target
.getAttribute('href', 2));
93 if (protocol
== location
.protocol
)
99 url
= absolute_url() + '/' + target
.getAttribute('href', 2);
104 url
= encodeURIComponent(url
);
105 var query
= target
.search
;
106 if ((query
&& query
.search("noajax=1") != -1) || target
.name
== 'noajax')
113 if (browser
.isIE55
|| browser
.isIE6up
) {
114 AjaxLinkHandler
.prototype.loadUrl = function(url
) {
115 if (location
.hash
.slice(1) == url
)
117 this.historyFrame
.contentWindow
.location
.search
= '?url=' + escape(url
);
118 location
.hash
= escape(url
);
122 AjaxLinkHandler
.prototype.loadUrl = function(url
) {
123 if (location
.hash
.slice(1) == url
)
125 location
.hash
= escape(url
);
129 AjaxLinkHandler
.prototype.loadHash = function(hash
) {
130 this.previousHash
= hash
;
131 location
.hash
= hash
;
134 AjaxLinkHandler
.prototype.ie_loadHistory = function(url
) {
135 location
.hash
= escape(url
);
138 function ajaxSubmitFormHandler(evt
) {
139 var target
= getTargetedObject(evt
);
140 if (target
.nodeName
== 'INPUT' && (target
.type
== 'submit' || target
.type
== 'image')) {
142 while (form
!= document
) {
143 form
= form
.parentNode
;
144 if (form
.nodeName
== 'FORM') {
145 var fm
= new FormManager(form
, document
.getElementById("mainCell"));
146 fm
.submitButton
= target
;
147 //disableDefault(evt);
155 function _addRootHandlers() {
156 if ((AJAX_CONFIG
& 1) == 1) {
157 window
.linkHandler
= new AjaxLinkHandler(200);
158 if (browser
.isIE55
|| browser
.isIE6up
) {
159 _disableRootClickHandler
= false;
162 if ((AJAX_CONFIG
& 2) == 2) {
163 addListener(document
, 'click', ajaxSubmitFormHandler
);
167 registerStartupFunction(_addRootHandlers
);