diff -u b/core/misc/ajax.es6.js b/core/misc/ajax.es6.js --- b/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -1036,8 +1036,24 @@ // Apply any settings from the returned JSON if available. const settings = response.settings || ajax.settings || drupalSettings; + // Store SVG elements + const svgStorage = {}; + // Parse response.data into an element collection. - const $newContent = $($.parseHTML(response.data, true)); + const $newContent = $($.parseHTML(response.data, true).map((element) => { + // If the response contains an SVG, replace it with a placeholder. + if (element.nodeName && element.nodeName === 'svg') { + // Create an ID to reference later. + const hash = `svg-${Math.random().toString(36).substring(7)}`; + svgStorage[hash] = element.outerHTML; + + // Create a plceholder DIV that will be replaced with the SVG. + const svgPlaceHolder = document.createElement('div'); + svgPlaceHolder.id = hash; + return svgPlaceHolder; + } + return element; + })); // If removing content from the wrapper, detach behaviors first. switch (method) { @@ -1055,6 +1071,14 @@ // Add the new content to the page. $wrapper[method]($newContent); + // If there is any SVG data, start replacing them. + if (Object.keys(svgStorage).length) { + Object.keys(svgStorage).forEach((key) => { + // Replace each placeholder DIV with the saved SVG data. + $(`#${key}`).replaceWith(svgStorage[key]); + }); + } + // Immediately hide the new content if we're using any effects. if (effect.showEffect !== 'show') { $newContent.hide(); diff -u b/core/misc/ajax.js b/core/misc/ajax.js --- b/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -487,7 +487,19 @@ var settings = response.settings || ajax.settings || drupalSettings; - var $newContent = $($.parseHTML(response.data, true)); + var svgStorage = {}; + + var $newContent = $($.parseHTML(response.data, true).map(function (element) { + if (element.nodeName && element.nodeName === 'svg') { + var hash = 'svg-' + Math.random().toString(36).substring(7); + svgStorage[hash] = element.outerHTML; + + var svgPlaceHolder = document.createElement('div'); + svgPlaceHolder.id = hash; + return svgPlaceHolder; + } + return element; + })); switch (method) { case 'html': @@ -503,6 +515,12 @@ $wrapper[method]($newContent); + if (Object.keys(svgStorage).length) { + Object.keys(svgStorage).forEach(function (key) { + $('#' + key).replaceWith(svgStorage[key]); + }); + } + if (effect.showEffect !== 'show') { $newContent.hide(); } @@ -599 +617 @@ -})(jQuery, window, Drupal, drupalSettings); +})(jQuery, window, Drupal, drupalSettings); \ No newline at end of file