PageSourceSearch

https://www.npharm.org/js/svgeezy.js

js npharm.org collected 2026-10-05 20:40:20 UTC 1,614 bytes, 69 lines download raw bytes

1/*
2 * SVGeezy.js
3 *
4 * Copyright 2016, Ben Howdle http://benhowdle.im
5 *
6 * Date: Sun Aug 26 20:38 2012 GMT
7 */
8
9/*
10	//call like so, pass in a class name that you don't want it to check and a filetype to replace .svg with
11	svgeezy.init('nocheck', 'png');
12*/
13
14window.svgeezy = function() {
15
16	return {
17
18		init: function(avoid, filetype, forceFallbackAlways) {
19			this.avoid = avoid || false;
20			this.filetype = filetype || 'png';
21			this.svgSupport = false;
22			if (!forceFallbackAlways) {
23				this.svgSupport = this.supportsSvg();
24			}
25			if(!this.svgSupport) {
26				this.images = document.getElementsByTagName('img');
27				this.imgL = this.images.length;
28				this.fallbacks();
29			}
30		},
31
32		fallbacks: function() {
33			if (this.imgL == 0) {
34				return;
35			}
36			while(--this.imgL) {
37				if(this.avoid && this.hasClass(this.images[this.imgL], this.avoid)) {
38					continue;
39				}
40				var src = this.images[this.imgL].getAttribute('src');
41				if(src === null || this.getFileExt(src) != 'svg') {
42					continue;
43				}
44				var newSrc = src.replace('.svg', '.' + this.filetype);
45				this.images[this.imgL].setAttribute('src', newSrc);
46				
47			}
48		},
49
50		getFileExt: function(src) {
51			var ext = src.split('.').pop();
52
53			if(ext.indexOf("?") !== -1) {
54				ext = ext.split('?')[0];
55			}
56
57			return ext;
58		},
59
60		hasClass: function(element, cls) {
61			return(' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
62		},
63
64		supportsSvg: function() {
65			return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1");
66		}
67	};
68
69}();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.