aboutsummaryrefslogtreecommitdiff
path: root/js/stage
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-05-23 16:09:22 -0700
committerNivesh Rajbhandari2012-05-23 16:09:22 -0700
commitf97590388467b5a3316f6f155162fc293915fddc (patch)
treea2888e65b53704caeb9f4f84d5a85dbdb19e4ff6 /js/stage
parentf1dbf7c58e91a27c80f3a607e87ad122d803c500 (diff)
downloadninja-f97590388467b5a3316f6f155162fc293915fddc.tar.gz
Fixed scrolling and centering stage code. Also, moved liveNodeList into the design view and added an option to exclude styles and text nodes when retrieving the live nodes.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/stage')
-rwxr-xr-xjs/stage/layout.js11
-rwxr-xr-xjs/stage/stage-deps.js50
-rwxr-xr-xjs/stage/stage.reel/stage.js60
3 files changed, 40 insertions, 81 deletions
diff --git a/js/stage/layout.js b/js/stage/layout.js
index 9c5e2167..107e8abf 100755
--- a/js/stage/layout.js
+++ b/js/stage/layout.js
@@ -64,10 +64,10 @@ exports.Layout = Montage.create(Component, {
64 if(this.application.ninja.documentController.activeDocument.currentView === "design") { 64 if(this.application.ninja.documentController.activeDocument.currentView === "design") {
65 this.elementsToDraw = this.application.ninja.documentController.activeDocument.documentRoot.childNodes; 65 this.elementsToDraw = this.application.ninja.documentController.activeDocument.documentRoot.childNodes;
66 } 66 }
67 67//
68 // Draw the elements and the 3d info 68// // Draw the elements and the 3d info
69 this.draw(); 69// this.draw();
70 this.draw3DInfo(false); 70// this.draw3DInfo(false);
71 } 71 }
72 }, 72 },
73 73
@@ -89,7 +89,8 @@ exports.Layout = Montage.create(Component, {
89 89
90 if(this.application.ninja.documentController.activeDocument.currentView === "design"){ 90 if(this.application.ninja.documentController.activeDocument.currentView === "design"){
91 // Make an array copy of the line node list which is not an array like object 91 // Make an array copy of the line node list which is not an array like object
92 this.domTree = Array.prototype.slice.call(this.application.ninja.documentController.activeDocument._liveNodeList, 0); 92// this.domTree = Array.prototype.slice.call(this.application.ninja.documentController.activeDocument._liveNodeList, 0);
93 this.domTree = this.application.ninja.currentDocument.model.views.design.getLiveNodeList(true);
93 // Index of the current container 94 // Index of the current container
94 containerIndex = this.domTree.indexOf(this.application.ninja.currentSelectedContainer); 95 containerIndex = this.domTree.indexOf(this.application.ninja.currentSelectedContainer);
95 96
diff --git a/js/stage/stage-deps.js b/js/stage/stage-deps.js
index 0d53696b..d018b03b 100755
--- a/js/stage/stage-deps.js
+++ b/js/stage/stage-deps.js
@@ -26,38 +26,12 @@ exports.StageDeps = Montage.create(Component, {
26 value: drawUtils 26 value: drawUtils
27 }, 27 },
28 28
29 _userContentLeft: {
30 value: null
31 },
32
33 userContentLeft: {
34 get: function() { return this._userContentLeft; },
35 set: function(value) {
36 if(value != null) {
37 viewUtils.setUserContentLeft(value);
38 }
39 }
40 },
41
42 _userContentTop: {
43 value: null
44 },
45
46 userContentTop: {
47 get: function() { return this._userContentTop; },
48 set: function(value) {
49 if(value != null) {
50 viewUtils.setUserContentTop(value);
51 }
52 }
53 },
54
55 deserializedFromTemplate: { 29 deserializedFromTemplate: {
56 value: function() { 30 value: function() {
57 31
58 this.eventManager.addEventListener("appLoaded", this, false); 32 this.eventManager.addEventListener("appLoaded", this, false);
59 this.eventManager.addEventListener("openDocument", this, false); 33// this.eventManager.addEventListener("openDocument", this, false);
60 this.eventManager.addEventListener("switchDocument", this, false); 34// this.eventManager.addEventListener("switchDocument", this, false);
61 35
62 // Initialize Deps 36 // Initialize Deps
63 // HACK 37 // HACK
@@ -76,19 +50,6 @@ exports.StageDeps = Montage.create(Component, {
76 50
77 handleAppLoaded: { 51 handleAppLoaded: {
78 value: function() { 52 value: function() {
79
80 Object.defineBinding(this, "userContentLeft", {
81 boundObject: this.stage,
82 boundObjectPropertyPath: "_userContentLeft",
83 oneway: true
84 });
85
86 Object.defineBinding(this, "userContentTop", {
87 boundObject: this.stage,
88 boundObjectPropertyPath: "_userContentTop",
89 oneway: true
90 });
91
92 // Setup the snap manager pointer to the app model 53 // Setup the snap manager pointer to the app model
93 snapManager.appModel = this.application.ninja.appModel; 54 snapManager.appModel = this.application.ninja.appModel;
94 // bind the snap properties to the snap manager 55 // bind the snap properties to the snap manager
@@ -105,7 +66,8 @@ exports.StageDeps = Montage.create(Component, {
105 66
106 workingPlane = [0,0,1,0]; 67 workingPlane = [0,0,1,0];
107 68
108 snapManager.reload2DCache(); 69// snapManager.reload2DCache();
70 snapManager._isCacheInvalid = true;
109 snapManager.setupDragPlaneFromPlane (workingPlane); 71 snapManager.setupDragPlaneFromPlane (workingPlane);
110 72
111 drawUtils.initializeFromDocument(); 73 drawUtils.initializeFromDocument();
@@ -116,9 +78,9 @@ exports.StageDeps = Montage.create(Component, {
116 value: function(){ 78 value: function(){
117 workingPlane = [0,0,1,0]; 79 workingPlane = [0,0,1,0];
118 80
81 snapManager._isCacheInvalid = true;
119 snapManager.setupDragPlaneFromPlane (workingPlane); 82 snapManager.setupDragPlaneFromPlane (workingPlane);
120 snapManager.reload2DCache(); 83// snapManager.reload2DCache();
121
122 84
123 drawUtils.initializeFromDocument(); 85 drawUtils.initializeFromDocument();
124 } 86 }
diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js
index 69cfa7ba..a3903ac7 100755
--- a/js/stage/stage.reel/stage.js
+++ b/js/stage/stage.reel/stage.js
@@ -235,14 +235,6 @@ exports.Stage = Montage.create(Component, {
235 this._context = this._canvas.getContext("2d"); 235 this._context = this._canvas.getContext("2d");
236 this._drawingContext= this._drawingCanvas.getContext("2d"); 236 this._drawingContext= this._drawingCanvas.getContext("2d");
237 237
238 this._scrollLeft = this._iframeContainer.scrollLeft;
239 this._scrollTop = this._iframeContainer.scrollTop;
240 this._userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder;
241 this._userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder;
242
243 // TODO: Fix the mouse wheel scroll
244 // this._canvas.addEventListener("mousewheel", this, false);
245
246 // Setup event listeners 238 // Setup event listeners
247 this._drawingCanvas.addEventListener("mousedown", this, false); 239 this._drawingCanvas.addEventListener("mousedown", this, false);
248 this._drawingCanvas.addEventListener("mouseup", this, false); 240 this._drawingCanvas.addEventListener("mouseup", this, false);
@@ -269,30 +261,38 @@ exports.Stage = Montage.create(Component, {
269 // Event details will contain the active document prior to opening a new one 261 // Event details will contain the active document prior to opening a new one
270 handleOpenDocument: { 262 handleOpenDocument: {
271 value: function(evt) { 263 value: function(evt) {
264 var designView = this.application.ninja.currentDocument.model.views.design;
265
272 this.hideCanvas(false); 266 this.hideCanvas(false);
273 267
274 // Recalculate the canvas sizes because of splitter resizing 268 // Recalculate the canvas sizes because of splitter resizing
275 this._canvas.width = this._layoutCanvas.width = this._drawingCanvas.width = this.element.offsetWidth - 11 ; 269 this._canvas.width = this._layoutCanvas.width = this._drawingCanvas.width = this.element.offsetWidth - 11 ;
276 this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11; 270 this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11;
277 271
278
279 this.userContentBorder = 0;
280
281 this._scrollLeft = 0;
282 this._scrollTop = 0;
283 this._userContentLeft = this._documentOffsetLeft;
284 this._userContentTop = this._documentOffsetTop;
285
286 this._maxHorizontalScroll = this.application.ninja.currentDocument.documentRoot.scrollWidth - this._canvas.width - 11; 272 this._maxHorizontalScroll = this.application.ninja.currentDocument.documentRoot.scrollWidth - this._canvas.width - 11;
287 this._maxVerticalScroll = this.application.ninja.currentDocument.documentRoot.scrollHeight - this._canvas.height - 11; 273 this._maxVerticalScroll = this.application.ninja.currentDocument.documentRoot.scrollHeight - this._canvas.height - 11;
288 this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addEventListener("scroll", this, false); 274 designView.iframe.contentWindow.addEventListener("scroll", this, false);
289
290 // TODO - We will need to modify this once we support switching between multiple documents
291 this.application.ninja.toolsData.selectedToolInstance._configure(true);
292 275
293 this.addPropertyChangeListener("appModel.show3dGrid", this, false); 276 this.addPropertyChangeListener("appModel.show3dGrid", this, false);
294 277
278 this.stageDeps.handleOpenDocument();
295 this.layout.handleOpenDocument(); 279 this.layout.handleOpenDocument();
280
281 if(designView._template) {
282 var initialLeft = parseInt((this.canvas.width - designView._template.size.width)/2);
283 var initialTop = parseInt((this.canvas.height - designView._template.size.height)/2);
284 if(initialLeft > this.documentOffsetLeft) {
285 this.userPaddingLeft = -initialLeft;
286 }
287 if(initialTop > this.documentOffsetTop) {
288 this.userPaddingTop = -initialTop;
289 }
290 }
291
292 this.centerStage();
293
294 // TODO - We will need to modify this once we support switching between multiple documents
295 this.application.ninja.toolsData.selectedToolInstance._configure(true);
296 } 296 }
297 }, 297 },
298 298
@@ -485,10 +485,7 @@ exports.Stage = Montage.create(Component, {
485 // Need to clear the snap cache and set up the drag plane 485 // Need to clear the snap cache and set up the drag plane
486 //snapManager.setupDragPlaneFromPlane( workingPlane ); 486 //snapManager.setupDragPlaneFromPlane( workingPlane );
487 this.stageDeps.snapManager._isCacheInvalid = true; 487 this.stageDeps.snapManager._isCacheInvalid = true;
488 488 this.updatedStage = true;
489 this.needsDraw = true;
490 this.layout.draw();
491 //this._toolsList.action("DrawHandles");
492 } 489 }
493 }, 490 },
494 491
@@ -517,16 +514,15 @@ exports.Stage = Montage.create(Component, {
517 */ 514 */
518 centerStage: { 515 centerStage: {
519 value: function() { 516 value: function() {
520 if(this.application.ninja.currentDocument.documentRoot.id === "UserContent") { 517 var designView = this.application.ninja.currentDocument.model.views.design;
521 this._iframeContainer.scrollLeft = this._documentOffsetLeft - (this._iframeContainer.offsetWidth - this.application.ninja.currentDocument.documentRoot.parentNode.offsetWidth)/2; 518 if(designView._template) {
522 this._iframeContainer.scrollTop = this._documentOffsetTop - (this._iframeContainer.offsetHeight - this.application.ninja.currentDocument.documentRoot.parentNode.offsetHeight)/2; 519 designView.document.body.scrollLeft = this._documentOffsetLeft - parseInt((this.canvas.width - designView._template.size.width)/2);