Hello,

You may remember an email I sent to the list Friday February 11, 2000
regarding putting a textbox HTML editor inline with the content-management
software (Midgard or Userland Frontier [Manila]).

That same day I sent my code to Dave Winer at Userland, eschewing all claim
and rights to the code (since I have a philosophical problem with certain
kinds of patents - Amazon's 1-click, Geoworks WAP, etc.).

Today, lo and behold, Userland has implemented an HTML editor for textboxes!
I do not know if they used my idea (the code is very similar), or if they've
been working on it for a while, but it sure is a better implementation!
Viewing the source code, there doesn't seem to be any copyright or other
claim, so I've attached the editor code to the bottom of this message.

But you heard it here first!

Brad Marsh, Computer Specialist
Center for Evaluation and Research
http://www.tchp.org/cer

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<script language='JavaScript'>
<!--

var rightCaret = String.fromCharCode (62);

function isEditable (selectionRange) {

        //Return true if the selection is in an editable part of the page -- in the
textarea.

        if (selectionRange.parentElement ().tagName == "TEXTAREA")
                return (true);

        return (false);
        } //isEditable


function getSelectionRange () {

        //Get a reference to the current selection range.
        //If there is no selection range, or it's not in a textarea, return null.

        var selectionRange;
        selectionRange = document.selection.createRange ();

        if (isEditable (selectionRange)) {

                var currentText = selectionRange.text;
                if (currentText != "")
                        return (selectionRange);
                }

        return (null);
        } //getSelectionRange


function highlightButton (buttonRef) {

        //Highlight the button only if there is currently editable text.

        var selectionRange;
        selectionRange = getSelectionRange ();

        if (selectionRange == null) {

                buttonRef.style.cursor = "default";
                return (false);
                }

        buttonRef.style.color = "maroon";
        //buttonRef.style.cursor = "hand";

        buttonRef.style.cursor = "default";

        return (true);
        } //highlightButton


function unHighlightButton (buttonRef) {

        //Unhighlight a button.

        buttonRef.style.color = "black";

        return (true);
        } //unHighlightButton


function urlPrompt () {

        //Prompt the user via dialog box for a URL.

        var url;
        url = prompt ("URL:", "http://");
        return (url);
        } //urlPrompt


function replaceText (selectionRange, preText, postText, currentText) {

        //Enclose the selected text with preText and postText.

        selectionRange.text = preText + currentText + postText;

        selectionRange.parentElement ().focus ();
        } //replaceText


function simpleEnclose (tagName) {

        //Enclose selected text with a tag and closing tag.

        if (tagName == "")
                return (false);

        var selectionRange;
        selectionRange = getSelectionRange ();

        if (selectionRange != null) {

                var currentText;
                currentText = selectionRange.text;

                var preText, postText;
                preText = "<" + tagName + rightCaret;
                postText = "</" + tagName + rightCaret;

                replaceText (selectionRange, preText, postText, currentText);
                }
        } //simpleEnclose


function addFormat (tagName) {

        //Handle tags in the Format menu.

        if (tagName == "")
                return (false);

        var selectionRange;
        selectionRange = getSelectionRange ();

        if (selectionRange != null) {

                var currentText;
                currentText = selectionRange.text;

                var preText, postText;
                preText = "<" + tagName + rightCaret;
                postText = "</" + tagName + rightCaret;

                if (tagName == "blockquote") {

                        preText = "\r\n\t" + preText;
                        postText = postText + "\r\n";
                        }

                if (tagName == "li") {

                        preText = "\r\n<li" + rightCaret;
                        postText = "";
                        }

                replaceText (selectionRange, preText, postText, currentText);
                }
        } //addFormat


function addFontColor (colorName) {

        //Enclose the selected text with a font tag that specifies the color

        if (colorName == "")
                return (false);

        var selectionRange;
        selectionRange = getSelectionRange ();

        if (selectionRange != null) {

                var currentText;
                currentText = selectionRange.text;

                var preText, postText;
                preText = "<font color=\"" + colorName + "\"" + rightCaret;
                postText = "</font" + rightCaret;

                replaceText (selectionRange, preText, postText, currentText);
                }
        } //addFontColor


function addFontFace (faceName) {

        //Enclose the selected text with a font tag that specifies the font face.

        if (faceName == "")
                return (false);

        var selectionRange;
        selectionRange = getSelectionRange ();

        if (selectionRange != null) {

                var currentText;
                currentText = selectionRange.text;

                var preText, postText;
                preText = "<font face=\"" + faceName + "\"" + rightCaret;
                postText = "</font" + rightCaret;

                replaceText (selectionRange, preText, postText, currentText);
                }
        } //addFontFace


function addAlignment (alignment) {

        //Enclose the selected text with a font tag that specifies the color

        if (alignment == "")
                return (false);

        var selectionRange;
        selectionRange = getSelectionRange ();

        if (selectionRange != null) {

                var currentText;
                currentText = selectionRange.text;

                var preText, postText;
                preText = "<p align=\"" + alignment + "\"" + rightCaret;
                postText = "</p" + rightCaret + "\r\n";

                replaceText (selectionRange, preText, postText, currentText);
                }
        } //addAlignment


function addLink () {

        //Prompt the user for a URL and make the selection a link.

        var selectionRange;
        selectionRange = getSelectionRange ();

        if (selectionRange != null) {

                var currentText;
                currentText = selectionRange.text;

                var url;
                url = urlPrompt ();

                if ((url == "") || (url == "http://") || (url == null))
                        return;

                var preText, postText;
                preText = "<a href=\"" + url + "\"" + rightCaret;
                postText = "</a" + rightCaret;

                replaceText (selectionRange, preText, postText, currentText);
                }
         } //addLink
//-->
</script>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++


--
This is The Midgard Project's mailing list. For more information,
please visit the project's web site at http://www.midgard-project.org

To unsubscribe the list, send an empty email message to address
[EMAIL PROTECTED]

Reply via email to