The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

[Tutorial] Create New BBcode Tags

View previous topic View next topic Go down

[Tutorial] Create New BBcode Tags

Post by Daemon on July 15th 2017, 6:00 pm

With this code you can create your own bbcode tags.

Image:


Create a new JS code with the following content:
Code:
/*
 * Create New BBcode Tags
 * Version: 2.1
 * Author: Daemon
 * Att: 01/03/2017
 * See more in: http://help.forumotion.com
 */
jQuery(document).ready(function($) {
 
    var bbCodes = {
 
        // Note: Add a comma at the end of each new entry
        // '{ATTR}' matches the 'title' of the tag, and '{CONTENT}' matches 'text' between tags
 
        success: {
            close: true,
            replacement: '<div class="success"><p>{ATTR}</p>{CONTENT}</div>'
        },
 
        warn: {
            close: true,
            replacement: '<div class="warn"><p>{ATTR}</p>{CONTENT}</div>'
        },
 
        info: {
            close: true,
            replacement: '<div class="information"><p>{ATTR}</p>{CONTENT}</div>'
        },
 
        alert: {
            close: true,
            replacement: '<div class="alert"><p>{ATTR}</p>{CONTENT}</div>'
        },
 
        guest: {
            close: true,
            replacement: '<div class="guest">{CONTENT}</div>',
            replace: function(content) {
                if (_userdata.session_logged_in < 1) {
                    return "You need to be logged in to view this content";
                    return content;
                }
            }
        }
 
        // Note: Do not add a comma at the end of the last entry
 
    };
 
    // Do not change anything down
 
    var getPost = $(".postbody, .blog_message");
    var entry;
    for (var i = 0, e;
        (e = getPost[i++]);) {
        entry = $(e);
        var re, match;
        $.each(bbCodes, function(tag, value) {
 
            re = value.close ? new RegExp("\\[" + tag + "(?:=(\"|'?)([^\\]]+)\\1)?\\]([\\s\\S]*?)\\[/" + tag + "]", "gi") : new RegExp("\\[" + tag + "(?:=(\"|'?)([^\\]]+)\\1)?\\]", "gi");
            match = entry.html().match(re);
 
            if (match) {
                var content, b, c, as_string, as_func, replacement;
                for (var tag in match) {
                    content = match[tag];
                    b = "$3";
                    if (value.replace) {
                        as_string = value.replace.toString();
                        as_func = eval('(' + as_string + ')');
                        if (as_func(content)) b = as_func(content);
                    }
                    replacement = value.replacement
                        .replace(/{ATTR}/g, "$2").replace(/{CONTENT}/g, b);
                    c = content.replace(re, replacement);
                    entry.html(entry.html().replace(content, c));
                }
            }
        });
    }
});


Last edited by Daemon on July 17th 2017, 5:49 pm; edited 5 times in total
avatar
Daemon
Forumember

Posts : 51
Reputation : 26
Language : Português

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Wolfuryo on July 15th 2017, 6:14 pm

Nice code, @Daemon. I was planning to make something like, but I guess there's no need for it now Smile). I'll test it when I'll have time.
avatar
Wolfuryo
Forumember

Posts : 352
Reputation : 92
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Daemon on July 15th 2017, 6:18 pm


Thank you very much, @Wolfuryo! You can test and opt for changes to improve.
avatar
Daemon
Forumember

Posts : 51
Reputation : 26
Language : Português

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Draxion on July 15th 2017, 6:24 pm

Sorry, @Daemon, I don't know if I am clueless when it comes to this code, but I tested it on my testing site (phpbb3) and I couldn't get it to work. Can you explain exactly how to get these tags to show? Thanks.


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1369
Reputation : 187
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Daemon on July 15th 2017, 6:30 pm

@Draxion wrote:Sorry, @Daemon, I don't know if I am clueless when it comes to this code, but I tested it on my testing site (phpbb3) and I couldn't get it to work. Can you explain exactly how to get these tags to show? Thanks.

You need to create a new JavaScript with investment on all pages.
By default, there are 5 new tags in this code, but you can create others.
Try the following:
[success="Title"]Content[/success]
avatar
Daemon
Forumember

