Fixed bug #9331: htmlArea RTE Acronym feature: List of unabridged terms shows wrong...
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / mod2 / class.tx_rtehtmlarea_acronym_mod.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2005-2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Acronym content for htmlArea RTE
29 *
30 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
31 *
32 * $Id$ *
33 */
34
35 class tx_rtehtmlarea_acronym_mod {
36 var $content;
37 var $modData;
38
39 /**
40 * document template object
41 *
42 * @var template
43 */
44 var $doc;
45
46 /**
47 * @return [type] ...
48 */
49 function init() {
50 global $BE_USER,$LANG,$BACK_PATH;
51
52 $this->doc = t3lib_div::makeInstance('template');
53 $this->doc->backPath = $BACK_PATH;
54 $this->doc->styleSheetFile = "";
55 $this->doc->styleSheetFile_post = "";
56 $this->doc->bodyTagAdditions = 'class="popupwin" onload="init();"';
57 $this->doc->form = '<form action="" id="content" name="content" method="POST">';
58 $JScode='
59 var dialog = window.opener.HTMLArea.Dialog.Acronym;
60 var editor = dialog.plugin.editor;
61 var param = null;
62 var html = editor.getSelectedHTML();
63 var sel = editor._getSelection();
64 var range = editor._createRange(sel);
65 var abbr = editor._activeElement(sel);
66 // Working around Safari issue
67 if (!abbr && editor._statusBarTree.selected) {
68 abbr = editor._statusBarTree.selected;
69 }
70 var abbrType = null;
71 var acronyms = new Object();
72 var abbreviations = new Object();
73 if (!(abbr != null && /^(acronym|abbr)$/i.test(abbr.nodeName))) {
74 abbr = editor._getFirstAncestor(sel, ["acronym", "abbr"]);
75 }
76 if (abbr != null && /^(acronym|abbr)$/i.test(abbr.nodeName)) {
77 param = { title : abbr.title, text : abbr.innerHTML};
78 abbrType = abbr.nodeName.toLowerCase();
79 } else {
80 param = { title : "", text : html};
81 }
82
83 function setType() {
84 if(document.content.acronym.checked) {
85 abbrType = "acronym";
86 document.getElementById("abbrType").innerHTML = "' . $LANG->getLL('Acronym') . '";
87 } else {
88 abbrType = "abbr";
89 document.getElementById("abbrType").innerHTML = "' . $LANG->getLL('Abbreviation') . '";
90 }
91 document.getElementById("title").value = param["title"];
92 fillSelect(param);
93 dialog.resize();
94 }
95
96 function init() {
97 dialog.initialize("noLocalize", "noResize");
98 var abbrData = dialog.plugin.getJavascriptFile(dialog.plugin.acronymUrl, "noEval");
99 if (abbrData) eval(abbrData);
100 if (dialog.plugin.pageTSConfiguration.noAcronym || dialog.plugin.pageTSConfiguration.noAbbr) {
101 document.getElementById("type").style.display = "none";
102 }
103 if (abbrType != null) {
104 document.getElementById("type").style.display = "none";
105 } else {
106 abbrType = !dialog.plugin.pageTSConfiguration.noAbbr ? "abbr" : "acronym";
107 }
108 if (abbrType == "acronym" && !dialog.plugin.pageTSConfiguration.noAcronym) {
109 document.content.acronym.checked = true;
110 } else {
111 document.content.abbreviation.checked = true;
112 }
113 setType();
114 HTMLArea._addEvents(document.content.title,["keypress", "keydown", "dragdrop", "drop", "paste", "change"],function(ev) { document.content.termSelector.selectedIndex=-1; document.content.acronymSelector.selectedIndex=-1; });
115 document.getElementById("title").focus();
116 };
117
118 function fillSelect(param) {
119 var termSelector = document.getElementById("termSelector");
120 var acronymSelector = document.getElementById("acronymSelector");
121 while (termSelector.options.length > 1) {
122 termSelector.options[termSelector.length-1] = null;
123 }
124 while (acronymSelector.options.length > 1) {
125 acronymSelector.options[acronymSelector.length-1] = null;
126 }
127 if (abbrType == "acronym") {
128 var abbrObj = acronyms;
129 } else {
130 var abbrObj = abbreviations;
131 }
132 if (abbrObj != "") {
133 var sameTerm = false;
134 var sameAbbreviation = false;
135 var selectedOption = false;
136 for (var i in abbrObj) {
137 if (abbrObj.hasOwnProperty(i)) {
138 if (param["title"]) {
139 sameTerm = (param["title"] == i);
140 } else {
141 sameTerm = (param["text"] == i);
142 }
143 sameAbbreviation = (param["text"] == abbrObj[i]);
144 if (!selectedOption && (sameTerm || sameAbbreviation)) {
145 selectedOption = i;
146 }
147 if (!param["text"] || sameTerm || sameAbbreviation) {
148 termSelector.options[termSelector.options.length] = new Option(i, i, false, (selectedOption == i));
149 acronymSelector.options[acronymSelector.options.length] = new Option(abbrObj[i], abbrObj[i], false, (selectedOption == i));
150 }
151 if (selectedOption == i) {
152 document.content.title.value = i;
153 }
154 }
155 }
156 }
157 if (acronymSelector.options.length == 1) {
158 document.getElementById("selector").style.display = "none";
159 } else {
160 document.getElementById("selector").style.display = "block";
161 }
162 };
163
164 function processAcronym(title) {
165 if (title == "" || title == null) {
166 if (abbr) {
167 dialog.plugin.removeMarkup(abbr);
168 }
169 } else {
170 var doc = editor._doc;
171 if (!abbr) {
172 abbr = doc.createElement(abbrType);
173 abbr.title = title;
174 if(document.content.acronymSelector.options.length != 1 && document.content.termSelector.selectedIndex > 0 && document.content.termSelector.options[document.content.termSelector.selectedIndex].value == title) {
175 html = document.content.acronymSelector.options[document.content.acronymSelector.selectedIndex].value;
176 }
177 abbr.innerHTML = html;
178 if (HTMLArea.is_ie) range.pasteHTML(abbr.outerHTML);
179 else editor.insertNodeAtSelection(abbr);
180 } else {
181 abbr.title = title;
182 if(document.content.acronymSelector.options.length != 1 && document.content.termSelector.selectedIndex > 0 && document.content.termSelector.options[document.content.termSelector.selectedIndex].value == title) abbr.innerHTML = document.content.acronymSelector.options[document.content.acronymSelector.selectedIndex].value;
183 }
184 }
185 };
186
187 function onOK() {
188 processAcronym(document.getElementById("title").value);
189 dialog.close();
190 return false;
191 };
192
193 function onDelete() {
194 processAcronym("");
195 dialog.close();
196 return false;
197 };
198 function onCancel() {
199 dialog.close();
200 return false;
201 };
202 ';
203
204 $this->doc->JScode .= $this->doc->wrapScriptTags($JScode);
205
206 $this->modData = $BE_USER->getModuleData('acronym.php','ses');
207 $BE_USER->pushModuleData('acronym.php',$this->modData);
208 }
209
210 /**
211 * [Describe function...]
212 *
213 * @return [type] ...
214 */
215 function main() {
216
217 $this->content='';
218 $this->content.=$this->main_acronym($this->modData['openKeys']);
219 }
220
221 /**
222 * [Describe function...]
223 *
224 * @return [type] ...
225 */
226 function printContent() {
227 echo $this->content;
228 }
229
230 /**
231 * Rich Text Editor (RTE) acronym selector
232 *
233 * @param [type] $openKeys: ...
234 * @return [type] ...
235 */
236 function main_acronym($openKeys) {
237 global $LANG, $BE_USER;
238
239 $content.=$this->doc->startPage($LANG->getLL('Insert/Modify Acronym',1));
240
241 $RTEtsConfigParts = explode(':',t3lib_div::_GP('RTEtsConfigParams'));
242 $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
243 $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
244
245 $content.='
246 <div class="title" id="abbrType">' . $LANG->getLL('Acronym',1) . '</div>
247 <fieldset id="type">
248 <legend>' . $LANG->getLL('Type_of_abridged_form',1) . '</legend>
249 <label for="abbreviation" class="checkbox">' . $LANG->getLL('Abbreviation',1) . '</label><input type="radio" name="type" id="abbreviation" value="abbreviation" checked="checked" onclick="setType();" />
250 <label for="acronym" class="checkbox">' . $LANG->getLL('Acronym',1) . '</label><input type="radio" name="type" id="acronym" value="acronym" onclick="setType();" />
251 </fieldset>
252 <fieldset id="selector">
253 <legend>' . $LANG->getLL('Defined_term',1) . '</legend>
254 <label for="termSelector" class="fl" id="termSelectorLabel" title="' . $LANG->getLL('Select_a_term',1) . '">' . $LANG->getLL('Unabridged_term',1) . '</label>
255 <select id="termSelector" name="termSelector" title="' . $LANG->getLL('Select_a_term',1) . '"
256 onChange="document.content.acronymSelector.selectedIndex=document.content.termSelector.selectedIndex; document.content.title.value=document.content.termSelector.options[document.content.termSelector.selectedIndex].value;">
257 <option value=""></option>
258 </select>
259 <label for="acronymSelector" id="acronymSelectorLabel" title="' . $LANG->getLL('Select_an_acronym',1) . '">' . $LANG->getLL('Abridged_term',1) . '</label>
260 <select id="acronymSelector" name="acronymSelector" title="' . $LANG->getLL('Select_an_acronym',1) . '"
261 onChange="document.content.termSelector.selectedIndex=document.content.acronymSelector.selectedIndex; document.content.title.value=document.content.termSelector.options[document.content.termSelector.selectedIndex].value;">
262 <option value=""></option>
263 </select>
264 </fieldset>
265 <fieldset>
266 <legend>' . $LANG->getLL('Term_to_abridge',1) . '</legend>
267 <label for="title" class="fl" title="' . $LANG->getLL('Use_this_term_explain',1) . '">' . $LANG->getLL('Use_this_term',1) . '</label>
268 <input type="text" id="title" name="title" size="60" title="' . $LANG->getLL('Use_this_term_explain',1) . '" />
269 </fieldset>
270 <div class="buttons">
271 <button type="button" title="' . $LANG->getLL('OK',1) . '"onclick="return onOK();">' . $LANG->getLL('OK',1) . '</button>
272 <button type="button" title="' . $LANG->getLL('Delete',1) . '" onclick="return onDelete();">' . $LANG->getLL('Delete',1) . '</button>
273 <button type="button" title="' . $LANG->getLL('Cancel',1) . '" onclick="return onCancel();">' . $LANG->getLL('Cancel',1) . '</button>
274 </div>';
275 $content.= $this->doc->endPage();
276 return $content;
277 }
278 }
279
280 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod2/class.tx_rtehtmlarea_acronym_mod.php']) {
281 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod2/class.tx_rtehtmlarea_acronym_mod.php']);
282 }
283
284 ?>