From 7d3e4c43a64cdb9ce19b71d8dc1783c0bc031d91 Mon Sep 17 00:00:00 2001 From: wout Date: Sun, 30 Dec 2012 19:20:31 +0100 Subject: Added hide() and show() --- src/element.js | 14 ++++++++++++++ src/event.js | 21 ++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/element.js b/src/element.js index e7701ce..6eea786 100644 --- a/src/element.js +++ b/src/element.js @@ -159,6 +159,20 @@ SVG.extend(SVG.Element, { }; }, + // show element + show: function() { + this.node.style.display = ''; + + return this; + }, + + // hide element + hide: function() { + this.node.style.display = 'none'; + + return this; + }, + // private: find svg parent _parent: function(pt) { var e = this; diff --git a/src/event.js b/src/event.js index ca1d290..4f587d2 100644 --- a/src/event.js +++ b/src/event.js @@ -1,20 +1,15 @@ -var eventTypes = ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove']; - -// generate events -for (var i = eventTypes.length - 1; i >= 0; i--) { - var t = eventTypes[i]; - +var eventTypes = ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove'].forEach(function(e) { // add event to SVG.Elment - SVG.Element.prototype[t] = function(f) { - var e = this; - + SVG.Element.prototype[e] = function(f) { + var s = this; + // bind event to element rather than element node - this.node['on' + t] = function() { - return f.apply(e, arguments); + this.node['on' + e] = function() { + return f.apply(s, arguments); }; - + // return self return this; }; -}; \ No newline at end of file +}); -- cgit v1.2.3