1 define(['libs/jquery', 'libs/underscore', 'modules/documentToolbar/actionView', 'libs/text!./template.html'], function($, _, actionView, template) {
6 return function(sandbox) {
13 node: $(_.template(template)()),
14 getOption: function(option) {
15 return this.node.find('.rng-module-documentToolbar-toolbarOption[data-option=' + option +']').val();
17 addAction: function(group, actionDescription) {
18 var action = sandbox.createAction(actionDescription.actionName, actionDescription.actionConfig),
20 addedActions.push(action);
21 view = actionView.create(action, sandbox.getTutorialItem(action.definition.name));
23 _.pairs(contextParams).forEach(function(pair) {
26 action.updateContextParam(name, value);
29 group.append(view.dom);
30 action.on('actionExecuted', function(ret) {
31 sandbox.publish('actionExecuted', action, ret);
34 view.on('hover', function() {
35 sandbox.publish('actionHovered', action);
37 view.on('leave', function() {
38 sandbox.publish('actionOff', action);
41 addActionsGroup: function() {
43 div.addClass('rng-module-documentToolbar-toolbarGroup');
44 this.node.append(div);
49 var setContextParam = function(what, ctx) {
50 contextParams[what] = ctx;
51 addedActions.forEach(function(action) {
52 action.updateContextParam(what, contextParams[what]);
56 sandbox.registerKeyHandler('keydown', function(e) {
57 if(e.keyCode === 17) {
58 addedActions.forEach(function(action) {
59 action.updateKeyParam('ctrl', true);
63 sandbox.registerKeyHandler('keyup', function(e) {
64 if(e.keyCode === 17) {
65 addedActions.forEach(function(action) {
66 action.updateKeyParam('ctrl', false);
73 var config = sandbox.getConfig().toolbar || {};
74 config.forEach(function(actionsGroup) {
75 var group = view.addActionsGroup();
76 actionsGroup.forEach(function(actionDescription) {
77 if(typeof actionDescription === 'string') {
78 actionDescription = {actionName: actionDescription, actionConfig: {}};
80 view.addAction(group, actionDescription);
83 sandbox.publish('ready');
85 getView: function() { return view.node; },
86 setDocumentFragment: function(fragment) {
88 document = fragment.document;
89 document.on('operationEnd', function() {
90 setContextParam('document', document);
92 setContextParam('document', document);
94 setContextParam('fragment', fragment);
97 setCanvas: function(_canvas) {
98 setContextParam('canvas', _canvas);
101 canvas.on('changed', function() {
102 setContextParam('canvas', _canvas);
106 getOption: function(option) { return view.getOption(option); }