ce8cb8b613952811d85c29c9fc616efb91b3c09d
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / htmlarea / HTMLArea.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 * Main script of TYPO3 htmlArea RTE
15 */
16 Ext.namespace('HTMLArea.CSS', 'HTMLArea.util.TYPO3', 'HTMLArea.util.Tips', 'HTMLArea.util.Color', 'Ext.ux.form', 'Ext.ux.menu', 'Ext.ux.Toolbar');
17 Ext.apply(HTMLArea, {
18 /***************************************************
19 * COMPILED REGULAR EXPRESSIONS *
20 ***************************************************/
21 RE_htmlTag : /<.[^<>]*?>/g,
22 RE_tagName : /(<\/|<)\s*([^ \t\n>]+)/ig,
23 RE_head : /<head>((.|\n)*?)<\/head>/i,
24 RE_body : /<body>((.|\n)*?)<\/body>/i,
25 reservedClassNames : /htmlarea/,
26 RE_email : /([0-9a-z]+([a-z0-9_-]*[0-9a-z])*){1}(\.[0-9a-z]+([a-z0-9_-]*[0-9a-z])*)*@([0-9a-z]+([a-z0-9_-]*[0-9a-z])*\.)+[a-z]{2,9}/i,
27 RE_url : /(([^:/?#]+):\/\/)?(([a-z0-9_]+:[a-z0-9_]+@)?[a-z0-9_-]{2,}(\.[a-z0-9_-]{2,})+\.[a-z]{2,5}(:[0-9]+)?(\/\S+)*\/?)/i,
28 RE_numberOrPunctuation : /[0-9.(),;:!¡?¿%#$'"_+=\\\/-]*/g,
29 /***************************************************
30 * BROWSER IDENTIFICATION *
31 ***************************************************/
32 isIEBeforeIE9: Ext.isIE6 || Ext.isIE7 || Ext.isIE8 || (Ext.isIE && typeof(document.documentMode) !== 'undefined' && document.documentMode < 9),
33 /***************************************************
34 * LOCALIZATION *
35 ***************************************************/
36 localize: function (label, plural) {
37 var i = plural || 0;
38 var localized = HTMLArea.I18N.dialogs[label] || HTMLArea.I18N.tooltips[label] || HTMLArea.I18N.msg[label] || '';
39 if (typeof localized === 'object' && typeof localized[i] !== 'undefined') {
40 localized = localized[i]['target'];
41 }
42 return localized;
43 },
44 /***************************************************
45 * INITIALIZATION *
46 ***************************************************/
47 init: function () {
48 if (!HTMLArea.isReady) {
49 // Apply global configuration settings
50 Ext.apply(HTMLArea, RTEarea[0]);
51 Ext.applyIf(HTMLArea, {
52 editorSkin : HTMLArea.editorUrl + 'skins/default/',
53 editorCSS : HTMLArea.editorUrl + 'skins/default/htmlarea.css'
54 });
55 if (!Ext.isString(HTMLArea.editedContentCSS)) {
56 HTMLArea.editedContentCSS = HTMLArea.editorSkin + 'htmlarea-edited-content.css';
57 }
58 HTMLArea.isReady = true;
59 HTMLArea.appendToLog('', 'HTMLArea', 'init', 'Editor url set to: ' + HTMLArea.editorUrl, 'info');
60 HTMLArea.appendToLog('', 'HTMLArea', 'init', 'Editor skin CSS set to: ' + HTMLArea.editorCSS, 'info');
61 HTMLArea.appendToLog('', 'HTMLArea', 'init', 'Editor content skin CSS set to: ' + HTMLArea.editedContentCSS, 'info');
62 }
63 },
64 /*
65 * Create an editor when HTMLArea is loaded and when Ext is ready
66 *
67 * @param string editorId: the id of the editor
68 *
69 * @return boolean false if successful
70 */
71 initEditor: function (editorId) {
72 if (document.getElementById('pleasewait' + editorId)) {
73 if (HTMLArea.checkSupportedBrowser()) {
74 document.getElementById('pleasewait' + editorId).style.display = 'block';
75 document.getElementById('editorWrap' + editorId).style.visibility = 'hidden';
76 if (!HTMLArea.isReady) {
77 HTMLArea.initEditor.defer(150, null, [editorId]);
78 } else {
79 // Create an editor for the textarea
80 var editor = new HTMLArea.Editor(Ext.apply(new HTMLArea.Config(editorId), RTEarea[editorId]));
81 editor.generate();
82 return false;
83 }
84 } else {
85 document.getElementById('pleasewait' + editorId).style.display = 'none';
86 document.getElementById('editorWrap' + editorId).style.visibility = 'visible';
87 }
88 }
89 return true;
90 },
91 /*
92 * Check if the client agent is supported
93 *
94 * @return boolean true if the client is supported
95 */
96 checkSupportedBrowser: function () {
97 return Ext.isGecko || Ext.isWebKit || Ext.isOpera || Ext.isIE;
98 },
99 /*
100 * Write message to JavaScript console
101 *
102 * @param string editorId: the id of the editor issuing the message
103 * @param string objectName: the name of the object issuing the message
104 * @param string functionName: the name of the function issuing the message
105 * @param string text: the text of the message
106 * @param string type: the type of message: 'log', 'info', 'warn' or 'error'
107 *
108 * @return void
109 */
110 appendToLog: function (editorId, objectName, functionName, text, type) {
111 var str = 'RTE[' + editorId + '][' + objectName + '::' + functionName + ']: ' + text;
112 if (typeof type === 'undefined') {
113 var type = 'info';
114 }
115 if (typeof console !== 'undefined' && typeof console === 'object') {
116 // If console is TYPO3.Backend.DebugConsole, write only error messages
117 if (Ext.isFunction(console.addTab)) {
118 if (type === 'error') {
119 console[type](str);
120 }
121 // IE may not have any console
122 } else if (typeof console[type] !== 'undefined') {
123 console[type](str);
124 }
125 }
126 }
127 });