1/* 2 ************************* 3 SVG Convert 4 ************************* 5 6 --- 7 Developer(s) 8 --- 9 10 Jason Mayo 11 http://bymayo.co.uk 12 http://twitter.com/madebymayo 13 14*/ 15 16 // ------------------------ 17 // Build 18 // ------------------------ 19 20 (function ($) { 21 22 $.fn.svgConvert = function(options) { 23 24 // 25 // Settings 26 // 27 28 var pluginSettings = $.extend( 29 { 30 svgCleanupAttr: ['width','height','id','x','y','xmlns','xmlns:a','xmlns:xlink','xml:space','enable-background','version','style'], 31 imgIncludeAttr: true, 32 imgCleanupAttr: [], 33 removeClass: true, 34 addClass: 'svg-converted', 35 onComplete: function() {} 36 }, 37 options 38 ); 39 40 // 41 // Variables 42 // 43 44 var pluginObj = this.selector, 45 pluginObjName = pluginObj.substring(1), 46 pluginObjLength = $(pluginObj).length; 47 48 pluginSettings.imgCleanupAttr.push('alt', 'src'); 49 50 // 51 // Build 52 // 53 54 $(pluginObj).each( 55 function(index) { 56 57 var imageObj = $(this), 58 imagePath = imageObj.attr('src'), 59 imageAttributes = {}; 60 61 // Image - Get Attributes 62 63 if (pluginSettings.imgIncludeAttr) { 64 65 $.each( 66 this.attributes, 67 function() { 68 if( 69 this.specified && 70 pluginSettings.imgCleanupAttr.indexOf(this.name) !== 0 71 ) { 72 if (this.name === 'class' && pluginSettings.removeClass) { 73 this.value = this.value.replace(pluginObjName + ' ', ''); 74 } 75 if (this.name === 'class' && pluginSettings.addClass) { 76 this.value = this.value += ' ' + pluginSettings.addClass; 77 } 78 imageAttributes[this.name] = this.value; 79 } 80 } 81 ); 82 83 } 84 85 $.get( 86 imagePath, 87 function(data) { 88 89 var svgData = $(data).find('svg'), 90 svgOutput; 91 92 // SVG - Cleanup Attributes 93 94 $.each( 95 pluginSettings.svgCleanupAttr, 96 function(i, item) { 97 svgData.removeAttr(item); 98 } 99 ); 100 101 // Image - Include Attributes 102 103 if (pluginSettings.imgIncludeAttr) { 104 105 $.each( 106 imageAttributes, 107 function(key, value) { 108 svgData.attr(key, value); 109 } 110 ); 111 112 } 113 114 // Output 115 116 imageObj.replaceWith($(data).find('svg')); 117 118 // Callback - Complete 119 120 if (index + 1 === pluginObjLength) { 121 pluginSettings.onComplete.call(this); 122 } 123 124 } 125 ); 126 127 } 128 ); 129 130 }; 131 132 }( jQuery ));
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.