
<script type="text/html" data-template-name="comment">
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
        <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
    </div>
    <div class="form-row node-text-editor-row">
        <input type="hidden" id="node-input-info" autofocus="autofocus">
        <div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-info-editor"></div>
    </div>
</script>

<script type="text/javascript">
    RED.nodes.registerType('comment',{
        category: 'common',
        color:"#ffffff",
        defaults: {
            name: {value:""},
            info: {value:""}
        },
        inputs:0,
        outputs:0,
        icon: "comment.svg",
        label: function() {
            return this.name||this._("comment.comment");
        },
        labelStyle: function() {
            return this.name?"node_label_italic":"";
        },
        info: function() {
            return this.name?"# "+this.name+"\n\n---\n\n":"";
        },
        oneditprepare: function() {
            var that = this;
            this.editor = RED.editor.createEditor({
                id: 'node-input-info-editor',
                mode: 'ace/mode/markdown',
                value: $("#node-input-info").val()
            });
            this.editor.focus();
        },
        oneditsave: function() {
            $("#node-input-info").val(this.editor.getValue());
            this.editor.destroy();
            delete this.editor;
        },
        oneditcancel: function() {
            this.editor.destroy();
            delete this.editor;
        },
        oneditresize: function(size) {
            var rows = $("#dialog-form>div:not(.node-text-editor-row)");
            var height = $("#dialog-form").height();
            for (var i=0; i<rows.length; i++) {
                height -= $(rows[i]).outerHeight(true);
            }
            var editorRow = $("#dialog-form>div.node-text-editor-row");
            height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
            $(".node-text-editor").css("height",height+"px");
            this.editor.resize();
        }
    });
</script>
