Latest custom input for Jeditable uses jWYSIWYG editor by Juan M Martínez. This code has been almost ready for a while. This week I finally had time to fix some outstanding FireFox bugs.

If you are interested in writing your own Jeditable custom inputs read the introduction. You might also be interested in MarkItUp! custom input which is similar to jWYSIWYG input.

To test see the working demo and then download the source.

Usage

First include all needed JavaScript and CSS in your HTML.

<script src="jquery.js"" type="text/javascript"></script>
<script src="jquery.wysiwyg.js" type="text/javascript"></script>
<script src="jquery.jeditable.js" type="text/javascript"></script>
<script src="jquery.jeditable.wysiwyg.js" type="text/javascript"></script>
<link rel="stylesheet" href="jquery.wysiwyg.css" type="text/css">

Now you can use input type wysiwyg. Set onblur to ignore. Otherwise clicking menubar will cause editing to quit. You should also include atleast submit and cancel parameters. All jWYSIWYG settings can be passed using wysiwyg parameter. Check documentation from Juan’s webpage.

$('.editable').editable('http://www.example.com/save.php', { 
    type      : 'wysiwyg',
    onblur    : 'ignore',
    submit    : 'OK',
    cancel    : 'Cancel',
    wysiwyg   : { controls : { separator04         : { visible : true },
                               insertOrderedList   : { visible : true },
                               insertUnorderedList : { visible : true }
                }
    }
});

I tested the code with IE6, IE7, FF2, Safari and Chrome. In case you find any problems drop me a line.


