35c2cceb0dc422213c54c43a74e6620008b7f63c
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / htmlarea / plugins / TYPO3Image / typo3image.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2005-2012 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 * TYPO3Image plugin for htmlArea RTE
29 */
30 HTMLArea.TYPO3Image = Ext.extend(HTMLArea.Plugin, {
31 /*
32 * This function gets called by the class constructor
33 */
34 configurePlugin: function (editor) {
35 this.pageTSConfiguration = this.editorConfiguration.buttons.image;
36 this.imageModulePath = this.pageTSConfiguration.pathImageModule;
37 /*
38 * Registering plugin "About" information
39 */
40 var pluginInformation = {
41 version : '2.3',
42 developer : 'Stanislas Rolland',
43 developerUrl : 'http://www.sjbr.ca/',
44 copyrightOwner : 'Stanislas Rolland',
45 sponsor : 'SJBR',
46 sponsorUrl : 'http://www.sjbr.ca/',
47 license : 'GPL'
48 };
49 this.registerPluginInformation(pluginInformation);
50 /*
51 * Registering the button
52 */
53 var buttonId = 'InsertImage';
54 var buttonConfiguration = {
55 id : buttonId,
56 tooltip : this.localize(buttonId + '-Tooltip'),
57 iconCls : 'htmlarea-action-image-edit',
58 action : 'onButtonPress',
59 hotKey : (this.pageTSConfiguration ? this.pageTSConfiguration.hotKey : null),
60 dialog : true
61 };
62 this.registerButton(buttonConfiguration);
63 return true;
64 },
65 /*
66 * This function gets called when the button was pressed
67 *
68 * @param object editor: the editor instance
69 * @param string id: the button id or the key
70 *
71 * @return boolean false if action is completed
72 */
73 onButtonPress: function (editor, id) {
74 // Could be a button or its hotkey
75 var buttonId = this.translateHotKey(id);
76 buttonId = buttonId ? buttonId : id;
77 var additionalParameter;
78 this.image = this.editor.getSelection().getParentElement();
79 if (this.image && !/^img$/i.test(this.image.nodeName)) {
80 this.image = null;
81 }
82 if (this.image) {
83 additionalParameter = '&act=image';
84 }
85 this.openContainerWindow(
86 buttonId,
87 this.getButton(buttonId).tooltip.title,
88 this.getWindowDimensions(
89 {
90 width: 610,
91 height: 500
92 },
93 buttonId
94 ),
95 this.makeUrlFromModulePath(this.imageModulePath, additionalParameter)
96 );
97 this.dialog.mon(Ext.get(Ext.isIE ? this.editor.document.body : this.editor.document.documentElement), 'drop', this.onDrop, this, {single: true});
98 return false;
99 },
100 /*
101 * Insert the image
102 * This function is called from the TYPO3 image script
103 */
104 insertImage: function(image) {
105 this.restoreSelection();
106 this.editor.getSelection().insertHtml(image);
107 this.close();
108 },
109 /*
110 * Handlers for drag and drop operations
111 */
112 onDrop: function (event) {
113 if (Ext.isWebKit) {
114 this.editor.iframe.onDrop();
115 }
116 this.close();
117 },
118 /*
119 * This function gets called when the toolbar is updated
120 */
121 onUpdateToolbar: function (button, mode, selectionEmpty, ancestors) {
122 if (mode === 'wysiwyg' && this.editor.isEditable() && button.itemId === 'InsertImage' && !button.disabled) {
123 var image = this.editor.getSelection().getParentElement();
124 if (image && !/^img$/i.test(image.nodeName)) {
125 image = null;
126 }
127 if (image) {
128 button.setTooltip({ title: this.localize('Modify image') });
129 } else {
130 button.setTooltip({ title: this.localize('Insert image') });
131 }
132 }
133 }
134 });