diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-07 12:22:48 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-03-10 13:19:45 +0100 |
commit | c4d93783496e9a3e67c157d63c4a94dc654120bf (patch) | |
tree | abb433d68699a0e1fbdac61cdbb44ed18ab505e1 /src/clip.js | |
parent | 1b8d97b266621d3af5de67b5162927d2e706cd34 (diff) | |
download | svg.js-c4d93783496e9a3e67c157d63c4a94dc654120bf.tar.gz svg.js-c4d93783496e9a3e67c157d63c4a94dc654120bf.zip |
Making initial changes for svg.js v3.0
- removed `SVG.Array.split()` function (#604)
- removed workaround for browser bug with stroke-width (#560)
- removed polyfills
- removed `ungroup()` in favour of `flatten()`
- gradients now have their corresponding nodename as type and not only radial/linear (#606)
- `SVG.Path.pointAt()` correctly returns an `SVG.Point` now (#607)
- replaced static reference to `masker` in `SVG.Mask` with the `masker()` method
- replaced static reference to `clipper` in `SVG.ClipPath` with the `clipper()` method
- replaced static reference to `targets` in `SVG.Mask` and `SVG.ClipPath` with the `targets()` method (all three #563)
Diffstat (limited to 'src/clip.js')
-rw-r--r-- | src/clip.js | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/src/clip.js b/src/clip.js index 2a92e44..70e2499 100644 --- a/src/clip.js +++ b/src/clip.js @@ -1,11 +1,6 @@ SVG.ClipPath = SVG.invent({ // Initialize node - create: function() { - this.constructor.call(this, SVG.create('clipPath')) - - // keep references to clipped elements - this.targets = [] - } + create: 'clipPath' // Inherit from , inherit: SVG.Container @@ -14,19 +9,22 @@ SVG.ClipPath = SVG.invent({ , extend: { // Unclip all clipped elements and remove itself remove: function() { - // unclip all targets - for (var i = this.targets.length - 1; i >= 0; i--) - if (this.targets[i]) - this.targets[i].unclip() - this.targets = [] + // unclip all targets + this.targets().each(function() { + this.unclip() + }) - // remove clipPath from parent + // remove clipPath from parent this.parent().removeElement(this) - + return this } + + , targets: function() { + return SVG.select('svg [clip-path*="' +this.id() +'"]') + } } - + // Add parent method , construct: { // Create clipping element @@ -40,19 +38,18 @@ SVG.ClipPath = SVG.invent({ SVG.extend(SVG.Element, { // Distribute clipPath to svg element clipWith: function(element) { - // use given clip or create a new one - this.clipper = element instanceof SVG.ClipPath ? element : this.parent().clip().add(element) + // use given clip or create a new one + var clipper = element instanceof SVG.ClipPath ? element : this.parent().clip().add(element) - // store reverence on self in mask - this.clipper.targets.push(this) - - // apply mask - return this.attr('clip-path', 'url("#' + this.clipper.attr('id') + '")') + // apply mask + return this.attr('clip-path', 'url("#' + clipper.attr('id') + '")') } // Unclip element , unclip: function() { - delete this.clipper return this.attr('clip-path', null) } - +, clipper: function() { + return this.reference('clip-path') + } + })
\ No newline at end of file |