1var FRB = FRB || {}; 2FRB.svgImgToInlineSvg = (function() 3{ 4 function clearIdsFromChildren(domObject) 5 { 6 /// <summary> 7 /// Removes any id attributes from the object and recursively through its children property. 8 /// </summary> 9 /// <param name="domObject">(object) The jQuery DOM object.</param> 10 11 // Change the id of the current object 12 domObject.prop("id", domObject.prop("id") + "-" + Math.floor((Math.random() * 1000) + 1)); 13 14 // Does this have any children 15 if (domObject.children().length === 0) { 16 domObject.siblings().each(function () { 17 $(this).prop("id", $(this).prop("id") + "-" + Math.floor((Math.random() * 1000) + 1)); 18 }); 19 return; 20 } 21 22 // Do recursion 23 clearIdsFromChildren(domObject.children()); 24 } 25 26 function doReplace(svgImgSelector) 27 { 28 var svgsArr = $(svgImgSelector); 29 //console.log('going to replace ' + svgsArr.length + ' svg images with inline svgs, selector: ' + svgImgSelector); 30 svgsArr.each(function() 31 { 32 var $img = $(this); 33 var imgId = $img.attr("id"); 34 var imgClass = $img.attr("class"); 35 var imgUrl = $img.attr("src"); 36 37 $.get(imgUrl, function(data) 38 { 39 // Get the svg tag, ignore the rest 40 var $svg = $(data).find("svg"); 41 42 // Add replaced image's id to the new svg 43 if (typeof imgId !== "undefined") 44 { 45 $svg = $svg.attr("id", imgId); 46 } 47 48 // Add replaced image's classes to the new svg 49 if (typeof imgClass !== "undefined") 50 { 51 $svg = $svg.attr("class", imgClass + " replaced-svg"); 52 } 53 54 // Remove any invalid xml tags as per http://validator.w3.org 55 $svg = $svg.removeAttr("xmlns:a"); 56 57 // Clear any 508 information from image editor 58 $svg.find("desc").remove(); 59 $svg.find("title").remove(); 60 $svg.find("defs").remove(); 61 62 // This is to remove any comments supplied by the image 63 $svg.contents().filter(function() 64 { 65 return this.nodeType === 8; 66 }).each(function() 67 { 68 $(this).remove(); 69 }); 70 71 // 508 compliance 72 clearIdsFromChildren($svg.children()); 73 74 // Replace image with new svg 75 $img.replaceWith($svg); 76 }, "xml"); 77 }); 78 } 79 80 return { 81 replaceSvgImgWithSvgInline: doReplace 82 }; 83})(); 84 85$(document).ready(function() { 86 FRB.svgImgToInlineSvg.replaceSvgImgWithSvgInline(".svg-get-data"); 87});
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.