[2.0.11] Accurate BBCode Insertion Mod

The cleanup is complete. This forum is now read only.

Rating:

Excellent!
18
64%
Very Good
1
4%
Good
4
14%
Fair
2
7%
Poor
3
11%
 
Total votes: 28

leecovuk
Registered User
Posts: 166
Joined: Mon Apr 11, 2005 2:11 pm

Post by leecovuk » Sun Oct 23, 2005 1:44 am

Peter,

I'm also having trouble getting the BBCode Box to work with Accurate Insertion. I did it before on a different install but I can't remember how.
By the way, I don't know if you're finding/using the 'new' Advanced BBCode Box taken over by hvmdesign.com which claims to achieve accurate insertion, but it doesn't do it in Firefox.
Presumably this is why, like me, you're trying to fix it !

What I did though, having doubts about the 'new Advanced BBCode Box, is I finally located the 'old' BBCode Box v 4.5.0 by Al Tnen, which I've installed and am now hoping to get 'accurate insertion' working in as many browsers as possible. Unfortunately his website seems to be in Arabic or something.
However, as in the past, I find it very difficult to pick through the various code snippets in this thread to work out the definitive way to go.

Any informed help much appreciated.

thanks,
lee

leecovuk
Registered User
Posts: 166
Joined: Mon Apr 11, 2005 2:11 pm

Post by leecovuk » Mon Nov 28, 2005 3:04 am

hello,

I'm posting here with some doubts as to the point, as every post I have made in this topic has never been answered. Maybe so far I have been asking the 'wrong' questions ... :?

My question is, how can I change presumably some javascript so that selecting an emoticon from 'view more emoticons' will be inserted at the cursor point in Mozilla Firefox?

I have already applied some code from this topic, and the inserting of 'standard' emoticons is already working at the cursor point in Firefox.
Both situations are working at the cursor point in IE.

The answer may well be in this topic, but as I've said before, I find it very difficult to follow the various contributions and pick through exactly what to do.

I am using the 'old' BBCode Box and in case it helps, here is my current add_bbcode.js
Feel free to ask to see posting_body.tpl or any other relevant files.

Many thanks .... still watching this topic .... !

lee

spsmyth
Registered User
Posts: 4
Joined: Sun Feb 12, 2006 12:16 am
Location: North Hollywood, CA
Contact:

Post by spsmyth » Sun Feb 12, 2006 12:28 am

peterpaulw wrote: A great mod :D . It should be part of the standard phpBB!

I put together most of the above improvements for Firefox compatibility in the summarized code below. Tested with Firefox 1, IE 6, Opera 8 (but not with Safari).

Code: Select all

##############################################################
## MOD Title: Accurate BBCode Insertion Mod
## MOD Author: Lord Z < info@znok.tk > (Jelle Aalbers) http://www.znok.tk, improved by Joe Dalton, sph, MarneusCalgarXP, peterpaulw
## MOD Description: This mod will insert BBCode accuratly into a post, (at the caret position) instead of putting it at the bottom.
## MOD Version: 1.0.1
##
## Installation Level: Easy
## Installation Time: ~ 2 Minutes
## Files To Edit: templates/subSilver/posting_body.tpl
## Included Files: n/a
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
##	
##	Why I wrote this mod
##	------------------------------------------------------
##	Usually, when a user wants to insert BBCode at a specific location while typing his post,
##	he has to type and select the text he wants to apply the BBCode to first, and then apply 
##	the BBCode to the selected text. When you try to just insert a BBCode-tag, it will appear
##	at the end of the post, and not at the caret position. This can be quite annoying.
##
##
##	What it does
##	------------------------------------------------------
##	It changes the way BBCode is inserted in a post into a more natural way. When you click
##	a BBCode-button, the tag will appear at the same place you where typing instead of at the
##	bottom of the post. If the caret isn't inside the message field, the tag will appear where the
##	user has lastly placed the caret inside the message field.
##
##	It won't alter the way BBCode is applied to selections, this worked well already.
##
##	It won't alter the behaviour of the 'Close all tags' button.  All tags are are still closed
##	at the bottom of the post when a user clicks this button.
##
##	If the client's browser doesn't support the technology to insert BBCode accuratly, it will
##	be placed the old-fashioned way.
##
##	The javascript function used to insert the code is (almost) identical to the function
##	wich is used for emoticons, so it behaves in almost the same way. It won't put any spaces
##	around your tag though, which does happens with emoticons.
##
##############################################################
## MOD History:
##
##   2004-05-18 - Version 1.0.1
##      - Improvements to make it work in all of Mozilla Firefox 1, Opera 8 and IE 6
##      - not tested on OS-X Safari
##
##   2004-12-16 - Version 1.0.0
##      - First version 
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/posting_body.tpl

#
#-----[ FIND ]------------------------------------------
#
function emoticon(text) {

#
#-----[ BEFORE, ADD ]------------------------------------------
#
function bbplace(text) {
    var txtarea = document.post.message;
    if (txtarea.createTextRange && txtarea.caretPos) {
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
        txtarea.focus();
    } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
        var startPos = txtarea.selectionStart;
        var endPos = txtarea.selectionEnd;
        txtarea.value = txtarea.value.substring(0, startPos)
                      + text
                      + txtarea.value.substring(endPos, txtarea.value.length);
        txtarea.focus();
        txtarea.selectionStart = startPos + text.length;
        txtarea.selectionEnd = startPos + text.length;
    } else {
        txtarea.value  += text;
        txtarea.focus();
    }
}

#
#-----[ FIND ]------------------------------------------
#
# This is in the function emoticon(text)
    } else {
            txtarea.value  += text;
            txtarea.focus();

#
#-----[ REPLACE WITH ]------------------------------------------
#
    } else {
            bbplace(text);
            txtarea.focus();
            
#
#-----[ FIND ]------------------------------------------
#
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				bbplace(bbtags[butnumber + 1]);

#
#-----[ FIND ]------------------------------------------
#
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			bbplace(bbtags[15]);

#
#-----[ FIND ]------------------------------------------
#
		// Open tag
		txtarea.value += bbtags[bbnumber];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		// Open tag
		bbplace(bbtags[bbnumber]);

#
#----[ FIND  ]------------------------------------------
#

	if (donotinsert) {      // Close all open tags up to the one just clicked & default button names
	      while (bbcode[bblast]) {
	            butnumber = arraypop(bbcode) - 1;
	            txtarea.value += bbtags[butnumber + 1];

#
#----[ REPLACE BY ]------------------------------------------
#

	if (donotinsert) {      // Close all open tags up to the one just clicked & default button names
	      while (bbcode[bblast]) {
	            butnumber = arraypop(bbcode) - 1;
	            bbplace(bbtags[butnumber + 1]); 

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#

# EoM 


I tried to install this code with EasyMod and it broke. I had to verify it first and make it verify. I would like to use this Mod, and I would like to use it on Mozilla, until then, I will defer usage. Great idea tho.

Steve
"This had better work."
--Grand Moff Tarkin, Ep. IV, A New Hope

spsmyth
Registered User
Posts: 4
Joined: Sun Feb 12, 2006 12:16 am
Location: North Hollywood, CA
Contact:

Post by spsmyth » Sun Feb 12, 2006 12:29 am

peterpaulw wrote: A great mod :D . It should be part of the standard phpBB!

I put together most of the above improvements for Firefox compatibility in the summarized code below. Tested with Firefox 1, IE 6, Opera 8 (but not with Safari).

Code: Select all

##############################################################
## MOD Title: Accurate BBCode Insertion Mod
## MOD Author: Lord Z < info@znok.tk > (Jelle Aalbers) http://www.znok.tk, improved by Joe Dalton, sph, MarneusCalgarXP, peterpaulw
## MOD Description: This mod will insert BBCode accuratly into a post, (at the caret position) instead of putting it at the bottom.
## MOD Version: 1.0.1
##
## Installation Level: Easy
## Installation Time: ~ 2 Minutes
## Files To Edit: templates/subSilver/posting_body.tpl
## Included Files: n/a
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
##	
##	Why I wrote this mod
##	------------------------------------------------------
##	Usually, when a user wants to insert BBCode at a specific location while typing his post,
##	he has to type and select the text he wants to apply the BBCode to first, and then apply 
##	the BBCode to the selected text. When you try to just insert a BBCode-tag, it will appear
##	at the end of the post, and not at the caret position. This can be quite annoying.
##
##
##	What it does
##	------------------------------------------------------
##	It changes the way BBCode is inserted in a post into a more natural way. When you click
##	a BBCode-button, the tag will appear at the same place you where typing instead of at the
##	bottom of the post. If the caret isn't inside the message field, the tag will appear where the
##	user has lastly placed the caret inside the message field.
##
##	It won't alter the way BBCode is applied to selections, this worked well already.
##
##	It won't alter the behaviour of the 'Close all tags' button.  All tags are are still closed
##	at the bottom of the post when a user clicks this button.
##
##	If the client's browser doesn't support the technology to insert BBCode accuratly, it will
##	be placed the old-fashioned way.
##
##	The javascript function used to insert the code is (almost) identical to the function
##	wich is used for emoticons, so it behaves in almost the same way. It won't put any spaces
##	around your tag though, which does happens with emoticons.
##
##############################################################
## MOD History:
##
##   2004-05-18 - Version 1.0.1
##      - Improvements to make it work in all of Mozilla Firefox 1, Opera 8 and IE 6
##      - not tested on OS-X Safari
##
##   2004-12-16 - Version 1.0.0
##      - First version 
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/posting_body.tpl

#
#-----[ FIND ]------------------------------------------
#
function emoticon(text) {

#
#-----[ BEFORE, ADD ]------------------------------------------
#
function bbplace(text) {
    var txtarea = document.post.message;
    if (txtarea.createTextRange && txtarea.caretPos) {
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
        txtarea.focus();
    } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
        var startPos = txtarea.selectionStart;
        var endPos = txtarea.selectionEnd;
        txtarea.value = txtarea.value.substring(0, startPos)
                      + text
                      + txtarea.value.substring(endPos, txtarea.value.length);
        txtarea.focus();
        txtarea.selectionStart = startPos + text.length;
        txtarea.selectionEnd = startPos + text.length;
    } else {
        txtarea.value  += text;
        txtarea.focus();
    }
}

#
#-----[ FIND ]------------------------------------------
#
# This is in the function emoticon(text)
    } else {
            txtarea.value  += text;
            txtarea.focus();

#
#-----[ REPLACE WITH ]------------------------------------------
#
    } else {
            bbplace(text);
            txtarea.focus();
            
#
#-----[ FIND ]------------------------------------------
#
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				bbplace(bbtags[butnumber + 1]);

#
#-----[ FIND ]------------------------------------------
#
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			bbplace(bbtags[15]);

#
#-----[ FIND ]------------------------------------------
#
		// Open tag
		txtarea.value += bbtags[bbnumber];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		// Open tag
		bbplace(bbtags[bbnumber]);

#
#----[ FIND  ]------------------------------------------
#

	if (donotinsert) {      // Close all open tags up to the one just clicked & default button names
	      while (bbcode[bblast]) {
	            butnumber = arraypop(bbcode) - 1;
	            txtarea.value += bbtags[butnumber + 1];

#
#----[ REPLACE BY ]------------------------------------------
#

	if (donotinsert) {      // Close all open tags up to the one just clicked & default button names
	      while (bbcode[bblast]) {
	            butnumber = arraypop(bbcode) - 1;
	            bbplace(bbtags[butnumber + 1]); 

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#

# EoM 


I tried to install this code with EasyMod and it broke. I had to verify it first and make it verify, but another attempt to install also broke. I would like to use this Mod, and I would like to use it on Mozilla, until then, I will defer usage. Your REPLACE tags are not working. Please verify and make the necessary corrections. Great idea tho.

Steve
"This had better work."
--Grand Moff Tarkin, Ep. IV, A New Hope

spsmyth
Registered User
Posts: 4
Joined: Sun Feb 12, 2006 12:16 am
Location: North Hollywood, CA
Contact:

Post by spsmyth » Sun Feb 12, 2006 12:30 am

peterpaulw wrote: A great mod :D . It should be part of the standard phpBB!

I put together most of the above improvements for Firefox compatibility in the summarized code below. Tested with Firefox 1, IE 6, Opera 8 (but not with Safari).

Code: Select all

##############################################################
## MOD Title: Accurate BBCode Insertion Mod
## MOD Author: Lord Z < info@znok.tk > (Jelle Aalbers) http://www.znok.tk, improved by Joe Dalton, sph, MarneusCalgarXP, peterpaulw
## MOD Description: This mod will insert BBCode accuratly into a post, (at the caret position) instead of putting it at the bottom.
## MOD Version: 1.0.1
##
## Installation Level: Easy
## Installation Time: ~ 2 Minutes
## Files To Edit: templates/subSilver/posting_body.tpl
## Included Files: n/a
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
##	
##	Why I wrote this mod
##	------------------------------------------------------
##	Usually, when a user wants to insert BBCode at a specific location while typing his post,
##	he has to type and select the text he wants to apply the BBCode to first, and then apply 
##	the BBCode to the selected text. When you try to just insert a BBCode-tag, it will appear
##	at the end of the post, and not at the caret position. This can be quite annoying.
##
##
##	What it does
##	------------------------------------------------------
##	It changes the way BBCode is inserted in a post into a more natural way. When you click
##	a BBCode-button, the tag will appear at the same place you where typing instead of at the
##	bottom of the post. If the caret isn't inside the message field, the tag will appear where the
##	user has lastly placed the caret inside the message field.
##
##	It won't alter the way BBCode is applied to selections, this worked well already.
##
##	It won't alter the behaviour of the 'Close all tags' button.  All tags are are still closed
##	at the bottom of the post when a user clicks this button.
##
##	If the client's browser doesn't support the technology to insert BBCode accuratly, it will
##	be placed the old-fashioned way.
##
##	The javascript function used to insert the code is (almost) identical to the function
##	wich is used for emoticons, so it behaves in almost the same way. It won't put any spaces
##	around your tag though, which does happens with emoticons.
##
##############################################################
## MOD History:
##
##   2004-05-18 - Version 1.0.1
##      - Improvements to make it work in all of Mozilla Firefox 1, Opera 8 and IE 6
##      - not tested on OS-X Safari
##
##   2004-12-16 - Version 1.0.0
##      - First version 
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/posting_body.tpl

#
#-----[ FIND ]------------------------------------------
#
function emoticon(text) {

#
#-----[ BEFORE, ADD ]------------------------------------------
#
function bbplace(text) {
    var txtarea = document.post.message;
    if (txtarea.createTextRange && txtarea.caretPos) {
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
        txtarea.focus();
    } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
        var startPos = txtarea.selectionStart;
        var endPos = txtarea.selectionEnd;
        txtarea.value = txtarea.value.substring(0, startPos)
                      + text
                      + txtarea.value.substring(endPos, txtarea.value.length);
        txtarea.focus();
        txtarea.selectionStart = startPos + text.length;
        txtarea.selectionEnd = startPos + text.length;
    } else {
        txtarea.value  += text;
        txtarea.focus();
    }
}

#
#-----[ FIND ]------------------------------------------
#
# This is in the function emoticon(text)
    } else {
            txtarea.value  += text;
            txtarea.focus();

#
#-----[ REPLACE WITH ]------------------------------------------
#
    } else {
            bbplace(text);
            txtarea.focus();
            
#
#-----[ FIND ]------------------------------------------
#
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				txtarea.value += bbtags[butnumber + 1];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				bbplace(bbtags[butnumber + 1]);

#
#-----[ FIND ]------------------------------------------
#
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			bbplace(bbtags[15]);

#
#-----[ FIND ]------------------------------------------
#
		// Open tag
		txtarea.value += bbtags[bbnumber];

#
#-----[ REPLACE WITH ]------------------------------------------
#
		// Open tag
		bbplace(bbtags[bbnumber]);

#
#----[ FIND  ]------------------------------------------
#

	if (donotinsert) {      // Close all open tags up to the one just clicked & default button names
	      while (bbcode[bblast]) {
	            butnumber = arraypop(bbcode) - 1;
	            txtarea.value += bbtags[butnumber + 1];

#
#----[ REPLACE BY ]------------------------------------------
#

	if (donotinsert) {      // Close all open tags up to the one just clicked & default button names
	      while (bbcode[bblast]) {
	            butnumber = arraypop(bbcode) - 1;
	            bbplace(bbtags[butnumber + 1]); 

#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#

# EoM 


I tried to install this code with EasyMod and it broke. I had to verify it first and make it verify, but another attempt to install also broke. I would like to use this Mod, and I would like to use it on Mozilla, until then, I will defer usage. Your REPLACE tags are not working. Please verify and make the necessary corrections. Great idea tho.

Steve
"This had better work."
--Grand Moff Tarkin, Ep. IV, A New Hope

spsmyth
Registered User
Posts: 4
Joined: Sun Feb 12, 2006 12:16 am
Location: North Hollywood, CA
Contact:

Post by spsmyth » Sun Feb 12, 2006 12:43 am

Sorry, I don't know what happened...
"This had better work."
--Grand Moff Tarkin, Ep. IV, A New Hope

niksa
Registered User
Posts: 612
Joined: Mon Sep 08, 2003 7:20 pm
Location: Future birthplace of James T. Kirk
Contact:

Post by niksa » Sun Feb 12, 2006 12:43 am

(You posted 3 times in a row!)

What was the exact error EM said?

NightriderXP
Registered User
Posts: 1418
Joined: Sat Oct 09, 2004 8:17 am
Location: Florida, US
Contact:

Post by NightriderXP » Sun Feb 12, 2006 5:32 pm

I haven't attempted to install the code above, but I can see the REPLACE BY command at the very end will fail in EM. It should be REPLACE WITH just like all the others...

Image

rapghsi
Registered User
Posts: 40
Joined: Sat Jan 07, 2006 12:11 pm

very good

Post by rapghsi » Sun Feb 12, 2006 6:40 pm

very good

sbourdon
Registered User
Posts: 174
Joined: Sat Nov 13, 2004 6:29 pm

Post by sbourdon » Thu Feb 16, 2006 12:41 am

Hello,

Great MOD, but there is one little problem: the code for the Font colour and Font size boxes is still inserted at the end of the post...

How can we fix this?


Thanks! ;-)

sbourdon
Registered User
Posts: 174
Joined: Sat Nov 13, 2004 6:29 pm

Post by sbourdon » Sun Apr 23, 2006 2:28 am

Hi,

In Firefox, when selecting text or clicking on a BBCode Button, we are always taken back to the beginning of the post after the insertion of the code; this does not happen in IE.

Is there a way to fix this so that the focus remains on the inserted BBcode?


Thank you! :)

User avatar
bonelifer
Community Team Member
Community Team Member
Posts: 3475
Joined: Wed Oct 27, 2004 11:35 pm
Name: William
Contact:

Post by bonelifer » Thu Jun 15, 2006 12:24 am

Anyone using this with phpBB 2.0.21?
Knowledge Base | phpBB Board Rules | Search Customisation Database
Image
Please don't contact me via PM or email for phpBB support .

Threatcon
Registered User
Posts: 131
Joined: Tue Dec 10, 2002 5:38 am
Location: Florida
Contact:

Post by Threatcon » Sun Jun 25, 2006 5:11 pm

bonelifer wrote: Anyone using this with phpBB 2.0.21?


Yes it works as advertised. Make sure to use version 1.0.1 of this mod.

Code: Select all

##   2004-05-18 - Version 1.0.1
##      - Improvements to make it work in all of Mozilla Firefox 1, Opera 8 and IE 6

User avatar
bonelifer
Community Team Member
Community Team Member
Posts: 3475
Joined: Wed Oct 27, 2004 11:35 pm
Name: William
Contact:

Post by bonelifer » Mon Jun 26, 2006 6:15 pm

I found out why it wasn't working correctly for me. There was some code replacement that got repeated in the installation file. I remove the inappropriate version of the replacement and put the correct one in the right place and now it installs via Easymod and works correctly. I also changed the "replace by" to "replace with".

Here it is correctly fixed(verified in Firefox 1.5.0.4:

Code: Select all

##############################################################
## MOD Title: Accurate BBCode Insertion Mod
## MOD Author: Lord Z < info@znok.tk > (Jelle Aalbers) http://www.znok.tk, improved by Joe Dalton, sph, MarneusCalgarXP, peterpaulw
## MOD Description: This mod will insert BBCode accuratly into a post, (at the caret position) instead of putting it at the bottom.
## MOD Version: 1.0.1
##
## Installation Level: Easy
## Installation Time: ~ 2 Minutes
## Files To Edit: templates/subSilver/posting_body.tpl
## Included Files: n/a
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/
##############################################################
## Author Notes:
##   
##   Why I wrote this mod
##   ------------------------------------------------------
##   Usually, when a user wants to insert BBCode at a specific location while typing his post,
##   he has to type and select the text he wants to apply the BBCode to first, and then apply
##   the BBCode to the selected text. When you try to just insert a BBCode-tag, it will appear
##   at the end of the post, and not at the caret position. This can be quite annoying.
##
##
##   What it does
##   ------------------------------------------------------
##   It changes the way BBCode is inserted in a post into a more natural way. When you click
##   a BBCode-button, the tag will appear at the same place you where typing instead of at the
##   bottom of the post. If the caret isn't inside the message field, the tag will appear where the
##   user has lastly placed the caret inside the message field.
##
##   It won't alter the way BBCode is applied to selections, this worked well already.
##
##   It won't alter the behaviour of the 'Close all tags' button.  All tags are are still closed
##   at the bottom of the post when a user clicks this button.
##
##   If the client's browser doesn't support the technology to insert BBCode accuratly, it will
##   be placed the old-fashioned way.
##
##   The javascript function used to insert the code is (almost) identical to the function
##   wich is used for emoticons, so it behaves in almost the same way. It won't put any spaces
##   around your tag though, which does happens with emoticons.
##
##############################################################
## MOD History:
##
##   2004-05-18 - Version 1.0.1
##      - Improvements to make it work in all of Mozilla Firefox 1, Opera 8 and IE 6
##      - not tested on OS-X Safari
##
##   2004-12-16 - Version 1.0.0
##      - First version
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/posting_body.tpl

#
#-----[ FIND ]------------------------------------------
#
function emoticon(text) {

#
#-----[ BEFORE, ADD ]------------------------------------------
#
function bbplace(text) {
    var txtarea = document.post.message;
    if (txtarea.createTextRange && txtarea.caretPos) {
        var caretPos = txtarea.caretPos;
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
        txtarea.focus();
    } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
        var startPos = txtarea.selectionStart;
        var endPos = txtarea.selectionEnd;
        txtarea.value = txtarea.value.substring(0, startPos)
                      + text
                      + txtarea.value.substring(endPos, txtarea.value.length);
        txtarea.focus();
        txtarea.selectionStart = startPos + text.length;
        txtarea.selectionEnd = startPos + text.length;
    } else {
        txtarea.value  += text;
        txtarea.focus();
    }
}

#
#-----[ FIND ]------------------------------------------
#
# This is in the function emoticon(text)
    } else {
            txtarea.value  += text;
            txtarea.focus();

#
#-----[ REPLACE WITH ]------------------------------------------
#
    } else {
            bbplace(text);
            txtarea.focus();
           
#
#-----[ FIND ]------------------------------------------
#
      while (bbcode[bblast]) {
            butnumber = arraypop(bbcode) - 1;
            txtarea.value += bbtags[butnumber + 1];

#
#-----[ REPLACE WITH ]------------------------------------------
#
      while (bbcode[bblast]) {
            butnumber = arraypop(bbcode) - 1;
            bbplace(bbtags[butnumber + 1]);

#
#-----[ FIND ]------------------------------------------
#
		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			txtarea.value += bbtags[15];

#
#-----[ REPLACE WITH ]------------------------------------------
#
      if (imageTag && (bbnumber != 14)) {      // Close image tag before adding another
         bbplace(bbtags[15]);

#
#-----[ FIND ]------------------------------------------
#
      // Open tag
      txtarea.value += bbtags[bbnumber];

#
#-----[ REPLACE WITH ]------------------------------------------
#
      // Open tag
      bbplace(bbtags[bbnumber]);


#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#

# EoM
Knowledge Base | phpBB Board Rules | Search Customisation Database
Image
Please don't contact me via PM or email for phpBB support .

User avatar
lefty74
Registered User
Posts: 3649
Joined: Wed Sep 14, 2005 8:26 pm
Location: NL
Contact:

Post by lefty74 » Tue Jun 27, 2006 4:57 pm

sbourdon wrote: Hi,

In Firefox, when selecting text or clicking on a BBCode Button, we are always taken back to the beginning of the post after the insertion of the code; this does not happen in IE.

Is there a way to fix this so that the focus remains on the inserted BBcode?


Thank you! :)


the same happens to me in Firefox. anyone an idea how to fix it?

thanks a lot

for the rest it works excellent!
lefty74
zoocrew.eu - help us save our wildlife
My MODS | Due to lack of time I unfortunately am unable to work on my mods anymore, anyone who has ideas to improve them and would like to take any of them over, please PM me.

Post Reply

Return to “[2.0.x] MOD Database Cleanup”