aboutsummaryrefslogtreecommitdiff
path: root/js/stage/stage.reel/stage.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/stage/stage.reel/stage.js')
-rwxr-xr-xjs/stage/stage.reel/stage.js255
1 files changed, 172 insertions, 83 deletions
diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js
index b181dc70..c7afb95c 100755
--- a/js/stage/stage.reel/stage.js
+++ b/js/stage/stage.reel/stage.js
@@ -108,7 +108,6 @@ exports.Stage = Montage.create(Component, {
108 // We will set this to false while moving objects to improve performance 108 // We will set this to false while moving objects to improve performance
109 showSelectionBounds: { value: true }, 109 showSelectionBounds: { value: true },
110 110
111 _documentRoot: { value: null },
112 _viewport: { value: null }, 111 _viewport: { value: null },
113 _documentOffsetLeft: { value: 0 }, 112 _documentOffsetLeft: { value: 0 },
114 _documentOffsetTop: { value: 0 }, 113 _documentOffsetTop: { value: 0 },
@@ -118,11 +117,6 @@ exports.Stage = Montage.create(Component, {
118 _userContentTop: { value: 0 }, 117 _userContentTop: { value: 0 },
119 _userContentBorder: { value: 0 }, 118 _userContentBorder: { value: 0 },
120 119
121 documentRoot: {
122 get: function () { return this._documentRoot; },
123 set: function(value) { this._documentRoot = value; }
124 },
125
126 viewport: { 120 viewport: {
127 get: function () { return this._viewport; }, 121 get: function () { return this._viewport; },
128 set: function(value) { this._viewport = value; } 122 set: function(value) { this._viewport = value; }
@@ -161,6 +155,54 @@ exports.Stage = Montage.create(Component, {
161 set: function(value) { this._userContentBorder = value; } 155 set: function(value) { this._userContentBorder = value; }
162 }, 156 },
163 157
158 _activeDocument : {
159 value : null,
160 enumerable : false
161 },
162
163 activeDocument : {
164 get : function() {
165 return this._activeDocument;
166 },
167 set : function(document) {
168 ///// If the document is null set default stylesheets to null
169
170 if(!document) {
171 return false;
172 }
173
174 ///// setting document via binding
175 this._activeDocument = document;
176
177 },
178 enumerable : false
179 },
180
181 _userPaddingLeft: { value: 0 },
182 _userPaddingTop: { value: 0 },
183
184 userPaddingLeft: {
185 get: function() { return this._userPaddingLeft; },
186 set: function(value) {
187 this._userPaddingLeft = value;
188 this._documentOffsetLeft = -value;
189 this.application.ninja.currentDocument.model.documentRoot.ownerDocument.getElementsByTagName("HTML")[0].style["padding-left"] = -value + "px";
190 this.userContentLeft = this._documentOffsetLeft;
191 this.updatedStage = true;
192 }
193 },
194
195 userPaddingTop: {
196 get: function() { return this._userPaddingTop; },
197 set: function(value) {
198 this._userPaddingTop = value;
199 this._documentOffsetTop = -value;
200 this.application.ninja.currentDocument.model.documentRoot.ownerDocument.getElementsByTagName("HTML")[0].style["padding-top"] = -value + "px";
201 this.userContentTop = this._documentOffsetTop;
202 this.updatedStage = true;
203 }
204 },
205
164 willDraw: { 206 willDraw: {
165 value: function() { 207 value: function() {
166 if(this.resizeCanvases) { 208 if(this.resizeCanvases) {
@@ -190,14 +232,6 @@ exports.Stage = Montage.create(Component, {
190 this._context = this._canvas.getContext("2d"); 232 this._context = this._canvas.getContext("2d");
191 this._drawingContext= this._drawingCanvas.getContext("2d"); 233 this._drawingContext= this._drawingCanvas.getContext("2d");
192 234
193 this._scrollLeft = this._iframeContainer.scrollLeft;
194 this._scrollTop = this._iframeContainer.scrollTop;
195 this._userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder;
196 this._userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder;
197
198 // TODO: Fix the mouse wheel scroll
199 // this._canvas.addEventListener("mousewheel", this, false);
200
201 // Setup event listeners 235 // Setup event listeners
202 this._drawingCanvas.addEventListener("mousedown", this, false); 236 this._drawingCanvas.addEventListener("mousedown", this, false);
203 this._drawingCanvas.addEventListener("mouseup", this, false); 237 this._drawingCanvas.addEventListener("mouseup", this, false);
@@ -211,6 +245,7 @@ exports.Stage = Montage.create(Component, {
211 245
212 246
213 this.eventManager.addEventListener( "openDocument", this, false); 247 this.eventManager.addEventListener( "openDocument", this, false);
248 this.eventManager.addEventListener( "switchDocument", this, false);
214 this.eventManager.addEventListener( "enableStageMove", this, false); 249 this.eventManager.addEventListener( "enableStageMove", this, false);
215 this.eventManager.addEventListener( "disableStageMove", this, false); 250 this.eventManager.addEventListener( "disableStageMove", this, false);
216 251
@@ -224,67 +259,75 @@ exports.Stage = Montage.create(Component, {
224 // Event details will contain the active document prior to opening a new one 259 // Event details will contain the active document prior to opening a new one
225 handleOpenDocument: { 260 handleOpenDocument: {
226 value: function(evt) { 261 value: function(evt) {
262 this.initWithDocument();
263 }
264 },
265
266 handleSwitchDocument: {
267 value: function(evt) {
268 this.initWithDocument(true);
269 }
270 },
271
272 initWithDocument: {
273 value: function(didSwitch) {
274 var designView = this.application.ninja.currentDocument.model.views.design;
275
227 this.hideCanvas(false); 276 this.hideCanvas(false);
228 277
229 // Recalculate the canvas sizes because of splitter resizing 278 // Recalculate the canvas sizes because of splitter resizing
230 this._canvas.width = this._layoutCanvas.width = this._drawingCanvas.width = this.element.offsetWidth - 11 ; 279 this._canvas.width = this._layoutCanvas.width = this._drawingCanvas.width = this.element.offsetWidth - 11 ;
231 this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11; 280 this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11;
232 281
233 this._documentRoot = this.application.ninja.currentDocument.documentRoot; 282 designView.iframe.contentWindow.addEventListener("scroll", this, false);
234 283
235 // Hardcode this value so that it does not fail for the new stage architecture 284 this.addPropertyChangeListener("appModel.show3dGrid", this, false);
236 // TODO: Remove marker for old template: NINJA-STAGE-REWORK
237 if(this.application.ninja.currentDocument.documentRoot.id === "UserContent") {
238 this._viewport = this.application.ninja.currentDocument.documentRoot.parentNode;
239 285
240 this.documentOffsetLeft = this._viewport.offsetLeft; 286 this._userPaddingLeft = 0;
241 this.documentOffsetTop = this._viewport.offsetTop; 287 this._userPaddingTop = 0;
242 288
243 // Center the stage 289 this._documentOffsetLeft = 0;
244 this.centerStage(); 290 this._documentOffsetTop = 0;
245 291
246 this._scrollLeft = this._iframeContainer.scrollLeft; 292 this._userContentLeft = 0;
247 this._scrollTop = this._iframeContainer.scrollTop; 293 this._userContentTop = 0;
248 this.application.ninja.currentDocument.savedLeftScroll = this._iframeContainer.scrollLeft;
249 this.application.ninja.currentDocument.savedTopScroll = this._iframeContainer.scrollTop;
250 294
251 this.userContentBorder = parseInt(this._documentRoot.elementModel.controller.getProperty(this._documentRoot, "border")); 295 this._scrollLeft = 0;
296 this._scrollTop = 0;
252 297
253 this._userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; 298 this.stageDeps.handleOpenDocument();
254 this._userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; 299 this.layout.handleOpenDocument();
255 300
256 this._iframeContainer.addEventListener("scroll", this, false); 301 if(designView._template) {
302 var initialLeft = parseInt((this.canvas.width - designView._template.size.width)/2);
303 var initialTop = parseInt((this.canvas.height - designView._template.size.height)/2);
304 if(initialLeft > this.documentOffsetLeft) {
305 this.userPaddingLeft = -initialLeft;
306 }
307 if(initialTop > this.documentOffsetTop) {
308 this.userPaddingTop = -initialTop;
309 }
310 }
257 311
258 this.application.ninja.currentDocument.iframe.style.opacity = 1.0; 312 if(didSwitch) {
313 this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft = this.application.ninja.currentDocument.model.scrollLeft;
314 this.application.ninja.currentDocument.model.views.design.document.body.scrollTop = this.application.ninja.currentDocument.model.scrollTop;
315 this.handleScroll();
259 } else { 316 } else {
260 this.userContentBorder = 0; 317 this.centerStage();
261
262 this._scrollLeft = 0;
263 this._scrollTop = 0;
264 this._userContentLeft = 0;
265 this._userContentTop = 0;
266
267 this.application.ninja.currentDocument._window.addEventListener("scroll", this, false);
268 } 318 }
269 319
270
271
272 // TODO - We will need to modify this once we support switching between multiple documents 320 // TODO - We will need to modify this once we support switching between multiple documents
273 this.application.ninja.toolsData.selectedToolInstance._configure(true); 321 this.application.ninja.toolsData.selectedToolInstance._configure(true);
274
275 this.addEventListener("change@appModel.show3dGrid", this, false);
276
277 this.layout.handleOpenDocument();
278 } 322 }
279 }, 323 },
280 324
281 /** 325 /**
282 * Event handler for the change @ 3DGrid 326 * Event handler for the change @ 3DGrid
283 */ 327 */
284 handleEvent: { 328 handleChange: {
285 value: function(e) { 329