X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/8a17c686a21178f73ea93a9d7f2c6ee3bf90aa72..7b7f19b8680ed7653359bede5833d2cffc11ef8c:/src/editor/modules/documentToolbar/documentToolbar.js?ds=inline diff --git a/src/editor/modules/documentToolbar/documentToolbar.js b/src/editor/modules/documentToolbar/documentToolbar.js index 33f95a6..6e3d630 100644 --- a/src/editor/modules/documentToolbar/documentToolbar.js +++ b/src/editor/modules/documentToolbar/documentToolbar.js @@ -1,87 +1,107 @@ -define(['libs/jquery', 'libs/underscore', 'utils/wlxml', 'libs/text!./template.html'], function($, _, wlxmlUtils, template) { +define(['libs/jquery', 'libs/underscore', 'modules/documentToolbar/actionView', 'libs/text!./template.html'], function($, _, actionView, template) { 'use strict'; -/* globals Node */ + return function(sandbox) { - var documentTemplates = sandbox.getBootstrappedData(), - currentNode; + var addedActions = [], + contextParams = {}, + document, canvas; var view = { - node: $(_.template(template)({wlxmlUtils: wlxmlUtils, templates: documentTemplates})), - setup: function() { - var view = this; + node: $(_.template(template)()), + getOption: function(option) { + return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val(); + }, + addAction: function(group, actionDescription) { + var action = sandbox.createAction(actionDescription.actionName, actionDescription.actionConfig), + view; + addedActions.push(action); + view = actionView.create(action); - this.node.find('button').click(function(e) { - e.stopPropagation(); - - var btn = $(e.currentTarget), - btnName = btn.attr('data-name'), - meta = btn.attr('data-meta'), - params = {}, - command = btnName; - - if(myHandlers[btnName]) { - myHandlers[btnName](btn); - } else { - if(btn.attr('data-btn-type') === 'toggle') { - command = 'toggle-' + command; - btn.toggleClass('active'); - params.toggle = btn.hasClass('active'); - } - - if(btnName === 'new-node') { - command = 'newNodeRequested'; - params.wlxmlTag = view.getOption('newTag-tag'); - params.wlxmlClass = view.getOption('newTag-class'); - if(meta) { - var split = meta.split('/'); - params.wlxmlTag = split[0]; - params.wlxmlClass = split[1]; - } - } else { - params.meta = meta; - } - - if(command === 'undo' || command === 'redo') { - params.callback = function(disable) { - btn.attr('disabled', !disable); - }; - } + _.pairs(contextParams).forEach(function(pair) { + var name = pair[0], + value = pair[1]; + action.updateContextParam(name, value); + }); - _.extend(params, {ctrlKey: e.ctrlKey}); + group.append(view.dom); + action.on('actionExecuted', function(ret) { + sandbox.publish('actionExecuted', action, ret); + }); - sandbox.publish('command', command, params); - } + view.on('hover', function() { + sandbox.publish('actionHovered', action); + }); + view.on('leave', function() { + sandbox.publish('actionOff', action); }); }, - getOption: function(option) { - return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val(); + addActionsGroup: function() { + var div = $('