Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Created February 28, 2013 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-martin/5054863 to your computer and use it in GitHub Desktop.
Save chris-martin/5054863 to your computer and use it in GitHub Desktop.
var svgTags = ['g', 'image'];
['width', 'height', 'opacity'].forEach(function(p) {
var o = $.fn[p];
$.fn[p] = function(x) {
if (x === undefined) {
return o.call(this);
}
return this.each(function() {
if (svgTags.indexOf(this.tagName) !== -1) {
$(this).attr(p, x);
} else {
o.call(this, x);
}
});
};
});
['show', 'hide'].forEach(function(p) {
var o = $.fn[p];
$.fn[p] = function(x) {
return this.each(function() {
if (svgTags.indexOf(this.tagName) !== -1) {
$(this)[0].setAttribute('display', p === 'show' ? 'inline' : 'none');
} else {
o.call(this);
}
});
};
});
['x', 'y'].forEach(function(p) {
$.fn[p] = function(x) {
if (x === undefined) {
return this[0][p];
}
this.each(function() {
$(this).attr(p, x);
});
return this;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment