From 1a759361b82127f9d5c1428dc889fffdf2daaf86 Mon Sep 17 00:00:00 2001
From: John Mayhew
Date: Thu, 3 May 2012 15:11:56 -0700
Subject: First round of moving color chips into the sub tools. Shape and Pen
 tool now have chips in the sub tool bar. Still need to complete adding chips
 to the Brush tool and finalizing the subtool bar layout to our spec for all
 of the subtools.

---
 .../color/colorpanelbase.reel/colorpanelbase.js    | 2835 ++++++++++----------
 1 file changed, 1420 insertions(+), 1415 deletions(-)

(limited to 'js/panels')

diff --git a/js/panels/color/colorpanelbase.reel/colorpanelbase.js b/js/panels/color/colorpanelbase.reel/colorpanelbase.js
index af62dd07..64cdc360 100755
--- a/js/panels/color/colorpanelbase.reel/colorpanelbase.js
+++ b/js/panels/color/colorpanelbase.reel/colorpanelbase.js
@@ -15,35 +15,35 @@ var Montage = 			require("montage/core/core").Montage,
 ////////////////////////////////////////////////////////////////////////
 //Exporting as ColorPanelBase
 exports.ColorPanelBase = Montage.create(Component, {
-	////////////////////////////////////////////////////////////////////
-	//
-	hasTemplate: {
+    ////////////////////////////////////////////////////////////////////
+    //
+    hasTemplate: {
         value: true
     },
     ////////////////////////////////////////////////////////////////////
     //Storing ColorPanel sliders mode
     _panelMode: {
-    	enumerable: false,
-    	value: 'rgb'
+        enumerable: false,
+        value: 'rgb'
     },
     ////////////////////////////////////////////////////////////////////
     //Storing ColorPanel sliders mode
     panelMode: {
-    	enumerable: true,
-        get: function() {
+        enumerable: true,
+        get: function () {
             return this._panelMode;
         },
-        set: function(value) {
-        	if (value !== this._panelMode) {
-        		this._panelMode = value;
-        	}
+        set: function (value) {
+            if (value !== this._panelMode) {
+                this._panelMode = value;
+            }
         }
     },
     ////////////////////////////////////////////////////////////////////
     //
     _colorBar: {
-    	enumerable: false,
-    	value: null
+        enumerable: false,
+        value: null
     },
     ////////////////////////////////////////////////////////////////////
     //Storing color manager
@@ -54,19 +54,19 @@ exports.ColorPanelBase = Montage.create(Component, {
     ////////////////////////////////////////////////////////////////////
     //
     colorManager: {
-    	enumerable: true,
-        get: function() {
+        enumerable: true,
+        get: function () {
             return this._colorManager;
         },
-        set: function(value) {
-        	if (value !== this._colorManager) {
-        		this._colorManager = value;
-        		//Updating input buttons
-        		this._colorManager.addEventListener('change', this._update.bind(this));
-        		this._colorManager.addEventListener('changing', this._update.bind(this));
-        		//Updating history buttons once color is set
-        		this._colorManager.addEventListener('change', this._updateHistoryButtons.bind(this));
-        	}
+        set: function (value) {
+            if (value !== this._colorManager) {
+                this._colorManager = value;
+                //Updating input buttons
+                this._colorManager.addEventListener('change', this._update.bind(this));
+                this._colorManager.addEventListener('changing', this._update.bind(this));
+                //Updating history buttons once color is set
+                this._colorManager.addEventListener('change', this._updateHistoryButtons.bind(this));
+            }
         }
     },
     ////////////////////////////////////////////////////////////////////
@@ -78,50 +78,50 @@ exports.ColorPanelBase = Montage.create(Component, {
     ////////////////////////////////////////////////////////////////////
     //
     _combo: {
-    	enumerable: false,
-    	value: [{slider: null, hottext: null}, {slider: null, hottext: null}, {slider: null, hottext: null}, {slider: null, hottext: null}]
+        enumerable: false,
+        value: [{ slider: null, hottext: null }, { slider: null, hottext: null }, { slider: null, hottext: null }, { slider: null, hottext: null}]
     },
     ////////////////////////////////////////////////////////////////////
     //
     _buttons: {
-    	enumerable: false,
-    	value: {chip: [], fill: [], stroke: [], current: [], previous: [], rgbmode: [], hslmode: [], hexinput: [], nocolor: [], reset: [], swap: [], mlabel1: [], mlabel2: [], mlabel3: []}
+        enumerable: false,
+        value: { chip: [], fill: [], stroke: [], current: [], previous: [], rgbmode: [], hslmode: [], hexinput: [], nocolor: [], reset: [], swap: [], mlabel1: [], mlabel2: [], mlabel3: [] }
     },
     ////////////////////////////////////////////////////////////////////
     //
     historyCache: {
-    	enumerable: false,
-    	value: {current: null, previous: null}
+        enumerable: false,
+        value: { current: null, previous: null }
     },
     ////////////////////////////////////////////////////////////////////
     //
     colorChipProps: {
-    	enumerable: true,
-    	value: {side: 'top', align: 'center', wheel: true, palette: true, gradient: true, image: true, panel: false}
+        enumerable: true,
+        value: { side: 'top', align: 'center', wheel: true, palette: true, gradient: true, image: true, panel: false }
     },
     ////////////////////////////////////////////////////////////////////
     //
     currentChip: {
-    	enumerable: true,
-    	value: null
+        enumerable: true,
+        value: null
     },
     ////////////////////////////////////////////////////////////////////
     //
     previousInput: {
-    	enumerable: true,
-    	value: null
+        enumerable: true,
+        value: null
     },
     ////////////////////////////////////////////////////////////////////
     //Setting up elements/components
     prepareForDraw: {
-    	enumerable: false,
-    	value: function() {
-    		//TODO: Remove temporary hack, color history should be initilized
+        enumerable: false,
+        value: function () {
+            //TODO: Remove temporary hack, color history should be initilized
             this.addEventListener('firstDraw', this, false);
             this.application.ninja.colorController.colorView = this;
-    		this.colorManager.colorHistory.fill = [{m: 'nocolor', c: {}, a: 1}];
-    		this.colorManager.colorHistory.stroke = [{m: 'nocolor', c: {}, a: 1}];
-    	}
+            this.colorManager.colorHistory.fill = [{ m: 'nocolor', c: {}, a: 1}];
+            this.colorManager.colorHistory.stroke = [{ m: 'nocolor', c: {}, a: 1}];
+        }
     },
 
     handleFirstDraw: {
@@ -131,1521 +131,1526 @@ exports.ColorPanelBase = Montage.create(Component, {
             this.application.ninja.colorController.createToolbar();
             this.applyDefaultColors();
             this.removeEventListener('firstDraw', this, false);
+
+            // Workaround for delaying subtool colorchip creation until the color panel is initialized.
+            // This can be removed and the subtools must be updated once we create a new view for color buttons
+            // and they no longer rely on the view of the color panel.
+            this.application.ninja.colorController.colorPanelDrawn = true;
         }
     },
 
     ////////////////////////////////////////////////////////////////////
     //Assigning values and binding
     willDraw: {
-    	enumerable: false,
-    	value: function() {
-    		////////////////////////////////////////////////////////////
-    		//TODO: remove ID dependencies
-    		createCombo(this._combo[0], "cp_slider1", "cp_hottext1", true, this.element);
-    		createCombo(this._combo[1], "cp_slider2", "cp_hottext2", true, this.element);
-    		createCombo(this._combo[2], "cp_slider3", "cp_hottext3", true, this.element);
-    		createCombo(this._combo[3], "cp_slider4", "cp_hottext4", false, this.element);
-    		////////////////////////////////////////////////////////////
-    		//Function to create slider/hottext combination
-    		function createCombo (c, slid, htid, color, e) {
-    			//Only creating, not drawing
-    			c.slider = Slider.create();
-    			c.hottext = HotText.create();
-    			c.slider.element = e.getElementsByClassName(slid)[0];
-    			c.hottext.element = e.getElementsByClassName(htid)[0];
-    			c.slider.changesColor = c.hottext.changesColor = color;
-    			c.slider.cInputType = 'slider';
-    			c.slider.cInputType = 'hottext';
-    			//Binding Hottext to Slider
-    			Object.defineBinding(c.hottext, "value", {
-    				boundObject: c.slider,
-        		    boundObjectPropertyPath: "_value", //TODO: Check if needed
-        		    oneway: false,
-                    boundValueMutator: function(value) {
-                    	return Math.round(value);
+        enumerable: false,
+        value: function () {
+            ////////////////////////////////////////////////////////////
+            //TODO: remove ID dependencies
+            createCombo(this._combo[0], "cp_slider1", "cp_hottext1", true, this.element);
+            createCombo(this._combo[1], "cp_slider2", "cp_hottext2", true, this.element);
+            createCombo(this._combo[2], "cp_slider3", "cp_hottext3", true, this.element);
+            createCombo(this._combo[3], "cp_slider4", "cp_hottext4", false, this.element);
+            ////////////////////////////////////////////////////////////
+            //Function to create slider/hottext combination
+            function createCombo(c, slid, htid, color, e) {
+                //Only creating, not drawing
+                c.slider = Slider.create();
+                c.hottext = HotText.create();
+                c.slider.element = e.getElementsByClassName(slid)[0];
+                c.hottext.element = e.getElementsByClassName(htid)[0];
+                c.slider.changesColor = c.hottext.changesColor = color;
+                c.slider.cInputType = 'slider';
+                c.slider.cInputType = 'hottext';
+                //Binding Hottext to Slider
+                Object.defineBinding(c.hottext, "value", {
+                    boundObject: c.slider,
+                    boundObjectPropertyPath: "_value", //TODO: Check if needed
+                    oneway: false,
+                    boundValueMutator: function (value) {
+                        return Math.round(value);
                     }
-    			});
-    			//Binding Slider to Hottext
-    			Object.defineBinding(c.slider, "value", {
-    				boundObject: c.hottext,
-        		    boundObjectPropertyPath: "value",
-        		    oneway: false,
-                    boundValueMutator: function(value) {
+                });
+                //Binding Slider to Hottext
+                Object.defineBinding(c.slider, "value", {
+                    boundObject: c.hottext,
+                    boundObjectPropertyPath: "value",
+                    oneway: false,
+                    boundValueMutator: function (value) {
                         return Math.round(value);
                     }
-    			});
-    		}
-    		////////////////////////////////////////////////////////////
-    		//Creating ColorBar and sending color manager
-    		this._colorBar = ColorBar.create();
-        	this._colorBar.element = this.element.getElementsByClassName("cp_spectrum")[0];
-    		////////////////////////////////////////////////////////////
-    		//Adding/Initializing buttons
-    		this.addButton('fill', this.element.getElementsByClassName('cpe_fill')[0]);
-    		this.addButton('fillicon', this.element.getElementsByClassName('cpe_fill_icon')[0]);
-    		this.addButton('stroke', this.element.getElementsByClassName('cpe_stroke')[0]);
-    		this.addButton('strokeicon', this.element.getElementsByClassName('cpe_stroke_icon')[0]);
-    		
-    		this.addButton('current', this.element.getElementsByClassName('cp_color_current')[0]);
-    		this.addButton('previous', this.element.getElementsByClassName('cp_color_previous')[0]);
-    		
-    		this.addButton('hexinput', this.element.getElementsByClassName('cp_hottext5')[0]);
-    		this.addButton('reset', this.element.getElementsByClassName('cp_reset')[0]);
-    		this.addButton('nocolor', this.element.getElementsByClassName('cp_nocolor')[0]);
-    		this.addButton('swap', this.element.getElementsByClassName('cp_swap')[0]);
-    		
-    		//TODO: Add HSL mode when Chrome can pass proper mode in color, also add in CSS button states
-    		//this.addButton('hslmode', this.element.getElementsByClassName('cp_hsl_mode')[0]);
-    		this.addButton('rgbmode', this.element.getElementsByClassName('cp_rgb_mode')[0]);
-    		
-    		this.addButton('mlabel1', this.element.getElementsByClassName('sh_label1')[0]);
-    		this.addButton('mlabel2', this.element.getElementsByClassName('sh_label2')[0]);
-    		this.addButton('mlabel3', this.element.getElementsByClassName('sh_label3')[0]);
-    		
-    		
-    		
-    		//Initialing values of sliders according to current mode
-    		if (this._panelMode === 'rgb') {
-    			this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 255;
-    			this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 255;
-    			this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 255;
-    		} else if (this._panelMode === 'hsl') {
-    			this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 360;
-    			this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 100;
-    			this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 100;
-    		}
-    		//Alpha slider/hottext is indepenent of color panel mode
-    		this._combo[3].slider.maxValue = this._combo[3].hottext.maxValue = 100;
-    	}
+                });
+            }
+            ////////////////////////////////////////////////////////////
+            //Creating ColorBar and sending color manager
+            this._colorBar = ColorBar.create();
+            this._colorBar.element = this.element.getElementsByClassName("cp_spectrum")[0];
+            ////////////////////////////////////////////////////////////
+            //Adding/Initializing buttons
+            this.addButton('fill', this.element.getElementsByClassName('cpe_fill')[0]);
+            this.addButton('fillicon', this.element.getElementsByClassName('cpe_fill_icon')[0]);
+            this.addButton('stroke', this.element.getElementsByClassName('cpe_stroke')[0]);
+            this.addButton('strokeicon', this.element.getElementsByClassName('cpe_stroke_icon')[0]);
+
+            this.addButton('current', this.element.getElementsByClassName('cp_color_current')[0]);
+            this.addButton('previous', this.element.getElementsByClassName('cp_color_previous')[0]);
+
+            this.addButton('hexinput', this.element.getElementsByClassName('cp_hottext5')[0]);
+            this.addButton('reset', this.element.getElementsByClassName('cp_reset')[0]);
+            this.addButton('nocolor', this.element.getElementsByClassName('cp_nocolor')[0]);
+            this.addButton('swap', this.element.getElementsByClassName('cp_swap')[0]);
+
+            //TODO: Add HSL mode when Chrome can pass proper mode in color, also add in CSS button states
+            //this.addButton('hslmode', this.element.getElementsByClassName('cp_hsl_mode')[0]);
+            this.addButton('rgbmode', this.element.getElementsByClassName('cp_rgb_mode')[0]);
+
+            this.addButton('mlabel1', this.element.getElementsByClassName('sh_label1')[0]);
+            this.addButton('mlabel2', this.element.getElementsByClassName('sh_label2')[0]);
+            this.addButton('mlabel3', this.element.getElementsByClassName('sh_label3')[0]);
+
+
+
+            //Initialing values of sliders according to current mode
+            if (this._panelMode === 'rgb') {
+                this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 255;
+                this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 255;
+                this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 255;
+            } else if (this._panelMode === 'hsl') {
+                this._combo[0].slider.maxValue = this._combo[0].hottext.maxValue = 360;
+                this._combo[1].slider.maxValue = this._combo[1].hottext.maxValue = 100;
+                this._combo[2].slider.maxValue = this._combo[2].hottext.maxValue = 100;
+            }
+            //Alpha slider/hottext is indepenent of color panel mode
+            this._combo[3].slider.maxValue = this._combo[3].hottext.maxValue = 100;
+        }
     },
     ////////////////////////////////////////////////////////////////////
     //Drawing elements/components
     draw: {
-    	enumerable: false,
-    	value: function() {
-    		////////////////////////////////////////////////////////////
-    		//Drawing slider/hottext combinations
-    		for (var i=0; i<this._combo.length; i++) {
-    			this._combo[i].slider.needsDraw = true;
-    			this._combo[i].hottext.needsDraw = true;
-    		}
-    		//Drawing Color Bar
+        enumerable: false,
+        value: function () {
+            ////////////////////////////////////////////////////////////
+            //Drawing slider/hottext combinations
+            for (var i = 0; i < this._combo.length; i++) {
+                this._combo[i].slider.needsDraw = true;
+                this._combo[i].hottext.needsDraw = true;
+            }
+            //Drawing Color Bar
             this._colorBar.needsDraw = true;
-    	}
+        }
     },
     ////////////////////////////////////////////////////////////////////
     //
     didDraw: {
-    	enumerable: false,
-    	value: function() {
-    		//Drawing color bar after layout has been drawn since width/height are needed
-    		this._colorBar.needsDraw = true;
-    		//Adding events to color bar component
-    		this._colorBar.addEventListener('change', this, false);
-		    this._colorBar.addEventListener('changing', this, false);
-		    //Custom background drawing function per individual slider
-    		this._combo[0].slider.customBackground = this._slider0Background.bind(this);
-    		this._combo[1].slider.customBackground = this._slider1Background.bind(this);
-    		this._combo[2].slider.customBackground = this._slider2Background.bind(this);
-    		this._combo[3].slider.customBackground = this._slider3Background.bind(this);
-    		//Listening for change events to update sliders
-    		this._combo[0].slider.addEventListener("change", this._updateSliders.bind(this));
-    		this._combo[1].slider.addEventListener("change", this._updateSliders.bind(this));
-    		this._combo[2].slider.addEventListener("change", this._updateSliders.bind(this));
-    		this._combo[3].slider.addEventListener("change", this._updateSliders.bind(this));
-    		//
-    		this._combo[0].slider.addEventListener("change", this._updateValueFromSH.bind(this));
-    		this._combo[1].slider.addEventListener("change", this._updateValueFromSH.bind(this));
-    		this._combo[2].slider.addEventListener("change", this._updateValueFromSH.bind(this));
-    		this._combo[3].slider.addEventListener("change", this._updateValueFromSH.bind(this));
-    		//
-    		this._combo[0].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
-    		this._combo[1].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
-    		this._combo[2].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
-    		this._combo[3].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
-    		//
-    		this._combo[0].slider.addEventListener("changing", this._updateSliders.bind(this));
-    		this._combo[1].slider.addEventListener("changing", this._updateSliders.bind(this));
-    		this._combo[2].slider.addEventListener("changing", this._updateSliders.bind(this));
-    		this._combo[3].slider.addEventListener("changing", this._updateSliders.bind(this));
-    	}
+        enumerable: false,
+        value: function () {
+            //Drawing color bar after layout has been drawn since width/height are needed
+            this._colorBar.needsDraw = true;
+            //Adding events to color bar component
+            this._colorBar.addEventListener('change', this, false);
+            this._colorBar.addEventListener('changing', this, false);
+            //Custom background drawing function per individual slider
+            this._combo[0].slider.customBackground = this._slider0Background.bind(this);
+            this._combo[1].slider.customBackground = this._slider1Background.bind(this);
+            this._combo[2].slider.customBackground = this._slider2Background.bind(this);
+            this._combo[3].slider.customBackground = this._slider3Background.bind(this);
+            //Listening for change events to update sliders
+            this._combo[0].slider.addEventListener("change", this._updateSliders.bind(this));
+            this._combo[1].slider.addEventListener("change", this._updateSliders.bind(this));
+            this._combo[2].slider.addEventListener("change", this._updateSliders.bind(this));
+            this._combo[3].slider.addEventListener("change", this._updateSliders.bind(this));
+            //
+            this._combo[0].slider.addEventListener("change", this._updateValueFromSH.bind(this));
+            this._combo[1].slider.addEventListener("change", this._updateValueFromSH.bind(this));
+            this._combo[2].slider.addEventListener("change", this._updateValueFromSH.bind(this));
+            this._combo[3].slider.addEventListener("change", this._updateValueFromSH.bind(this));
+            //
+            this._combo[0].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
+            this._combo[1].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
+            this._combo[2].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
+            this._combo[3].hottext.addEventListener("change", this._updateValueFromSH.bind(this));
+            //
+            this._combo[0].slider.addEventListener("changing", this._updateSliders.bind(this));
+            this._combo[1].slider.addEventListener("changing", this._updateSliders.bind(this));
+            this._combo[2].slider.addEventListener("changing", this._updateSliders.bind(this));
+            this._combo[3].slider.addEventListener("changing", this._updateSliders.bind(this));
+        }
     },
     ////////////////////////////////////////////////////////////////////
     //Color Updating from Mananger
     _update: {
         enumerable: false,
         value: function (e) {
-        	//Local variables
-        	var i, bgcolor, bgimg, input = this.colorManager.input.toLocaleLowerCase(), other;
-    		//Setting help variable (opposite type)
-    		if (input === 'stroke') {
-        		other = 'fill';
-        	} else if (input === 'fill') {
-        		other = 'stroke';
-        	} else {
-        		return;
-        	}
-        	//Checking for event mode to be color change (NOT PANEL MODE RELATED)
-        	if (e._event.mode === 'hsv' || e._event.mode === 'hsl' || e._event.mode === 'rgb' || e._event.mode === 'hex' || e._event.mode === 'nocolor' || e._event.mode === 'gradient') {
-        		//Checking for panel color mode (RGB or HSL) to assign correct slider values
-        		if (this.panelMode === 'rgb' && e._event.rgba) {
-    				this._combo[0].slider.value = e._event.rgba.r;
-    				this._combo[1].slider.value = e._event.rgba.g;
-    				this._combo[2].slider.value = e._event.rgba.b;
-    				this._combo[3].slider.value = Math.round(100*e._event.rgba.a);
-    				bgcolor = 'rgba('+e._event.rgba.r+', '+e._event.rgba.g+', '+e._event.rgba.b+', '+e._event.rgba.a+')';
-    			} else if (this.panelMode === 'hsl' && e._event.hsla) {
-    				this._combo[0].slider.value = e._event.hsla.h;
-    				this._combo[1].slider.value = e._event.hsla.s;
-    				this._combo[2].slider.value = e._event.hsla.l;
-    				this._combo[3].slider.value = Math.round(100*e._event.hsla.a);
-    				bgcolor = 'hsla('+e._event.hsla.h+', '+e._event.hsla.s+'%, '+e._event.hsla.l+'%, '+e._event.hsla.a+')';
-    			}
-    			if (e._event.mode === 'gradient') {
-    				bgimg = e._event.value.value.css;
-    			}
-       			//Checking for background string to use
-    			if (bgcolor || bgimg) {
-        			//Looping through all input buttons
-    				for(i=0; this._buttons[input][i]; i++) {
-    					this._buttons[input][i].style.background = 'none';
-    					this._buttons[input][i].style.backgroundColor = 'none';
-    					this._buttons[input][i].style.backgroundImage = 'none';
-    					//Setting background color
-    					if (bgimg) {
-    						this._buttons[input][i].style.backgroundImage = bgimg;
-    					} else if(this._buttons[input][i].style.backgroundImage){
-    						this._buttons[input][i].style.backgroundImage = 'none';
-    					}
-    					if (bgcolor) {
-    						this._buttons[input][i].style.backgroundColor = bgcolor;
-    					}
-    					//Checking for type history
-    					if (this.colorManager.colorHistory[input].length) {
-    						//Check for 'nocolor' to apply proper highlight
-    						if (this.colorManager.colorHistory[other][this.colorManager.colorHistory[other].length-1].m === 'nocolor') {
-    							this.selectInputHighlight(this._buttons[input], this._buttons[other], false, true);
-    						} else {
-    							this.selectInputHighlight(this._buttons[input], this._buttons[other], false, false);
-    						}
-    					}
- 					}
-    			} else {
-    				//Checking for type history
-    				if (this.colorManager.colorHistory[other].length) {
-    				//Check for 'nocolor' to apply proper highlight
-    				if (this.colorManager.colorHistory[other][this.colorManager.colorHistory[other].length-1].m === 'nocolor') {
-    					this.selectInputHighlight(this._buttons[input], this._buttons[other], true, true);
-    				} else {
-	    				this.selectInputHighlight(this._buttons[input], this._buttons[other], true, false);
-    					}
-    				}
-    			}
-    		}
-    		//Updating all hex input areas
-    		for(i=0; this._buttons.hexinput[i]; i++) {
-    			this._buttons.hexinput[i]._valueSyncedWithInputField = false;
-    			this._buttons.hexinput[i].needsDraw = true;
-    		}
+            //Local variables
+            var i, bgcolor, bgimg, input = this.colorManager.input.toLocaleLowerCase(), other;
+            //Setting help variable (opposite type)
+            if (input === 'stroke') {
+                other = 'fill';
+            } else if (input === 'fill') {
+                other = 'stroke';
+            } else {
+                return;
+            }
+            //Checking for event mode to be color change (NOT PANEL MODE RELATED)
+            if (e._event.mode === 'hsv' || e._event.mode === 'hsl' || e._event.mode === 'rgb' || e._event.mode === 'hex' || e._event.mode === 'nocolor' || e._event.mode === 'gradient') {
+                //Checking for panel color mode (RGB or HSL) to assign correct slider values
+                if (this.panelMode === 'rgb' && e._event.rgba) {
+                    this._combo[0].slider.value = e._event.rgba.r;
+                    this._combo[1].slider.value = e._event.rgba.g;
+                    this._combo[2].slider.value = e._event.rgba.b;
+                    this._combo[3].slider.value = Math.round(100 * e._event.rgba.a);
+                    bgcolor = 'rgba(' + e._event.rgba.r + ', ' + e._event.rgba.g + ', ' + e._event.rgba.b + ', ' + e._event.rgba.a + ')';
+                } else if (this.panelMode === 'hsl' && e._event.hsla) {
+                    this._combo[0].slider.value = e._event.hsla.h;
+                    this._combo[1].slider.value = e._event.hsla.s;
+                    this._combo[2].slider.value = e._event.hsla.l;
+                    this._combo[3].slider.value = Math.round(100 * e._event.hsla.a);
+                    bgcolor = 'hsla(' + e._event.hsla.h + ', ' + e._event.hsla.s + '%, ' + e._event.hsla.l + '%, ' + e._event.hsla.a + ')';
+                }
+                if (e._event.mode === 'gradient') {
+                    bgimg = e._event.value.value.css;
+                }
+                //Checking for background string to use
+                if (bgcolor || bgimg) {
+                    //Looping through all input buttons
+                    for (i = 0; this._buttons[input][i]; i++) {
+                        this._buttons[input][i].style.background = 'none';
+                        this._buttons[input][i].style.backgroundColor = 'none';
+                        this._buttons[input][i].style.backgroundImage = 'none';
+                        //Setting background color
+                        if (bgimg) {
+                            this._buttons[input][i].style.backgroundImage = bgimg;
+                        } else if (this._buttons[input][i].style.backgroundImage) {
+                            this._buttons[input][i].style.backgroundImage = 'none';
+                        }
+                        if (bgcolor) {
+                            this._buttons[input][i].style.backgroundColor = bgcolor;
+                        }
+                        //Checking for type history
+                        if (this.colorManager.colorHistory[input].length) {
+                            //Check for 'nocolor' to apply proper highlight
+                            if (this.colorManager.colorHistory[other][this.colorManager.colorHistory[other].length - 1].m === 'nocolor') {
+                                this.selectInputHighlight(this._buttons[input], this._buttons[other], false, true);
+                            } else {
+                                this.selectInputHighlight(this._buttons[input], this._buttons[other], false, false);
+                            }
+                        }
+                    }
+                } else {
+                    //Checking for type history
+                    if (this.colorManager.colorHistory[other].length) {
+                        //Check for 'nocolor' to apply proper highlight
+                        if (this.colorManager.colorHistory[other][this.colorManager.colorHistory[other].length - 1].m === 'nocolor') {
+                            this.selectInputHighlight(this._buttons[input], this._buttons[other], true, true);
+                        } else {
+                            this.selectInputHighlight(this._buttons[input], this._buttons[other], true, false);
+                        }
+                    }
+                }
+            }
+            //Updating all hex input areas
+            for (i = 0; this._buttons.hexinput[i]; i++) {
+                this._buttons.hexinput[i]._valueSyncedWithInputField = false;
+                this._buttons.hexinput[i].needsDraw = true;
+            }
         }
     },
     ////////////////////////////////////////////////////////////////////
     //Updating history buttons (individually kept per input type)
     _updateHistoryButtons: {
-    	enumerable: false,
-    	value: function (e) {
-    		//Locals
-    		var bg = 'none', img, i, input = this.colorManager.input.toLowerCase(), color, hsv, mode = e._event.mode, prev, alpha, ctx, cvs;
-    		if (input === 'chip') {
-    			return;
-    		}
-    		//Creating background color string according to panel mode (not input color mode)
-       		if (mode === 'hsv' || mode === 'hsl' || mode === 'rgb' || mode === 'hex' || mode === 'alpha') {
-        		if (this.panelMode === 'rgb' && e._event.rgba) {
-        			color = e._event.rgba;
-    				bg = 'rgba('+color.r+', '+color.g+', '+color.b+', '+color.a+')';
-    			} else if (this.panelMode === 'hsl' && e._event.hsla) {
-    				color = e._event.hsla;
-	    			bg = 'hsla('+color.h+', '+color.s+'%, '+color.l+'%, '+color.a+')';
-    			} else {
-    				bg = 'nocolor';
-    			}
-    			color = null;
-    			for (i=0; this._buttons.current[i]; i++) {
-    				cvs = this._buttons.current[i].getElementsByTagName('canvas')[0];
-    				ctx = cvs.getContext('2d');
-    				ctx.clearRect(0, 0, cvs.width, cvs.height);
-	    			this._buttons.current[i].style.backgroundColor = bg;
-					this._buttons.current[i].style.backgroundImage = 'none';
-				}
-    		} else if (mode === 'gradient') {
-    			//
-    			color = e._event.value;
-    			bg = e._event.value.value.css;
-    			for (i=0; this._buttons.current[i]; i++) {
-    				cvs = this._buttons.current[i].getElementsByTagName('canvas')[0];
-    				ctx = cvs.getContext('2d');
-    				ctx.clearRect(0, 0, cvs.width, cvs.height);
-	    			this._buttons.current[i].style.background = 'none';
-	    			this._buttons.current[i].style.backgroundColor = 'none';
-					this._buttons.current[i].style.backgroundImage = bg;
-				}
-    		} else {
-    			//
-    			bg = 'nocolor';
-    			for (i=0; this._buttons.current[i]; i++) {
-    				//TODO: combine no color into one reusable funtion
-	    			cvs = this._buttons.current[i].getElementsByTagName('canvas')[0];
-    				ctx = cvs.getContext('2d');
-    				ctx.clearRect(0, 0, cvs.width, cvs.height);
-    				ctx.beginPath();
-    				ctx.moveTo(0, cvs.height);
-	  				ctx.lineTo(cvs.width, 0);
-	  				ctx.lineWidth = 16;
-    				ctx.strokeStyle = "#FF0000";
-					ctx.stroke();
-					this._buttons.current[i].style.backgroundColor = 'white';
-					this._buttons.current[i].style.backgroundImage = 'none';
-    			}
-    		}
-    		this.historyCache.current = bg;
-    		//Using history of input type to set colors of 'previous' buttons
-    		for (i=0; this._buttons.previous[i]; i++) {
-    			//
-    			if (this.colorManager.colorHistory[input].length > 1) {
-    				//
-    				prev = this.colorManager.colorHistory[input][this.colorManager.colorHistory[input].length-2];
-    				alpha = prev.a;
-    				//
-    				cvs = this._buttons.previous[i].getElementsByTagName('canvas')[0];
-	    			ctx = cvs.getContext('2d');
-    				ctx.clearRect(0, 0, cvs.width, cvs.height);
-    				//
-    				this._buttons.previous[i].style.background = 'none';
-    				this._buttons.previous[i].style.backgroundImage = 'none';
-    				this._buttons.previous[i].style.backgroundColor = 'none';
-    				//
-    				switch (prev.m) {
-    					case 'hsv':
-    						hsv = prev.c;
-    						color = this.colorManager.hsvToRgb(hsv.h/(Math.PI*2), hsv.s, hsv.v);
-    						this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba('+color.r+', '+color.g+', '+color.b+', '+alpha+')';
-    						break;
-    					case 'hsl':
-    						color = prev.c;
-							this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'hsla('+color.h+', '+color.s+'%, '+color.l+'%, '+alpha+')';
-    						break;
-    					case 'rgb':
-    						color = prev.c;
-    						this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba('+color.r+', '+color.g+', '+color.b+', '+alpha+')';
-    						break;
-    					case 'hex':
-    						this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = prev.c.hex;
-    						break;
-    					case 'gradient':
-    						this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = prev.c.value.css;
-    						break;
-    					case 'nocolor':
-    						ctx.beginPath();
-    						ctx.moveTo(0, cvs.height);
-			  				ctx.lineTo(cvs.width, 0);
-	  						ctx.lineWidth = 16;
-    						ctx.strokeStyle = "#FF0000";
-							ctx.stroke();
-							this._buttons.previous[i].style.backgroundColor = 'white';
-							this.historyCache.previous = 'nocolor';
-    						break;
-    					default:
-    						this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'transparent';
-    						this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = 'transparent';
-    						break;
-    				}
-    			} else {
-    				this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'transparent';
-    				this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = 'transparent';
-    			}
-    		}
-       	}
+        enumerable: false,
+        value: function (e) {
+            //Locals
+            var bg = 'none', img, i, input = this.colorManager.input.toLowerCase(), color, hsv, mode = e._event.mode, prev, alpha, ctx, cvs;
+            if (input === 'chip') {
+                return;
+            }
+            //Creating background color string according to panel mode (not input color mode)
+            if (mode === 'hsv' || mode === 'hsl' || mode === 'rgb' || mode === 'hex' || mode === 'alpha') {
+                if (this.panelMode === 'rgb' && e._event.rgba) {
+                    color = e._event.rgba;
+                    bg = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + color.a + ')';
+                } else if (this.panelMode === 'hsl' && e._event.hsla) {
+                    color = e._event.hsla;
+                    bg = 'hsla(' + color.h + ', ' + color.s + '%, ' + color.l + '%, ' + color.a + ')';
+                } else {
+                    bg = 'nocolor';
+                }
+                color = null;
+                for (i = 0; this._buttons.current[i]; i++) {
+                    cvs = this._buttons.current[i].getElementsByTagName('canvas')[0];
+                    ctx = cvs.getContext('2d');
+                    ctx.clearRect(0, 0, cvs.width, cvs.height);
+                    this._buttons.current[i].style.backgroundColor = bg;
+                    this._buttons.current[i].style.backgroundImage = 'none';
+                }
+            } else if (mode === 'gradient') {
+                //
+                color = e._event.value;
+                bg = e._event.value.value.css;
+                for (i = 0; this._buttons.current[i]; i++) {
+                    cvs = this._buttons.current[i].getElementsByTagName('canvas')[0];
+                    ctx = cvs.getContext('2d');
+                    ctx.clearRect(0, 0, cvs.width, cvs.height);
+                    this._buttons.current[i].style.background = 'none';
+                    this._buttons.current[i].style.backgroundColor = 'none';
+                    this._buttons.current[i].style.backgroundImage = bg;
+                }
+            } else {
+                //
+                bg = 'nocolor';
+                for (i = 0; this._buttons.current[i]; i++) {
+                    //TODO: combine no color into one reusable funtion
+                    cvs = this._buttons.current[i].getElementsByTagName('canvas')[0];
+                    ctx = cvs.getContext('2d');
+                    ctx.clearRect(0, 0, cvs.width, cvs.height);
+                    ctx.beginPath();
+                    ctx.moveTo(0, cvs.height);
+                    ctx.lineTo(cvs.width, 0);
+                    ctx.lineWidth = 16;
+                    ctx.strokeStyle = "#FF0000";
+                    ctx.stroke();
+                    this._buttons.current[i].style.backgroundColor = 'white';
+                    this._buttons.current[i].style.backgroundImage = 'none';
+                }
+            }
+            this.historyCache.current = bg;
+            //Using history of input type to set colors of 'previous' buttons
+            for (i = 0; this._buttons.previous[i]; i++) {
+                //
+                if (this.colorManager.colorHistory[input].length > 1) {
+                    //
+                    prev = this.colorManager.colorHistory[input][this.colorManager.colorHistory[input].length - 2];
+                    alpha = prev.a;
+                    //
+                    cvs = this._buttons.previous[i].getElementsByTagName('canvas')[0];
+                    ctx = cvs.getContext('2d');
+                    ctx.clearRect(0, 0, cvs.width, cvs.height);
+                    //
+                    this._buttons.previous[i].style.background = 'none';
+                    this._buttons.previous[i].style.backgroundImage = 'none';
+                    this._buttons.previous[i].style.backgroundColor = 'none';
+                    //
+                    switch (prev.m) {
+                        case 'hsv':
+                            hsv = prev.c;
+                            color = this.colorManager.hsvToRgb(hsv.h / (Math.PI * 2), hsv.s, hsv.v);
+                            this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + alpha + ')';
+                            break;
+                        case 'hsl':
+                            color = prev.c;
+                            this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'hsla(' + color.h + ', ' + color.s + '%, ' + color.l + '%, ' + alpha + ')';
+                            break;
+                        case 'rgb':
+                            color = prev.c;
+                            this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + alpha + ')';
+                            break;
+                        case 'hex':
+                            this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = prev.c.hex;
+                            break;
+                        case 'gradient':
+                            this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = prev.c.value.css;
+                            break;
+                        case 'nocolor':
+                            ctx.beginPath();
+                            ctx.moveTo(0, cvs.height);
+                            ctx.lineTo(cvs.width, 0);
+                            ctx.lineWidth = 16;
+                            ctx.strokeStyle = "#FF0000";
+                            ctx.stroke();
+                            this._buttons.previous[i].style.backgroundColor = 'white';
+                            this.historyCache.previous = 'nocolor';
+                            break;
+                        default:
+                            this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'transparent';
+                            this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = 'transparent';
+                            break;
+                    }
+                } else {
+                    this._buttons.previous[i].style.backgroundColor = this.historyCache.previous = 'transparent';
+                    this._buttons.previous[i].style.backgroundImage = this.historyCache.previous = 'transparent';
+                }
+            }
+        }
     },
     ////////////////////////////////////////////////////////////////////
     //Draws no color icon on button's canvas
     drawButtonNoColor: {
-    	enumerable: true,
-    	value: function (btn, cvs) {
-    		//
-    		var ctx = cvs.getContext('2d');
-    		ctx.clearRect(0, 0, cvs.width, cvs.height);
-    		//
-    		ctx.beginPath();
-    		ctx.moveTo(0, cvs.height);
-  			ctx.lineTo(cvs.width, 0);
-	  		ctx.lineWidth = Math.round(cvs.width/18);
-			ctx.strokeStyle = "#FF0000";
-			ctx.stroke();
-			btn.style.backgroundColor = 'white';
-			btn.style.backgroundImage = 'none';
-    	}
+        enumerable: true,
+        value: function (btn, cvs) {
+            //
+            var ctx = cvs.getContext('2d');
+            ctx.clearRect(0, 0, cvs.width, cvs.height);
+            //
+            ctx.beginPath();
+            ctx.moveTo(0, cvs.height);
+            ctx.lineTo(cvs.width, 0);
+            ctx.lineWidth = Math.round(cvs.width / 18);
+            ctx.strokeStyle = "#FF0000";
+            ctx.stroke();
+            btn.style.backgroundColor = 'white';
+            btn.style.backgroundImage = 'none';
+        }
     },
     ////////////////////////////////////////////////////////////////////
     //
     addButton: {
-    	enumerable: true,
-    	value: function (type, button) {
-    		//
-    		switch (type.toLocaleLowerCase()) {
-    			case 'chip':
-    				//
-    				var cvs = document.createElement('canvas');
-    				cvs.style.width = '100%';
-    				cvs.style.height = '100%';
-    				cvs.style.pointerEvents = 'none';
-    				cvs.style.float = 'left';
-    				//
-    				this._buttons.chip.push(button);
-    				button.style.cursor = 'pointer';
-    				button.color = function (m, c) {
-    					if (this.colorValue && c && this.colorValue.css === c.css) {
-    						return;
-    					}
-    					if (c && c.css) {
-    						this.ctx.clearRect(0, 0, this.cvs.width, this.cvs.height);
-    						this.style.backgroundColor = c.css;
-    					} else {
-    						this.drawNoColor(this, this.cvs);
-    					}
-    					this.colorValue = c;
-    					this.colorMode = m;
-    					this.otherInput = false;
-    					//
-    					var actionEvent = document.createEvent("CustomEvent");
-            			actionEvent.initEvent('change', true, true);
-            			actionEvent.color = c;
-            			actionEvent.colorMode = m;
-            			actionEvent.input = 'chip';
-            			this.dispatchEvent(actionEvent);
-    				};
-    				button.drawNoColor = this.drawButtonNoColor;
-    				button.addEventListener('click', this.selectColorWithChip.bind(this));
-    				button.cvs = cvs;
-    				button.ctx = cvs.getContext('2d');
-    				button.appendChild(cvs);
-    				break;
-    			case 'fill':
-    				this._buttons.fill.push(button);
-    				button.style.cursor = 'pointer';
-    				button.inputType = 'fill';
-    				button.title = 'Fill';
-    				button.popup = true;
-    				button.addEventListener('click', this.selectInputType.bind(this));
-    				button.innerHTML = "";
-    				var cvs = document.createElement('canvas');
-    				cvs.style.width = '100%';
-    				cvs.style.height = '100%';
-    				cvs.style.pointerEvents = 'none';
-    				cvs.style.float = 'left';
-    				button.appendChild(cvs);
-    				//
-    				if (this.application.ninja.colorController.fill && this.application.ninja.colorController.fill.css !== 'none') {
-    					button.style.background = 'none';
-						if (this.application.ninja.colorController.fill.css.indexOf('-webkit') >= 0) {
-							button.style.backgroundColor = 'none';
-							button.style.backgroundImage = this.application.ninja.colorController.fill.css;
-						} else {
-							button.style.backgroundColor = this.application.ninja.colorController.fill.css;
-							button.style.backgroundImage = 'none';
-						}
-    				} else {
-    					this.drawButtonNoColor(button, button.getElementsByTagName('canvas')[0]);
-    				}
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'fillicon':
-    				button.innerHTML = '';
-    				this._buttons.fill.push(button);
-    				button.style.cursor = 'pointer';
-    				button.inputType = 'fill';
-    				button.title = 'Fill';
-    				button.addEventListener('click', this.selectInputType.bind(this));
-    				button.className = button.className + ' cpe_fill_icon';
-    				if (this.colorManager.input === 'fill') {
-    					button.className = button.className + ' selected';
-    				}
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'stroke':
-    				this._buttons.stroke.push(button);
-    				button.style.cursor = 'pointer';
-    				button.inputType = 'stroke';
-    				button.popup = true;
-    				button.title = 'Stroke';
-    				button.addEventListener('click', this.selectInputType.bind(this));
-    				button.innerHTML = "";
-    				var cvs = document.createElement('canvas');
-    				cvs.style.width = '100%';
-    				cvs.style.height = '100%';
-    				cvs.style.pointerEvents = 'none';
-    				cvs.style.float = 'left';
-    				button.appendChild(cvs);
-    				//
-    				if (this.application.ninja.colorController.stroke && this.application.ninja.colorController.stroke.css !== 'none') {
-    					button.style.background = 'none';
-    					if (this.application.ninja.colorController.stroke.css.indexOf('-webkit') >= 0) {
-    						button.style.backgroundColor = 'none';
-    						button.style.backgroundImage = this.application.ninja.colorController.stroke.css;
-    					} else {
-    						button.style.backgroundColor = this.application.ninja.colorController.stroke.css;
-    						button.style.backgroundImage = 'none';
-    					}
-    				} else {
-    					this.drawButtonNoColor(button, button.getElementsByTagName('canvas')[0]);
-    					//this.selectInputHighlight(this._buttons['stroke'], this._buttons['fill'], false, true);
-    				}
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'strokeicon':
-    				button.innerHTML = '';
-    				this._buttons.stroke.push(button);
-    				button.style.cursor = 'pointer';
-    				button.title = 'Stroke';
-    				button.inputType = 'stroke';
-    				button.addEventListener('click', this.selectInputType.bind(this));
-    				button.className = button.className + ' cpe_stroke_icon';
-    				if (this.colorManager.input === 'stroke') {
-    					button.className = button.className + ' selected';
-    				}
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'current':
-    				this._buttons.current.push(button);
-    				button.style.cursor = 'default';
-    				button.innerHTML = "";
-    				button.title = 'Current Color'
-    				var cvs = document.createElement('canvas');
-    				cvs.style.width = '100%';
-    				cvs.style.height = '100%';
-    				cvs.style.pointerEvents = 'none';
-    				cvs.style.float = 'left';
-    				button.appendChild(cvs);
-    				if (this.historyCache.current) {
-    					//TODO:Remove hack
-    					if (this.historyCache.current === 'nocolor') {
-    						this.drawButtonNoColor(button, cvs);
-    					} else {
-    						button.style.backgroundColor = this.historyCache.current;
-    					}
-    				}
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'previous':
-    				this._buttons.previous.push(button);
-    				button.addEventListener('click', this.setPreviousColor.bind(this));
-    				button.style.cursor = 'pointer';
-    				button.innerHTML = "";
-    				button.title = 'Previous Color';
-    				var cvs = document.createElement('canvas');
-    				cvs.style.width = '100%';
-    				cvs.style.height = '100%';
-    				cvs.style.pointerEvents = 'none';
-    				cvs.style.float = 'left';
-    				button.appendChild(cvs);
-    				if (this.historyCache.previous) {
-    					if (this.historyCache.previous === 'nocolor') {
-    						this.drawButtonNoColor(button, cvs);
-    					} else {
-    						button.style.backgroundColor = this.historyCache.previous;
-    					}
-    				}
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'mlabel1':
-    				this._buttons.mlabel1.push(button);
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'mlabel2':
-    				this._buttons.mlabel2.push(button);
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'mlabel3':
-    				this._buttons.mlabel3.push(button);
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'rgbmode':
-    				this._buttons.rgbmode.push(button);
-    				button.title = 'Color Mode: RGB';
-    				button.addEventListener('click', this.rgbMode.bind(this));
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'hslmode':
-    				this._buttons.hslmode.push(button);
-    				button.title = 'Color Mode: HSL';
-    				button.addEventListener('click', this.hslMode.bind(this));
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'reset':
-    				this._buttons.reset.push(button);
-    				button.title = 'Default Colors';
-    				button.addEventListener('click', this.applyDefaultColors.bind(this));
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'nocolor':
-    				this._buttons.nocolor.push(button);
-    				button.title = 'No Color';
-    				button.addEventListener('click', this.setNoColor.bind(this));
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'swap':
-    				this._buttons.swap.push(button);
-    				button.title = 'Swap Colors';
-    				button.addEventListener('click', this.swapColors.bind(this));
-    				break;
-    				////////////////////////////////////////////////////////
-    			case 'hexinput':
-    				var hexinp = HotText.create();
-    				hexinp.element = button;
-    				hexinp.labelFunction = this._updateHexValue.bind(this);
-    				hexinp.inputFunction = this._hottextHexInput.bind(this);
-    				hexinp.needsDraw = true;
-    				this._buttons.hexinput.push(hexinp);
-    				return hexinp;
-    				break;
-    				////////////////////////////////////////////////////////
-    			default:
-    				console.log("ERROR: An error occured, the button '"+button+"' has an invalid type of "+type+".");
-    				break;
-    		}
-    	}
+        enumerable: true,
+        value: function (type, button) {
+            //
+            switch (type.toLocaleLowerCase()) {
+                case 'chip':
+                    //
+                    var cvs = document.createElement('canvas');
+                    cvs.style.width = '100%';
+                    cvs.style.height = '100%';
+                    cvs.style.pointerEvents = 'none';
+                    cvs.style.float = 'left';
+                    //
+                    this._buttons.chip.push(button);
+                    button.style.cursor = 'pointer';
+                    button.color = function (m, c) {
+                        if (this.colorValue && c && this.colorValue.css === c.css) {
+                            return;
+                        }
+                        if (c && c.css) {
+                            this.ctx.clearRect(0, 0, this.cvs.width, this.cvs.height);
+                            this.style.backgroundColor = c.css;
+                        } else {
+                            this.drawNoColor(this, this.cvs);
+                        }
+                        this.colorValue = c;
+                        this.colorMode = m;
+                        this.otherInput = false;
+                        //
+                        var actionEvent = document.createEvent("CustomEvent");
+                        actionEvent.initEvent('change', true, true);
+                        actionEvent.color = c;
+                        actionEvent.colorMode = m;
+                        actionEvent.input = 'chip';
+                        this.dispatchEvent(actionEvent);
+                    };
+                    button.drawNoColor = this.drawButtonNoColor;
+                    button.addEventListener('click', this.selectColorWithChip.bind(this));
+                    button.cvs = cvs;
+                    button.ctx = cvs.getContext('2d');
+                    button.appendChild(cvs);
+                    break;
+                case 'fill':
+                    this._buttons.fill.push(button);
+                    button.style.cursor = 'pointer';
+                    button.inputType = 'fill';
+                    button.title = 'Fill';
+                    button.popup = true;
+                    button.addEventListener('click', this.selectInputType.bind(this));
+                    button.innerHTML = "";
+                    var cvs = document.createElement('canvas');
+                    cvs.style.width = '100%';
+                    cvs.style.height = '100%';
+                    cvs.style.pointerEvents = 'none';
+                    cvs.style.float = 'left';
+                    button.appendChild(cvs);
+                    //
+                    if (this.application.ninja.colorController.fill && this.application.ninja.colorController.fill.css !== 'none') {
+                        button.style.background = 'none';
+                        if (this.application.ninja.colorController.fill.css.indexOf('-webkit') >= 0) {
+                            button.style.backgroundColor = 'none';
+                            button.style.backgroundImage = this.application.ninja.colorController.fill.css;
+                        } else {
+                            button.style.backgroundColor = this.application.ninja.colorController.fill.css;
+                            button.style.backgroundImage = 'none';
+                        }
+                    } else {
+                        this.drawButtonNoColor(button, button.getElementsByTagName('canvas')[0]);
+                    }
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'fillicon':
+                    button.innerHTML = '';
+                    this._buttons.fill.push(button);
+                    button.style.cursor = 'pointer';
+                    button.inputType = 'fill';
+                    button.title = 'Fill';
+                    button.addEventListener('click', this.selectInputType.bind(this));
+                    button.className = button.className + ' cpe_fill_icon';
+                    if (this.colorManager.input === 'fill') {
+                        button.className = button.className + ' selected';
+                    }
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'stroke':
+                    this._buttons.stroke.push(button);
+                    button.style.cursor = 'pointer';
+                    button.inputType = 'stroke';
+                    button.popup = true;
+                    button.title = 'Stroke';
+                    button.addEventListener('click', this.selectInputType.bind(this));
+                    button.innerHTML = "";
+                    var cvs = document.createElement('canvas');
+                    cvs.style.width = '100%';
+                    cvs.style.height = '100%';
+                    cvs.style.pointerEvents = 'none';
+                    cvs.style.float = 'left';
+                    button.appendChild(cvs);
+                    //
+                    if (this.application.ninja.colorController.stroke && this.application.ninja.colorController.stroke.css !== 'none') {
+                        button.style.background = 'none';
+                        if (this.application.ninja.colorController.stroke.css.indexOf('-webkit') >= 0) {
+                            button.style.backgroundColor = 'none';
+                            button.style.backgroundImage = this.application.ninja.colorController.stroke.css;
+                        } else {
+                            button.style.backgroundColor = this.application.ninja.colorController.stroke.css;
+                            button.style.backgroundImage = 'none';
+                        }
+                    } else {
+                        this.drawButtonNoColor(button, button.getElementsByTagName('canvas')[0]);
+                        //this.selectInputHighlight(this._buttons['stroke'], this._buttons['fill'], false, true);
+                    }
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'strokeicon':
+                    button.innerHTML = '';
+                    this._buttons.stroke.push(button);
+                    button.style.cursor = 'pointer';
+                    button.title = 'Stroke';
+                    button.inputType = 'stroke';
+                    button.addEventListener('click', this.selectInputType.bind(this));
+                    button.className = button.className + ' cpe_stroke_icon';
+                    if (this.colorManager.input === 'stroke') {
+                        button.className = button.className + ' selected';
+                    }
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'current':
+                    this._buttons.current.push(button);
+                    button.style.cursor = 'default';
+                    button.innerHTML = "";
+                    button.title = 'Current Color'
+                    var cvs = document.createElement('canvas');
+                    cvs.style.width = '100%';
+                    cvs.style.height = '100%';
+                    cvs.style.pointerEvents = 'none';
+                    cvs.style.float = 'left';
+                    button.appendChild(cvs);
+                    if (this.historyCache.current) {
+                        //TODO:Remove hack
+                        if (this.historyCache.current === 'nocolor') {
+                            this.drawButtonNoColor(button, cvs);
+                        } else {
+                            button.style.backgroundColor = this.historyCache.current;
+                        }
+                    }
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'previous':
+                    this._buttons.previous.push(button);
+                    button.addEventListener('click', this.setPreviousColor.bind(this));
+                    button.style.cursor = 'pointer';
+                    button.innerHTML = "";
+                    button.title = 'Previous Color';
+                    var cvs = document.createElement('canvas');
+                    cvs.style.width = '100%';
+                    cvs.style.height = '100%';
+                    cvs.style.pointerEvents = 'none';
+                    cvs.style.float = 'left';
+                    button.appendChild(cvs);
+                    if (this.historyCache.previous) {
+                        if (this.historyCache.previous === 'nocolor') {
+                            this.drawButtonNoColor(button, cvs);
+                        } else {
+                            button.style.backgroundColor = this.historyCache.previous;
+                        }
+                    }
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'mlabel1':
+                    this._buttons.mlabel1.push(button);
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'mlabel2':
+                    this._buttons.mlabel2.push(button);
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'mlabel3':
+                    this._buttons.mlabel3.push(button);
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'rgbmode':
+                    this._buttons.rgbmode.push(button);
+                    button.title = 'Color Mode: RGB';
+                    button.addEventListener('click', this.rgbMode.bind(this));
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'hslmode':
+                    this._buttons.hslmode.push(button);
+                    button.title = 'Color Mode: HSL';
+                    button.addEventListener('click', this.hslMode.bind(this));
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'reset':
+                    this._buttons.reset.push(button);
+                    button.title = 'Default Colors';
+                    button.addEventListener('click', this.applyDefaultColors.bind(this));
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'nocolor':
+                    this._buttons.nocolor.push(button);
+                    button.title = 'No Color';
+                    button.addEventListener('click', this.setNoColor.bind(this));
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'swap':
+                    this._buttons.swap.push(button);
+                    button.title = 'Swap Colors';
+                    button.addEventListener('click', this.swapColors.bind(this));
+                    break;
+                //////////////////////////////////////////////////////// 
+                case 'hexinput':
+                    var hexinp = HotText.create();
+                    hexinp.element = button;
+                    hexinp.labelFunction = this._updateHexValue.bind(this);
+                    hexinp.inputFunction = this._hottextHexInput.bind(this);
+                    hexinp.needsDraw = true;
+                    this._buttons.hexinput.push(hexinp);
+                    return hexinp;
+                    break;
+                /////