Compile Bootstrap CSS on our own, include it into build CSS file.
[fnpeditor.git] / src / editor / modules / nodePane / nodePane.js
1 define([
2 'libs/text!./template.html',
3 'libs/jquery',
4 'libs/underscore',
5 'modules/nodePane/metaWidget/metaWidget',
6 'utils/wlxml'
7 ], function(templateSrc, $, _, metaWidget, wlxmlUtils) {
8
9 'use strict';
10
11 return function(sandbox) {
12     
13     var view = $(_.template(templateSrc)({tagNames: wlxmlUtils.wlxmlTagNames, classNames: wlxmlUtils.wlxmlClassNames})),
14         currentNode;
15     
16     view.on('change', 'select', function(e) {
17         var target = $(e.target);
18         var attr = target.attr('class').split('-')[3] === 'tagSelect' ? 'Tag' : 'Class',
19             value = target.val().replace(/-/g, '.');
20         currentNode['set' + attr](value);
21     });
22    
23     return {
24         start: function() {
25             sandbox.publish('ready');
26         },
27         getView: function() {
28             return view;
29         },
30         setNodeElement: function(wlxmlNodeElement) {
31             var module = this;
32             if(!currentNode) {
33                 wlxmlNodeElement.document.on('change', function(event) {
34                     if(event.type === 'nodeAttrChange' && event.meta.node.sameNode(currentNode)) {
35                         module.setNodeElement(currentNode);
36                     }
37                 });
38             }
39
40             view.find('.rng-module-nodePane-tagSelect').val(wlxmlNodeElement.getTagName());
41
42             var escapedClassName = (wlxmlNodeElement.getClass() || '').replace(/\./g, '-');
43             view.find('.rng-module-nodePane-classSelect').val(escapedClassName);
44
45             var widget = metaWidget.create({attrs:wlxmlNodeElement.getMetaAttributes()});
46             widget.on('valueChanged', function(key, value) {
47                 wlxmlNodeElement.setMetaAttribute(key, value);
48                 //wlxmlNodeElement.setMetaAttribute(key, value);
49             });
50             view.find('.metaFields').empty().append(widget.el);
51
52             currentNode = wlxmlNodeElement;
53         }
54     };
55     
56 };
57
58 });