diff -r 0d9a58d2c515 -r 0d28b7c10758 web/wp-content/themes/elegant-box/js/comment.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/themes/elegant-box/js/comment.js Fri Mar 12 13:29:04 2010 +0000 @@ -0,0 +1,98 @@ +/* +Author: mg12 +Update: 2008/08/13 +Author URI: http://www.neoease.com/ +*/ +(function() { + +function reply(authorId, commentId, commentBox) { + var author = document.getElementById(authorId).innerHTML; + var insertStr = '@' + author.replace(/\t|\n|\r\n/g, "") + ' \n'; + + appendReply(insertStr, commentBox); +} + +function quote(authorId, commentId, commentBodyId, commentBox) { + var author = document.getElementById(authorId).innerHTML; + var comment = document.getElementById(commentBodyId).innerHTML; + + var insertStr = '
'; + insertStr += '\n' + author.replace(/\t|\n|\r\n/g, "") + ' :'; + insertStr += comment.replace(/\t/g, ""); + insertStr += '
\n'; + + insertQuote(insertStr, commentBox); +} + +function appendReply(insertStr, commentBox) { + if(document.getElementById(commentBox) && document.getElementById(commentBox).type == 'textarea') { + field = document.getElementById(commentBox); + + } else { + alert("The comment box does not exist!"); + return false; + } + + if (field.value.indexOf(insertStr) > -1) { + alert("You've already appended this reply!"); + return false; + } + + if (field.value.replace(/\s|\t|\n/g, "") == '') { + field.value = insertStr; + } else { + field.value = field.value.replace(/[\n]*$/g, "") + '\n\n' + insertStr; + } + field.focus(); +} + +function insertQuote(insertStr, commentBox) { + if(document.getElementById(commentBox) && document.getElementById(commentBox).type == 'textarea') { + field = document.getElementById(commentBox); + + } else { + alert("The comment box does not exist!"); + return false; + } + + if(document.selection) { + field.focus(); + sel = document.selection.createRange(); + sel.text = insertStr; + field.focus(); + + } else if (field.selectionStart || field.selectionStart == '0') { + var startPos = field.selectionStart; + var endPos = field.selectionEnd; + var cursorPos = startPos; + field.value = field.value.substring(0, startPos) + + insertStr + + field.value.substring(endPos, field.value.length); + cursorPos += insertStr.length; + field.focus(); + field.selectionStart = cursorPos; + field.selectionEnd = cursorPos; + + } else { + field.value += insertStr; + field.focus(); + } +} + +function loadCommentShortcut(frm, submitbnt, desc) { + document.getElementById(frm).onkeydown = function (moz_ev) { + var ev = null; + ev = window.event ? window.event : moz_ev; + if (ev != null && ev.ctrlKey && ev.keyCode == 13) { + document.getElementById(submitbnt).click(); + } + }; + document.getElementById(submitbnt).value += desc; +} + +window['CMT'] = {}; +window['CMT']['reply'] = reply; +window['CMT']['quote'] = quote; +window['CMT']['loadCommentShortcut'] = loadCommentShortcut; + +})(); \ No newline at end of file