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.js116
1 files changed, 94 insertions, 22 deletions
diff --git a/js/stage/stage.reel/stage.js b/js/stage/stage.reel/stage.js
index b181dc70..cac99326 100755
--- a/js/stage/stage.reel/stage.js
+++ b/js/stage/stage.reel/stage.js
@@ -118,6 +118,9 @@ exports.Stage = Montage.create(Component, {
118 _userContentTop: { value: 0 }, 118 _userContentTop: { value: 0 },
119 _userContentBorder: { value: 0 }, 119 _userContentBorder: { value: 0 },
120 120
121 _maxHorizontalScroll: { value: 0 },
122 _maxVerticalScroll: { value: 0 },
123
121 documentRoot: { 124 documentRoot: {
122 get: function () { return this._documentRoot; }, 125 get: function () { return this._documentRoot; },
123 set: function(value) { this._documentRoot = value; } 126 set: function(value) { this._documentRoot = value; }
@@ -161,6 +164,60 @@ exports.Stage = Montage.create(Component, {
161 set: function(value) { this._userContentBorder = value; } 164 set: function(value) { this._userContentBorder = value; }
162 }, 165 },
163 166
167 _activeDocument : {
168 value : null,
169 enumerable : false
170 },
171
172 activeDocument : {
173 get : function() {
174 return this._activeDocument;
175 },
176 set : function(document) {
177 ///// If the document is null set default stylesheets to null
178
179 if(!document) {
180 return false;
181 }
182
183 ///// setting document via binding
184 this._activeDocument = document;
185
186 },
187 enumerable : false
188 },
189
190 _userPaddingLeft: { value: 0 },
191 _userPaddingTop: { value: 0 },
192
193 userPaddingLeft: {
194 get: function() { return this._userPaddingLeft; },
195 set: function(value) {
196 this._userPaddingLeft = value;
197 this._documentOffsetLeft = -value;
198 if(!this._documentRoot) {
199 this._documentRoot = this.application.ninja.currentDocument.documentRoot;
200 }
201 this._documentRoot.ownerDocument.getElementsByTagName("HTML")[0].style["padding-left"] = -value + "px";
202 this.userContentLeft = this._documentOffsetLeft;
203 this.updatedStage = true;
204 }
205 },
206
207 userPaddingTop: {
208 get: function() { return this._userPaddingTop; },
209 set: function(value) {
210 this._userPaddingTop = value;
211 this._documentOffsetTop = -value;
212 if(!this._documentRoot) {
213 this._documentRoot = this.application.ninja.currentDocument.documentRoot;
214 }
215 this._documentRoot.ownerDocument.getElementsByTagName("HTML")[0].style["padding-top"] = -value + "px";
216 this.userContentTop = this._documentOffsetTop;
217 this.updatedStage = true;
218 }
219 },
220
164 willDraw: { 221 willDraw: {
165 value: function() { 222 value: function() {
166 if(this.resizeCanvases) { 223 if(this.resizeCanvases) {
@@ -261,10 +318,12 @@ exports.Stage = Montage.create(Component, {
261 318
262 this._scrollLeft = 0; 319 this._scrollLeft = 0;
263 this._scrollTop = 0; 320 this._scrollTop = 0;
264 this._userContentLeft = 0; 321 this._userContentLeft = this._documentOffsetLeft;
265 this._userContentTop = 0; 322 this._userContentTop = this._documentOffsetTop;
266 323
267 this.application.ninja.currentDocument._window.addEventListener("scroll", this, false); 324 this._maxHorizontalScroll = this._documentRoot.scrollWidth - this._canvas.width - 11;
325 this._maxVerticalScroll = this._documentRoot.scrollHeight - this._canvas.height - 11;
326 this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addEventListener("scroll", this, false);
268 } 327 }
269 328
270 329
@@ -272,7 +331,7 @@ exports.Stage = Montage.create(Component, {
272 // TODO - We will need to modify this once we support switching between multiple documents 331 // TODO - We will need to modify this once we support switching between multiple documents
273 this.application.ninja.toolsData.selectedToolInstance._configure(true); 332 this.application.ninja.toolsData.selectedToolInstance._configure(true);
274 333
275 this.addEventListener("change@appModel.show3dGrid", this, false); 334 this.addPropertyChangeListener("appModel.show3dGrid", this, false);
276 335
277 this.layout.handleOpenDocument(); 336 this.layout.handleOpenDocument();
278 } 337 }
@@ -281,10 +340,9 @@ exports.Stage = Montage.create(Component, {
281 /** 340 /**
282 * Event handler for the change @ 3DGrid 341 * Event handler for the change @ 3DGrid
283 */ 342 */
284 handleEvent: { 343 handleChange: {
285 value: function(e) { 344 value: function(notification) {
286 if(e.type === "change@appModel.show3dGrid") { 345 if("appModel.show3dGrid" === notification.currentPropertyPath) {
287
288 if(this.appModel.show3dGrid) { 346 if(this.appModel.show3dGrid) {
289 347
290 drawUtils.drawXY = true; 348 drawUtils.drawXY = true;
@@ -382,9 +440,9 @@ exports.Stage = Montage.create(Component, {
382 handleMousewheel: { 440 handleMousewheel: {
383 value: function(event) { 441 value: function(event) {
384 if(event._event.wheelDelta > 0) { 442 if(event._event.wheelDelta > 0) {
385 this._iframeContainer.scrollTop -= 20; 443 this.application.ninja.currentDocument.model.views.design.document.body.scrollTop -= 20;
386 } else { 444 } else {
387 this._iframeContainer.scrollTop += 20; 445 this.application.ninja.currentDocument.model.views.design.document.body.scrollTop += 20;
388 } 446 }
389 } 447 }
390 }, 448 },
@@ -459,11 +517,17 @@ exports.Stage = Montage.create(Component, {
459 this.userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; 517 this.userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder;
460 this.userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; 518 this.userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder;
461 } else { 519 } else {
462 this._scrollLeft = this.application.ninja.currentDocument.documentRoot.scrollLeft; 520 this._scrollLeft = this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft;
463 this._scrollTop = this.application.ninja.currentDocument.documentRoot.scrollTop; 521 this._scrollTop = this.application.ninja.currentDocument.model.views.design.document.body.scrollTop;
522
523 this.userContentLeft = this._documentOffsetLeft - this._scrollLeft;
524 this.userContentTop = this._documentOffsetTop - this._scrollTop;
464 525
465 this.userContentLeft = -this._scrollLeft; 526 // TODO - scroll events are not dependable. We may need to use a timer to simulate
466 this.userContentTop = -this._scrollTop; 527 // scrollBegin and scrollEnd. For now, the Pan Tool will keep track of the stage's scroll values
528 // on mouse down.
529// this._maxHorizontalScroll = this._documentRoot.scrollWidth - this._canvas.width - 11;
530// this._maxVerticalScroll = this._documentRoot.scrollHeight - this._canvas.height - 11;
467 } 531 }
468 532
469 // Need to clear the snap cache and set up the drag plane 533 // Need to clear the snap cache and set up the drag plane
@@ -501,11 +565,16 @@ exports.Stage = Montage.create(Component, {
501 */ 565 */
502 centerStage: { 566 centerStage: {
503 value: function() { 567 value: function() {
504 this._iframeContainer.scrollLeft = this._documentOffsetLeft - (this._iframeContainer.offsetWidth - this._documentRoot.parentNode.offsetWidth)/2; 568 if(this.application.ninja.currentDocument.documentRoot.id === "UserContent") {
505 this._iframeContainer.scrollTop = this._documentOffsetTop - (this._iframeContainer.offsetHeight - this._documentRoot.parentNode.offsetHeight)/2; 569 this._iframeContainer.scrollLeft = this._documentOffsetLeft - (this._iframeContainer.offsetWidth - this._documentRoot.parentNode.offsetWidth)/2;
570 this._iframeContainer.scrollTop = this._documentOffsetTop - (this._iframeContainer.offsetHeight - this._documentRoot.parentNode.offsetHeight)/2;
506 571
507 this._scrollLeft = this._iframeContainer.scrollLeft; 572 this._scrollLeft = this._iframeContainer.scrollLeft;
508 this._scrollTop = this._iframeContainer.scrollTop; 573 this._scrollTop = this._iframeContainer.scrollTop;
574 } else {
575 this._scrollLeft = this._userContentLeft = this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft = 0;
576 this._scrollTop = this._userContentTop = this.application.ninja.currentDocument.model.views.design.document.body.scrollTop = 0;
577 }
509 } 578 }
510 }, 579 },
511 580
@@ -540,13 +609,16 @@ exports.Stage = Montage.create(Component, {
540 */ 609 */
541 getElement: { 610 getElement: {
542 value: function(position, selectable) { 611 value: function(position, selectable) {
543 var point, element; 612 var point, element,
613 docView = this.application.ninja.currentDocument.model.views.design;
544 614
545 point = webkitConvertPointFromPageToNode(this.canvas, new WebKitPoint(position.pageX, position.pageY)); 615 point = webkitConvertPointFromPageToNode(this.canvas, new WebKitPoint(position.pageX - docView.iframe.contentWindow.pageXOffset + this.documentOffsetLeft, position.pageY - docView.iframe.contentWindow.pageYOffset + this.documentOffsetTop));
546 element = this.application.ninja.currentDocument.GetElementFromPoint(point.x + this.scrollLeft,point.y + this.scrollTop); 616 element = this.application.ninja.currentDocument.model.views.design.getElementFromPoint(point.x - this.userContentLeft,point.y - this.userContentTop);
547 617
618 if(!element) debugger;
548 // workaround Chrome 3d bug 619 // workaround Chrome 3d bug
549 if(this.application.ninja.toolsData.selectedToolInstance._canSnap && this.application.ninja.currentDocument.inExclusion(element) !== -1) { 620 if(this.application.ninja.toolsData.selectedToolInstance._canSnap && this.application.ninja.currentDocument.inExclusion(element) !== -1) {
621 point = webkitConvertPointFromPageToNode(this.canvas, new WebKitPoint(position.pageX, position.pageY));
550 element = this.getElementUsingSnapping(point); 622 element = this.getElementUsingSnapping(point);
551 } 623 }
552 624
@@ -877,7 +949,7 @@ exports.Stage = Montage.create(Component, {
877 //TODO - Maybe move to mediator. 949 //TODO - Maybe move to mediator.
878 var newVal = value/100.0; 950 var newVal = value/100.0;
879 if (newVal >= 1) 951 if (newVal >= 1)
880 this.application.ninja.currentDocument.iframe.style.zoom = value/100; 952 this.application.ninja.currentDocument.model.views.design.iframe.style.zoom = value/100;
881 953
882 this.updatedStage = true; 954 this.updatedStage = true;
883 955