Skip to content

Instantly share code, notes, and snippets.

@bouchard
Created September 3, 2010 04:44
Show Gist options
  • Save bouchard/563428 to your computer and use it in GitHub Desktop.
Save bouchard/563428 to your computer and use it in GitHub Desktop.
/*
* svgObject: a jQuery plugin, version: 0.1 (2010-09-03)
* @requires jQuery v.1.4.2 or later
*
* svgObject parses all SVG images linked in the document as IMG tags, and replaces
* the IMG tags with OBJECTs instead to make it all work nicely in FF 3.6+ and Safari 5+
*
* This:
*
* <img class="up svg" src="/images/up.svg" />
*
* is converted to the following, for Firefox:
*
* <object data="/images/up.svg" type="image/svg+xml" class="up svg"></object>
*
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
* Copyright (c) 2010, Brady Bouchard (brady [at] ldawn.com)
*/
(function($) {
$.fn.svgObject = function() {
if ($.browser.webkit) {
return this;
} else {
return this.each(function() {
var e = $(this);
var o = $('<object>')
.attr('type', 'image/svg+xml')
.attr('data', e.attr('src'))
.attr('class', e.attr('class'))
.attr('id', e.attr('id'));
e.replaceWith(o);
});
}
}
})(jQuery);
/* Change the selector below, if you want to match other classes. */
jQuery(document).ready(function() {
jQuery('img.svg').svgObject();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment