WIP, WYSIWYG in place
Il post in italiano, non di minor prolissità , si trova qui.
The experiment that I’m going to introduce you today is of ’syllogistic’ type, and his name is WIP - WYSIWYG in place, in other words an AJAX edit-in-place with the use of a WYSIWYG editor.
This is the demo, and this is the explanation of the obscure phrase above:
- What are WYSIWYG, Edit-in-place and WIP?
- How can I use it?
- How does it works?
- Where I can download it?
What are WYSIWYG, Edit-in-place and WIP?
WYSIWYG (pronunciation: “wizzy-wig”) is the acronym of “What You See Is What You Get” and correspond to give to the user the exact perception, during the creation of a document, of what will be printed on screen or on paper. (Examples of WYSIWYGs are text editor like Word and PowerPoint or graphics program like Photoshop or Flash.)
In the web the need to create and modify in an easy way, without any knowledge, an HTML code bring to life the Rich TextArea, some textareas surmounted by a bar with some buttons that make them similar to a ordinary editor. (Writing a text, selecting it and clicking one of the buttons is possible to insert the text in a particular HTML tag: if for example you want that a text portion written in the textarea would be in bold, is necessary to select the text and click on the ‘B’ button, that will insert the text between two <strong> tags).
WYSIWYGs never been well accepted under the point of view of web standards, because accused to not well formed code, not allowing the separation between structure and presentation (an example of this is the tag <FONT face=Arial bgcolor=#000000>) or to run only with Internet Explorer.
In the last years are born, so, some WYSIWYG - a few of these open-source - that well repaired to the errors of the precursors: among them XINHA (acronym of ‘XINHA is not HTMLArea’, being the son of the excellent HTMLArea, which developing - blocked some years ago - is powered now by an opensource community), TinyMCE (the Wordpress default editor) and FCK Editor.
One year ago I also suggested WYM, a “What You See Is What You Mean” editor, that has as goal to guide the user in the structuring of the document skipping the visual layout. Under my point of view this is a instrument I would see better related to us working with code than a newbie used to a Word-like editing; the ideal could be the customization of the editor in the way that a user is forced to exclusively use the tags related to the structure of a page, creating so a valid (I’m speaking about XHTML) and well formed code, deleting for example the modifying of the size and the font family leaving their definition, as usual, to CSS.
For possible changes XINHA, TinyMCE and FCK allow to switch to a “code mode”, useful for example to add a span or the id to a paragraph.
The Edit-in-place (or in-place editing), instead, is a javascript technique that allows to make a text directly editable in the page where it’s inserted: clicking on a particular text this is inserted in a textarea of the same size, and possible modifications are send to server after the click of a ’saving’ button. Some implementations: the patriarch Editable Content by Tim Taylor, Edit text by Peter Paul Kock, Script.aculo.us’s Ajax in place editor, AJAX Edit in place by Joseph Scott.
The EIP, so, is useful for simple ‘on the fly’ changes that avoid the passage trought the classic admin section.
The WIP born, as I tell you in the first paragraph, from a reasoning similar to syllogism.
The action that describe the editing-in-place could be probably is:
Modify any text with a <textarea>
The editor HTMLArea had as official slogan:
Turn any <textarea> in a WYSIWYG Editor
So is possibile:
Modify any text with a WYSIWYG Editor
How can I use it?
The WIP is composed by an unique javascript file that allows to obtain a edit-in-place on the text in a html using a WYSIWYG editor and to communicate the changes to a server.
The editor where I tested the script is XINHA, so the first thing you must to do is to download it from this page and rename the folder “xinha-xxx” in “xinha”.
The example package wip.zip (downloadable from here), contains the script wipxinha.js, HTML+CSS for example and a file send.php that will simulate the server side.
All the file must be placed on a webserver, and the “xinha” folder must be inserted inside the “wip” folder (so, if you test on your PC the file HTML must be at the address “http://localhost/wip/wipxinha.html”, while the editor at the address “http://localhost/wip/xinha/”).
The HTML wipxinha.html contains the following javascript code:
<script type="text/javascript">
_editor_url = "xinha";
_editor_lang = "en";
_editor_skin = "green-look";
</script>
<script type="text/javascript" src="xinha/htmlarea.js"></script>
<script type="text/javascript" src="wipxinha.js"></script>
First instruction indicate the path of the editor, the second the default language, the third the toolbar style; the last two instead recall the main script of the editor and the WIP.
Inside the HTML could be modified all the divs that have as class “edit”: at the mouse over the div will change the colour, while with the double click will appear an editor with the same size of the div. Via a click on the button “save” the text recover the original format with the ch-ch-changes made, while with a click on the button “cancel” obviously the changes will not be saved.
How does it works?
The javascript object WIP contains seven functions: two of initialization, one for the inserting of the text in a textarea, one for the transformation from textarea to editor, two for the sending of the data to the server throught XMLHttpRequest, one of reset.
Make a portion of text editable
As I said before, a portion of text is editable only if it’s inserted in a div with default class: the default name of the class is ‘edit’, but it could be modify thought the global variable editableClass. The div be able to contain other elements like p, span or others divs (you can think about the several <div class="post"> in the default theme of Wordpress).
<div class="edit">
<p id="test">Paragraph to edit</p>
<p id="test2">Second paragraph to edit</p>
</div>
First function will select all these div present in the page:
init : function() {
var editElements = [];
var els = document.getElementsByTagName('*');
var elsLen = els.length;
var patternEdit = new RegExp("(^|\\s)" + wip.editableClass + "(\\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if ( patternEdit.test(els[i].className) ) {
editElements[j++] = els[i];
}
}
for(var i = 0; editel = editElements[i]; i++) {
wip.prepare(editel);
}
} ,
or rather a modified version of a classic getElementsByClass.
For every element will be called a function prepare: at the event mouseover the div will be highlight with a colour modifiable via the variable hoverColor; at the mouseout the div will recover the original colour (previously saved using the external function getCSSProp); at the double click, instead, will be called the function that will create the textarea.
prepare : function(editel) {
editel.onmouseover = function() {
bg = getCSSProp(this, "background-color");
this.style.backgroundColor = wip.hoverColor;
}
editel.onmouseout = function() {
this.style.backgroundColor = bg;
}
editel.ondblclick = function() {wip.edit(this);}
},
In the example one you can find a demo with the function see above, in the example two, instead, a fade effect (similar to the last scrip.aculo.us’s EIP demo) with the use of the Fade Anything Technique.
Insert the text in a textarea
The function edit(elem), that I don’t quote again but you can find in the third example, will save the selected div in a variable text, storing the properties associated to the text throught the function getCSSProp.
Using the DOM it will substitute the div with a form that will have an id with the value: 1) the id del div if the id was present; 2) a Unix timestamp with the date at the instant of the double click.
Inside the form will be created: a textarea with inside the text saved before, a button “Save” which click will call the function send(id, text) and a button “Cancel” related, instead, to the function cancel(id, text).
The function send will send to the server, simulated by send.php, the content of the modified text: in this example the instruction inside the file return only the text send, so all the changes will be lost at the refresh of the page; usually, instead, a file of this type (or a file related to it) must also have the task to write the changes on the database.
Replace the textarea with the WYSIWYG editor
XINHA allows to indicate an external file (in this case throught a couple of functions inserted in our javascript) which textareas will be substitued by the editors, and customize them with some instructions described in this page.
The array xinha_editors will contain the names of the textareas that could be replaced with XINHA, so the last two instruction of the edit function:
wip.xinha_editors.push(parid);
this.startXINHA();
will insert the array name, equal to the id of the form, in the textarea created by the function edit, showing the editor.
In the function startXINHA() will be set the sizes of the editor, equal to the textarea ones, and selected in two arrays the buttons (array cinha_config.toolbar) and the plugins[1] to insert in the toolbar.
As I was saying before, I inserted only the buttons that modify the structure of the HTML (bold, italic, ul etc.) and a plugin that insert a button for the char map.
The script has been tested on Firefox and Internet Explorer, while on Opera the editor XINHA is not supported yet.
I’d like to thanks as usual magister Skid “human debugger” X, and I invite you to suggest possible bugs [2]), mainly about the (for me) obscure Safari.
In a short time I will try something similar with TinyMCE, that allows to use a configuration script, while I’m still taking a look to FCK e WYM.
Where I can download all?
- WIP [.js - 10 kB]
- WIP + examples [.zip -15 kB]
- Latest XINHA[.zip/.tar.gz - ~1.3 MB]
[1] There are several plugins available, more or less useful according to the needs. One of these, InsertSmiley, allows to insert some hundreds of emoticons; I’m not a big reader of forums, but I have never seen an emoticon that represent in a so tragic way the couple life:
![]()
[2] After all, I resorted to a Jason Kottke rule:
The markup is not as semantically clean as it could be, but one of the important lessons I’ve learned over the years is that a 90% product today is better than a 99% product three months from now.
How I wish this worked with Safari
Yes, Xinha doesn’t work with Opera and Safari. As I wrote above, you could try to use TinyMCE instead, modifying the second part of the script (I will update this post when the time will be with me :-) )
[…] WIP - WYSIWYG in place - from The Lab of the weblog Central Scrutinizer […]
Is that possible to use FCK in your examples? If yes - would you be so kind to send me a short instruction how to do it?
Thanks in advance
After working all day I visited this website and guess what? I sound this source and I don’t feel tired any more! It’s the best entertaining source!
Thanks for the code. I had to add a line to get it to work with the latest version of xinha. The parid must be a string, so I added the line [parid = “” + parid]
edit : function(elem) {
elem.onmouseover = null;
var parid = elem.id ? elem.id : new Date().getTime();
parid = “” + parid
Many thanks Gene! I’ll modify soon my code.
Great entertaining source ! But I can’t anderstand howto select each editable field with a registered id… I try to use it with flatfile. Try to change each value of the var parid but with no success !
If someone can help me….
I’ve added the fix that Gene provided, but still seem to have issues. After one change, the ‘id’ becomes a time-stamp instead of the ID.
If you have any thoughts on this issue, I’d appreciate it.
I figured out my previous question. In the ‘handle’ function you need to set the id attribute of the newly created container:
parnew.setAttribute(’id’, parid);
78n2eoqkzx6z3xzh
hay i am kirpal
I placed a rather long page in the browser window and received the following message. in my error console:
Error: frmold is null
Source File: http://…/wipxinha.js LINE 189
If you have any thoughts, I would appreciate your insight.
Thank you,
jesse
I’m sorry for answering my own question in part. … I think I’ve bumped into the limit of sending information via ‘GET’. Is there a way to convert your code to send via ‘POST’ ?
That was great, thanks! Louis vuitton gucci chloe bags http://www.pursefocus.com replica designer handbags,
It’s so hard to get backlinks these days, honestly i need a backlink by comments on your blog / forums or guestbook to make my website appear in search engine. I am getting desperate Now! I know you’ll laugh while reading this comment !!! Here is my website vimax I know my comments do not relate to the topic, but PLEASE HELP ME!! APPROVING MY COMMENT!
Regards: PoormanBH2011
you’re really a good webmaster. The web site loading speed is amazing. It seems that you’re doing any unique trick. Moreover, The contents are masterwork. you have done a great job on this topic!
I’ve been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. Personally, if all web owners and bloggers made good content as you did, the net will be much more useful than ever before.
This is too useful suggestions. I have to say I love scanning this lots. It will help me to become better grasp on the subject. It is very well written and published. I shall definitely search for this specific content pretty engaging. Hopefully you could grant more one day.
You made some first rate factors there. I regarded on the web for the problem and found most individuals will go along with together with your website.
A lot of of what you articulate happens to be supprisingly legitimate and it makes me ponder why I had not looked at this with this light before. Your piece really did switch the light on for me as far as this particular subject matter goes. Nevertheless at this time there is actually one position I am not too cozy with so while I make an effort to reconcile that with the core idea of the point, permit me see just what the rest of your visitors have to say.Well done.
this is great info
It is truly a nice and helpful piece of information. Iˇ¦m satisfied that you simply shared this useful info with us. Please keep us informed like this. Thanks for sharing.
Thank you for your thoughtful post!
Would you be keen on exchanging hyperlinks?
Hello I am so glad I found your site, I really found you by mistake, while I was browsing on Aol for something else, Regardless I am here now and would just like to say thanks a lot for a tremendous post and a all round entertaining blog (I also love the theme/design), I don’t have time to read it all at the minute but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to read much more, Please do keep up the excellent job.
I think this internet site holds some real great information for everyone : D.
Thank you for some other fantastic article. Where else could anybody get that type of info in such an ideal method of writing? I’ve a presentation next week, and I am on the search for such information.
WIP, WYSIWYG in place - from The Lab of the weblog Central Scrutinizer I was recommended this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You’re wonderful! Thanks! your article about WIP, WYSIWYG in place - from The Lab of the weblog Central ScrutinizerBest Regards Lawrence
Nice articles, thanks for sharing information .
I want to share a little information about the penis enlargement products by PillsExpert
Vimax is the best penis enlargement pills are made from natural materials, enhance male sexual performance, making the penis thicker and lenght, and helps men achieve erections are stronger and more durable and with no side effects. 98% of men admitted to the benefits after using the Vimax pills can last a long time to have sex, increasing the thickness of the penis, and increase the length of your penis up to 3 -4 inches and it is permanent.
A lot of of the responses on this particular site dont make sense.
The codes are working.
harika gozukuyor
great information for everyone