Jump to content

Jitbit WYSWYG BBCode Editor


Matty999555

Recommended Posts

I found this great peice of code:

 

http://wysiwygbbcode.codeplex.com/

 

I have added a few extra functions into but I can't work out how this one line works:

 

myeditor.execCommand("CreateLink", false, mylink);

 

heres the code so far:

 

http://pastebin.com/Axe6emk9

 

Thanks

 

EDIT: As it contains BBCode i screwed the page.

Link to comment
https://forums.phpfreaks.com/topic/205982-jitbit-wyswyg-bbcode-editor/
Share on other sites

Fixed the Mail function:

function doMail() {
    if (editorVisible) {
        ifm.contentWindow.focus();
        var mylink = prompt("Enter an Email:", "");
        var mylink = "mailto:" + mylink;
        if ((mylink != null) && (mylink != "")) {
            if (isIE) { //IE
                var range = ifm.contentWindow.document.selection.createRange();
                if (range.text == '') {
                    range.pasteHTML("<a href='" + mylink + "'>" + mylink + "</a>");
                }
                else
                    myeditor.execCommand("CreateLink", false, mylink);
            }
            else if (window.getSelection) { //FF
                var userSelection = ifm.contentWindow.getSelection().getRangeAt(0);
                if(userSelection.toString().length==0)
                    myeditor.execCommand('inserthtml', false, "<a href='" + mylink + "'>" + mylink + "</a>");
                else
                    myeditor.execCommand("CreateLink", false, mylink);
            }
            else
                myeditor.execCommand("CreateLink", false, mylink);
        }
    }
    else {
        AddTag('[url=mailto:',']click here[/url]');
    }
}

 

Fixed Text Size:

function doSize() {
    if (editorVisible) {
        ifm.contentWindow.focus();
        var mylink = prompt("Enter a text-size:", "14px");
        if ((mylink != null) && (mylink != "")) {
            if (isIE) { //IE
                var range = ifm.contentWindow.document.selection.createRange();
                if (range.text == '') {
                    range.pasteHTML("<span style=\"font-size: " + mylink + ";\"></span>");
                }
                else
                    myeditor.execCommand('inserthtml', false, "<span style=\"font-size: " + mylink + ";\">" + range.text + "</span>");
            }
            else if (window.getSelection) { //FF
                var userSelection = ifm.contentWindow.getSelection().getRangeAt(0);
                if(userSelection.toString().length==0)
                    myeditor.execCommand('inserthtml', false, "<span style=\"font-size: " + mylink + ";\">" + userSelection.toString() + "</span>");
                else
                    myeditor.execCommand('inserthtml', false, "<span style=\"font-size: " + mylink + ";\">" + userSelection.toString() + "</span>");
            }
            else
                myeditor.execCommand('inserthtml', false, "<span style=\"font-size: " + mylink + ";\">" + userSelection.toString() + "</span>");
        }
    }
    else {
        AddTag('[size=]','[/size]');
    }
}

 

The Quote doesn't work while in wysiwyg mode

function doQuote() {
    if (editorVisible) {
        ifm.contentWindow.focus();
        if (isIE) { //IE
            var range = ifm.contentWindow.document.selection.createRange();
            if (range.text == '') {
                range.pasteHTML("<blockquote></blockquote>");
            }
            else
                myeditor.execCommand('inserthtml', false, "<blockquote>" + range.text + "</blockquote>");
        }
        else if (window.getSelection) { //FF
            var userSelection = ifm.contentWindow.getSelection().getRangeAt(0);
            if(userSelection.toString().length==0)
                myeditor.execCommand('inserthtml', false, "<blockquote>" + userSelection.toString() + "</blockquote>");
            else
                myeditor.execCommand('inserthtml', false, "<blockquote>" + userSelection.toString() + "</blockquote>");
        }
        else
            myeditor.execCommand('inserthtml', false, "<blockquote>" + userSelection.toString() + "</blockquote>");
    }
    else {
        AddTag('[quote]', '[/quote]');
    }
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.