MarkItUp! for Jeditable

April 8th, 2008

In the heels of autogrow textarea comes next custom input for Jeditable. This time we will use markItUp! universal markup editor by Jay Salvat.

If you are not familiar with Jeditable custom inputs read the introduction. Also see autogrow and timepicker tutorials.

If you are just looking for the code download it here.

Creating custom input

Throughout the tutorial we will be using following code to trigger Jeditable. Note variable called markitupHTML. It holds configuration of used markItUp! tagset. In this example I use slightly modified HTML tagset. For more information on tagsets see markItUp! documentation.

$(".edit").editable("http://www.example.com/save.php", { 
    type      : "markitup",
    submit    : 'OK',
    cancel    : 'Cancel',
    tooltip   : "Click to edit...",
    onblur    : "ignore",
    markitup  : markitupHTML
});

Again we start by adding custom input type called markitup.

$.editable.addInputType('markitup', {
});

Right now code does not do much anything. It only creates the buttons and hidden input. Click text below to see it in action.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Add textarea element

Next we add texarea element. Unlike in previous tutorials we do not copy and paste code from default textarea element. Instead we use a shortcut:

$.editable.addInputType('markitup', {
    element : $.editable.types.textarea.element
});

Now normal textarea is added. Click text below to see how it works.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Attach markItUp! to textarea

We wanted to see pretty textarea with toolbar. First we search textarea input inside Jeditable form. This is done with $(‘textarea’, this) selector. Then we attach markItUp! to it.

$.editable.addInputType('markitup', {
    element : $.editable.types.textarea.element,
    plugin  : function(settings, original) {
        $('textarea', this).markItUp(settings.markitup);
    }
});

Now you can edit code with tag editor. Click text below to test yourself.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

And we are done. This illustrates how easy it is to customize Jeditable with other plugins. Only six lines of code can create pretty inline tag editor. There is also separate Textile demo. As always, all suggestions and feedback are welcome.

1 Response to “MarkItUp! for Jeditable”

  1. Thomas Mery Says:

    Hello there,

    a huge thanks for this plugin and the ability to link it with markitup :)

    I don’t know if I can post this here but …

    I am running through a problem with ie7 and making elements in an iframe editable.

    I posted an example here :

    http://www.thomas-mery.net/dev/jeditable_iframe/

    what happens is that when trying to edit an element in the iframe ie7 chokes on line 212 of jquery.jeditable.js

    /* add created form to self */ $(self).prepend(form);

    complaining that form is an ‘invalid argument’

    replacing form by form.html() makes the form appear but no events seem to be working (Enter, Escape …)

    would you point me in a direction where i can fid ways to fix this ? Or just point out what I am missing :)

    Thanks a lot for any help, as I’m kind of stuck with this issue

    Thomas

Leave a Reply