[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

peterpaulw
Registered User
Posts: 5
Joined: Mon May 09, 2005 3:20 pm

Post by peterpaulw » Wed May 18, 2005 7:12 am

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 

bombon
Registered User
Posts: 2
Joined: Wed May 18, 2005 9:14 am

Post by bombon » Wed May 18, 2005 9:47 am

Hi,

I´m using this mod with BBCodeBox. BBCodeBox is also integrated in phpBB Plus.

Here what to do:

Code: Select all

#
#-----[ OPEN ]------------------------------------------
#
bbcode_box/add_bbcode.js

#
#-----[ FIND ]------------------------------------------
#
function BBCplain() {

#
#-----[ 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 ALL ]------------------------------------------
#
document.post.message.value+=ToAdd;

#
#-----[ REPLACE ALL WITH ]------------------------------------------
#
bbplace(ToAdd);

#
#-----[ FIND ALL ]------------------------------------------
#
document.post.message.value+="[hr]";

#
#-----[ REPLACE ALL WITH ]------------------------------------------
#
bbplace("[hr]");

#
#-----[ FIND ALL ]------------------------------------------
#
document.post.message.value += bbopen + bbclose;

#
#-----[ REPLACE ALL WITH ]------------------------------------------
#
bbplace(bbopen + bbclose);

#
#-----[ FIND ALL ]------------------------------------------
#
document.post.message.value += text;

#
#-----[ REPLACE ALL WITH ]------------------------------------------
#
bbplace(text);

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

# EoM
Last edited by bombon on Thu May 19, 2005 11:40 am, edited 1 time in total.
excuse my bad english please...

http://www.nagan-rothas.de
http://www.ddcom.de

bombon
Registered User
Posts: 2
Joined: Wed May 18, 2005 9:14 am

Post by bombon » Wed May 18, 2005 2:16 pm

hmm

edit2:
now it works - i have changed the instructions above...
excuse my bad english please...

http://www.nagan-rothas.de
http://www.ddcom.de

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

Post by leecovuk » Tue Jun 07, 2005 3:20 am

Hello Bombon and anyone else who has posted fixes here,

I am also using BBCode Box from phpbbhacks.com and have noticed the 'accurate bbcode insertion' doesn't work in Firefox.
I haven't got _this_ mod here installed at the moment, because I am unclear of how to adjust both/either mods so that Firefox and IE (at least) are supported.

So, can someone please pull together the required code fixes for me, presumably from bits already posted in this thread?

The only mods I have at the moment on phpBB 2.0.15 are :
EasyMod
Country Flags
BBCode Box

I am willing to _attempt_ to roll back to an earlier phpBB version if totally necessary for things to work.

Many thanks.

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

Post by leecovuk » Fri Jun 17, 2005 1:57 am

bump
just in case.
thanks.

Opaque
Registered User
Posts: 52
Joined: Sat Mar 01, 2003 5:55 am

Post by Opaque » Sat Jun 18, 2005 9:18 am

Hmm, just wondering, does this phpbb.com/phpbb forum have this mod installed? It seems to handle this quite nicely here too :|

But yeah Mod version 1.0.1 is working absolutely great for the PCNX forum at (http://www.pcnx.com/forum/ - it's actually something I was looking for for a LONG time (vBulletin has this by default :P and so did UBB - we used to use UBB :|)

I can confirm that it does not work on Safari 2.0 on Tiger, but works fine on IE and Firefox. (strangely enough this is also the case for phpbb.com/phpbb)...
P C N X .com - your pc annex :: Computing News At Your Fingertips

Harvey_S
Registered User
Posts: 22
Joined: Sat Jun 25, 2005 4:51 pm
Location: Powell Ohio

Post by Harvey_S » Thu Jul 07, 2005 6:23 pm

breadcrust wrote: Excuse the language but, I'm extermly *beep* off at this mod. Nowhere does it say it only works on IE.

I dont think Opera, Gecko browsers (mozilla/firefox/etc) or khtml browsers (konqueror/safiri) are to blame for not having this "technology", the author is to blame for not supporting anything other than IE, because other browsers could be well capable of this sort of mod, its just the author as decided to write code that only works for m$ apps. :x

i think the author should try to fix this straight away, or if anything, release a new revision version, with no code changed, but some more notes about this problem and actually saying only Internet Explorer works with it.

this could of been one of my favorite mods ever, but because of this IE only support, im rating this MOD as poor.


I know this was posted a while ago but I have to reply anyways because noone should get away with a post like that! Breadcrust does not understand that this mod is an OPTION that the author has provided at no cost and that the indignation expressed is to say the least inappropriate. Breadcrust is obviously very knowledgeable :roll: about the programming needed to create mods for various browsers. He should get lost for a while and write a better version of this mod instead of demanding that the author do it for him. I'm rating this post as worse than poor :x :x

King Moonraiser
Registered User
Posts: 50
Joined: Wed Jun 15, 2005 8:31 pm
Contact:

Post by King Moonraiser » Thu Jul 07, 2005 8:18 pm

The last find and replace seems redundant since it's already handled by an earlier replace.

Perhaps this section needs to be modified, too?:

Code: Select all

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			txtarea.value += bbtags[butnumber + 1];
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}
UPDATE: I ried the mod without modifying the above section and everything seems to work just fine. Hopefully the original author will make these fixes and re-release. It's an excellent fix!

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

Post by leecovuk » Mon Aug 01, 2005 6:53 pm

removed by poster

pbowser
Registered User
Posts: 19
Joined: Sat Mar 05, 2005 7:29 pm

Post by pbowser » Tue Aug 02, 2005 5:16 pm

Thanks for this! Using JoeDalton's enhancements as posted by PeterPaulW works in Firefox. Unfortunately after applying a tag, the display still 'jumps' back to the top of the textarea, which is annoying when you're working on a long post. I realize this is not caused by this mod, but nonetheless is there any way to fix this behaviour?[/quote]

Capmaster
Registered User
Posts: 69
Joined: Tue Jul 05, 2005 1:26 pm

Post by Capmaster » Sun Oct 02, 2005 7:55 pm

Thanks for the mod!!!

That tendency for the bbcode to get placed at the end has been a major peeve of mine for a long time :evil:

This mod kicked its butt 8)
Image
Some mornings, it's just not worth chewing through the leather straps

C2CokeRocks
Registered User
Posts: 51
Joined: Sun Apr 10, 2005 6:44 am

Post by C2CokeRocks » Mon Oct 17, 2005 11:20 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).


Ah, thank you so much.

I can confirm this mod works in 2.0.17 and with your added fixes it works in firefox just fine.

*edit*
There is only one odd thing about this mod.
I had to install the Auto Cookie mod after installing this mod.

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

Post by leecovuk » Mon Oct 17, 2005 6:48 pm

hello everyone,

I'm kind of interested to find out if I've got this mod (and maybe some associated ones such as BBCode Box) working as best as I can.
If anyone confidently knows the 'best' cross-browser responses, it'd be great if you could register on my install and try out a couple of posts.
I think I am currently 'ok' in IE6 and Mozilla Firefox.

Feel free to PM me to get the url of my phpBB if you're interested and genuinely knowledgeable in the ins and outs of this issue. ie if you tested my install and found a particular browser or function is not working as well as it could, I would need you to kindly know which files I/we should look at to add extra tweaks.

many thanks,
lee

C2CokeRocks
Registered User
Posts: 51
Joined: Sun Apr 10, 2005 6:44 am

Post by C2CokeRocks » Thu Oct 20, 2005 5:45 pm

One request that would really make this mod perfect.

Currently it doesn't work with the Userfriendly URL-input while posting mod. It would sure be awesome if it did.

http://www.phpbb.com/phpBB/viewtopic.php?t=257732

Peter77s
Registered User
Posts: 260
Joined: Fri Sep 17, 2004 8:18 pm
Location: Michigan

Post by Peter77s » Sat Oct 22, 2005 11:11 pm

bombon wrote: Hi,

I´m using this mod with BBCodeBox. BBCodeBox is also integrated in phpBB Plus.

Here what to do:

Code: Select all

#
#-----[ OPEN ]------------------------------------------
#
bbcode_box/add_bbcode.js

# EoM


Great idea, but it doesn't work. it doubles the bb code each time I press

and if i end code and same wth smilies.

Post Reply

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