Skip to content

Instantly share code, notes, and snippets.

@ewebdev
Created February 26, 2014 14:20
Show Gist options
  • Save ewebdev/9230250 to your computer and use it in GitHub Desktop.
Save ewebdev/9230250 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.loadSvg = function (options) {
var opts = $.extend({}, $.fn.loadSvg.defaults, options);
return this.each(function () {
var $stage = $(this);
$stage.load($stage.data('src'), function (response) {
$stage.addClass(opts.loadedCls);
if (opts.setSize) {
$stage.children('svg').css({width: $stage.width(), height: $stage.height()});
}
if (response) {
opts.success && opts.success.call($stage, response);
} else {
opts.error && opts.success.call($stage, response);
}
});
});
};
$.fn.loadSvg.defaults = {
loadedCls: 'svg-loaded',
setSize: true,
success: null,
error: null
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment