39ba7315a6fbe73f4d5e15d8a6c7ce830d6a4e76
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / htmlarea / plugins / DefaultColor / default-color.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
5 * All rights reserved
6 *
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 * A copy is found in the textfile GPL.txt and important notices to the license
16 * from the author is found in LICENSE.txt distributed with these scripts.
17 *
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This script is a modified version of a script published under the htmlArea License.
25 * A copy of the htmlArea License may be found in the textfile HTMLAREA_LICENSE.txt.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /*
30 * Default Color Plugin for TYPO3 htmlArea RTE
31 *
32 * TYPO3 SVN ID: $Id: $
33 */
34 DefaultColor = HTMLArea.Plugin.extend({
35
36 constructor : function(editor, pluginName) {
37 this.base(editor, pluginName);
38 },
39
40 /*
41 * This function gets called by the class constructor
42 */
43 configurePlugin : function(editor) {
44
45 this.buttonsConfiguration = this.editorConfiguration.buttons;
46
47 /*
48 * Registering plugin "About" information
49 */
50 var pluginInformation = {
51 version : "1.0",
52 developer : "Stanislas Rolland",
53 developerUrl : "http://www.sjbr.ca/",
54 copyrightOwner : "Stanislas Rolland",
55 sponsor : "SJBR",
56 sponsorUrl : "http://www.sjbr.ca/",
57 license : "GPL"
58 };
59 this.registerPluginInformation(pluginInformation);
60
61 /*
62 * Registering the buttons
63 */
64 var buttonList = this.buttonList;
65 for (var i = 0; i < buttonList.length; ++i) {
66 var button = buttonList[i];
67 buttonId = button[0];
68 var buttonConfiguration = {
69 id : buttonId,
70 tooltip : this.localize(buttonId.toLowerCase()),
71 action : "onButtonPress",
72 hotKey : (this.buttonsConfiguration[button[1]] ? this.buttonsConfiguration[button[1]].hotKey : null),
73 dialog : true
74 };
75 this.registerButton(buttonConfiguration);
76 }
77
78 return true;
79 },
80
81 /*
82 * The list of buttons added by this plugin
83 */
84 buttonList : [
85 ["ForeColor", "textcolor"],
86 ["HiliteColor", "bgcolor"]
87 ],
88
89 /*
90 * This function gets called when the button was pressed.
91 *
92 * @param object editor: the editor instance
93 * @param string id: the button id or the key
94 * @param object target: the target element of the contextmenu event, when invoked from the context menu
95 *
96 * @return boolean false if action is completed
97 */
98 onButtonPress : function(editor, id, target) {
99 // Could be a button or its hotkey
100 var buttonId = this.translateHotKey(id);
101 buttonId = buttonId ? buttonId : id;
102
103 this.commandId = buttonId;
104
105 switch (buttonId) {
106 case "HiliteColor" :
107 if (HTMLArea.is_ie || HTMLArea.is_safari) {
108 this.commandId = "BackColor";
109 }
110 case "ForeColor" :
111 this.dialog = this.openDialog(buttonId, this.makeUrlFromPopupName("select_color"), "setColor", HTMLArea._colorToRgb(this.editor._doc.queryCommandValue(this.commandId)), {width:300, height:210});
112 break;
113 default:
114 this.dialog = this.openDialog(buttonId, this.makeUrlFromPopupName("select_color"), "returnToCaller", HTMLArea._colorToRgb("000000"), {width:300, height:210});
115 break;
116 }
117 return false;
118 },
119
120 /*
121 * Set the color
122 *
123 * @param object param: the returned color
124 *
125 * @return boolean false
126 */
127 setColor : function(color) {
128 this.editor.focusEditor();
129 if (color) {
130 this.editor._doc.execCommand(this.commandId, false, "#" + color);
131 }
132 return false;
133 },
134
135 /*
136 * Return to caller
137 *
138 * @param object param: the returned color
139 *
140 * @return boolean false
141 */
142 returnToCaller : function(color) {
143 if (color && this.editor.plugins[this.commandId]
144 && this.editor.plugins[this.commandId].instance
145 && this.editor.plugins[this.commandId].instance.dialog
146 && this.editor.plugins[this.commandId].instance.dialog.dialogWindow) {
147 this.editor.plugins[this.commandId].instance.dialog.dialogWindow.insertColor("#" + color);
148 }
149 return false;
150 }
151 });
152