Posts : 51
Reputation : 26
Language : Português

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Wolfuryo on July 15th 2017, 6:31 pm

@Draxion,

If you use the default code without edits, then you can use this in your posts on the forum:
Code:
[successo="abc"]abc[/successo]
Code:
[warn="abc"]abc[/warn]
Code:
[info="abc"]abc[/info]
Code:
[alert="abc"]abc[/alert]
Code:
[guest="abc"]abc[/guest]

The code will automatically replace them with HTML.
avatar
Wolfuryo
Forumember

Posts : 352
Reputation : 92
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Draxion on July 15th 2017, 6:34 pm

Nope, still doesn't work.

There's a syntax error in the coding.


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1369
Reputation : 187
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Wolfuryo on July 15th 2017, 6:48 pm

I tested it on my punBB forum(the templates are heavily modified) and it's not working.
The console says this:
Code:
SyntaxError: expected expression, got ')'
It also says that the problem is at character 91609(real useful lol).
I don't know exactly what causes the error, but I noticed something in the code:
Code:
var getPost = $(".postbody , .blog_message");
From what I can see, this is the list of elements where the code searches for bbcodes. The list is incomplete and will only work for 1 or 2 forum versions. I think you should search for bbcodes on the whole page. This way, there won't be any problems with the different selectors.

If no one finds the issue till tomorrow, I think I'll start working on a code for this.
avatar
Wolfuryo
Forumember

Posts : 352
Reputation : 92
Language : Romanian and English

http://board.realmsn.com

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Daemon on July 15th 2017, 7:13 pm

I apologize ... I ended up deleting what I should not when I went to post here. Try it now.


@Edit:

I edited the post and ended up putting the code twice. HAHAHAH

Try it now, again...
avatar
Daemon
Forumember

Posts : 51
Reputation : 26
Language : Português

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Draxion on July 15th 2017, 7:21 pm

Still, says "Syntax Error"

I'm getting it here.
Code:
re = value.close ? new RegExp("\\[" + tag + "(?:=("|'?)([^\\]]+)\\1)?\\]([\\s\\S]*?)\\[/" + tag + "]", "gi") : new RegExp("\\[" + tag + "(?:=("|'?)([^\\]]+)\\1)?\\]", "gi");


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1369
Reputation : 187
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Daemon on July 15th 2017, 7:50 pm

@Draxion wrote:Still, says "Syntax Error"

I'm getting it here.
Code:
re = value.close ? new RegExp("\\[" + tag + "(?:=("|'?)([^\\]]+)\\1)?\\]([\\s\\S]*?)\\[/" + tag + "]", "gi") : new RegExp("\\[" + tag + "(?:=("|'?)([^\\]]+)\\1)?\\]", "gi");

Read the edit I made in my last post.
avatar
Daemon
Forumember

Posts : 51
Reputation : 26
Language : Português

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Draxion on July 15th 2017, 7:55 pm

Sorry, still getting the same error.

EDIT: My bad. I didn't refresh the page and therefore I took the same code. ;P hahah


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1369
Reputation : 187
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Daemon on July 15th 2017, 8:00 pm

@Draxion wrote:Sorry, still getting the same error.

EDIT: My bad. I didn't refresh the page and therefore I took the same code. ;P hahah

Hahahah... Works fine now? Very Happy
avatar
Daemon
Forumember

Posts : 51
Reputation : 26
Language : Português

Back to top Go down

Re: [Tutorial] Create New BBcode Tags

Post by Draxion on July 15th 2017, 8:00 pm

Yes, works great! Yes


NEVER provide your founder's account or email
Please provide forum's URL when dealing with design and appearance issues
Don't forget to mark the topic as when the issue is resolved. This helps the staff greatly.
PM Support is prohibited!
TOS | General Rules | FAQ | Tricks & Tips | Latest Updates | Introduce Yourself

avatar
Draxion
Support Moderator
Support Moderator

Male Posts : 1369
Reputation : 187
Language : English
Location : USA

http://www.draxionsgameden.com/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum