Click here to Skip to main content
Click here to Skip to main content

Fully JavaScript Enabled Editor

By , 7 Sep 2010
 

Images

  1. Editor

    screenshot1.jpg

  2. Inserting Links

    insertlink.jpg

  3. Inserting Images

    insertimage.jpg

  4. Inserting Table

    insertable.jpg

  5. Inserting Special Characters

    insertchars.jpg

Introduction

Well, I have tried a fully JavaScript enabled editor. Here I have updated it with more features.

Code

In the article, I am giving sample code. The full code is available in the zip file.

I have planned to release this editor as a product with more advanced features. So as of now for demo purposes, I have shown inserting links, images, table and special characters. All other features like inserting flash, media files, templates, saving templates and inserting all major HTML controls and context menu for the editor and for the controls and browser compatibility and handling postback events will be available in the licensed version.

Setting Color

function setColor(colorTo,x,y)
{
    editFrame.focus();
    editFrame.document.execCommand(colorTo,true, colorArray[x][y]);
    popDivId.style.display = "none";
}

Setting Font

function setFont(fontName)
{
    editFrame.focus();
    editFrame.document.execCommand("FontName", false, fontName);
    popDivId.style.display = "none";
}

Setting Font Size

function setFontSize(fontSize)
{
    editFrame.focus();
    editFrame.document.execCommand("FontSize", false, fontSize);
    popDivId.style.display = "none";
}

Setting General Action

function doAction(action)
{
    editFrame.focus();
    if(action == "ClearAll")
    {
        editFrame.document.execCommand("SelectAll",true);
        action = "Delete";
    }
    editFrame.document.execCommand(action,true);
}

Showing Dialog Boxes

function showDialog(link,w, h)//380, 125
{
    if(link == "li")
        link = "InsertLink.htm";
    else if(link == "sc")
        link = "SpecialChars.htm";
    var returnedTxt= showModalDialog(link,"", "dialogWidth:"+ 
		w +"px; dialogHeight:"+ h +"px; status:no; center:yes");
    editFrame.focus();
    if(returnedTxt)
    {
        var theRange = editFrame.document.selection.createRange();
        theRange.pasteHTML(returnedTxt);
    }
}

Showing Popup Windows

var cWnd;
function showInsertPopup(opt, w, h) // w=350, h=340
{
    var srcfile = "imgWindow.aspx";
    if(opt == "im")
        srcfile = "imgWindow.aspx";
    else if(opt == "tb")
        srcfile = "InsertTable.htm";
    var left = (window.screen.width - parseInt(w))/2;
    var top = (window.screen.height - parseInt(h))/2;
    if(cWnd)
        cWnd.close();
    cWnd = window.open(srcfile,"", "width="+ w +",height="+ 
	h +",location=no, status=no, top="+ top +", left="+ left);
}

Setting HTML Action

function doHtmlAction(atype)
{
    editFrame.focus();
    var selectedRegion = editFrame.document.selection.createRange();
    if(atype == "lower")
        selectedRegion.text = selectedRegion.text.toLowerCase();
    else if(atype == "upper")
        selectedRegion.text = selectedRegion.text.toUpperCase();
}

Points of Interest

  • Since Undo and Redo are again included
  • Also developed in VB.NET and PHP
  • Bugs in Font Size, Font Family, Forecolor, Backcolor are fixed

Conclusion

Thank you. I expect feedback from you, and you expect more from me.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Saleth Prakash
India India
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberMd. Touhidul Alam Shuvo20 Jun '11 - 17:47 
thnks
GeneralMy vote of 4memberGaurav Chaurasiya20 Sep '10 - 8:10 
it's seems good in javascript and looking for more advance feature.
GeneralMy vote of 4memberEric Xue (brokensnow)7 Sep '10 - 18:22 
thanks for sharing, but have you thought about making a custom reusable asp.net ajax control rather than leaving the code everywhere? have you thought about leveraging asp.net ajax or jquery library rather than using plain javascript all over the place? BTW, great effort!!
Generalnot working IN MOZILLAmemberMember 365136526 Feb '10 - 1:17 
EACH ACTION GETTING REFRESHED IN MOZILLA FIRE FOX.PLZ HELP
QuestionCan you provide more property for each control??memberJLKEngine00827 Nov '08 - 22:24 
Can you provide more property for each control?,
I hope you can provide this function, each control may have itself property, you can provide a infowindow to modify the basic property, such as windth, height, etc.
 
you can reference : http://boxover.swazz.org
boxover is very good ,you can use it provide a infowindow to modify the basic property.
QuestionWhy you removed Undo and Redo ???memberJLKEngine00827 Nov '08 - 20:41 
Why you removed Undo and Redo ??? I think it is very helpful!!
How can you cancel the Action and how can you Provide Prevous and Next Action ??
 
I look forward to Providing Undo and Redo !!
GeneralMy vote of 2memberAxelM27 Nov '08 - 20:24 
-
QuestionHow can you provide context menus for each controls?memberJLKEngine00827 Nov '08 - 20:21 
1, How can you provide context menus for each controls? this is very usefully.
2, Can you provide more property for each controls, I want to use it in my web form Design, and I want to use this provide Visuable form Design.
 
thanks very much!!
 
e-mail: hy2001al@163.com
GeneralJavaScript editormemberMember 420697421 Oct '08 - 0:33 
Hello
 
very good work.
 
In order to works also in FIREFOX, note this :
 
In the past the hand value was Microsoft's way of saying pointer; and Explorer 5.0 and 5.5 only support hand. Because it's the cursor value that's used most often, most other browsers have also implemented hand.
 
Since Explorer 6 and 7 support pointer, there's no more reason to use hand, except when older Explorers are part of your target audience. In that case, the only cross-browser syntax is:

 
element {
cursor: pointer;
cursor: hand;
}

 
Note that the two declarations must be in this order.
 
I have changed this doAction function:
 
function doAction(action)
{
editFrame.focus();
if(action == "ClearAll")
{
editFrame.document.execCommand("SelectAll",true);
action = "Delete";
}
editFrame.document.execCommand(action,false,null);
}

 
with these changes it works in IE 7 and FIREFOX 3.0.3.
 
For use with PHP, you have to point out that it is necessary to change in the EditorScript.js .aspx with .php
 
best regards
 
Giovanni Rossati
GeneralThere is some bug in your new version!!memberJLKEngine00816 Oct '08 - 6:31 
1,In this version, undo an redo cannot use!!
2,Can you modify popomenu ? That is provide a popomenu for reach control,which can set more property for each control!! please
reference http://www.fckeditor.net ,I hope you can made it better!!
3, can you provide datasource to each control , such as textbox,listbox,dropdown etc, please reference
http://www.codeproject.com/KB/scripting/Panel.aspx
http://www.codeproject.com/KB/scripting/List_Box.aspx
 
4,can you provide client webservice, that is can relation to DB .
 
I hope you can modify it ! I Lookforward to your new version!
 
e-mail: hy2001al@163.com
http://www.linjon.cn

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 7 Sep 2010
Article Copyright 2008 by Saleth Prakash
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid