SVGInline code. YAAAAY. Also Category theory talk.

This commit is contained in:
Oliver Kennedy 2018-01-23 23:19:33 -05:00
parent d31acd98ac
commit 5148cf8bc7
2 changed files with 1219 additions and 0 deletions

View file

@ -0,0 +1,38 @@
// Courtesy of...
// https://github.com/flying-sheep/revealjs-template/blob/master/src/data-src-svg.js
// as per
// https://github.com/hakimel/reveal.js/issues/1258
'use strict';
(function() {
var svgsToLoad = document.querySelectorAll('svg[data-src]');
console.log(svgsToLoad)
var loadSVGs = Array.map(svgsToLoad, function (svg) {
fetch(svg.getAttribute('data-src')).then(function (response) {
return response.text();
}).then(function (svgCode) {
var svgDoc = new DOMParser().parseFromString(svgCode, 'image/svg+xml');
var newSVG = svgDoc.documentElement;
for (var i = 0; i < svg.attributes.length; i++) {
var attr = svg.attributes[i];
newSVG.setAttribute(attr.name, attr.value);
}
svg.parentNode.replaceChild(newSVG, svg);
});
});
Promise.all(loadSVGs).then(function (val) {
var stretchSVGs = document.querySelectorAll('svg.stretch:not([preserveAspectRatio])');
Array.call(stretchSVGs, function (svg) {
if (!svg.hasAttribute('viewBox')) {
var w = svg.getAttribute('width');
var h = svg.getAttribute('height');
svg.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
}
svg.setAttribute('preserveAspectRatio', 'xMidYMid meet');
});
});
})()

File diff suppressed because it is too large Load diff