diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-25 23:26:38 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-10-25 23:26:38 +0200 |
commit | 464af8b747389b7fdb569a933591c863b9be0f6b (patch) | |
tree | a23da0d70a26c142616207b0a0a489affd2f3ac6 /src/A.js | |
parent | f46aedf58fbc93483cb21017ffed10e439830108 (diff) | |
download | svg.js-464af8b747389b7fdb569a933591c863b9be0f6b.tar.gz svg.js-464af8b747389b7fdb569a933591c863b9be0f6b.zip |
Rename files so that they reflect their exported classes (see next commit)
Diffstat (limited to 'src/A.js')
-rw-r--r-- | src/A.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/A.js b/src/A.js new file mode 100644 index 0000000..cb0a341 --- /dev/null +++ b/src/A.js @@ -0,0 +1,41 @@ +SVG.A = SVG.invent({ + // Initialize node + create: 'a', + + // Inherit from + inherit: SVG.Container, + + // Add class methods + extend: { + // Link url + to: function (url) { + return this.attr('href', url, SVG.xlink) + }, + // Link target attribute + target: function (target) { + return this.attr('target', target) + } + }, + + // Add parent method + construct: { + // Create a hyperlink element + link: function (url) { + return this.put(new SVG.A()).to(url) + } + } +}) + +SVG.extend(SVG.Element, { + // Create a hyperlink element + linkTo: function (url) { + var link = new SVG.A() + + if (typeof url === 'function') { url.call(link, link) } else { + link.to(url) + } + + return this.parent().put(link).put(this) + } + +}) |