MyBB Community Forums

Full Version: Reply bullet, numbering, superscript, subscript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi.
in reply i want direct bullet and numbering after click on that button means normally for bullet we have to insert like this..[list*][*][/list] remove * list. but i want to direct insertion of bullet ,numbering,etc in only single click.
i think u guys understand very well.
thank you.
i have install sr mycode.
I think I understand. You want a one click button that inserts the list and some bullets?
(2012-12-30, 11:55 AM)JordanMussi Wrote: [ -> ]I think I understand. You want a one click button that inserts the list and some bullets?

ya.definately.
please help me.
How many bullets and what type do you want (
  • ,
    1. )?
You could use jQuery for this. In my custom forum software I made a file for this.

jq = jQuery.noConflict();
jq(document).ready(function () {
    /* First we make a master object that has eveery property.  By doing this we can open and close tags correctly. */
    taglist = new Object();
    taglist.bold = 0;
    taglist.italic = 0;
    taglist.color = 0;
    taglist.url = 0;
    taglist.quote = 0;
    taglist.numericallist = 0;
    taglist.unorderedlist = 0;
    taglist.markedtext = "";

    jq("#bold").click(function () {
        highlightedtext = taglist.markedtext.toString();
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
        if (highlightedtext == "") {
            jq("#message").val(function (old, current) {
                if (taglist.bold % 2 == 1) {
                    bolder = "[/b]";
                }
                else {
                    bolder = "[b]";
                }
                taglist.bold += 1;
                return current + bolder;
            }); // Closes function to grab value
        } // End no marked text
        else {
            jq("#message").val(function (old, current) {
                oldmessage = jq("#message").val();
                replacement = "[b]" + highlightedtext + "[/b]";
                newmessage = oldmessage.replace(oldmessage, replacement);
                taglist.markedtext = "";
                return newmessage;
            });
        } // Close marked text
    }); // Closes Bolding

    jq("#italic").click(function () {
        highlightedtext = taglist.markedtext.toString();
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
        if (highlightedtext == "") {
            jq("#message").val(function (old, current) {
                if (taglist.italic % 2 == 1) {
                    italics = "[/i]";
                }
                else {
                    italics = "[i]";
                }
                taglist.italic += 1;
                return current + italics;
            });
        } // End no marked text
        else {
            jq("#message").val(function (old, current) {
                oldmessage = jq("#message").val();
                replacement = "[i]" + highlightedtext + "[/i]";
                newmessage = oldmessage.replace(oldmessage, replacement);
                taglist.markedtext = "";
                return newmessage;
            });
        } // End Marked Text
    }); // Close Italics

    jq("#linker").click(function () {
        highlightedtext = taglist.markedtext.toString();
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
        if (highlightedtext == "") {
            jq("#message").val(function (old, current) {
                if (taglist.url % 2 == 1) {
                    urls = "[/url]";
                }
                else {
                    urls = "[url]";
                }
                taglist.url += 1;
                return current + urls;
            });
        } // End No marked text
        else {
            jq("#message").val(function (old, current) {
                oldmessage = jq("#message").val();
                replacement = "[url]" + highlightedtext + "[/url]";
                newmessage = oldmessage.replace(oldmessage, replacement);
                taglist.markedtext = "";
                return newmessage;
            });
        } // End Marked Text
    }); // End Urls

    jq("#quote").click(function () {
        highlightedtext = taglist.markedtext.toString();
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
        if (highlightedtext == "") {
            jq("#message").val(function (old, current) {
                if (taglist.quote % 2 == 1) {
                    quotes = "[/quote]";
                }
                else {
                    quotes = "[quote]";
                }
                taglist.quote += 1;
                return current + quotes;
            });
        }
        else {
            jq("#message").val(function (old, current) {
                oldmessage = jq("#message").val();
                replacement = "[quote]" + highlightedtext + "[/quote]";
                newmessage = oldmessage.replace(oldmessage, replacement);
                taglist.markedtext = "";
                return newmessage;
            });
        } // End Marked Text
    }); // End Quote tag

    jq("#numericallist").click(function () {
        highlightedtext = taglist.markedtext.toString();
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
        if (highlightedtext == "") {
            jq("#message").val(function (old, current) {
                if (taglist.numericallist % 2 == 1) {
                    lists = "[/list]";
                }
                else {
                    lists = "[list=1][*]";
                }
                taglist.numericallist += 1;
                return current + lists;
            });
        }
        else {
            jq("#message").val(function (old, current) {
                oldmessage = jq("#message").val();
                replacement = "[list=1][*]" + highlightedtext + "[/list]";
                newmessage = oldmessage.replace(oldmessage, replacement);
                taglist.markedtext = "";
                return newmessage;
            });
        } // End Marked Text
    }); // End Numerical lists

    jq("#unorderedlist").click(function () {
        highlightedtext = taglist.markedtext.toString();
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
        if (highlightedtext == "") {
            jq("#message").val(function (old, current) {
                if (taglist.unorderedlist % 2 == 1) {
                    lists = "[/list]";
                }
                else {
                    lists = "[list][*]";
                }
                taglist.unorderedlist += 1;
                return current + lists;
            });
        }
        else {
            jq("#message").val(function (old, current) {
                oldmessage = jq("#message").val();
                replacement = "[list][*]" + highlightedtext + "[/list]";
                newmessage = oldmessage.replace(oldmessage, replacement);
                taglist.markedtext = "";
                return newmessage;
            });
        } // End Marked Text
    }); // End Unordered lists

    jq("#colorpicker").change(function () {
        highlightedtext = taglist.markedtext.toString();
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
        if (highlightedtext == "") {
            var colorchoice = jq("#colorpicker").val();
            if (colorchoice != 0) {
                jq("#message").val(function (old, current) {
                    colors = "[color=" + colorchoice + "][/color]";
                    taglist.color += 1;
                    return current + colors;
                });
            }
        }
        else {
            jq("#message").val(function (old, current) {
                oldmessage = jq("#message").val();
                var colorchoice = jq("#colorpicker").val();
                if (colorchoice != 0) {
                    replacement = "[color=" + colorchoice + "]" + highlightedtext + "[/color]";
                    newmessage = oldmessage.replace(oldmessage, replacement);
                    taglist.markedtext = "";
                    return newmessage;
                }
            });
        } // End Marked Text
    }); // End Colorpicker

    jq("#message").select(function () {
        if (window.getSelection) {
            taglist.markedtext = window.getSelection().toString();
        }
        else if (document.getSelection) {
            taglist.markedtext = document.getSelection();
        }
        else if (document.selection) {
                // this is specifically for IE 
            taglist.markedtext = document.selection.createRange().text;
        }
    });
}); // End Of file

In the headerinclude you have to first include the jQuery library like this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

Right after that you can place the Javascript code I posted.

Finally the HTML code you'll need for the buttons:

<span class="editor" id="newreply">
<button id="bold"><b>Bold</b></button>
<button id="italic"><i>Italic</i></button>
<button id="linker">URL</button>
<button id="quote">Quote</button>
<button id="numericallist">Numbered List</button>
<button id="unorderedlist">Bulleted List</button>
Color <select name="color" id="colorpicker">
<option value="0">Choose Color</option>
<option value="Red">Red</option>
<option value="Orange">Orange</option>
<option value="Yellow">Yellow</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
<option value="Indigo">Indigo</option>
<option value="Violet">Violet</option>
<option value="Purple">Purple</option>
<option value="Black">Black</option>
<option value="White">White</option>
</select>
</span>
where to edit that codes pls give it properly bro.i m not understand.
can any give me idea where to edit above code exactly???
pls.
Please give me informatio for it. Where to paste above code????
Thank you.