diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/ninja.reel/ninja.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/ninja.reel/ninja.js')
-rw-r--r-- | js/ninja.reel/ninja.js | 249 |
1 files changed, 249 insertions, 0 deletions
diff --git a/js/ninja.reel/ninja.js b/js/ninja.reel/ninja.js new file mode 100644 index 00000000..bc31e0e1 --- /dev/null +++ b/js/ninja.reel/ninja.js | |||
@@ -0,0 +1,249 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage/core/core").Montage, | ||
8 | Component = require("montage/ui/component").Component, | ||
9 | AppData = require("js/data/appdata").AppData; | ||
10 | |||
11 | exports.Ninja = Montage.create(Component, { | ||
12 | |||
13 | _appLoaded: { value: false }, | ||
14 | _preload: { value: false }, | ||
15 | |||
16 | toolsData: { value: null }, | ||
17 | appData: { value: AppData }, | ||
18 | |||
19 | currentDocument: { | ||
20 | value: null | ||
21 | }, | ||
22 | |||
23 | selectedElements: { | ||
24 | value: [] | ||
25 | }, | ||
26 | |||
27 | currentSelectedContainer: { | ||
28 | value: null | ||
29 | }, | ||
30 | |||
31 | templateDidLoad: { | ||
32 | value: function() { | ||
33 | this.eventManager.addEventListener( "preloadFinish", this, false); | ||
34 | } | ||
35 | }, | ||
36 | |||
37 | prepareForDraw: { | ||
38 | value: function() { | ||
39 | |||
40 | this.application.ninja = this; | ||
41 | |||
42 | this.toolsData.selectedTool = this.toolsData.defaultToolsData[0]; | ||
43 | this.toolsData.defaultSubToolsData = this.toolsData.defaultToolsData[7].subtools; | ||
44 | this.toolsData.selectedSubTool = this.toolsData.defaultToolsData[7].subtools[1]; | ||
45 | this.toolsData.selectedToolInstance = this.toolsList[this.toolsData.selectedTool.action]; | ||
46 | |||
47 | this.setupGlobalHelpers(); | ||
48 | |||
49 | window.addEventListener("resize", this, false); | ||
50 | |||
51 | this.eventManager.addEventListener( "appLoading", this, false); | ||
52 | this.eventManager.addEventListener( "selectTool", this, false); | ||
53 | this.eventManager.addEventListener( "selectSubTool", this, false); | ||
54 | this.eventManager.addEventListener( "onOpenDocument", this, false); | ||
55 | |||
56 | this.addEventListener("change@appModel.livePreview", this.executeLivePreview, false); | ||
57 | this.addEventListener("change@appModel.debug", this.toggleDebug, false); | ||
58 | |||
59 | NJevent("appLoading"); | ||
60 | } | ||
61 | }, | ||
62 | |||
63 | handleResize: { | ||
64 | value: function() { | ||
65 | this.stage.resizeCanvases = true; | ||
66 | } | ||
67 | }, | ||
68 | |||
69 | handlePreloadFinish: { | ||
70 | value: function(e) { | ||
71 | this._preload = true; | ||
72 | this.appLoaded(); | ||
73 | } | ||
74 | }, | ||
75 | |||
76 | handleAppLoading: { | ||
77 | value: function(e) { | ||
78 | this._appLoaded = true; | ||
79 | this.appLoaded(); | ||
80 | } | ||
81 | }, | ||
82 | |||
83 | appLoaded: { | ||
84 | value: function() { | ||
85 | if(this._appLoaded && this._preload) { | ||
86 | // App is now deserialized and files are preloaded | ||
87 | this.appModel.materials = MaterialsLibrary.materials; | ||
88 | } | ||
89 | } | ||
90 | }, | ||
91 | |||
92 | didDraw: { | ||
93 | value: function() { | ||
94 | NJevent("appLoaded"); | ||
95 | } | ||
96 | }, | ||
97 | |||
98 | handleSelectTool: { | ||
99 | value: function(event) { | ||
100 | |||
101 | this.toolsData.defaultToolsData[this.toolsData.defaultToolsData.indexOf(this.toolsData.selectedTool)].selected = false; | ||
102 | |||
103 | if(this.toolsData.selectedTool.container) { | ||
104 | this.toolsList[this.toolsData.selectedSubTool.action]._configure(false); | ||
105 | } else { | ||
106 | this.toolsList[this.toolsData.selectedTool.action]._configure(false); | ||
107 | } | ||
108 | |||
109 | this.toolsData.selectedTool = event.detail; | ||
110 | |||
111 | this.toolsData.defaultToolsData[this.toolsData.defaultToolsData.indexOf(this.toolsData.selectedTool)].selected = true; | ||
112 | |||
113 | if(this.toolsData.selectedTool.container) { | ||
114 | this.toolsData.selectedToolInstance = this.toolsList[this.toolsData.selectedSubTool.action]; | ||
115 | } else { | ||
116 | this.toolsData.selectedToolInstance = this.toolsList[this.toolsData.selectedTool.action]; | ||
117 | } | ||
118 | |||
119 | this.stage.SelectTool(this.toolsData.selectedTool.cursor); | ||
120 | this.toolsData.selectedToolInstance._configure(true); | ||
121 | |||
122 | } | ||
123 | }, | ||
124 | |||
125 | handleSelectSubTool: { | ||
126 | value: function(event) { | ||
127 | |||
128 | this.toolsData.defaultSubToolsData[this.toolsData.defaultSubToolsData.indexOf(this.toolsData.selectedSubTool)].selected = false; | ||
129 | |||
130 | this.toolsList[this.toolsData.selectedSubTool.action]._configure(false); | ||
131 | |||
132 | this.toolsData.selectedSubTool = event.detail; | ||
133 | |||
134 | this.toolsData.defaultSubToolsData[this.toolsData.defaultSubToolsData.indexOf(this.toolsData.selectedSubTool)].selected = true; | ||
135 | this.toolsData.selectedToolInstance = this.toolsList[this.toolsData.selectedSubTool.action]; | ||
136 | |||
137 | this.toolsList[this.toolsData.selectedSubTool.action]._configure(true); | ||
138 | |||
139 | } | ||
140 | }, | ||
141 | |||
142 | handleOnOpenDocument: { | ||
143 | value: function(event) { | ||
144 | this.currentDocument = event.detail; | ||
145 | |||
146 | this.appModel.show3dGrid = this.currentDocument.draw3DGrid; | ||
147 | |||
148 | this.currentDocument._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); | ||
149 | |||
150 | |||
151 | NJevent("openDocument"); | ||
152 | } | ||
153 | }, | ||
154 | |||
155 | userTemplateDidLoad: { | ||
156 | value: function(){ | ||
157 | this.currentSelectedContainer = this.currentDocument.documentRoot; | ||
158 | } | ||
159 | }, | ||
160 | |||
161 | handleLivePreview: { | ||
162 | value: function(event) { | ||
163 | |||
164 | } | ||
165 | }, | ||
166 | |||
167 | executeLivePreview: { | ||
168 | value: function() { | ||
169 | var background, overflow, transitionStopRule; | ||
170 | this.stage.hideCanvas(this.appModel.livePreview); | ||
171 | |||
172 | if(this.appModel.livePreview) { | ||
173 | background = "#000000"; | ||
174 | overflow = "hidden"; | ||
175 | transitionStopRule = "nj-css-garbage-selector"; | ||
176 | } else { | ||
177 | background = "#808080"; | ||
178 | overflow = "visible"; | ||
179 | transitionStopRule = "*" | ||
180 | } | ||
181 | |||
182 | this.currentDocument.documentRoot.elementModel.controller.setProperty(this.currentDocument.documentRoot, "background", background); | ||
183 | this.currentDocument.documentRoot.elementModel.controller.setProperty(this.currentDocument.documentRoot, "overflow", overflow); | ||
184 | this.currentDocument.documentRoot.elementModel.controller.changeSelector(this.currentDocument.documentRoot, "transitionStopRule", transitionStopRule); | ||
185 | |||
186 | } | ||
187 | }, | ||
188 | |||
189 | // Property to hold the js console.log function when restoring it | ||
190 | consoleLog: { value: null }, | ||
191 | toggleDebug: { | ||
192 | value: function() { | ||
193 | if(!this.consoleLog) this.consoleLog = console.log; | ||
194 | |||
195 | this.appModel.debug ? console.log = this.consoleLog : console.log = function() {}; | ||
196 | } | ||
197 | }, | ||
198 | |||
199 | getCurrentToolInstance: { | ||
200 | value: function() { | ||
201 | if(this.toolsData.selectedTool.container) { | ||
202 | return this.toolsList[this.toolsData.selectedSubTool.action]; | ||
203 | } else { | ||
204 | return this.toolsList[this.toolsData.selectedTool.action]; | ||
205 | } | ||
206 | } | ||
207 | }, | ||
208 | |||
209 | _handleAppLoaded: { | ||
210 | value: function(event){ | ||
211 | |||
212 | /* | ||
213 | Object.defineBinding(docBar, "type", { | ||
214 | boundObject: DocumentManagerModule.DocumentManager, | ||
215 | boundObjectPropertyPath: "activeDocument.documentType" | ||
216 | }); | ||
217 | |||
218 | Object.defineBinding(docBar, "currentView", { | ||
219 | boundObject: DocumentManagerModule.DocumentManager, | ||
220 | boundObjectPropertyPath: "activeDocument.currentView", | ||
221 | oneway: false | ||
222 | }); | ||
223 | |||
224 | Object.defineBinding(docBar, "zoomFactor", { | ||
225 | boundObject: DocumentManagerModule.DocumentManager, | ||
226 | boundObjectPropertyPath: "activeDocument.zoomFactor", | ||
227 | oneway: false | ||
228 | }); | ||
229 | */ | ||
230 | |||
231 | } | ||
232 | }, | ||
233 | |||
234 | setupGlobalHelpers: { | ||
235 | value: function() { | ||
236 | |||
237 | var self = this; | ||
238 | |||
239 | NJevent = function( id, data ){ | ||
240 | |||
241 | var newEvent = document.createEvent( "CustomEvent" ); | ||
242 | newEvent.initCustomEvent( id, false, true, data ); | ||
243 | self.eventManager.dispatchEvent( newEvent ); | ||
244 | |||
245 |