19 include_once($ROOT_PATH.
'wysiwyg_plugin.inc');
20 require_once dirname(__FILE__).
'/../../../../core/include/init.inc';
46 wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
47 $this->
_add_button(
'matrix_dt',
'Matrix_DT',
'Insert Definition Term',
'false',
'63');
48 $this->
_add_button(
'matrix_dd',
'Matrix_DD',
'Insert Definition Description',
'false',
'62');
63 <script type=
"text/javascript" language=
"Javascript">
65 HTMLArea.prototype._definitionListFilter =
function(node) {
66 switch (node.tagName) {
80 HTMLArea.prototype._definitionListWithSelection =
function(type) {
82 var sel = this._getSelection();
83 var range = this._createRange(sel);
84 var parent = this.getParentElement();
85 var type_string = ((type ==
"DT") ?
"term" :
"definition");
87 var selected_html =
"";
88 if (HTMLArea.is_gecko) {
89 var parent_node = range.startContainer.parentNode;
91 var start_node = range.startContainer;
92 var end_node = range.endContainer;
95 if (start_node.nodeType == 1) {
96 start_text = start_node.innerHTML;
97 }
else if (start_node.nodeType == 3) {
98 start_text = start_node.nodeValue;
100 if (end_node.nodeType == 1) {
101 end_text = end_node.innerHTML;
102 }
else if (end_node.nodeType == 3) {
103 end_text = end_node.nodeValue;
105 while (this._definitionListFilter(parent_node)) {
106 parent_node = parent_node.parentNode;
110 var children = parent.childNodes;
111 var valid_node_indexes = Array();
112 for (var i=0; i < children.length; i++) {
113 if (children[i].nodeType == 1 && children[i].innerHTML !=
"") {
114 if (children[i].innerHTML == start_text) start_index = i;
115 else if (children[i].innerHTML == end_text) end_index = i;
116 valid_node_indexes.push(i);
117 }
else if (children[i].nodeType == 3) {
118 var tmp = children[i].nodeValue.replace(/\s/g,
"");
120 if (tmp == start_text.replace(/\s/g,
"")) start_index = i;
121 else if (tmp == end_text.replace(/\s/g,
"")) end_index = i;
122 valid_node_indexes.push(i);
127 dl = this._doc.createElement(
"DL");
128 var remove_list = Array();
129 for (var j=0; j < valid_node_indexes.length; j++) {
130 var index = valid_node_indexes[j];
131 if (index >= start_index && index <= end_index) {
132 if (children[index].tagName ==
"DT" || children[index].tagName ==
"DD") {
133 if (type_string == children[index].tagName)
continue;
134 tmp = this._doc.createElement(type);
135 tmp.innerHTML = children[index].innerHTML;
136 parent_node.replaceChild(tmp, children[index]);
138 tmp = this._doc.createElement(type);
139 if (children[index].nodeType == 1 || children[index].nodeType == 3) {
140 switch (children[index].nodeType) {
142 tmp.innerHTML = children[index].innerHTML;
145 tmp.innerHTML = children[index].nodeValue;
149 remove_list.push(children[index]);
154 if (dl.childNodes.length > 0) {
155 parent_node.insertBefore(dl, children[start_index]);
156 for (var k=0; k < remove_list.length; k++) {
157 parent_node.removeChild(remove_list[k]);
160 }
else if (HTMLArea.is_ie) {
161 var selected_html = range.htmlText;
165 var e =
'<(P|DT|DD)>(.+)<\/(P|DT|DD)>|([^>]+)<BR>|([^>]+)';
166 var re =
new RegExp(e,
"ig");
167 var p_re =
new RegExp(
'<(P)>([^>]+)<\/(P)>',
"ig");
168 var d_re =
new RegExp(
'<(DT|DD)>([^>]+)<\/(DT|DD)>',
"ig");
169 var b_re =
new RegExp(
'([^>]+)<BR>',
"ig");
170 var n_re =
new RegExp(
'([^>]+)',
"ig");
172 var surround_dl =
false;
175 var result = selected_html.match(re);
176 for (var i = 0; i < result.length; i++) {
177 var curr_type = result[i].replace(re,
"$1");
179 if (result[i].match(p_re)) {
180 tmp += result[i].replace(p_re,
"<" + type +
">$2<\/" + type +
">");
182 }
else if (result[i].match(d_re)) {
183 tmp += result[i].replace(d_re,
"<" + type +
">$2<\/" + type +
">");
188 }
else if (result[i].match(b_re)) {
189 tmp += result[i].replace(b_re,
"<" + type +
">$1<\/" + type +
">");
191 }
else if (result[i].match(n_re)) {
192 tmp += result[i].replace(n_re,
"<" + type +
">$1<\/" + type +
">");
199 new_html =
'<DL>' + tmp +
'</DL>';
200 }
else if (!surround_dl) {
203 range.pasteHTML(new_html);
205 alert(
"Please do not select DD or DT tags with other types of tags.");
213 HTMLArea.prototype._definitionList =
function(type) {
214 var sel = this._getSelection();
215 var range = this._createRange(sel);
216 var parent = this.getParentElement();
217 var type_string = ((type ==
"DT") ?
"term" :
"definition");
219 if (parent.tagName !=
"DT" && parent.tagName !=
"DD") {
222 var dl = this._doc.createElement(
"dl");
223 var child = this._doc.createElement(type.toLowerCase());
225 var text = this._doc.createTextNode(
"Type the " + type_string);
227 child.appendChild(text);
228 dl.appendChild(child);
229 parent.appendChild(dl);
230 if (HTMLArea.is_gecko) {
231 range.selectNode(text);
233 sel.removeAllRanges();
235 }
else if (HTMLArea.is_ie) {
236 range.findText(
"Type the " + type_string);
242 var dl = parent.parentNode;
243 var dl_parent = dl.parentNode;
244 if (HTMLArea.is_gecko) {
245 var data = parent.firstChild.data;
246 }
else if (HTMLArea.is_ie) {
247 var data = parent.innerText;
249 if (type == parent.tagName) {
251 dl.removeChild(parent);
252 if (data != null && data !=
"Type the " + type_string) {
253 var new_text = this._doc.createTextNode(data);
254 dl_parent.appendChild(new_text);
256 if (dl.childNodes.length == 0) {
257 dl_parent.removeChild(dl);
259 }
else if (type != parent.tagName) {
261 var new_child = this._doc.createElement(type);
262 var next_type_string = ((type ==
"DT") ?
"term" :
"definition");
263 var prev_type_string = ((type ==
"DT") ?
"definition" :
"term");
264 if (data != (
"Type the " + prev_type_string)) {
265 var new_text = this._doc.createTextNode(data);
267 var new_text = this._doc.createTextNode(
"Type the " + next_type_string);
270 new_child.appendChild(new_text);
271 dl.replaceChild(new_child, parent);
275 HTMLArea.prototype._handleDefinitionShortcut =
function() {
277 var sel = this._getSelection();
278 var range = this._createRange(sel);
279 var parent = this.getParentElement();
281 var dl = parent.parentNode;
282 if (HTMLArea.is_gecko) {
283 var data = parent.firstChild.data;
284 }
else if (HTMLArea.is_ie) {
285 var data = parent.innerText;
288 var next_type = (parent.tagName ==
"DT") ?
"DD" :
"DT";
289 var prev_type_string = ((next_type ==
"DT") ?
"definition" :
"term");
290 var type_string = ((next_type ==
"DT") ?
"term" :
"definition");
292 if (dl.tagName ==
"DL") {
293 if (data ==
"" || data ==
"Type the " + prev_type_string) {
295 var dl_parent = dl.parentNode;
296 dl.removeChild(parent);
297 if (data != null && data !=
"Type the " + prev_type_string) {
298 var new_text = this._doc.createTextNode(data);
299 dl_parent.appendChild(new_text);
301 if (dl.childNodes.length == 0) {
302 dl_parent.removeChild(dl);
305 var new_child = this._doc.createElement(next_type.toLowerCase());
306 var new_text = this._doc.createTextNode(
"Type the " + type_string);
307 new_child.appendChild(new_text);
308 dl.appendChild(new_child);
310 if (HTMLArea.is_gecko) {
312 range.selectNode(new_text);
313 sel.removeAllRanges();
315 }
else if (HTMLArea.is_ie) {
316 range.findText(
"Type the " + type_string);
340 var sel = this._getSelection();
341 var range = this._createRange(sel);
343 if (HTMLArea.is_gecko) {
345 }
else if (HTMLArea.is_ie) {
346 range_comp = range.text;
348 if (range_comp ==
"" || range_comp ==
"Type the term" || range_comp ==
"Type the definition") {
349 this._definitionList(
"DT");
351 this._definitionListWithSelection(
"DT");
355 var sel = this._getSelection();
356 var range = this._createRange(sel);
358 if (HTMLArea.is_gecko) {
360 }
else if (HTMLArea.is_ie) {
361 range_comp = range.text;
363 if (range_comp ==
"" || range_comp ==
"Type the term" || range_comp ==
"Type the definition") {
364 this._definitionList(
"DD");
366 this._definitionListWithSelection(
"DD");
386 this._handleDefinitionShortcut();
387 HTMLArea._stopEvent(ev);