Help Desk Software & Beyond
May 21, 2012, 11:41:10 PM *
Welcome, Guest. Please login or register.
To post messages you need to register. We apologize for inconvenience, but this is to prevent spam.
Registration is instant (no email verification) and we do not ask for any personal information.

Login with username, password and session length
News: Welcome to Help Desk Software forum!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [MOD] 'Quote' function for BBCode editor. (TTX any version)  (Read 1472 times)
Sparky
Moderator
Hero Member
*****

Karma: 83
Posts: 2,228


stop pushing all those buttons


View Profile
« on: October 25, 2007, 04:38:40 PM »

How would you like to be able to automatically quote any selection of text from anywhere on the Ticket page with the click of a button?

Quote
Quote:  hello, i'm being quoted here.

This simple function will let you do just that.

Add this Javascript to the top of the ticket.html page.

Code:
<script language="JavaScript"><!--
function getSelectedText(){
  if (window.getSelection){
    txt = window.getSelection();
  }
  else if (document.getSelection) {
    txt = document.getSelection();
  }
  else if (document.selection){
    txt = document.selection.createRange().text;
  }
  else return;
  return txt;
}

function makequote(bbopen, bbclose) {
  var mytxt = getSelectedText();
  var fld = document.getElementById('problem');
  //trackme(fld);//
  // IE
  if (caretPos != null && fld.createTextRange) {
    var range = caretPos;
    //fld.focus();//
    var wasempty = mytxt.length == 0 ? true : false;
    range.text = bbopen + mytxt + bbclose;
    if (wasempty) {
      range.moveStart('character', -bbclose.length);
      range.moveEnd('character', -bbclose.length);
      range.select();
    } else {
      fld.focus(range);
    }
  // Not IE
  } else if (typeof(fld.selectionStart) != "undefined") {
    mytxt = String(mytxt);
    var savescroll = fld.scrollTop;
    var start = fld.selectionStart;
    var end = fld.selectionEnd;
    var txt = fld.value.substring(start, end);
    if (txt.length != 0) {
       fld.value = fld.value.substr(0, start) + bbopen + txt + bbclose + fld.value.substr(end);
    } else {
       fld.value = fld.value.substr(0, start) + bbopen + mytxt + bbclose + fld.value.substr(end);
    }
    var pos;
    if (txt.length == 0 && mytxt.length == 0){
       pos = start + bbopen.length;
    } else if (mytxt.length != 0) {
       pos = start + bbopen.length + mytxt.length + bbclose.length;
    } else {
       pos = start + bbopen.length + txt.length + bbclose.length;
    }
    fld.selectionStart = pos;
    fld.selectionEnd = pos;
    fld.focus();
    fld.scrollTop = savescroll;
  }
}
//-->
</script>


The add the "quote selection" button to the other BB Code buttons or anyplace else on your ticket.html page.

Code:
<input name="quote" type="button" class="buttons" id="quote" tabindex="-1"
onclick="makequote('[b]Quote:[/b] [i]', '[/i]'); return false;" value="Quote Selection">

Verify that your text area also contains an ID.  If not, just add the part in red.  Just make sure it looks like this including the mouse events...

Quote
<textarea name="problem" id="problem" wrap="virtual" cols="70" rows="10" onselect="trackme(this);" onclick="trackme(this);" onkeyup="trackme(this);" onchange="trackme(this);">



It will work on text selected from anyplace on the page including hi-lighted text from within the message box itself.

If you have something selected from one of the older messages, it will format it with all the proper tags and insert it at the cursor position of your message box.

If you select text from within your message box, it will format it with all the proper tags and place your cursor at the end of the new item.

If you have nothing selected, it puts your cursor in a position where you can just type in the text to be quoted.

Tested in IE, FireFox, & Safari which covers more than 98% or practically everyone.

Let me know if you find problems.
« Last Edit: January 16, 2008, 05:28:34 PM by sparky672 » Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
Sparky
Moderator
Hero Member
*****

Karma: 83
Posts: 2,228


stop pushing all those buttons


View Profile
« Reply #1 on: October 25, 2007, 05:06:44 PM »

Enhance it further by making the quoted text indented and bordered by lines above/below.  Since the notification emails have been in HTML since version 2.22, those should look good too.



In TTXMarkup.pm add the part in red to these two lines...

Quote
$buff =~ s/\[(\/?)(u|b|i|code|small|hr|blockquote)]/<$1$2>/gi;

Quote
$buff =~ s/\[(\/?)(u|b|i|code|small|hr|blockquote)]//gi;


Then make your "quote selection" button look like this...

Code:
<input name="quote" type="button" class="buttons" id="quote" tabindex="-1"
onclick="makequote('[blockquote][hr][b]Quote:[/b] [i]', '[/i][hr][/blockquote]'); return false;" value="Quote Selection">
« Last Edit: October 25, 2007, 08:42:21 PM by sparky672 » Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC3 | SMF © 2001-2006, Lewis Media Valid XHTML 1.0! Valid CSS!
Page created in 0.022 seconds with 19 queries.