Skip to content

Commit ed8f5c8

Browse files
committed
bug #13729 Fix the toolbar JS for IE (stof)
This PR was merged into the 2.6 branch. Discussion ---------- Fix the toolbar JS for IE | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | n/a - fix the binding of listeners on XMLHttpRequest to always use the addEventListener method. It does not make sense to change it to attachEvent as it is about binding listeners on DOM elements. - fix the feature detection for the event binding on DOM elements: - the attachEvent and addEventListener methods are on DOM elements, not on the document object - the standard method should be preferred in IE versions supporting both methods - avoid JS errors when XMLHttpRequest is not defined by avoiding to override its open method when the object is not there (old IE versions will still not intercept ajax calls though) this is the complete fix for the code submitted in #13636 (the fix in symfony/symfony#13684 was incomplete). Commits ------- b7aa171 Fix the toolbar JS for IE
2 parents 075002a + b7aa171 commit ed8f5c8

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base_js.html.twig

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@
173173
174174
var addEventListener;
175175
176-
if (document.attachEvent) {
176+
var el = document.createElement('div');
177+
if (!'addEventListener' in el) {
177178
addEventListener = function (element, eventName, callback) {
178179
element.attachEvent('on' + eventName, callback);
179180
};
@@ -184,40 +185,42 @@
184185
}
185186
186187
{% if excluded_ajax_paths is defined %}
187-
var proxied = XMLHttpRequest.prototype.open;
188-
189-
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
190-
var self = this;
191-
192-
/* prevent logging AJAX calls to static and inline files, like templates */
193-
if (url.substr(0, 1) === '/' && !url.match(new RegExp("{{ excluded_ajax_paths }}"))) {
194-
var stackElement = {
195-
loading: true,
196-
error: false,
197-
url: url,
198-
method: method,
199-
start: new Date()
200-
};
201-
202-
requestStack.push(stackElement);
203-
204-
addEventListener(this, 'readystatechange', function() {
205-
if (self.readyState == 4) {
206-
stackElement.duration = new Date() - stackElement.start;
207-
stackElement.loading = false;
208-
stackElement.error = self.status < 200 || self.status >= 400;
209-
stackElement.profile = self.getResponseHeader("X-Debug-Token");
210-
stackElement.profilerUrl = self.getResponseHeader("X-Debug-Token-Link");
211-
212-
Sfjs.renderAjaxRequests();
213-
}
214-
});
188+
if (window.XMLHttpRequest) {
189+
var proxied = XMLHttpRequest.prototype.open;
190+
191+
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
192+
var self = this;
193+
194+
/* prevent logging AJAX calls to static and inline files, like templates */
195+
if (url.substr(0, 1) === '/' && !url.match(new RegExp("{{ excluded_ajax_paths }}"))) {
196+
var stackElement = {
197+
loading: true,
198+
error: false,
199+
url: url,
200+
method: method,
201+
start: new Date()
202+
};
203+
204+
requestStack.push(stackElement);
205+
206+
this.addEventListener('readystatechange', function() {
207+
if (self.readyState == 4) {
208+
stackElement.duration = new Date() - stackElement.start;
209+
stackElement.loading = false;
210+
stackElement.error = self.status < 200 || self.status >= 400;
211+
stackElement.profile = self.getResponseHeader("X-Debug-Token");
212+
stackElement.profilerUrl = self.getResponseHeader("X-Debug-Token-Link");
213+
214+
Sfjs.renderAjaxRequests();
215+
}
216+
}, false);
215217
216-
Sfjs.renderAjaxRequests();
217-
}
218+
Sfjs.renderAjaxRequests();
219+
}
218220
219-
proxied.apply(this, Array.prototype.slice.call(arguments));
220-
};
221+
proxied.apply(this, Array.prototype.slice.call(arguments));
222+
};
223+
}
221224
{% endif %}
222225
223226
return {

0 commit comments

Comments
 (0)