forked from MarkLodato/visual-git-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visual-git-guide.js
41 lines (41 loc) · 1.24 KB
/
visual-git-guide.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Webkit browsers can't zoom properly with object tags.
if (navigator.userAgent.indexOf("AppleWebKit") > -1) {
replacePNG = function(img, src) {
var h = img.height, w = img.width;
img.src = src;
img.height = h;
img.width = w;
return 0;
}
} else {
replacePNG = function(img, src) {
var p = img.parentNode;
var obj = document.createElement('object');
obj.type = 'image/svg+xml';
obj.data = src;
obj.width = img.width;
obj.height = img.height;
p.appendChild(obj);
p.removeChild(img);
return -1;
}
}
var svg_disabled = window.location.search.indexOf("no-svg") > 0;
// Replace all the PNGs with SVGs on browsers that support them.
function replace_all_PNGs() {
var hasSVG = document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1");
if (hasSVG) {
if (svg_disabled) {
document.getElementById('link-to-svg').style.display = 'block';
return;
}
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
var img = images[i];
var src = img.src.match(/^(.*\.svg)\.png$/)
if (src)
i += replacePNG(img, src[1]);
}
document.getElementById('link-to-png').style.display = 'block';
}
}