Commit 90a54b2f authored by Romain Courteaud's avatar Romain Courteaud

Support content type parameters.

Thanks to Caleb James DeLisle.
parent 1da1d7bb
...@@ -615,8 +615,9 @@ ...@@ -615,8 +615,9 @@
$.ajax(url) $.ajax(url)
.done(function (value, textStatus, jqXHR) { .done(function (value, textStatus, jqXHR) {
var klass, tmp_constructor, key; var klass, tmp_constructor, key;
if ((jqXHR.getResponseHeader("Content-Type") || "") if (/^text\/html[;]?/.test(
=== 'text/html') { jqXHR.getResponseHeader("Content-Type") || ""
)) {
try { try {
if (!gadget_model_dict.hasOwnProperty(url)) { if (!gadget_model_dict.hasOwnProperty(url)) {
......
...@@ -440,6 +440,37 @@ ...@@ -440,6 +440,37 @@
server.respond(); server.respond();
}); });
test('Content type parameter are supported', function () {
// Check that declareGadgetKlass does not fail if the page content type
// contains a parameter
var server = sinon.fakeServer.create(),
url = 'https://example.org/files/qunittest/test';
server.respondWith("GET", url, [200, {
"Content-Type": "text/html; charset=utf-8",
}, "<html></html>"]);
stop();
renderJS.declareGadgetKlass(url)
.done(function (Klass) {
var instance;
equal(Klass.prototype.path, url);
instance = new Klass();
ok(instance instanceof RenderJSGadget);
ok(instance instanceof Klass);
ok(Klass !== RenderJSGadget);
})
.fail(function (jqXHR, textStatus) {
ok(false, "Failed to load " + textStatus + " " + jqXHR.status);
})
.always(function () {
start();
});
server.respond();
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declareJS // declareJS
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment