mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 15:25:26 +00:00
title tags must come before any svg tags to update the title
fixes https://github.com/bigskysoftware/htmx/issues/459
This commit is contained in:
parent
78b2bddab0
commit
bdefbd4fec
@ -692,11 +692,15 @@ return (function () {
|
||||
|
||||
var TITLE_FINDER = /<title>([\s\S]+?)<\/title>/im;
|
||||
function findTitle(content) {
|
||||
if(content.indexOf('<title>') > -1 &&
|
||||
(content.indexOf('<svg>') == -1 ||
|
||||
content.indexOf('<title>') < content.indexOf('<svg>'))) {
|
||||
var result = TITLE_FINDER.exec(content);
|
||||
if (result) {
|
||||
return result[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function selectAndSwap(swapStyle, target, elt, responseText, settleInfo) {
|
||||
var title = findTitle(responseText);
|
||||
|
@ -789,6 +789,33 @@ describe("Core htmx AJAX Tests", function(){
|
||||
window.document.title.should.equal("htmx rocks!");
|
||||
});
|
||||
|
||||
it('svg title tags do not update title', function()
|
||||
{
|
||||
var originalTitle = window.document.title
|
||||
this.server.respondWith("GET", "/test", function (xhr) {
|
||||
xhr.respond(200, {}, "<svg><title>" + originalTitle + "UPDATE" + "</title></svg>Clicked!");
|
||||
});
|
||||
var btn = make('<button hx-get="/test">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerText.should.equal("Clicked!");
|
||||
window.document.title.should.equal(originalTitle);
|
||||
});
|
||||
|
||||
it('title tags before svg title tags do update title', function()
|
||||
{
|
||||
var originalTitle = window.document.title
|
||||
var newTitle = originalTitle + "!!!";
|
||||
this.server.respondWith("GET", "/test", function (xhr) {
|
||||
xhr.respond(200, {}, "<title>" + newTitle + "</title><svg><title>foo</title></svg>Clicked!");
|
||||
});
|
||||
var btn = make('<button hx-get="/test">Click Me!</button>')
|
||||
btn.click();
|
||||
this.server.respond();
|
||||
btn.innerText.should.equal("Clicked!");
|
||||
window.document.title.should.equal(newTitle);
|
||||
});
|
||||
|
||||
it('title update does not URL escapte', function()
|
||||
{
|
||||
this.server.respondWith("GET", "/test", function (xhr) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user