From 81bea17aefb26859f825b9293c7c99192874806e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 8 Nov 2011 20:40:44 +0400 Subject: upgrade Dojo to 1.6.1 --- lib/dijit/_editor/plugins/TextColor.js | 143 +++++++++++++++++++++------------ 1 file changed, 93 insertions(+), 50 deletions(-) (limited to 'lib/dijit/_editor/plugins/TextColor.js') diff --git a/lib/dijit/_editor/plugins/TextColor.js b/lib/dijit/_editor/plugins/TextColor.js index da7bbc9a6..2f24d0424 100644 --- a/lib/dijit/_editor/plugins/TextColor.js +++ b/lib/dijit/_editor/plugins/TextColor.js @@ -1,62 +1,105 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ -if(!dojo._hasResource["dijit._editor.plugins.TextColor"]){ -dojo._hasResource["dijit._editor.plugins.TextColor"]=true; +if(!dojo._hasResource["dijit._editor.plugins.TextColor"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dijit._editor.plugins.TextColor"] = true; dojo.provide("dijit._editor.plugins.TextColor"); dojo.require("dijit._editor._Plugin"); dojo.require("dijit.ColorPalette"); -dojo.declare("dijit._editor.plugins.TextColor",dijit._editor._Plugin,{buttonClass:dijit.form.DropDownButton,useDefaultCommand:false,constructor:function(){ -this.dropDown=new dijit.ColorPalette(); -this.connect(this.dropDown,"onChange",function(_1){ -this.editor.execCommand(this.command,_1); + + +dojo.declare("dijit._editor.plugins.TextColor", dijit._editor._Plugin, { + // summary: + // This plugin provides dropdown color pickers for setting text color and background color + // + // description: + // The commands provided by this plugin are: + // * foreColor - sets the text color + // * hiliteColor - sets the background color + + // Override _Plugin.buttonClass to use DropDownButton (with ColorPalette) to control this plugin + buttonClass: dijit.form.DropDownButton, + + // useDefaultCommand: Boolean + // False as we do not use the default editor command/click behavior. + useDefaultCommand: false, + + constructor: function(){ + this.dropDown = new dijit.ColorPalette(); + this.connect(this.dropDown, "onChange", function(color){ + this.editor.execCommand(this.command, color); + + }); + }, + + updateState: function(){ + // summary: + // Overrides _Plugin.updateState(). This updates the ColorPalette + // to show the color of the currently selected text. + // tags: + // protected + + var _e = this.editor; + var _c = this.command; + if(!_e || !_e.isLoaded || !_c.length){ + return; + } + + if(this.button){ + var disabled = this.get("disabled"); + this.button.set("disabled", disabled); + if(disabled){ return; } + + var value; + try{ + value = _e.queryCommandValue(_c)|| ""; + }catch(e){ + //Firefox may throw error above if the editor is just loaded, ignore it + value = ""; + } + } + + if(value == ""){ + value = "#000000"; + } + if(value == "transparent"){ + value = "#ffffff"; + } + + if(typeof value == "string"){ + //if RGB value, convert to hex value + if(value.indexOf("rgb")> -1){ + value = dojo.colorFromRgb(value).toHex(); + } + }else{ //it's an integer(IE returns an MS access #) + value =((value & 0x0000ff)<< 16)|(value & 0x00ff00)|((value & 0xff0000)>>> 16); + value = value.toString(16); + value = "#000000".slice(0, 7 - value.length)+ value; + + } + + if(value !== this.dropDown.get('value')){ + this.dropDown.set('value', value, false); + } + } }); -},updateState:function(){ -var _2=this.editor; -var _3=this.command; -if(!_2||!_2.isLoaded||!_3.length){ -return; -} -if(this.button){ -var _4; -try{ -_4=_2.queryCommandValue(_3)||""; -} -catch(e){ -_4=""; -} -} -if(_4==""){ -_4="#000000"; -} -if(_4=="transparent"){ -_4="#ffffff"; -} -if(typeof _4=="string"){ -if(_4.indexOf("rgb")>-1){ -_4=dojo.colorFromRgb(_4).toHex(); -} -}else{ -_4=((_4&255)<<16)|(_4&65280)|((_4&16711680)>>>16); -_4=_4.toString(16); -_4="#000000".slice(0,7-_4.length)+_4; -} -if(_4!==this.dropDown.get("value")){ -this.dropDown.set("value",_4,false); -} -}}); -dojo.subscribe(dijit._scopeName+".Editor.getPlugin",null,function(o){ -if(o.plugin){ -return; -} -switch(o.args.name){ -case "foreColor": -case "hiliteColor": -o.plugin=new dijit._editor.plugins.TextColor({command:o.args.name}); -} + +// Register this plugin. +dojo.subscribe(dijit._scopeName + ".Editor.getPlugin", null, function(o){ + if(o.plugin){ + return; + } + switch(o.args.name){ + case "foreColor": + case "hiliteColor": + o.plugin = new dijit._editor.plugins.TextColor({ + command: o.args.name + }); + } }); + } -- cgit v1.2.3