26 Responses to “WYSIWYG Inline Edit with Jeditable”

  1. Ilija Studen says:

    “Working demo” is not working for me (Safari 3.1.2 on Mac OS X 10.5.4). When I click on “edit in place” I get redirected back on http://www.appelsiini.net/projects/jeditable page.

  2. Mika Tuupola says:

    Your browser is following a link in the text. Click anywhere else than on the link. Following a link can be disabled with jQuery. But I just remove the link from example text because it is confusing.

  3. Prashant Sakhuja says:

    Mika, Great work with the script. I was not sure how you are saving the edited text using: http://www.appelsiini.net/projects/jeditable/wysiwyg/php/save.php Can you share the logic for this.

  4. Mika Tuupola says:

    Prashant: Same way as you would you save text with any normal form? Check the source for example scripts. You can ignore all parts which say Textile, unless you plan to use Textile rendering.

  5. Thiago says:

    Dear Mika, The style is applied in the form. You do not think it would be better if it were applied in the input?

    Thus:

    /* apply css or style or both */
    if (settings.cssclass) {
        if ('inherit' == settings.cssclass) {
            input.attr('class', $(self).attr('class'));
        } else {
            input.attr('class', settings.cssclass);
        }
    }
    
    if (settings.style) {
        if ('inherit' == settings.style) {
            input.attr('style', $(self).attr('style'));
            /* IE needs the second line or display wont be inherited */
            input.css('display', $(self).css('display'));                
        } else {
            input.attr('style', settings.style);
        }
    }
    
  6. Mika Tuupola says:

    Thiago: I guess it’s just matter of taste how you want to write selectors. You can style input now with:

    form.editable > textarea {
     color : #F00
    }
    

    If class was applied to input you would:

    textarea.editable {
     color : #F00
    }
    
  7. Ian Tresman says:

    Two suggested features for Jeditable:

    1. Jeditable activates only after “login” (or authentication)

    2. After login, editable areas optionally are (a) all highlighted on the page, and/or (b) highlighted when cursor moves over element.

  8. Mika Tuupola says:

    Ian: Good points, but both of them are something that should be handled outside of the plugin. For example:

    1) Backend should add class editable (or something similar) after authentication to those elements which should become editable.

    2) You are already using jQuery so why not just use jQuery to handle highlighting. Something like:

    $('.editable').hover(
        function() {
            $(this).addClass('hover');
        }, 
        function() {
            $(this).removeClass('hover');
       }
    );
    
  9. none says:

    Where I can find a list of all the options editor jwysiwyg?

  10. Mika Tuupola says:

    From jWYSIWYG homepage.

  11. Ian Tresman says:

    Is you file, save.php available for download somewhere, so we can see how to process the edited text, and pass it back to the original HTML file.

  12. Mika Tuupola says:

    All files are downloadable from Subversion. The example save.php script is pretty rudimentary. It just saves values to new row in database. You can also ignore all Textile parts. They are used for demoing Textile rendering.

  13. Thiago Santos says:

    Hello !

    You wrote a great plugins, but i founded what appear be a “bug”: when the object selected is a true link like: “Google.com When you click, the link is loaded and therefore the input field appears.

    best regards, Thiago Santos

  14. Mika Tuupola says:

    Thiago: I have been thinking for a while is it a bug or feautre :) Meaning should Jeditable override default behaviour link or not. In any case you can fix it with something like:

    $('.editable > a').bind("click", function(){
        return false;
    });
    
  15. Thiago Santos says:

    Thanks for your reply Mika, jEditable could have an option for enable or not this “bug-feature”!

    Thanks again, sucess !

    Thiago Santos

  16. Leo Machado says:

    Hi Mika!

    Where is DB.php file? i search in http://svn.appelsiini.net/viewvc/javascript/trunk/jquery_jeditable/php/

    but i didn`t found! thanks

  17. Mika Tuupola says:

    It is part of PEAR DB library. You can install it from commandline with:

    >pear install DB
    
  18. Leo Machado says:

    Hi again Mike, and sorry for my English..

    this script is very good, and i could adapt to my need, but the only question is when I edit the “editable_textile,” he query the database, but always when I click, he brings an old result.

    Is there any way to eliminate this cache?

    Thank you, Leo

  19. Mika Tuupola says:

    Leo: Do you have example code somewhere online? I am not sure if I understand correctly when the old content comes back. When you start editing or when you submit edited content.

    In any case to me it sounds like your database query fails to save the content.

  20. Doug Beleznay says:

    in comment # 8 you suggest adding the .hover method through jquery – but I have found some problems with that.

    The way that Jeditable resizes itself during editing means that when I click the save or cancel it sometimes does not catch the mouseexit events, so the item stays highlighted.

    I have tried adding a callback function in order to remove it, but that doesn’t work if you click on the cancel button (it looks like the callback isn’t getting called)

    callback : function(){$(this).removeClass(‘hover’);}

    It looks like knight_killer has added callbacks for mouse over and leave at http://stackoverflow.com/questions/152104/problems-using-jeditable-and-autogrow

    I might try that, but was wondering if you had any other thoughts.

  21. Brad says:

    Hey there,

    I’ve been trying to get jeditable working with 90% success – can edit text once, and after that I get the error “DB Error: constraint violation”. I’m new to sqlite/pear, and am trying to understand what could be going on.

    It appears like the db/table got set up right:

    sqlite> .dump BEGIN TRANSACTION; CREATE TABLE config (id INTEGER primary key, token VARCHAR, value TEXT, date DATETIME); INSERT INTO config VALUES; COMMIT; sqlite>

    ... and there are no errors except the “constraint violation” that returns as status for “echo $status = $dbh->query($query);”

    This is pretty much the neatest plugin I’ve ever seen and I’m trying hard to get it to work as-is before I port it over to mysql.

    Thanks so much!

    Cheers, Brad

  22. Touya says:

    I find a bug with loadurl: script:

    $("#editable_discount").editable("/seller/setting_discount", { 
      loadurl  : '/seller/load_discount',
      style  : "display: inline;",
      tooltip   : 'click to edit',
      type      : 'text'
    });
    

    html

    <div id="editable_discount">55555</div>
    

    moves cause the bug:

    1 click editable_discount,modify value into 444,confirm 2 click editable_discount again,then loadurl get 55555 back again, seems IE7 cached the result… should I add t=new Date() somewhere after the loadurl?How to ? Thanks..

  23. Mika Tuupola says:

    Touya: Are you sure your values are saved to database? Does this happen with IE7 only and others work as expected?

  24. Mika Tuupola says:

    Brad: It sounds like your DB installation cannot create sequences. Have you tried with MySQL driver? DB library is actually kinda old and I should rewrite examples using PDO.

  25. Zouz says:

    What if i want the dir to be RTL ???

  26. Peter says:

    Hi Mika,

    Thanks for the very fine work you publish here! Independantly, jEditable and jWysiwyg are very useful work by themselves. I wonder what is the advantage of having them both together? E.g. if I need Wysiwyg, I’d just use jWysiwyg (alone).

    Keep up the good work!

Leave a Reply



(will not be published)



(you can use Textile for formatting)