Browse Source

Simplified ui.js a bit more.

Mr.doob 12 years ago
parent
commit
1b3da84d98
1 changed files with 19 additions and 30 deletions
  1. 19 30
      editor/js/UI.js

+ 19 - 30
editor/js/UI.js

@@ -12,8 +12,6 @@ UI.Element.prototype = {
 
 	},
 
-	// styles
-
 	setStyle: function ( style, array ) {
 
 		for ( var i = 0; i < array.length; i ++ ) {
@@ -24,44 +22,18 @@ UI.Element.prototype = {
 
 	},
 
-	// content
-
 	setTextContent: function ( value ) {
 
 		this.dom.textContent = value;
 
 		return this;
 
-	},
-
-	// events
-
-	onMouseOver: function ( callback ) {
-
-		this.dom.addEventListener( 'mouseover', callback, false );
-
-		return this;
-
-	},
-
-	onMouseOut: function ( callback ) {
-
-		this.dom.addEventListener( 'mouseout', callback, false );
-
-		return this;
-
-	},
-
-	onClick: function ( callback ) {
-
-		this.dom.addEventListener( 'click', callback, false );
-
-		return this;
-
 	}
 
 }
 
+// properties
+
 var properties = [ 'left', 'top', 'right', 'bottom', 'width', 'height', 'border', 'borderLeft',
 'borderTop', 'borderRight', 'borderBottom', 'margin', 'marginLeft', 'marginTop', 'marginRight',
 'marginBottom', 'padding', 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom', 'color',
@@ -80,6 +52,23 @@ properties.forEach( function ( property ) {
 
 } );
 
+// events
+
+var events = [ 'MouseOver', 'MouseOut', 'Click' ];
+
+events.forEach( function ( event ) {
+
+	var method = 'on' + event;
+
+	UI.Element.prototype[ method ] = function ( callback ) {
+
+		this.dom.addEventListener( event.toLowerCase(), callback, false );
+		return this;
+
+	};
+
+} );
+
 
 // Panel