aboutsummaryrefslogtreecommitdiff
path: root/js/tools/TagTool.js
diff options
context:
space:
mode:
authorhwc4872012-05-11 13:52:55 -0700
committerhwc4872012-05-11 13:52:55 -0700
commit137bfc9d4c41cc918d969565bec28a834fe10472 (patch)
treee9fa109fc65218f45e386df48b713ff5858f3d62 /js/tools/TagTool.js
parentd21aaca3d7093b6af968b7f9f764ab54e004f02b (diff)
parent27f4cacb39de1c2e3910748dadc9fc16d0655480 (diff)
downloadninja-137bfc9d4c41cc918d969565bec28a834fe10472.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: js/lib/geom/geom-obj.js js/lib/geom/rectangle.js js/tools/TagTool.js
Diffstat (limited to 'js/tools/TagTool.js')
-rwxr-xr-xjs/tools/TagTool.js218
1 files changed, 23 insertions, 195 deletions
diff --git a/js/tools/TagTool.js b/js/tools/TagTool.js
index 807d5139..43a774e1 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,202 +66,36 @@ 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 } 70 }
84 }
85 },
86 71
87 HandleDoubleClick: { 72 this._isDrawing = false;
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 } 73 }
97 }, 74 },
98 75
99 /* This will overwrite the existing function in drawing tool. Do not uncomment 76 // TODO: Fix Classname
100 HandleKeyPress: { 77 // TODO: Add position support
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 }
111 }
112 },
113
114
115 HandleKeyUp: {
116 value: function(event) {
117 if(event.keyCode === 93 || event.keyCode === 91) { // Command Keycode
118 this.editSymbol = null;
119 }
120 }
121 },
122 */
123
124 Configure: {
125 value: function(wasSelected) {
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
144 // Insert Element
145 this.application.ninja.elementMediator.addElements(element.el, element.data);
146 } else {
147 element = this.makeStaticElement(this.makeTag());
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 81
82 // Create the element
83 if(this.options.selectedElement === "custom") {
84 element = document.application.njUtils.make(this.options.customName.value, null, this.application.ninja.currentDocument);
160 if (!NJUtils) NJUtils = require("js/lib/NJUtils").NJUtils; 85 if (!NJUtils) NJUtils = require("js/lib/NJUtils").NJUtils;
161 86
162 if(selectedTag === "divTool") {
163 newTag = NJUtils.makeNJElement("div", "div", "block");
164 } else if(selectedTag === "imageTool") {
165 newTag = NJUtils.makeNJElement("image", "image", "image");
166 } else if(selectedTag === "videoTool") {
167 newTag = NJUtils.makeNJElement("video", "video", "video", {
168 innerHTML: "Your browser does not support the VIDEO element."
169 });
170 } else if(selectedTag === "canvasTool") {
171 newTag = NJUtils.makeNJElement("canvas", "canvas", "canvas");
172 } else if(selectedTag === "customTool") {
173 newTag = NJUtils.makeNJElement(this.options.customName.value, this.options.customName.value, "block");
174 }
175 /* SWF Tag tool - Not used for now. Will revisit this at a later time.
176 else if(selectedTag === "flashTool") {
177 // Generate the swfobject script tag if not found in the user document
178// documentControllerModule.DocumentController.SetSWFObjectScript();
179
180 newTag = NJUtils.makeNJElement("object", "Object", "block", {
181 classId: "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
182 });
183
184 var param = NJUtils.makeNJElement("param", "Object", "block", {
185 name: "movie",
186 value: ""
187 });
188
189 var param2 = NJUtils.makeNJElement("param", "Object","block", {
190 name: "wmode",
191 value: "transparent"
192 });
193
194 var param3 = NJUtils.makeNJElement("param", "Object","block", {
195 name: "play",
196 value: "false"
197 });
198
199
200 newTag.appendChild(param);
201 newTag.appendChild(param2);
202 newTag.appendChild(param3);
203 // TODO Alternative Content
204
205 }
206 */
207 else {
208 console.log("Invalid Tool is selected.");
209 }
210
211 try {
212// newTag.className = this.options.classField.value;
213 // TODO: Fix this one
214
215 }
216
217 catch(err) {
218 console.log("Could not set Tag ID/Class " + err.description);
219 }
220
221 return newTag;
222 }
223 },
224
225 makeElement: {
226 value: function(w, h, planeMat, midPt, tag, isShape) {
227 var left = Math.round(midPt[0] - 0.5 * w);
228 var top = Math.round(midPt[1] - 0.5 * h);
229
230 var styles = {
231 'position': 'absolute',
232 'top' : top + 'px',
233 'left' : left + 'px'
234 };
235
236 if(!MathUtils.isIdentityMatrix(planeMat)) {
237 styles['-webkit-transform-style'] = 'preserve-3d';
238 styles['-webkit-transform'] = DrawingToolBase.getElementMatrix(planeMat, midPt);
239 } else if(isShape) {
240 styles['-webkit-transform-style'] = 'preserve-3d';
241 }
242
243 // TODO - for canvas, set both as style and attribute.
244 // Otherwise, we need to create a separate controller for canvas elements
245 if(tag.tagName === "CANVAS") {
246 tag.width = w;
247 tag.height = h;
248 } else { 87 } else {
249 styles['width'] = w + 'px'; 88 element = document.application.njUtils.make(this.options.selectedElement, null, this.application.ninja.currentDocument);
250 styles['height'] = h + 'px';
251 } 89 }
252 90
253 return {el: tag, data:styles}; 91 // Create the model
254</