]> git.wh0rd.org Git - tt-rss.git/blob - lib/dijit/_editor/plugins/TextColor.js.uncompressed.js
modify dojo rebuild script to remove uncompressed files
[tt-rss.git] / lib / dijit / _editor / plugins / TextColor.js.uncompressed.js
1 define("dijit/_editor/plugins/TextColor", [
2         "require",
3         "dojo/colors", // colors.fromRgb
4         "dojo/_base/declare", // declare
5         "dojo/_base/lang",
6         "../_Plugin",
7         "../../form/DropDownButton"
8 ], function(require, colors, declare, lang, _Plugin, DropDownButton){
9
10 // module:
11 //              dijit/_editor/plugins/TextColor
12
13
14 var TextColor = declare("dijit._editor.plugins.TextColor", _Plugin, {
15         // summary:
16         //              This plugin provides dropdown color pickers for setting text color and background color
17         // description:
18         //              The commands provided by this plugin are:
19         //
20         //              - foreColor - sets the text color
21         //              - hiliteColor - sets the background color
22
23         // Override _Plugin.buttonClass to use DropDownButton (with ColorPalette) to control this plugin
24         buttonClass: DropDownButton,
25
26         // useDefaultCommand: Boolean
27         //              False as we do not use the default editor command/click behavior.
28         useDefaultCommand: false,
29
30         _initButton: function(){
31                 this.inherited(arguments);
32
33                 // Setup to lazy load ColorPalette first time the button is clicked
34                 var self = this;
35                 this.button.loadDropDown = function(callback){
36                         require(["../../ColorPalette"], lang.hitch(this, function(ColorPalette){
37                                 this.dropDown = new ColorPalette({
38                                         dir: self.editor.dir,
39                                         ownerDocument: self.editor.ownerDocument,
40                                         value: self.value,
41                                         onChange: function(color){
42                                                 self.editor.execCommand(self.command, color);
43                                         }
44                                 });
45                                 callback();
46                         }));
47                 };
48         },
49
50         updateState: function(){
51                 // summary:
52                 //              Overrides _Plugin.updateState().  This updates the ColorPalette
53                 //              to show the color of the currently selected text.
54                 // tags:
55                 //              protected
56
57                 var _e = this.editor;
58                 var _c = this.command;
59                 if(!_e || !_e.isLoaded || !_c.length){
60                         return;
61                 }
62
63                 if(this.button){
64                         var disabled = this.get("disabled");
65                         this.button.set("disabled", disabled);
66                         if(disabled){ return; }
67
68                         var value;
69                         try{
70                                 value = _e.queryCommandValue(_c)|| "";
71                         }catch(e){
72                                 //Firefox may throw error above if the editor is just loaded, ignore it
73                                 value = "";
74                         }
75                 }
76
77                 if(value == ""){
78                         value = "#000000";
79                 }
80                 if(value == "transparent"){
81                         value = "#ffffff";
82                 }
83
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();
88                         }
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;
93
94                 }
95
96                 this.value = value;
97
98                 var dropDown = this.button.dropDown;
99                 if(dropDown && value !== dropDown.get('value')){
100                         dropDown.set('value', value, false);
101                 }
102         }
103 });
104
105 // Register this plugin.
106 _Plugin.registry["foreColor"] = function(){
107         return new TextColor({command: "foreColor"});
108 };
109 _Plugin.registry["hiliteColor"] = function(){
110         return new TextColor({command: "hiliteColor"});
111 };
112
113
114 return TextColor;
115 });