Debian Codegraph @

dojox/drawing/ui/dom/Toolbar.js

raw symbols SCIP
1 define(["dojo", "../../util/common"], function(dojo, commonUtil){
2 dojo.deprecated("dojox.drawing.ui.dom.Toolbar", "It may not even make it to the 1.4 release.", 1.4);
3
4 return dojo.declare("dojox.drawing.ui.dom.Toolbar", [], {
5 // NOTE:
6 // dojox.drawing.Toolbar is DEPRECATED.
7 // The intention never was to use HTML as buttons for a Drawing.
8 // This was implemented in order to finish the project for which
9 // Drawing was developed.
10 // Instead use: drawing/ui/Toolbar.js
11
12 // summary:
13 // Creates a Toolbar to be used with a DojoX Drawing.
14 // description:
15 // Currently works in markup only. A class is required with
16 // either horizontal or vertical as a class (IE prevented using
17 // either as a default). Assign an attribute of 'drawingId' with
18 // the id of the DojoX Drawing to which this is assigned.
19 // The node children will be assigned as the Tools in the toolbar.
20 // Plugins can also be assigned.
21 // The Toolbar is largely self contained and has no real public
22 // methods or events. the Drawing object should be used.
23 //
24 // example:
25 // | <div dojoType="dojox.drawing.Toolbar" drawingId="drawing" class="drawingToolbar vertical">
26 // | <div tool="dojox.drawing.tools.Line" selected="false"> Line</div>
27 // | <div tool="dojox.drawing.tools.Rect" selected="true"> Rect</div>
28 // | <div plugin="dojox.drawing.plugins.tools.Zoom" options="{zoomInc:.1,minZoom:.5,maxZoom:2}">Zoom</div>
29 // | </div>
30
31 // TODO: Toolbar works in markup only. Need programmatic.
32 // NOTE: There are plans to make the toolbar out of dojox.gfx vectors.
33 // This may change the APIs in the future.
34
35 // baseClass:String
36 // The CSS style to apply to the toolbar node
37 baseClass:"drawingToolbar",
38
39 // buttonClass:String
40 // The CSS style to apply to each button node
41 buttonClass:"drawingButton",
42
43 // iconClass:String
44 // The CSS style to apply to each button icon node
45 iconClass:"icon",
46
47 constructor: function(props, node){
48 // props is null from markup
49 dojo.addOnLoad(this, function(){
50 this.domNode = dojo.byId(node);
51 dojo.addClass(this.domNode, this.baseClass);
52 this.parse();
53 });
54 },
55
56 createIcon: function(/*HTMLNode*/node, /*Function?*/constr){
57 // summary:
58 // Internal. Creates an icon node for each button.
59 // node:
60 // The button node.
61 // constr:
62 // Optional. If not supplied, an icon is not created.
63 // Information for each icon is derived from
64 // the ToolsSetup object defined at the end
65 // of each tool. See: stencil._Base
66
67 var setup = constr && constr.setup ? constr.setup : {};
68 if(setup.iconClass){
69 var icon = setup.iconClass ? setup.iconClass : "iconNone";
70 var tip = setup.tooltip ? setup.tooltip : "Tool";
71
72 var iNode = dojo.create("div", {title:tip}, node);
73 dojo.addClass(iNode, this.iconClass);
74 dojo.addClass(iNode, icon);
75
76 dojo.connect(node, "mouseup", function(evt){
77 dojo.stopEvent(evt);
78 dojo.removeClass(node, "active");
79 });
80 dojo.connect(node, "mouseover", function(evt){
81 dojo.stopEvent(evt);
82 dojo.addClass(node, "hover");
83 });
84 dojo.connect(node, "mousedown", this, function(evt){
85 dojo.stopEvent(evt);
86 dojo.addClass(node, "active");
87 });
88
89 dojo.connect(node, "mouseout", this, function(evt){
90 dojo.stopEvent(evt);
91 dojo.removeClass(node, "hover");
92 });
93 }
94 },
95
96 createTool: function(/*HTMLNode*/node){
97 // summary:
98 // Creates a button on the Toolbar that is
99 // a Tool, not a Plugin. Tools draw Stencils,
100 // Plugins do actions.
101 // node: HTMLNode
102 // The button node.
103
104 node.innerHTML = "";
105 var type = dojo.attr(node, "tool");
106 this.toolNodes[type] = node;
107 dojo.attr(node, "tabIndex", 1);
108 var constr = dojo.getObject(type);
109
110 this.createIcon(node, constr);
111
112 this.drawing.registerTool(type, constr);
113 dojo.connect(node, "mouseup", this, function(evt){
114 dojo.stopEvent(evt);
115 dojo.removeClass(node, "active");
116 this.onClick(type);
117 });
118 dojo.connect(node, "mouseover", function(evt){
119 dojo.stopEvent(evt);
120 dojo.addClass(node, "hover");
121 });
122 dojo.connect(node, "mousedown", this, function(evt){
123 dojo.stopEvent(evt);
124 dojo.addClass(node, "active");
125 });
126
127 dojo.connect(node, "mouseout", this, function(evt){
128 dojo.stopEvent(evt);
129 dojo.removeClass(node, "hover");
130 });
131 },
132
133 parse: function(){
134 // summary:
135 // Initializing method that reads the dom node and its
136 // children for tools and plugins.
137
138 var drawingId = dojo.attr(this.domNode, "drawingId");
139 this.drawing = commonUtil.byId(drawingId);
140 !this.drawing && console.error("Drawing not found based on 'drawingId' in Toolbar. ");
141 this.toolNodes = {};
142 var _sel;
143 dojo.forEach(this.domNode.childNodes, function(node, i){
144 if(node.nodeType!==1){
145 return;
146 }
147 node.className = this.buttonClass;
148 var tool = dojo.attr(node, "tool");
149 var action = dojo.attr(node, "action");
150 var plugin = dojo.attr(node, "plugin");
151 if(tool){
152 if(i==0 || dojo.attr(node, "selected")=="true"){
153 _sel = tool;
154 }
155 this.createTool(node);
156
157 }else if(plugin){
158 var p = {name:plugin, options:{}},
159 opt = dojo.attr(node, "options");
160 if(opt){
161 p.options = eval("("+opt+")");
162 }
163 p.options.node = node;
164 node.innerHTML = "";
165 this.drawing.addPlugin(p);
166 this.createIcon(node, dojo.getObject(dojo.attr(node, "plugin")));
167 }
168
169 }, this);
170 this.drawing.initPlugins();
171 dojo.connect(this.drawing, "setTool", this, "onSetTool");
172 this.drawing.setTool(_sel);
173 },
174 onClick: function(/*String*/type){
175 // summary:
176 // Event fired from clicking a Tool, not a PLugin.
177 // Plugin clicks are handled within the plugin's class.
178 // type:
179 // Fully qualified name of class. ex: dojox.drawing.tools.Ellipse
180
181 this.drawing.setTool(type);
182 },
183 onSetTool: function(/*String*/type){
184 // summary:
185 // handles buttons clicks and selects or deselects
186 for(var n in this.toolNodes){
187 if(n == type){
188 dojo.addClass(this.toolNodes[type], "selected");
189 this.toolNodes[type].blur();
190 }else{
191 dojo.removeClass(this.toolNodes[n], "selected");
192 }
193
194 }
195 }
196 });
197
198 });