Rails& wysihtml5 - 更改时保存

时间:2012-12-09 01:41:22

标签: jquery ruby-on-rails wysihtml5

我们正在使用gem'bootstrap-wysihtml5-rails','0.3.1.13'。当焦点丢失时,我想从textarea保存更改的内容。

我试图在视图中直接使用jquery,包含脚本标记:

$("textarea").live("blur", function(){ alert("Focus lost"); });

如果我使用“模糊”(或焦点),则会在页面加载时多次触发警报,但在失去焦点时则不会,当我使用“更改”时根本没有任何事情发生。

在另一次尝试中,我试图以相同的行为挂钩到wysihtml5事件:

function integrate_wysihtml5() {
var editor = $('.wysihtml5').each(function(i, elem) {
    $(elem).wysihtml5({
        "font-styles": false, //Font styling, e.g. h1, h2, etc. Default true
        "emphasis": true, //Italics, bold, etc. Default true
        "lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
        "html": false, //Button which allows you to edit the generated HTML. Default false
        "link": false, //Button to insert a link. Default true
        "image": false, //Button to insert an image. Default true,
        "color": false //Button to change color of font  
    });
});

function onChange() { alert("The content of the editor has changed"); };
editor.on("change", onChange);

}

3 个答案:

答案 0 :(得分:2)

$('.textarea').wysihtml5({
    events: {
        change: function() {
            var html = this.textarea.getValue();
            //ajax method
        }
    }
}

答案 1 :(得分:0)

抓住变革事件的好方法:

editor.composer.element.addEventListener("keyup", myOnChange);
editor.on("aftercommand:composer", myOnChange);

但我不认为你的每一个都是好的,wysihtml5不适用于多个可编辑的部分,在这里你使用bootstrap版本,但我认为它是相同的。 这主要是我写jquery.scribe

的原因

那么,也许就是这样?

$('.wysihtml5').each(function(i, elem) {
    var editor = $(elem).wysihtml5({
        "font-styles": false, //Font styling, e.g. h1, h2, etc. Default true
        "emphasis": true, //Italics, bold, etc. Default true
        "lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
        "html": false, //Button which allows you to edit the generated HTML. Default false
        "link": false, //Button to insert a link. Default true
        "image": false, //Button to insert an image. Default true,
        "color": false //Button to change color of font  
    });

    editor.composer.element.addEventListener("keyup", myOnChange);
    editor.on("aftercommand:composer", myOnChange);
});

答案 2 :(得分:0)

我像这样附加听众:

import tensorflow as tf

class Model:

    def __init__(self, x):
        self.x = x
        self._output = None

    @property
    def output(self):
        if not self._output:
            weight = tf.Variable(tf.constant(4.0))
            bias = tf.Variable(tf.constant(2.0))
            self._output = tf.multiply(self.x, weight) + bias
        return self._output

def main():
    x = tf.placeholder(tf.float32)
    model = Model(x)

    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        output = sess.run(model.output, {x: 4.0})
        print(output)

if __name__ == '__main__':
    main()

希望它有所帮助。