Browse Source

Editor: Update Element.addClass implementation

jlewin 12 years ago
parent
commit
cba5e46a3e
2 changed files with 6 additions and 4 deletions
  1. 1 0
      editor/js/Sidebar.Material.js
  2. 5 4
      editor/js/libs/ui.js

+ 1 - 0
editor/js/Sidebar.Material.js

@@ -21,6 +21,7 @@ Sidebar.Material = function ( editor ) {
 
 	var container = new UI.Panel();
 	container.setDisplay( 'none' );
+	container.addClass( 'Material' );
 
 	container.add( new UI.Text().setValue( 'MATERIAL' ) );
 	container.add( new UI.Break(), new UI.Break() );

+ 5 - 4
editor/js/libs/ui.js

@@ -25,12 +25,13 @@ UI.Element.prototype = {
 
 		debugger;
 
-		var classes = this.dom.className.split(/\S+/g);
+		var classes = this.dom.className.split(/\s+/g);
 
-		for ( var i = 0; i < classes.length; i++ ) {
+		// Exit early and avoid dom update if already set
+		var index = classes.indexOf(value);
+		if ( index >= 0 ) {
 
-			// Exit early and prevent reassignment if already exists
-			if ( classes[i] === value ) return;
+			return;
 
 		}