| 1 |
define([ |
| 2 |
"dojo", |
| 3 |
"dijit", |
| 4 |
"dojox", |
| 5 |
"dijit/_base/popup", |
| 6 |
"dijit/_Widget", |
| 7 |
"dijit/_TemplatedMixin", |
| 8 |
"dijit/_WidgetsInTemplateMixin", |
| 9 |
"dijit/_editor/_Plugin", |
| 10 |
"dijit/TooltipDialog", |
| 11 |
"dijit/form/Button", |
| 12 |
"dijit/form/DropDownButton", |
| 13 |
"dojox/widget/ColorPicker", |
| 14 |
"dojo/_base/connect", |
| 15 |
"dojo/_base/declare", |
| 16 |
"dojo/i18n", |
| 17 |
"dojo/i18n!dojox/editor/plugins/nls/TextColor" |
| 18 |
], function(dojo, dijit, dojox, popup, _Widget, _TemplatedMixin, _WidgetsInTemplateMixin, _Plugin) { |
| 19 |
|
| 20 |
dojo.experimental("dojox.editor.plugins.TextColor"); |
| 21 |
|
| 22 |
var TextColorDropDown = dojo.declare("dojox.editor.plugins._TextColorDropDown", [_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
templateString: "<div style='display: none; position: absolute; top: -10000; z-index: -10000'>" + |
| 32 |
"<div dojoType='dijit.TooltipDialog' dojoAttachPoint='dialog' class='dojoxEditorColorPicker'>" + |
| 33 |
"<div dojoType='dojox.widget.ColorPicker' dojoAttachPoint='_colorPicker'></div>" + |
| 34 |
"<br>" + |
| 35 |
"<center>" + |
| 36 |
"<button dojoType='dijit.form.Button' type='button' dojoAttachPoint='_setButton'>${setButtonText}</button>" + |
| 37 |
" " + |
| 38 |
"<button dojoType='dijit.form.Button' type='button' dojoAttachPoint='_cancelButton'>${cancelButtonText}</button>" + |
| 39 |
"</center>" + |
| 40 |
"</div>" + |
| 41 |
"</div>", |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
widgetsInTemplate: true, |
| 46 |
|
| 47 |
constructor: function(){ |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
var strings = dojo.i18n.getLocalization("dojox.editor.plugins", "TextColor"); |
| 52 |
dojo.mixin(this, strings); |
| 53 |
}, |
| 54 |
|
| 55 |
startup: function(){ |
| 56 |
|
| 57 |
|
| 58 |
if(!this._started){ |
| 59 |
this.inherited(arguments); |
| 60 |
this.connect(this._setButton, "onClick", dojo.hitch(this, function(){ |
| 61 |
this.onChange(this.get("value")); |
| 62 |
})); |
| 63 |
this.connect(this._cancelButton, "onClick", dojo.hitch(this, function(){ |
| 64 |
dijit.popup.close(this.dialog); |
| 65 |
this.onCancel(); |
| 66 |
})); |
| 67 |
|
| 68 |
dojo.style(this.domNode, "display", "block"); |
| 69 |
} |
| 70 |
}, |
| 71 |
|
| 72 |
_setValueAttr: function(value, priorityChange){ |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
this._colorPicker.set("value", value, priorityChange); |
| 80 |
}, |
| 81 |
|
| 82 |
_getValueAttr: function(){ |
| 83 |
|
| 84 |
|
| 85 |
return this._colorPicker.get("value"); |
| 86 |
}, |
| 87 |
|
| 88 |
onChange: function(value){ |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
}, |
| 94 |
|
| 95 |
onCancel: function(){ |
| 96 |
|
| 97 |
|
| 98 |
} |
| 99 |
}); |
| 100 |
|
| 101 |
|
| 102 |
var TextColor = dojo.declare("dojox.editor.plugins.TextColor", _Plugin, { |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
buttonClass: dijit.form.DropDownButton, |
| 115 |
|
| 116 |
|
| 117 |
useDefaultCommand: false, |
| 118 |
|
| 119 |
constructor: function(){ |
| 120 |
this._picker = new TextColorDropDown(); |
| 121 |
dojo.body().appendChild(this._picker.domNode); |
| 122 |
this._picker.startup(); |
| 123 |
this.dropDown = this._picker.dialog; |
| 124 |
this.connect(this._picker, "onChange", function(color){ |
| 125 |
this.editor.execCommand(this.command, color); |
| 126 |
}); |
| 127 |
this.connect(this._picker, "onCancel", function(){ |
| 128 |
this.editor.focus(); |
| 129 |
}); |
| 130 |
}, |
| 131 |
|
| 132 |
updateState: function(){ |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
var _e = this.editor; |
| 139 |
var _c = this.command; |
| 140 |
if(!_e || !_e.isLoaded || !_c.length){ |
| 141 |
return; |
| 142 |
} |
| 143 |
|
| 144 |
var disabled = this.get("disabled"); |
| 145 |
|
| 146 |
var value; |
| 147 |
if(this.button){ |
| 148 |
this.button.set("disabled", disabled); |
| 149 |
if(disabled){ |
| 150 |
return; |
| 151 |
} |
| 152 |
try{ |
| 153 |
value = _e.queryCommandValue(_c)|| ""; |
| 154 |
}catch(e){ |
| 155 |
|
| 156 |
value = ""; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
if(value == ""){ |
| 161 |
value = "#000000"; |
| 162 |
} |
| 163 |
if(value == "transparent"){ |
| 164 |
value = "#ffffff"; |
| 165 |
} |
| 166 |
|
| 167 |
if(typeof value == "string"){ |
| 168 |
|
| 169 |
if(value.indexOf("rgb")> -1){ |
| 170 |
value = dojo.colorFromRgb(value).toHex(); |
| 171 |
} |
| 172 |
}else{ |
| 173 |
value =((value & 0x0000ff)<< 16)|(value & 0x00ff00)|((value & 0xff0000)>>> 16); |
| 174 |
value = value.toString(16); |
| 175 |
value = "#000000".slice(0, 7 - value.length)+ value; |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
if(value !== this._picker.get('value')){ |
| 180 |
this._picker.set('value', value, false); |
| 181 |
} |
| 182 |
}, |
| 183 |
|
| 184 |
destroy: function(){ |
| 185 |
|
| 186 |
|
| 187 |
this.inherited(arguments); |
| 188 |
this._picker.destroyRecursive(); |
| 189 |
delete this._picker; |
| 190 |
} |
| 191 |
}); |
| 192 |
|
| 193 |
|
| 194 |
TextColor._TextColorDropDown = TextColorDropDown; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
dojo.subscribe(dijit._scopeName + ".Editor.getPlugin", null, function(o){ |
| 199 |
if(o.plugin){ |
| 200 |
return; |
| 201 |
} |
| 202 |
switch(o.args.name){ |
| 203 |
case "foreColor": |
| 204 |
case "hiliteColor": |
| 205 |
o.plugin = new TextColor({ |
| 206 |
command: o.args.name |
| 207 |
}); |
| 208 |
} |
| 209 |
}); |
| 210 |
|
| 211 |
return TextColor; |
| 212 |
|
| 213 |
}); |