54d6e1c9811b12cffee85e71291afb5cd421435b
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / htmlarea / plugins / TextIndicator / text-indicator.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010-2011 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 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /*
28 * TextIndicator Plugin for TYPO3 htmlArea RTE
29 */
30 HTMLArea.TextIndicator = Ext.extend(HTMLArea.Plugin, {
31 /*
32 * This function gets called by the class constructor
33 */
34 configurePlugin : function (editor) {
35 /*
36 * Registering plugin "About" information
37 */
38 var pluginInformation = {
39 version : '1.1',
40 developer : 'Stanislas Rolland',
41 developerUrl : 'http://www.sjbr.ca/',
42 copyrightOwner : 'Stanislas Rolland',
43 sponsor : 'SJBR',
44 sponsorUrl : 'http://www.sjbr.ca/',
45 license : 'GPL'
46 };
47 this.registerPluginInformation(pluginInformation);
48
49 /*
50 * Registering the indicator
51 */
52 var buttonId = 'TextIndicator';
53 var textConfiguration = {
54 id: buttonId,
55 cls: 'indicator',
56 text: 'A',
57 tooltip: this.localize(buttonId.toLowerCase())
58 };
59 this.registerText(textConfiguration);
60 return true;
61 },
62
63 /*
64 * This function gets called when the toolbar is updated
65 */
66 onUpdateToolbar: function (button, mode, selectionEmpty, ancestors) {
67 var editor = this.editor;
68 if (mode === 'wysiwyg' && editor.isEditable()) {
69 var doc = editor._doc;
70 try {
71 var style = {
72 backgroundColor: HTMLArea._makeColor(doc.queryCommandValue((Ext.isIE || Ext.isWebKit) ? 'BackColor' : 'HiliteColor')),
73 color: HTMLArea._makeColor(doc.queryCommandValue('ForeColor')),
74 fontFamily: doc.queryCommandValue('FontName'),
75 fontWeight: 'normal',
76 fontStyle: 'normal'
77 };
78 // Mozilla
79 if (/transparent/i.test(style.backgroundColor)) {
80 style.backgroundColor = HTMLArea._makeColor(doc.queryCommandValue('BackColor'));
81 }
82 try {
83 style.fontWeight = doc.queryCommandState('Bold') ? 'bold' : 'normal';
84 } catch(e) {
85 style.fontWeight = 'normal';
86 }
87 try {
88 style.fontStyle = doc.queryCommandState('Italic') ? 'italic' : 'normal';
89 } catch(e) {
90 style.fontStyle = 'normal';
91 }
92 button.getEl().setStyle(style);
93 } catch (e) { }
94 }
95 }
96 });