Advertisement
Guest User

Untitled

a guest
May 9th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.93 KB | None | 0 0
  1. jQuery('.logo img').each(function(){
  2. var $img = jQuery(this);
  3. var imgID = $img.attr('id');
  4. var imgClass = $img.attr('class');
  5. var imgURL = $img.attr('src');
  6.  
  7. jQuery.get(imgURL, function(data) {
  8. // Get the SVG tag, ignore the rest
  9. var $svg = jQuery(data).find('svg');
  10.  
  11. // Add replaced image's ID to the new SVG
  12. if(typeof imgID !== 'undefined') {
  13. $svg = $svg.attr('id', imgID);
  14. }
  15. // Add replaced image's classes to the new SVG
  16. if(typeof imgClass !== 'undefined') {
  17. $svg = $svg.attr('class', imgClass+' replaced-svg');
  18. }
  19.  
  20. // Remove any invalid XML tags as per http://validator.w3.org
  21. $svg = $svg.removeAttr('xmlns:a');
  22.  
  23. // Check if the viewport is set, if the viewport is not set the SVG wont't scale.
  24. if(!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) {
  25. $svg.attr('viewBox', '0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width'))
  26. }
  27.  
  28. // Replace image with new SVG
  29. $img.replaceWith($svg);
  30.  
  31. }, 'xml');
  32.  
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement