aboutsummaryrefslogtreecommitdiff
path: root/js/tools/TagTool.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-05-22 13:22:26 -0700
committerPushkar Joshi2012-05-22 13:22:26 -0700
commit01dbc1f329a95bc7e3b93224543d88ad5bdbd315 (patch)
treeceb527713554f506c537168e36a10452cd09ad10 /js/tools/TagTool.js
parentb9262c831952e77135b79c2de7c455d5e7ff0589 (diff)
parentc37a876b373ddc7cb19277aaeaa6bb2d2d5a50ac (diff)
downloadninja-01dbc1f329a95bc7e3b93224543d88ad5bdbd315.tar.gz
Merge branch 'master' into brushtool
Diffstat (limited to 'js/tools/TagTool.js')
-rwxr-xr-xjs/tools/TagTool.js219
1 files changed, 26 insertions, 193 deletions
diff --git a/js/tools/TagTool.js b/js/tools/TagTool.js
index d946db72..5520fa89 100755
--- a/js/tools/TagTool.js
+++ b/js/tools/TagTool.js
@@ -13,18 +13,14 @@ var DrawingToolBase = require("js/tools/drawing-tool-base").DrawingToolBase;
13exports.TagTool = Montage.create(DrawingTool, { 13exports.TagTool = Montage.create(DrawingTool, {
14 drawingFeedback: { value: { mode: "Draw3D", type: "rectangle" } }, 14 drawingFeedback: { value: { mode: "Draw3D", type: "rectangle" } },
15 15
16 _editSymbol: { value: null }, 16 Configure: {
17 17 value: function(wasSelected) {
18 editSymbol:{ 18 if(wasSelected) {
19 get: function() { return this._editSymbol; }, 19 NJevent("enableStageMove");
20 set: function(item) { 20 this.application.ninja.stage.stageDeps.snapManager.setupDragPlaneFromPlane( workingPlane );
21 if(item) {
22// stageManagerModule.stageManager.drawElementBoundingBox(item, true);
23 } else { 21 } else {
24// stageManagerModule.stageManager.drawSelectionRec(true); 22 NJevent("disableStageMove");
25 } 23 }
26
27 this._editSymbol = item;
28 } 24 }
29 }, 25 },
30 26
@@ -59,11 +55,9 @@ exports.TagTool = Montage.create(DrawingTool, {
59 this._escape = false; 55 this._escape = false;
60 return; 56 return;
61 } 57 }
62
63 var drawData, selectedItem;
64 58
65 if(this._hasDraw) { 59 if(this._hasDraw) {
66 drawData = this.getDrawingData(); 60 var drawData = this.getDrawingData();
67 61
68 if(drawData) { 62 if(drawData) {
69 this.insertElement(drawData); 63 this.insertElement(drawData);
@@ -72,200 +66,39 @@ exports.TagTool = Montage.create(DrawingTool, {
72 this._hasDraw = false; 66 this._hasDraw = false;
73 this.endDraw(event); 67 this.endDraw(event);
74 } else { 68 } else {
75 if(this.editSymbol) { 69 this.doSelection(event);
76 this.insertElement();
77 } else {
78 //selectedItem = this.doSelection(event);
79 this.doSelection(event);
80 }
81
82 this._isDrawing = false;
83 }
84 }
85 },
86
87 HandleDoubleClick: {
88 value: function(event) {
89 /*
90 if(selectionManagerModule.selectionManager.isDocument) {
91 this.editSymbol = documentManagerModule.DocumentManager.activeDocument.documentRoot;
92 } else {
93 this.editSymbol = selectionManagerModule.selectionManager._selectedItems[0];
94 }
95 */
96 }
97 },
98
99 /* This will overwrite the existing function in drawing tool. Do not uncomment
100 HandleKeyPress: {
101 value: function(event) {
102 if(event.metaKey) {
103 // TODO fix this
104 if(selectionManagerModule.selectionManager.isDocument) {
105 this.editSymbol = documentManagerModule.DocumentManager.activeDocument.documentRoot;
106 } else {
107 this.editSymbol = selectionManagerModule.selectionManager._selectedItems[0];
108 }
109
110 } 70 }
111 }
112 },
113
114 71
115 HandleKeyUp: { 72 this._isDrawing = false;
116 value: function(event) {
117 if(event.keyCode === 93 || event.keyCode === 91) { // Command Keycode
118 this.editSymbol = null;
119 }
120 } 73 }
121 }, 74 },
122 */
123 75
124 Configure: { 76 // TODO: Fix Classname
125 value: function(wasSelected) { 77 // TODO: Add position support
126 if(wasSelected) {
127 NJevent("enableStageMove");
128 this.application.ninja.stage.stageDeps.snapManager.setupDragPlaneFromPlane( workingPlane );
129 } else {
130 NJevent("disableStageMove");
131 }
132 }
133 },
134
135 insertElement: { 78 insertElement: {
136 value: function(data) { 79 value: function(drawData) {
137 var element; 80 var element, styles;
138
139 // TODO Refactor into 1 function
140 if(data) {
141 // Get Tag & CSS -- ~~ shortcut for ABS
142 element = this.makeElement(~~data.width, ~~data.height, data.planeMat, data.midPt, this.makeTag());
143 81
144 // Insert Element 82 // Create the element
145 this.application.ninja.elementMediator.addElements(element.el, element.data); 83 if(this.options.selectedElement === "custom") {
84 element = document.application.njUtils.make(this.options.customName.value, null, this.application.ninja.currentDocument);
146 } else { 85 } else {
147 element = this.makeStaticElement(this.makeTag()); 86 element = document.application.njUtils.make(this.options.selectedElement, null, this.application.ninja.currentDocument);
148 this._insertStatic(this.editSymbol, element.el, element.style);
149 }
150
151 }
152 },
153
154 makeTag: {
155 value: function() {
156 var selectedTag, newTag;
157
158 selectedTag = this.options.selectedElement;
159
160 if(selectedTag === "divTool") {
161 newTag = NJUtils.makeNJElement("div", "div", "block");
162 } else if(selectedTag === "imageTool") {
163 newTag = NJUtils.makeNJElement("image", "image", "image");
164 } else if(selectedTag === "videoTool") {
165 newTag = NJUtils.makeNJElement("video", "video", "video", {
166 innerHTML: "Your browser does not support the VIDEO element."
167 });
168 } else if(selectedTag === "canvasTool") {
169 newTag = NJUtils.makeNJElement("canvas", "canvas", "canvas");
170 } else if(selectedTag === "customTool") {
171 newTag = NJUtils.makeNJElement(this.options.customName.value, this.options.customName.value, "block");
172 }
173 /* SWF Tag tool - Not used for now. Will revisit this at a later time.
174 else if(selectedTag === "flashTool") {
175 // Generate the swfobject script tag if not found in the user document
176// documentControllerModule.DocumentController.SetSWFObjectScript();
177
178 newTag = NJUtils.makeNJElement("object", "Object", "block", {
179 classId: "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
180 });
181
182 var param = NJUtils.makeNJElement("param", "Object", "block", {
183 name: "movie",
184 value: ""
185 });
186
187 var param2 = NJUtils.makeNJElement("param", "Object","block", {
188 name: "wmode",
189 value: "transparent"
190 });
191
192 var param3 = NJUtils.makeNJElement("param", "Object","block", {
193 name: "play",
194 value: "false"
195 });
196
197
198 newTag.appendChild(param);
199 newTag.appendChild(param2);
200 newTag.appendChild(param3);
201 // TODO Alternative Content
202
203 }
204 */
205 else {
206 console.log("Invalid Tool is selected.");
207 } 87 }
208 88
209 try { 89 // Create the model
210// newTag.className = this.options.classField.value; 90 document.application.njUtils.createModel(element);
211 // TODO: Fix this one
212 91
213 } 92 // Create the styles
214 93 styles = document.application.njUtils.stylesFromDraw(element, ~~drawData.width, ~~drawData.height, drawData);
215 catch(err) {
216 console.log("Could not set Tag ID/Class " + err.description);
217 }
218
219 return newTag;
220 }
221 },
222
223 makeElement: {
224 value: function(w, h, planeMat, midPt, tag, isShape) {
225 var left = Math.round(midPt[0] - 0.5 * w);
226 var top = Math.round(midPt[1] - 0.5 * h);
227
228 var styles = {
229 'position': 'absolute',
230 'top' : top + 'px',
231 'left' : left + 'px'
232 };
233
234 if(!MathUtils.isIdentityMatrix(planeMat)) {
235 styles['-webkit-transform-style'] = 'preserve-3d';
236 styles['-webkit-transform'] = DrawingToolBase.getElementMatrix(planeMat, midPt);
237 } else if(isShape) {
238 styles['-webkit-transform-style'] = 'preserve-3d';
239 }
240 94
241 // TODO - for canvas, set both as style and attribute. 95 // Add color
242 // Otherwise, we need to create a separate controller for canvas elements 96 if(this.options.getProperty("fill.colorMode") !== "nocolor") {
243 if(tag.tagName === "CANVAS") { 97 styles['background-color'] = this.options.getProperty("fill.color.css");
244 tag.width = w;
245 tag.height = h;
246 } else {
247 styles['width'] = w + 'px';
248 styles['height'] = h + 'px';
249 } 98 }
250 99