ctrl + enter creates new node element after current text element (wlxmlTag=block)
[fnpeditor.git] / modules / nodePane / metaWidget / metaWidget.js
1 define([
2 'libs/jquery-1.9.1.min',
3 'libs/underscore-min',
4 'libs/backbone-min',
5 'libs/text!./stringField.html'
6 ], function($, _, Backbone, stringFieldTpl) {
7
8 'use strict';
9
10 var templates = {
11     string: _.template(stringFieldTpl)
12 };
13
14 var getAttrElement = function(attr) {
15     var toret = $('<div>');   
16     toret.append(templates.string({name: attr.name, value: attr.value}));
17     return toret;
18 };
19
20 var MetaWidget = Backbone.View.extend({
21     events: {
22         'change [metaField-name]': 'onMetaFieldChange' 
23     },
24     initialize: function() {
25         var view = this;
26         this.options.attrs.forEach(function(attr) {
27             view.$el.append(getAttrElement(attr));
28         });
29     },
30     onMetaFieldChange: function(e) {
31         var target = $(e.target);
32         this.trigger('valueChanged', target.attr('metaField-name'), target.val());
33     }
34 });
35
36
37 return {
38     create: function(options) {
39         return new MetaWidget(options);
40     }
41 };
42
43 });