Last active
March 28, 2016 18:38
-
-
Save nborko/5943c44ec0a58d9b915d to your computer and use it in GitHub Desktop.
jquery shims for [add|remove|has]Class for svg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jquery shims for [add|remove|has]Class for svg */ | |
(function ($) { | |
$.fn.addClass = (function(addClass) { | |
return function(value) { | |
return addClass.apply(this, arguments).each(function () { | |
if (this instanceof SVGElement) { | |
$(this).attr('class', $('<div/>', {'class': $(this).attr('class')}).addClass(value).attr('class')); | |
} | |
}); | |
}; | |
})($.fn.addClass); | |
$.fn.removeClass = (function(removeClass) { | |
return function(value) { | |
return removeClass.apply(this, arguments).each(function () { | |
if (this instanceof SVGElement) { | |
$(this).attr('class', $('<div/>', {'class': $(this).attr('class')}).removeClass(value).attr('class')); | |
} | |
}); | |
}; | |
})($.fn.removeClass); | |
$.fn.hasClass = (function(hasClass) { | |
return function(value) { | |
return hasClass.apply(this, arguments) || this.map(function () { | |
if (this instanceof SVGElement) { | |
return $('<div/>', {'class': $(this).attr('class')}).hasClass(value) || null; | |
} | |
}).length > 0; | |
}; | |
})($.fn.hasClass); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment