• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Easy BBCode

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
2 posts • Page 1 of 1

Postby Mephisto » Tue Aug 22, 2006 11:49 am

Hi all !


To improve usability of BBCode I made some modifications over the "insert_text" function.


What does it do ?
- Same features as default function
- If no text is selected, a prompt box asks the user to write a text. When the prompt box is validated the text witht the bbcode is automaticaly added to the send message box


Location of the script :
file : Chat_root/themes/Your_theme/templates/pfcclient.js.tpl.php
line : 1277


News function :
Code: Select all
/**
   * BBcode ToolBar
   */
  insert_text: function(open, close)
  {
    var msgfield = $('<?php echo $prefix; ?>words');
   
    // IE support
    if (document.selection && document.selection.createRange)
    {
      msgfield.focus();
      sel = document.selection.createRange();
     if(sel.text.lenght==0) var texte = prompt('Tapez le texte à mettre en forme :','');
     else var texte = sel.text;
      sel.text = open + texte + close;
      msgfield.focus();
    }
   
    // Moz support
    else if (msgfield.selectionStart || msgfield.selectionStart == '0')
    {
      var startPos = msgfield.selectionStart;
      var endPos = msgfield.selectionEnd;
    
     if(startPos==endPos) var texte = prompt('Tapez le texte à mettre en forme :','');
      else var texte = msgfield.value.substring(startPos, endPos);
    
     msgfield.value = msgfield.value.substring(0, startPos) + open + texte + close + msgfield.value.substring(endPos, msgfield.value.length);
     msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
     msgfield.focus();
    }
   
    // Fallback support for other browsers
    else
    {
     var texte = prompt('Tapez le texte à mettre en forme :','');
      msgfield.value += open + texte + close;
      msgfield.focus();
    }
    return;
  },

Have fun ;)
Mephisto
New member
 
Posts: 5
Joined: Mon Aug 14, 2006 8:24 am
Top

Postby phpfreechat » Tue Aug 22, 2006 1:26 pm

Thank you mephisto, I just integrated a modified version of your contribution in the official pfc source code.

Code: Select all
  /**
   * BBcode ToolBar
   */
  insert_text: function(open, close)
  {
    var msgfield = $('pfc_words');
   
    // IE support
    if (document.selection && document.selection.createRange)
    {
      msgfield.focus();
      sel = document.selection.createRange();
      var text = sel.text;
      if (text == "")
        text = prompt(this.res.getLabel('Enter the text to format'),'');
      if (text.length > 0)
      {
        sel.text = open + text + close;
        // @todo move the cursor just after the BBCODE, this doesn't work when the text to enclose is selected, IE6 keeps the whole selection active after the operation.
        msgfield.focus();
      }
    }
   
    // Moz support
    else if (msgfield.selectionStart || msgfield.selectionStart == '0')
    {
      var startPos = msgfield.selectionStart;
      var endPos = msgfield.selectionEnd;
     
      var text = msgfield.value.substring(startPos, endPos);
      var extralength = 0;
      if (startPos == endPos)
      {
        text = prompt(this.res.getLabel('Enter the text to format'),'');
        extralength = text.length;
      }
      if (text.length > 0)
      {
        msgfield.value = msgfield.value.substring(0, startPos) + open + text + close + msgfield.value.substring(endPos, msgfield.value.length);
        msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + extralength + close.length;
        msgfield.focus();
      }
    }
   
    // Fallback support for other browsers
    else
    {
      var text = prompt(this.res.getLabel('Enter the text to format'),'');
      if (text.length > 0)
      {
        msgfield.value += open + text + close;
        msgfield.focus();
      }
    }
    return;
  },
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top


Post a reply
2 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 13 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub