1 define("dijit/_editor/plugins/TextColor", [
3 "dojo/colors", // colors.fromRgb
4 "dojo/_base/declare", // declare
7 "../../form/DropDownButton"
8 ], function(require, colors, declare, lang, _Plugin, DropDownButton){
11 // dijit/_editor/plugins/TextColor
14 var TextColor = declare("dijit._editor.plugins.TextColor", _Plugin, {
16 // This plugin provides dropdown color pickers for setting text color and background color
18 // The commands provided by this plugin are:
20 // - foreColor - sets the text color
21 // - hiliteColor - sets the background color
23 // Override _Plugin.buttonClass to use DropDownButton (with ColorPalette) to control this plugin
24 buttonClass: DropDownButton,
26 // useDefaultCommand: Boolean
27 // False as we do not use the default editor command/click behavior.
28 useDefaultCommand: false,
30 _initButton: function(){
31 this.inherited(arguments);
33 // Setup to lazy load ColorPalette first time the button is clicked
35 this.button.loadDropDown = function(callback){
36 require(["../../ColorPalette"], lang.hitch(this, function(ColorPalette){
37 this.dropDown = new ColorPalette({
39 ownerDocument: self.editor.ownerDocument,
41 onChange: function(color){
42 self.editor.execCommand(self.command, color);
50 updateState: function(){
52 // Overrides _Plugin.updateState(). This updates the ColorPalette
53 // to show the color of the currently selected text.
58 var _c = this.command;
59 if(!_e || !_e.isLoaded || !_c.length){
64 var disabled = this.get("disabled");
65 this.button.set("disabled", disabled);
66 if(disabled){ return; }
70 value = _e.queryCommandValue(_c)|| "";
72 //Firefox may throw error above if the editor is just loaded, ignore it
80 if(value == "transparent"){
84 if(typeof value == "string"){
85 //if RGB value, convert to hex value
86 if(value.indexOf("rgb")> -1){
87 value = colors.fromRgb(value).toHex();
89 }else{ //it's an integer(IE returns an MS access #)
90 value =((value & 0x0000ff)<< 16)|(value & 0x00ff00)|((value & 0xff0000)>>> 16);
91 value = value.toString(16);
92 value = "#000000".slice(0, 7 - value.length)+ value;
98 var dropDown = this.button.dropDown;
99 if(dropDown && value !== dropDown.get('value')){
100 dropDown.set('value', value, false);
105 // Register this plugin.
106 _Plugin.registry["foreColor"] = function(){
107 return new TextColor({command: "foreColor"});
109 _Plugin.registry["hiliteColor"] = function(){
110 return new TextColor({command: "hiliteColor"});