File contents
--- CMFBoard/skins/cmfboard/emoticons.js.dtml.orig 2004-07-05 12:38:20.000000000 +0800
+++ CMFBoard/skins/cmfboard/emoticons.js.dtml 2004-07-05 14:02:45.000000000 +0800
@@ -15,10 +15,29 @@
return false;
}
+function insertAtCursor(myField, myValue) {
+ //IE support
+ if (document.selection) {
+ myField.focus();
+ sel = document.selection.createRange();
+ sel.text = myValue;
+ }
+ //MOZILLA/NETSCAPE support
+ else if (myField.selectionStart || myField.selectionStart == '0') {
+ var startPos = myField.selectionStart;
+ var endPos = myField.selectionEnd;
+ myField.value = myField.value.substring(0, startPos)
+ + myValue
+ + myField.value.substring(endPos, myField.value.length);
+ } else {
+ myField.value += myValue;
+ }
+}
+
function emoticon(ecode, form_name) {
// Inserts emoticon codes
frm = document.forms[form_name];
- frm.text.value = frm.text.value + ecode;
+ insertAtCursor(frm.text, ecode);
frm.text.focus();
return false;
}
@@ -31,8 +50,7 @@
var tmp_image = prompt('Please enter Email:', '');
if (tmp_image) {
var pseudo_html = '[email]' + tmp_image + '[/email]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;
@@ -41,8 +59,7 @@
var tmp_image = prompt('Please enter the URL where your image is located:', 'http://');
if (tmp_image) {
var pseudo_html = '[img]' + tmp_image + '[/img]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;
@@ -51,9 +68,8 @@
var tmp_href = prompt('Please enter the URL for your page:', 'http://');
var tmp_title = prompt('Please enter the title for the link You just provided:', tmp_href)
if (tmp_href && tmp_title) {
- pseudo_html = '[url href="' + tmp_href + '"]' + tmp_title + '[/url]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ var pseudo_html = '[url href="' + tmp_href + '"]' + tmp_title + '[/url]';
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;
@@ -62,18 +78,16 @@
var tmp_word = prompt('Please enter a word or sentence:', '');
if (tmp_word) {
var pseudo_html = '[em]' + tmp_word + '[/em]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;
}
if (wiz_type == "bold") {
var tmp_word = prompt('Please enter a word or sentence:', '');
- if (tmp_word) {
+ if (tmp_word) {
var pseudo_html = '[strong]' + tmp_word + '[/strong]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;
@@ -82,8 +96,7 @@
var tmp_word = prompt('Please enter a word or sentence:', '');
if (tmp_word) {
var pseudo_html = '[size]' + tmp_word + '[/size]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;
@@ -92,8 +105,7 @@
var tmp_word = prompt('Please enter a word or sentence:', '');
if (tmp_word) {
var pseudo_html = '[size]' + tmp_word + '[/size]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;
@@ -102,8 +114,7 @@
var tmp_word = prompt('Please enter a word or sentence:', '');
if (tmp_word) {
var pseudo_html = '[code]' + tmp_word + '[/code]';
- new_content = content.value + pseudo_html;
- content.value = new_content;
+ insertAtCursor(content, pseudo_html);
}
content.focus();
return false;