19 include_once($ROOT_PATH.
'wysiwyg_plugin.inc');
49 if ((ev.type ==
"keypress")) {
50 var key = (HTMLArea.is_ie ? ev.keyCode : ev.charCode);
51 if ((key == 32) || (key == 13) || (key == 9) || (key == 0)) {
52 expandKeywords(editor);
54 }
else if (ev.type ==
"keydown") {
55 var key = (HTMLArea.is_ie ? ev.keyCode : ev.charCode);
57 expandKeywords(editor);
75 if (!$GLOBALS[
'SQ_SYSTEM']->am->installed(
'thesaurus')) {
77 <script type=
"text/javascript">
function expandKeywords() {} </script>
81 $thesaurusid = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'content_type_wysiwyg',
'SQ_THESAURUS');
84 <script type=
"text/javascript">
function expandKeywords() {} </script>
89 $thesaurus = &$GLOBALS[
'SQ_SYSTEM']->am->getAsset($thesaurusid,
'',
true);
90 if (!$thesaurus->id) {
92 <script type=
"text/javascript">
function expandKeywords() {} </script>
97 $abbrevs = $thesaurus->getAbbreviations();
98 if (!is_array($abbrevs) || empty($abbrevs)) {
100 <script type=
"text/javascript">
function expandKeywords() {} </script>
106 <script type=
"text/javascript">
107 var abbrevs = Array();
110 foreach ($abbrevs as $abbrev => $word) {
111 echo
" abbrevs['$abbrev'] = '$word';\n";
115 var stripTagsRE = /(<\S[^>]*>)|(\W)/g;
117 HTMLArea.prototype.replaceLastWord =
function(oldWord, newWord) {
118 switch (this._editMode) {
120 if (HTMLArea.is_gecko) {
121 var range = this._createRange(this._getSelection());
122 if (range.startContainer.data.replace(
new RegExp(/\s+$/),
'') ==
'') {
123 var contentNode = range.startContainer.parentNode.previousSibling.firstChild;
124 range.selectNodeContents(contentNode);
125 range.setEnd(range.endContainer, range.endContainer.data.length);
126 range.setStart(range.startContainer, range.startContainer.data.length-oldWord.length);
128 range.setStart(range.startContainer, range.startOffset-oldWord.length-1);
131 range.deleteContents();
132 toBeInserted = document.createTextNode(newWord+
' ');
133 var node = range.startContainer;
134 var pos = range.startOffset;
135 node.insertData(pos, toBeInserted.data);
136 range.setEnd(node, pos + newWord.length + 1);
137 range.setStart(node, pos + newWord.length + 1);
138 }
else if (HTMLArea.is_ie) {
139 var doc = this._docContent;
140 while (doc.nodeName !=
'BODY') {
141 doc = doc.parentNode;
143 doc = doc.parentNode.parentNode;
144 var rng = doc.selection.createRange();
145 rng.moveStart(
'character', -1 * oldWord.length);
155 function expandKeywords(editor)
157 var lastWord = getLastWord(editor);
158 if (((newWord = abbrevs[lastWord]) != null) && (typeof newWord ==
'string')) {
159 if (confirm(newWord +
'?')) {
160 editor.replaceLastWord(lastWord, newWord);
162 delete abbrevs[lastWord];
167 function getLastWord(editor)
169 if (HTMLArea.is_gecko) {
170 var range = editor._createRange(editor._getSelection());
171 var contentNode = range.startContainer;
172 var html = contentNode.nodeValue.substr(0, range.endOffset);
173 html = html.replace(
new RegExp(/\s+$/),
'');
175 html = contentNode.parentNode.previousSibling.innerHTML;
176 html = html.replace(
new RegExp(/\s+$/),
'');
178 return html.substring(html.lastIndexOf(
" ")+1);
180 var doc = editor._docContent;
181 while (doc.nodeName !=
'BODY') {
182 doc = doc.parentNode;
184 doc = doc.parentNode.parentNode;
185 var rng = doc.selection.createRange();
186 while ((rng.text.charAt(0) !=
' ') && (rng.htmlText.charAt(0) !=
'>') && (rng.text.charCodeAt(0) != 13)) {
187 if (rng.moveStart(
'character', -1) == 0)
break;
189 while ((rng.text.charAt(0) ==
' ') || (rng.htmlText.charAt(0) ==
'>')) {
190 rng.moveStart(
'character', 1);
192 return rng.text.replace(
new RegExp(/^\s+/),
'');