1 define(['libs/jquery', 'libs/underscore', 'utils/wlxml', 'libs/text!./template.html'], function($, _, wlxmlUtils, template) {
6 return function(sandbox) {
8 var documentTemplates = sandbox.getBootstrappedData(),
12 node: $(_.template(template)({tagNames: wlxmlUtils.wlxmlTagNames, classNames: wlxmlUtils.wlxmlClassNames, templates: documentTemplates})),
16 this.node.find('button').click(function(e) {
19 var btn = $(e.currentTarget),
20 btnName = btn.attr('data-name'),
21 meta = btn.attr('data-meta'),
25 if(myHandlers[btnName]) {
26 myHandlers[btnName](btn);
28 if(btn.attr('data-btn-type') === 'toggle') {
29 command = 'toggle-' + command;
30 btn.toggleClass('active');
31 params.toggle = btn.hasClass('active');
34 if(btnName === 'new-node') {
35 command = 'newNodeRequested';
36 params.wlxmlTag = view.getOption('newTag-tag');
37 params.wlxmlClass = view.getOption('newTag-class');
39 var split = meta.split('/');
40 params.wlxmlTag = split[0];
41 params.wlxmlClass = split[1];
47 if(command === 'undo' || command === 'redo') {
48 params.callback = function(disable) {
49 btn.attr('disabled', !disable);
53 sandbox.publish('command', command, params);
57 getOption: function(option) {
58 return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();
63 templatesBtn: function() {
64 if(currentNode && currentNode.nodeType === Node.ELEMENT_NODE) {
65 var templateId = parseInt(view.node.find('[data-name=templates-select]').val(), 10);
66 documentTemplates.forEach(function(template) {
67 if(template.id === templateId) {
68 var toAdd = currentNode.document.createDocumentNode(template.content);
69 currentNode.after(toAdd);
79 start: function() { sandbox.publish('ready'); },
80 getView: function() { return view.node; },
81 setNodeElement: function(node) {
84 getOption: function(option) { return view.getOption(option); }