6a6dcae3b84ca506dca418c7147076ad6277b4f6
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / htmlarea / plugins / TYPO3Image / typo3image.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2005-2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.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 * TYPO3 CVS ID: $Id:$
31 */
32 TYPO3Image = HTMLArea.Plugin.extend({
33
34 constructor : function(editor, pluginName) {
35 this.base(editor, pluginName);
36 },
37
38 /*
39 * This function gets called by the class constructor
40 */
41 configurePlugin : function(editor) {
42
43 this.pageTSConfiguration = this.editorConfiguration.buttons.image;
44 this.imageModulePath = this.pageTSConfiguration.pathImageModule;
45
46 /*
47 * Registering plugin "About" information
48 */
49 var pluginInformation = {
50 version : "1.0",
51 developer : "Stanislas Rolland",
52 developerUrl : "http://www.fructifor.ca/",
53 copyrightOwner : "Stanislas Rolland",
54 sponsor : "Fructifor Inc.",
55 sponsorUrl : "http://www.fructifor.ca/",
56 license : "GPL"
57 };
58 this.registerPluginInformation(pluginInformation);
59
60 /*
61 * Registering the button
62 */
63 var buttonId = "InsertImage";
64 var buttonConfiguration = {
65 id : buttonId,
66 tooltip : this.localize(buttonId + "-Tooltip"),
67 action : "onButtonPress",
68 hotKey : (this.pageTSConfiguration ? this.pageTSConfiguration.hotKey : null),
69 dialog : true
70 };
71 this.registerButton(buttonConfiguration);
72
73 return true;
74 },
75
76 /*
77 * This function gets called when the button was pressed
78 *
79 * @param object editor: the editor instance
80 * @param string id: the button id or the key
81 * @param object target: the target element of the contextmenu event, when invoked from the context menu
82 *
83 * @return boolean false if action is completed
84 */
85 onButtonPress : function(editor, id, target) {
86 // Could be a button or its hotkey
87 var buttonId = this.translateHotKey(id);
88 buttonId = buttonId ? buttonId : id;
89
90 var additionalParameter;
91 if (typeof(target) !== "undefined") {
92 this.image = target;
93 } else {
94 this.image = this.editor.getParentElement();
95 }
96 if (this.image && !/^img$/i.test(this.image.nodeName)) {
97 this.image = null;
98 }
99 if (this.image) {
100 additionalParameter = "&act=image";
101 }
102
103 this.dialog = this.openDialog("InsertImage", this.makeUrlFromModulePath(this.imageModulePath, additionalParameter), null, null, {width:550, height:350}, "yes");
104 return false;
105 },
106
107 /*
108 * Insert the image
109 * This function is called from the typo3-image-popup
110 */
111 insertImage : function(image) {
112 this.editor.focusEditor();
113 this.editor.insertHTML(image);
114 this.dialog.close();
115 }
116 });
117