diff options
author | Wout <wout@impinc.co.uk> | 2014-06-10 13:39:15 +0200 |
---|---|---|
committer | Wout <wout@impinc.co.uk> | 2014-06-10 13:39:15 +0200 |
commit | 7e6b5edfdd08dd28120442a2c3528c3d94c346c3 (patch) | |
tree | 6693bb631dab6a126fdc214d537856c4ae9ac8f7 /dist/svg.js | |
parent | 8e44d115af4907276cb23567dc2d2a10d0efdf2f (diff) | |
parent | c13717a8d8d85e5d1d408e27a6db881fe773cc04 (diff) | |
download | svg.js-1.0.0-rc.7.tar.gz svg.js-1.0.0-rc.7.zip |
Merge pull request #200 from pklingem/master1.0.0-rc.7
add class manipulation functions to Element
Diffstat (limited to 'dist/svg.js')
-rwxr-xr-x | dist/svg.js | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/dist/svg.js b/dist/svg.js index 74566cc..c8eed90 100755 --- a/dist/svg.js +++ b/dist/svg.js @@ -1,4 +1,4 @@ -/* svg.js 1.0.0-rc.6-1-g1286e3d - svg inventor regex default color array pointarray patharray number viewbox bbox rbox element parent container fx relative event defs group arrange mask clip gradient pattern doc shape use rect ellipse line poly path image text textpath nested hyperlink sugar set data memory loader helpers - svgjs.com/license */ +/* svg.js 1.0.0-rc.6-8-g63d8846 - svg inventor regex default color array pointarray patharray number viewbox bbox rbox element parent container fx relative event defs group arrange mask clip gradient pattern doc shape use rect ellipse line poly path image text textpath nested hyperlink sugar set data memory loader helpers - svgjs.com/license */ ;(function() { this.SVG = function(element) { @@ -1317,6 +1317,49 @@ , toString: function() { return this.attr('id') } + // Return array of classes on the node + , classes: function() { + var classAttr = this.node.getAttribute('class') + if (classAttr === null) { + return [] + } else { + return classAttr.trim().split(/\s+/) + } + } + // Return true if class exists on the node, false otherwise + , hasClass: function(className) { + return this.classes().indexOf(className) != -1 + } + // Add class to the node + , addClass: function(className) { + var classArray + if (!(this.hasClass(className))) { + classArray = this.classes() + classArray.push(className) + this.node.setAttribute('class', classArray.join(' ')) + } + return this + } + // Remove class from the node + , removeClass: function(className) { + var classArray + if (this.hasClass(className)) { + classArray = this.classes().filter(function(c) { + return c != className + }) + this.node.setAttribute('class', classArray.join(' ')) + } + return this + } + // Toggle the presence of a class on the node + , toggleClass: function(className) { + if (this.hasClass(className)) { + this.removeClass(className) + } else { + this.addClass(className) + } + return this + } // Private: find svg parent by instance , _parent: function(parent) { var element = this @@ -1329,6 +1372,7 @@ } }) + SVG.Parent = SVG.invent({ // Initialize node create: function(element) { |