777e1b1c04cb303c6c593112f1faed788ee7312b
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Resources / Public / JavaScript / HTMLArea / Configuration / Config.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * Configuration of af an Editor of TYPO3 htmlArea RTE
16 */
17 define('TYPO3/CMS/Rtehtmlarea/HTMLArea/Configuration/Config',
18 ['TYPO3/CMS/Rtehtmlarea/HTMLArea/UserAgent/UserAgent',
19 'TYPO3/CMS/Rtehtmlarea/HTMLArea/Util/Util'],
20 function (UserAgent, Util) {
21
22 /**
23 * Constructor: Sets editor configuration defaults
24 */
25 var Config = function (editorId) {
26 this.editorId = editorId;
27 // if the site is secure, create a secure iframe
28 this.useHTTPS = false;
29 // for Mozilla
30 this.useCSS = false;
31 this.enableMozillaExtension = true;
32 this.disableEnterParagraphs = false;
33 this.disableObjectResizing = false;
34 this.removeTrailingBR = true;
35 // style included in the iframe document
36 this.editedContentStyle = HTMLArea.editedContentCSS;
37 // Array of content styles
38 this.pageStyle = [];
39 // Maximum attempts at accessing the stylesheets
40 this.styleSheetsMaximumAttempts = 20;
41 // Remove tags (must be a regular expression)
42 this.htmlRemoveTags = /none/i;
43 // Remove tags and their contents (must be a regular expression)
44 this.htmlRemoveTagsAndContents = /none/i;
45 // Remove comments
46 this.htmlRemoveComments = false;
47 // Array of custom tags
48 this.customTags = [];
49 // BaseURL to be included in the iframe document
50 this.baseURL = document.baseURI;
51 // IE does not support document.baseURI
52 // Since document.URL is incorrect when using realurl, get first base tag and extract href
53 if (!this.baseURL) {
54 var baseTags = document.getElementsByTagName ('base');
55 if (baseTags.length > 0) {
56 this.baseURL = baseTags[0].href;
57 } else {
58 this.baseURL = document.URL;
59 }
60 }
61 if (this.baseURL && this.baseURL.match(/(.*\:\/\/.*\/)[^\/]*/)) {
62 this.baseURL = RegExp.$1;
63 }
64 // URL-s
65 this.popupURL = "Resources/Public/Html/";
66 // DocumentType
67 this.documentType = '<!DOCTYPE html\r'
68 + ' PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\r'
69 + ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r';
70 this.blankDocument = '<html><head></head><body></body></html>';
71 // Hold the configuration of buttons and hot keys registered by plugins
72 this.buttonsConfig = {};
73 this.hotKeyList = {};
74 // Default configurations for toolbar items
75 this.configDefaults = {
76 all: {
77 xtype: 'htmlareabutton',
78 disabledClass: 'buttonDisabled',
79 textMode: false,
80 selection: false,
81 dialog: false,
82 hidden: false,
83 hideMode: 'display'
84 },
85 htmlareabutton: {
86 cls: 'button',
87 overCls: 'buttonHover',
88 // Erratic behaviour of click event in WebKit and IE browsers
89 clickEvent: (UserAgent.isWebKit || UserAgent.isIE) ? 'mousedown' : 'click'
90 },
91 htmlareacombo: {
92 cls: 'select',
93 typeAhead: true,
94 lastQuery: '',
95 triggerAction: 'all',
96 editable: !UserAgent.isIE,
97 selectOnFocus: !UserAgent.isIE,
98 validationEvent: false,
99 validateOnBlur: false,
100 submitValue: false,
101 forceSelection: true,
102 mode: 'local',
103 storeRoot: 'options',
104 storeFields: [ { name: 'text'}, { name: 'value'}],
105 valueField: 'value',
106 displayField: 'text',
107 labelSeparator: '',
108 hideLabel: true,
109 tpl: '<tpl for="."><div ext:qtip="{value}" style="text-align:left;font-size:11px;" class="x-combo-list-item">{text}</div></tpl>'
110 }
111 };
112 };
113
114 /**
115 * Registers a button for inclusion in the toolbar, adding some standard configuration properties for the ExtJS widgets
116 *
117 * @param object buttonConfiguration: the configuration object of the button:
118 * id : unique id for the button
119 * tooltip : tooltip for the button
120 * textMode : enable in text mode
121 * context : disable if not inside one of listed elements
122 * hidden : hide in menu and show only in context menu
123 * selection : disable if there is no selection
124 * hotkey : hotkey character
125 * dialog : if true, the button opens a dialogue
126 * dimensions : the opening dimensions object of the dialogue window: { width: nn, height: mm }
127 * and potentially other ExtJS config properties (will be forwarded)
128 *
129 * @return boolean true if the button was successfully registered
130 */
131 Config.prototype.registerButton = function (config) {
132 config.itemId = config.id;
133 if (typeof this.buttonsConfig[config.id] !== 'undefined' && this.buttonsConfig[config.id] !== null) {
134 HTMLArea.appendToLog('', 'HTMLArea.Config', 'registerButton', 'A toolbar item with the same Id: ' + config.id + ' already exists and will be overidden.', 'warn');
135 }
136 // Apply defaults
137 Util.applyIf(config, this.configDefaults['all']);
138 Util.applyIf(config, this.configDefaults[config.xtype]);
139 // Set some additional properties
140 switch (config.xtype) {
141 case 'htmlareacombo':
142 if (config.options) {
143 // Create combo array store
144 config.store = new Ext.data.ArrayStore({
145 autoDestroy: true,
146 fields: config.storeFields,
147 data: config.options
148 });
149 } else if (config.storeUrl) {
150 // Create combo json store
151 config.store = new Ext.data.JsonStore({
152 autoDestroy: true,
153 autoLoad: true,
154 root: config.storeRoot,
155 fields: config.storeFields,
156 url: config.storeUrl
157 });
158 }
159 config.hideLabel = typeof config.fieldLabel !== 'string' || !config.fieldLabel.length || UserAgent.isIE6;
160 config.helpTitle = config.tooltip;
161 break;
162 default:
163 if (!config.iconCls) {
164 config.iconCls = config.id;
165 }
166 break;
167 }
168 config.cmd = config.id;
169 config.tooltip = { title: config.tooltip };
170 this.buttonsConfig[config.id] = config;
171 return true;
172 };
173
174 /**
175 * Register a hotkey with the editor configuration.
176 */
177 Config.prototype.registerHotKey = function (hotKeyConfiguration) {
178 if (typeof this.hotKeyList[hotKeyConfiguration.id] !== 'undefined') {
179 HTMLArea.appendToLog('', 'HTMLArea.Config', 'registerHotKey', 'A hotkey with the same key ' + hotKeyConfiguration.id + ' already exists and will be overidden.', 'warn');
180 }
181 if (typeof hotKeyConfiguration.cmd === 'string' && hotKeyConfiguration.cmd.length > 0 && typeof this.buttonsConfig[hotKeyConfiguration.cmd] !== 'undefined') {
182 this.hotKeyList[hotKeyConfiguration.id] = hotKeyConfiguration;
183 return true;
184 } else {
185 HTMLArea.appendToLog('', 'HTMLArea.Config', 'registerHotKey', 'A hotkey with key ' + hotKeyConfiguration.id + ' could not be registered because toolbar item with id ' + hotKeyConfiguration.cmd + ' was not registered.', 'warn');
186 return false;
187 }
188 };
189
190 /**
191 * Get the configured document type for dialogue windows
192 */
193 Config.prototype.getDocumentType = function () {
194 return this.documentType;
195 };
196
197 return Config;
198
199 });