mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-20 16:21:26 +02:00
@@ -70,6 +70,8 @@ class JavascriptRenderer
|
|||||||
|
|
||||||
protected $ajaxHandlerBindToJquery = true;
|
protected $ajaxHandlerBindToJquery = true;
|
||||||
|
|
||||||
|
protected $ajaxHandlerBindToXHR = false;
|
||||||
|
|
||||||
protected $openHandlerClass = 'PhpDebugBar.OpenHandler';
|
protected $openHandlerClass = 'PhpDebugBar.OpenHandler';
|
||||||
|
|
||||||
protected $openHandlerUrl;
|
protected $openHandlerUrl;
|
||||||
@@ -446,6 +448,27 @@ class JavascriptRenderer
|
|||||||
return $this->ajaxHandlerBindToJquery;
|
return $this->ajaxHandlerBindToJquery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether to call bindToXHR() on the ajax handler
|
||||||
|
*
|
||||||
|
* @param boolean $bind
|
||||||
|
*/
|
||||||
|
public function setBindAjaxHandlerToXHR($bind = true)
|
||||||
|
{
|
||||||
|
$this->ajaxHandlerBindToXHR = $bind;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether bindToXHR() will be called on the ajax handler
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isAjaxHandlerBoundToXHR()
|
||||||
|
{
|
||||||
|
return $this->ajaxHandlerBindToXHR;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the class name of the js open handler
|
* Sets the class name of the js open handler
|
||||||
*
|
*
|
||||||
@@ -817,7 +840,9 @@ class JavascriptRenderer
|
|||||||
|
|
||||||
if ($this->ajaxHandlerClass) {
|
if ($this->ajaxHandlerClass) {
|
||||||
$js .= sprintf("%s.ajaxHandler = new %s(%s);\n", $this->variableName, $this->ajaxHandlerClass, $this->variableName);
|
$js .= sprintf("%s.ajaxHandler = new %s(%s);\n", $this->variableName, $this->ajaxHandlerClass, $this->variableName);
|
||||||
if ($this->ajaxHandlerBindToJquery) {
|
if ($this->ajaxHandlerBindToXHR) {
|
||||||
|
$js .= sprintf("%s.ajaxHandler.bindToXHR();\n", $this->variableName);
|
||||||
|
} else if ($this->ajaxHandlerBindToJquery) {
|
||||||
$js .= sprintf("if (jQuery) %s.ajaxHandler.bindToJquery(jQuery);\n", $this->variableName);
|
$js .= sprintf("if (jQuery) %s.ajaxHandler.bindToJquery(jQuery);\n", $this->variableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1078,6 +1078,26 @@ if (typeof(PhpDebugBar) == 'undefined') {
|
|||||||
self.handle(xhr);
|
self.handle(xhr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches an event listener to XMLHttpRequest
|
||||||
|
*
|
||||||
|
* @this {AjaxHandler}
|
||||||
|
*/
|
||||||
|
bindToXHR: function() {
|
||||||
|
var self = this;
|
||||||
|
var proxied = XMLHttpRequest.prototype.open;
|
||||||
|
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
|
||||||
|
var xhr = this;
|
||||||
|
this.addEventListener("readystatechange", function() {
|
||||||
|
var skipUrl = self.debugbar.openHandler ? self.debugbar.openHandler.get('url') : null;
|
||||||
|
if (xhr.readyState == 4 && url.indexOf(skipUrl) !== 0) {
|
||||||
|
self.handle(xhr);
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
proxied.apply(this, Array.prototype.slice.call(arguments));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user