[BUGFIX] RTE Image Wizard
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Resources / Public / JavaScript / Plugins / TYPO3Image.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 * TYPO3Image plugin for htmlArea RTE
16 */
17 define(['TYPO3/CMS/Rtehtmlarea/HTMLArea/Plugin/Plugin',
18 'TYPO3/CMS/Rtehtmlarea/HTMLArea/UserAgent/UserAgent',
19 'TYPO3/CMS/Rtehtmlarea/HTMLArea/Util/Util'],
20 function (Plugin, UserAgent, Util) {
21
22 var TYPO3Image = function (editor, pluginName) {
23 this.constructor.super.call(this, editor, pluginName);
24 };
25 Util.inherit(TYPO3Image, Plugin);
26 Util.apply(TYPO3Image.prototype, {
27
28 /**
29 * This function gets called by the class constructor
30 */
31 configurePlugin: function (editor) {
32 this.pageTSConfiguration = this.editorConfiguration.buttons.image;
33 this.imageModulePath = this.pageTSConfiguration.pathImageModule;
34
35 /**
36 * Registering plugin "About" information
37 */
38 var pluginInformation = {
39 version : '2.3',
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 button
51 */
52 var buttonId = 'InsertImage';
53 var buttonConfiguration = {
54 id : buttonId,
55 tooltip : this.localize(buttonId + '-Tooltip'),
56 iconCls : 'htmlarea-action-image-edit',
57 action : 'onButtonPress',
58 hotKey : (this.pageTSConfiguration ? this.pageTSConfiguration.hotKey : null),
59 dialog : true
60 };
61 this.registerButton(buttonConfiguration);
62 return true;
63 },
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&fileUid=' + this.image.getAttribute('data-htmlarea-file-uid');
84 }
85 this.openContainerWindow(
86 buttonId,
87 this.getButton(buttonId).tooltip,
88 this.getWindowDimensions(
89 {
90 width: top.TYPO3.configuration.RTEPopupWindow.width,
91 height: top.TYPO3.configuration.RTEPopupWindow.height
92 },
93 buttonId
94 ),
95 this.makeUrlFromModulePath(this.imageModulePath, additionalParameter)
96 );
97 return false;
98 },
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 /**
111 * Remove the event listeners
112 */
113 removeListeners: function () {
114 },
115
116 /**
117 * This function gets called when the toolbar is updated
118 */
119 onUpdateToolbar: function (button, mode, selectionEmpty, ancestors) {
120 button.setInactive(true);
121 if (mode === 'wysiwyg' && this.editor.isEditable() && button.itemId === 'InsertImage' && !button.disabled) {
122 var image = this.editor.getSelection().getParentElement();
123 if (image && !/^img$/i.test(image.nodeName)) {
124 image = null;
125 }
126 if (image) {
127 button.setTooltip(this.localize('Modify image'));
128 button.setInactive(false);
129 } else {
130 button.setTooltip(this.localize('Insert image'));
131 }
132 }
133 }
134 });
135
136 return TYPO3Image;
137
138 });