public
Description: Wysiwyg input for Jeditable.
Homepage: http://www.appelsiini.net/2008/9/wysiwyg-for-jeditable
Clone URL: git://github.com/tuupola/jquery_jeditable_wysiwyg.git
jquery_jeditable_wysiwyg / jquery.jeditable.wysiwyg.js
100644 61 lines (59 sloc) 2.162 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Wysiwyg input for Jeditable
*
* Copyright (c) 2008 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Depends on jWYSIWYG plugin by Juan M Martinez:
* http://projects.bundleweb.com.ar/jWYSIWYG/
*
* Project home:
* http://www.appelsiini.net/projects/jeditable
*
* Revision: $Id$
*
*/
 
$.editable.addInputType('wysiwyg', {
    /* Use default textarea instead of writing code here again. */
    //element : $.editable.types.textarea.element,
    element : function(settings, original) {
        /* Hide textarea to avoid flicker. */
        var textarea = $('<textarea>').css("opacity", "0");
        if (settings.rows) {
            textarea.attr('rows', settings.rows);
        } else {
            textarea.height(settings.height);
        }
        if (settings.cols) {
            textarea.attr('cols', settings.cols);
        } else {
            textarea.width(settings.width);
        }
        $(this).append(textarea);
        return(textarea);
    },
    content : function(string, settings, original) {
        /* jWYSIWYG plugin uses .text() instead of .val() */
        /* For some reason it did not work work with generated */
        /* textareas so I am forcing the value here with .text() */
        $('textarea', this).text(string);
    },
    plugin : function(settings, original) {
        var self = this;
        /* Force autosave off to avoid "element.contentWindow has no properties" */
        settings.wysiwyg = $.extend({autoSave: false}, settings.wysiwyg);
        if (settings.wysiwyg) {
            setTimeout(function() { $('textarea', self).wysiwyg(settings.wysiwyg); }, 0);
        } else {
            setTimeout(function() { $('textarea', self).wysiwyg(); }, 0);
        }
    },
    submit : function(settings, original) {
        var iframe = $("iframe", this).get(0);
        var inner_document = typeof(iframe.contentDocument) == 'undefined' ? iframe.contentWindow.document.body : iframe.contentDocument.body;
        var new_content = $(inner_document).html();
        $('textarea', this).val(new_content);
    }
});