| 1 |
define([ |
| 2 |
"require", |
| 3 |
"dojo/colors", |
| 4 |
"dojo/_base/declare", |
| 5 |
"dojo/_base/lang", |
| 6 |
"../_Plugin", |
| 7 |
"../../form/DropDownButton" |
| 8 |
], function(require, colors, declare, lang, _Plugin, DropDownButton){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var TextColor = declare("dijit._editor.plugins.TextColor", _Plugin, { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
buttonClass: DropDownButton, |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
colorPicker: "dijit/ColorPalette", |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
useDefaultCommand: false, |
| 32 |
|
| 33 |
_initButton: function(){ |
| 34 |
this.command = this.name; |
| 35 |
|
| 36 |
this.inherited(arguments); |
| 37 |
|
| 38 |
|
| 39 |
var self = this; |
| 40 |
this.button.loadDropDown = function(callback){ |
| 41 |
function onColorPaletteLoad(ColorPalette){ |
| 42 |
self.button.dropDown = new ColorPalette({ |
| 43 |
dir: self.editor.dir, |
| 44 |
ownerDocument: self.editor.ownerDocument, |
| 45 |
value: self.value, |
| 46 |
onChange: function(color){ |
| 47 |
self.editor.execCommand(self.command, color); |
| 48 |
}, |
| 49 |
onExecute: function(){ |
| 50 |
self.editor.execCommand(self.command, this.get("value")); |
| 51 |
} |
| 52 |
}); |
| 53 |
callback(); |
| 54 |
} |
| 55 |
if(typeof self.colorPicker == "string"){ |
| 56 |
require([self.colorPicker], onColorPaletteLoad); |
| 57 |
}else{ |
| 58 |
onColorPaletteLoad(self.colorPicker); |
| 59 |
} |
| 60 |
}; |
| 61 |
}, |
| 62 |
|
| 63 |
updateState: function(){ |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
var _e = this.editor; |
| 71 |
var _c = this.command; |
| 72 |
if(!_e || !_e.isLoaded || !_c.length){ |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
if(this.button){ |
| 77 |
var disabled = this.get("disabled"); |
| 78 |
this.button.set("disabled", disabled); |
| 79 |
if(disabled){ |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
var value; |
| 84 |
try{ |
| 85 |
value = _e.queryCommandValue(_c) || ""; |
| 86 |
}catch(e){ |
| 87 |
|
| 88 |
value = ""; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
if(value == ""){ |
| 93 |
value = "#000000"; |
| 94 |
} |
| 95 |
if(value == "transparent"){ |
| 96 |
value = "#ffffff"; |
| 97 |
} |
| 98 |
|
| 99 |
if(typeof value == "string"){ |
| 100 |
|
| 101 |
if(value.indexOf("rgb") > -1){ |
| 102 |
value = colors.fromRgb(value).toHex(); |
| 103 |
} |
| 104 |
}else{ |
| 105 |
value = ((value & 0x0000ff) << 16) | (value & 0x00ff00) | ((value & 0xff0000) >>> 16); |
| 106 |
value = value.toString(16); |
| 107 |
value = "#000000".slice(0, 7 - value.length) + value; |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
this.value = value; |
| 112 |
|
| 113 |
var dropDown = this.button.dropDown; |
| 114 |
if(dropDown && dropDown.get && value !== dropDown.get('value')){ |
| 115 |
dropDown.set('value', value, false); |
| 116 |
} |
| 117 |
} |
| 118 |
}); |
| 119 |
|
| 120 |
|
| 121 |
_Plugin.registry["foreColor"] = function(args){ |
| 122 |
return new TextColor(args); |
| 123 |
}; |
| 124 |
_Plugin.registry["hiliteColor"] = function(args){ |
| 125 |
return new TextColor(args); |
| 126 |
}; |
| 127 |
|
| 128 |
return TextColor; |
| 129 |
}); |