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)({wlxmlUtils: wlxmlUtils, 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 _.extend(params, {ctrlKey: e.ctrlKey});
55 sandbox.publish('command', command, params);
59 getOption: function(option) {
60 return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();
65 templatesBtn: function() {
66 if(currentNode && currentNode.nodeType === Node.ELEMENT_NODE) {
67 var templateId = parseInt(view.node.find('[data-name=templates-select]').val(), 10);
68 documentTemplates.forEach(function(template) {
69 if(template.id === templateId) {
70 var toAdd = currentNode.document.createDocumentNode(template.content);
71 currentNode.after(toAdd);
81 start: function() { sandbox.publish('ready'); },
82 getView: function() { return view.node; },
83 setNodeElement: function(node) {
86 getOption: function(option) { return view.getOption(option); }