Guest User

Untitled

a guest
Jun 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function dadada(f, t) {
  2. var f = $(f);
  3. var start_tag = "[" + t + "]";
  4. var end_tag = "[\/" + t + "]";
  5.  
  6. if (document.selection) {
  7. f.focus();
  8. var selected = document.selection.createRange().text;
  9. var sel = document.selection.createRange();
  10. sel.text = start_tag + selected + end_tag;
  11. } else if (f.selectionStart || f.selectionStart == '0') {
  12. var startPos = f.selectionStart;
  13. var endPos = f.selectionEnd;
  14. var text = start_tag + f.value.substring( startPos, endPos ) + end_tag;
  15. f.value = f.value.substring(0, startPos) + text + f.value.substring(endPos, f.value.length);
  16. } else {
  17. f.value += start_tag + end_tag;
  18. }
  19. f.focus();
  20. }
Add Comment
Please, Sign In to add comment