panel.js
34 lines
| 1.2 KiB
| application/javascript
|
JavascriptLexer
rt@lightning
|
r228 | function addMarkToMsg(start, end) { | ||
var textarea = document.getElementById('id_text'); | ||||
if(!textarea) return; | ||||
if( document.selection ) { | ||||
textarea.focus(); | ||||
sel = document.selection.createRange(); | ||||
sel.text = start + sel.text + end; | ||||
} else if(textarea.selectionStart || textarea.selectionStart == '0') { | ||||
textarea.focus(); | ||||
var startPos = textarea.selectionStart; | ||||
var endPos = textarea.selectionEnd; | ||||
textarea.value = textarea.value.substring(0, startPos) + start + textarea.value.substring(startPos, endPos) + end + textarea.value.substring( endPos, textarea.value.length ); | ||||
} else { | ||||
textarea.value += start + end; | ||||
} | ||||
return false; | ||||
} | ||||
function addMarkPanel() { | ||||
$('.mark_btn').on('click', function() { | ||||
switch($(this).attr('id')) { | ||||
case "italic": | ||||
return addMarkToMsg('_', '_'); | ||||
case "bold": | ||||
return addMarkToMsg('__', '__'); | ||||
case "spoiler": | ||||
return addMarkToMsg('%%', '%%'); | ||||
case "comment": | ||||
return addMarkToMsg('//', ''); | ||||
case "quote": | ||||
return addMarkToMsg('>', ''); | ||||
} | ||||
}); | ||||
} | ||||