An alternative to UBB.threads
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FLocal/static/js/textEditor.js

261 lines
19 KiB

<EFBFBD><EFBFBD>function x() {
return;
}
var cancelEnter = false;
function fontlist() {
var fonts = new Array("Arial", "Arial Black", "Arial Narrow", "Book Antiqua", "Century Gothic", "Comic Sans MS", "Courier New", "Fixedsys", "Garamond", "Georgia", "Impact", "Lucida Console", "Lucida Sans Unicode", "Microsoft Sans Serif", "Palatino Linotype", "System", "Tahoma", "Times New Roman", "Trebuchet MS", "Verdana");
for(key in fonts) {
document.writeln('<option value="' + fonts[key] + '">' + fonts[key] + '</option>');
}
}
//shaller [26.11.2004 1:15]
function setOffsetPosition(elem,offset) {
if (isIe) {
elem.caretPos.moveStart ('character', offset);
elem.caretPos.moveEnd ('character', offset);
elem.caretPos.select();
} else if (isMozilla) {
cursorPos = elem.selectionStart + offset;
//alert(elem.selectionStart);
elem.setSelectionRange(cursorPos,cursorPos);
elem.focus();
}
}
function storeCaret (textEl) {
if(textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
} // end fn
function insertAtCaret (textEl, text) {
if(textEl.createTextRange && textEl.caretPos) {
var caretPos = textEl.caretPos;
caretPos.text = (caretPos.text.charAt(caretPos.text.length - 1) == ' ') ? text + ' ' : text;
} else if(isMozilla || isWebkit) {
cursorPos = textEl.selectionStart;
textEl.value = textEl.value.slice (0, cursorPos) + text + textEl.value.slice (cursorPos , textEl.value.length);
textEl.setSelectionRange(cursorPos+text.length,cursorPos+text.length);
textEl.focus();
} else {
textEl.value = textEl.value + text; // for non MSIE browsers just append it
}
return true;
}// fn
function checkKeyPressed(form, ev, sendWithEnter) {
//shaller 08.07.04
if(window.event && (isIe || isWebkit) && !isMac) {
if(window.event.keyCode == 10) {
form.submit();
} else if(sendWithEnter && window.event.keyCode == 13) {
form.submit();
} else if(window.event.shiftKey && window.event.keyCode == 2) {
window.event.returnValue = false;
DoPrompt("bold");
} else if(window.event.shiftKey && window.event.keyCode == 9) {
window.event.returnValue = false;
DoPrompt("italics");
}
} else {
if(ev.ctrlKey && ev.keyCode == 13) {
form.submit();
} else if(ev.ctrlKey && ev.shiftKey && ev.which == 66) {
ev.preventDefault();
DoPrompt("bold");
} else if(ev.ctrlKey && ev.shiftKey && ev.which == 73) {
ev.preventDefault();
DoPrompt("italics");
}
}
}
function DoSmilie(addSmilie) {
var revisedMessage;
var currentMessage = document.replier.Body.value;
revisedMessage = currentMessage+addSmilie;
document.replier.Body.value=revisedMessage;
document.replier.Body.focus();
return;
}
function DoColor(color) {
tmp_str = "[/color]";
insertAtCaret(document.replier.Body, ' ' + "[color=" +color + "] [/color]" + ' ' );
document.replier.Body.focus();
setOffsetPosition(document.replier.Body,-tmp_str.length-3);
return;
}
function DoSize(size) {
tmp_str = "[/size]";
insertAtCaret(document.replier.Body, ' ' + "[size=" +size + "] [/size]" + ' ' );
document.replier.Body.focus();
setOffsetPosition(document.replier.Body,-tmp_str.length-3);
return;
}
function DoFont(font) {
tmp_str = "[/font]";
insertAtCaret(document.replier.Body, ' ' + '[font="' + font + '"] [/font]' + ' ' );
document.replier.Body.focus();
setOffsetPosition(document.replier.Body,-tmp_str.length-3);
return;
}
/* Sending messages with Ctrl+Enter outside the textarea */
if(typeof(document.send_final) != "undefined") {
document.replier.Body.onfocus = function(event) {
cancelEnter=true;
}
document.replier.Body.onblur = function(event) {
cancelEnter=false;
}
document.onkeypress = function(event) {
if(!cancelEnter) {
checkKeyPressed(document.send_final, event, true);
}
}
}
function DoPrompt(action) {
var currentMessage = document.replier.Body.value;
if(action == "url") {
var thisURL = prompt("2548B5 ?>;=K9 URL AAK;:8, :>B>@CN 2K E>B8B5 2AB028BL.", "http://");
if (thisURL == null) {
return;
}
var thisTitle = prompt(""5?5@L 22548B5 =0720=85 web-AB@0=8FK, =0 :>B>@CN C:07K205B 40==0O 20<8 AAK;:0.", "web-AB@0=8F0");
if(thisTitle == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[url=" + thisURL + "]" + thisTitle + "[/url]" + ' ');
document.replier.Body.focus();
return;
} else if (action == "color") {
tmp_str = "[/color]";
var thisColor = prompt("2548B5 F25B B5:AB0. -B> <>65B 1KBL =0720=85, =0?@8<5@ blue, 8;8 16-@8G=>5 RGB-2K@065=85, =0?@8<5@ #ff1123","");
if(thisColor == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[color=" + thisColor + "] [/color] ");
document.replier.Body.focus();
setOffsetPosition(document.replier.Body,-tmp_str.length-3);
return;
} else if(action == "email") {
var thisEmail = prompt("2548B5 ?>;=K9 04@5Ae email, :>B>@K9 2K E>B8B5 2AB028BL.", "");
if(thisEmail == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[Email]" + thisEmail + "[/Email]" + ' ');
document.replier.Body.focus();
return;
} else if(action == "bold") {
var thisBold = prompt("2548B5 B5:AB, :>B>@K9 2K E>B8B5 2K45;8BL 68@=K< H@8DB><.", "");
if(thisBold == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[b]" + thisBold + "[/b]" + ' ');
document.replier.Body.focus();
return;
} else if(action == "italics") {
var thisItal = prompt("2548B5 B5:AB, :>B>@K9 2K E>B8B5 2K45;8BL =0:;>==K< H@8DB><.", "");
if(thisItal == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[i]" + thisItal + "[/i]" + ' ');
document.replier.Body.focus();
return;
} else if(action == "image") {
var thisImage = prompt("2548B5 ?>;=K9 URL :0@B8=:8, :>B>@CN 2K E>B8B5 2AB028BL 2 A>>1I5=85.", "http://");
if(thisImage == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[image]" + thisImage + "[/image]" + ' ' );
document.replier.Body.focus();
return;
} else if(action == "quote") {
tmp_str = "[/quote]";
insertAtCaret(document.replier.Body, ' ' + "[quote] [/quote]" + ' ');
document.replier.Body.focus();
setOffsetPosition(document.replier.Body,-tmp_str.length-3);
return;
} else if(action == "code") {
tmp_str = "[/code]";
insertAtCaret(document.replier.Body, ' ' + "[code] [/code]" + ' ');
document.replier.Body.focus();
setOffsetPosition(document.replier.Body,-tmp_str.length-3);
return;
} else if(action == "ecode") {
tmp_str = "[/ecode]";
insertAtCaret(document.replier.Body, ' ' + "[ecode] [/ecode]" + ' ');
document.replier.Body.focus();
setOffsetPosition(document.replier.Body,-tmp_str.length-3);
return;
} else if(action == "liststart") {
insertAtCaret(document.replier.Body, ' ' + "[list]" + ' ');
document.replier.Body.focus();
return;
} else if(action == "listend") {
insertAtCaret(document.replier.Body, ' ' + "[/list]" + ' ');
document.replier.Body.focus();
return;
} else if (action == "listitem") {
var thisItem = prompt("2548B5 M;5<5=B A?8A:0. ><=8B5 GB> A?8A>: 4>;65= =0G8=0BLAO A '0G0;0 A?8A:0' 8 7025@H0BLAO '>=F>< A?8A:0'.", "");
if(thisItem == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[*]" + thisItem + ' ' );
document.replier.Body.focus();
return;
} else if(action == "pollstart") {
var thisPOLL = prompt("2548B5 =0720=85 3>;>A>20=8O", "");
if(thisPOLL == null){
return;
}
insertAtCaret(document.replier.Body, "[pollstart]\n[polltitle=" + thisPOLL + "]\n");
document.replier.Body.focus();
return;
} else if (action == "polloption") {
var thisOption = prompt("2548B5 20@80=B 3>;>A>20=8O. ><=8B5 GB> 3>;>A>20=85 4>;6=> =0G8=0BLAO A '0G0;0 3>;>A>20=8O' 8 7025@H0BLAO '>=F>< 3>;>A>20=8O'.", "");
if(thisOption == null) {
return;
}
insertAtCaret(document.replier.Body, "[polloption=" + thisOption + "]\n");
document.replier.Body.focus();
return;
} else if(action == "pollstop") {
insertAtCaret(document.replier.Body, "[pollstop]\n");
document.replier.Body.focus();
return;
} else if(action == "user") {
var thisOption = prompt(">;L7>20B5;L", "");
if(thisOption == null) {
return;
}
insertAtCaret(document.replier.Body, "[user=" + thisOption + "]\n");
document.replier.Body.focus();
return;
} else if (action == "table") {
insertAtCaret(document.replier.Body, "[table width= border= cellspacing= cellpadding=]\n\n[/table]");
document.replier.Body.focus();
tmp_str = "[/table]";
setOffsetPosition(document.replier.Body,-tmp_str.length-1);
return;
} else if(action == "video") {
var thisVideo = prompt("YouTube link", "http://");
if(thisVideo == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[video]" + thisVideo + "[/video]" + ' ');
document.replier.Body.focus();
return;
} else if(action == "tex") {
var thisMath = prompt("LaTeX code", "");
if(thisMath == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[tex]" + thisMath + "[/tex]" + ' ' );
document.replier.Body.focus();
return;
} else if(action == "math") {
var thisMath = prompt("Math LaTeX code", "");
if(thisMath == null) {
return;
}
insertAtCaret(document.replier.Body, ' ' + "[math]" + thisMath + "[/math]" + ' ' );
document.replier.Body.focus();
return;
}
}