From 75fe4f36a6768d688792bc1925cfa4bfa508ac3e Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 22 May 2012 18:02:01 -0700 Subject: Adding redirect from app folder in templates This doesn't resolve the issue of XHR requests made in Montage. --- js/controllers/document-controller.js | 3 ++- js/document/views/design.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index d99fadbb..2eba556e 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -80,6 +80,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]}; } else if (request.url.indexOf('js/document/templates/html') !== -1) { return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]}; + } else if (request.url.indexOf('js/document/templates/app') !== -1) { + return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/app/'))[1]}; } else { //Error, not a valid folder } @@ -103,7 +105,6 @@ var DocumentController = exports.DocumentController = Montage.create(Component, }, //////////////////////////////////////////////////////////////////// - diff --git a/js/document/views/design.js b/js/document/views/design.js index b3887fdf..6da1b2e4 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -105,6 +105,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { // onTemplateLoad: { value: function (e) { + //console.log(this.iframe.contentWindow); this.application.ninja.documentController._hackRootFlag = true; //TODO: Add support to constructing URL with a base HREF var basetag = this.content.document.getElementsByTagName('base'); -- cgit v1.2.3 From d5b36812ba84e49aa8b597eea9f75bf36ddcb571 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 23 May 2012 15:24:25 -0700 Subject: fixing the styles manager to open code view files and closing the last document. Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 15 ++++++--------- js/controllers/styles-controller.js | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 3e15511d..aa037bd4 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -399,10 +399,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, if(this._documents.length > 0) { previousFocusedDocument = this._documents[this._documents.length - 1]; - this._activeDocument = previousFocusedDocument; - this.switchDocuments(this.activeDocument, previousFocusedDocument, true); + this.activeDocument = previousFocusedDocument; + this.switchDocuments(this.activeDocument, previousFocusedDocument, false); } else { - this._activeDocument = null; + this.activeDocument = null; this.application.ninja.stage.hideRulers(); this.application.ninja.stage.hideCanvas(true); @@ -524,13 +524,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.application.ninja.stage.restoreAllPanels(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.showRulers(); - } else if(currentDocument.currentView === "design" && newDocument.currentView === "code") { - this.application.ninja.stage.showCodeViewBar(true); - this.application.ninja.stage.collapseAllPanels(); - this.application.ninja.stage.hideCanvas(true); - this.application.ninja.stage.hideRulers(); } - }else if(!currentDocument && newDocument.currentView === "code"){ + } + + if(newDocument.currentView === "code") { this.application.ninja.stage.showCodeViewBar(true); this.application.ninja.stage.collapseAllPanels(); this.application.ninja.stage.hideCanvas(true); diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index dcbe0eaf..8ceb9774 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -81,7 +81,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { set : function(document) { ///// If the document is null set default stylesheets to null - if(!document) { + if(!document || document.currentView === "code") { this._activeDocument = null; this._stageStylesheet = null; this.defaultStylesheet = null; -- cgit v1.2.3 From 0ca1910df1c78116139664bf39a95cf0ec7c8dc8 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 23 May 2012 15:35:15 -0700 Subject: adding document views checks for the timeline and breadcrumb Signed-off-by: Valerio Virgillito --- js/components/layout/bread-crumb.reel/bread-crumb.js | 2 +- js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/components/layout/bread-crumb.reel/bread-crumb.js b/js/components/layout/bread-crumb.reel/bread-crumb.js index d2a6b1e4..aaefd923 100755 --- a/js/components/layout/bread-crumb.reel/bread-crumb.js +++ b/js/components/layout/bread-crumb.reel/bread-crumb.js @@ -21,7 +21,7 @@ exports.Breadcrumb = Montage.create(Component, { handleCloseDocument: { value: function(){ - if(!this.application.ninja.documentController.activeDocument) { + if(!this.application.ninja.documentController.activeDocument && this.application.ninja.currentDocument.currentView !== "code") { this.disabled = true; this.application.ninja.currentSelectedContainer = (this.application.ninja.currentDocument ? this.application.ninja.currentDocument.documentRoot : null); } diff --git a/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js b/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js index 80133edf..2c02e544 100644 --- a/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js +++ b/js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js @@ -596,7 +596,7 @@ var TimelinePanel = exports.TimelinePanel = Montage.create(Component, { // That's all we need to do for a brand new file. // But what if we're opening an existing document? - if (!this.application.ninja.documentController.creatingNewFile) { + if (!this.application.ninja.documentController.creatingNewFile && this.application.ninja.currentDocument.currentView !== "code") { // Opening an existing document. If it has DOM elements we need to restore their timeline info if (this.application.ninja.currentDocument.documentRoot.children[0]) { // Yes, it has DOM elements. Loop through them and create a new object for each. -- cgit v1.2.3 From f97590388467b5a3316f6f155162fc293915fddc Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 23 May 2012 16:09:22 -0700 Subject: 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 --- js/document/document-html.js | 2 +- js/document/views/design.js | 42 ++++++++++++++++++++++++-- js/helper-classes/3D/draw-utils.js | 19 +++++++----- js/helper-classes/3D/view-utils.js | 13 ++------- js/stage/layout.js | 11 +++---- js/stage/stage-deps.js | 50 ++++--------------------------- js/stage/stage.reel/stage.js | 60 ++++++++++++++++++-------------------- 7 files changed, 95 insertions(+), 102 deletions(-) (limited to 'js') diff --git a/js/document/document-html.js b/js/document/document-html.js index f92a425c..2fc32791 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js @@ -98,7 +98,7 @@ exports.HtmlDocument = Montage.create(Component, { this.documentRoot = this.model.views.design.document.body; } //TODO: Why is this needed? - this._liveNodeList = this.documentRoot.getElementsByTagName('*'); + this.model.views.design._liveNodeList = this.documentRoot.getElementsByTagName('*'); //Initiliazing document model document.application.njUtils.makeElementModel(this.documentRoot, "Body", "body"); //Adding observer to know when template is ready diff --git a/js/document/views/design.js b/js/document/views/design.js index b3887fdf..427ef706 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -67,7 +67,43 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { propertiesPanel: { value: null }, + //////////////////////////////////////////////////////////////////// + // + _liveNodeList: { + value: null + }, + + getLiveNodeList: { + value: function(useFilter) { + if(useFilter) { + var filteredNodes = [], + childNodes = Array.prototype.slice.call(this._liveNodeList, 0); + + childNodes.forEach(function(item) { + if( (item.nodeType === 1) && (item.nodeName !== "STYLE") && (item.nodeName !== "SCRIPT")) { + filteredNodes.push(item); + } + }); + return filteredNodes; + } else { + return this._liveNodeList; + } + } + }, + //////////////////////////////////////////////////////////////////// + // + + initialPaddingLeft: { + value: 0 + }, + + initialPaddingTop: { + value: 0 + }, + //////////////////////////////////////////////////////////////////// + // + // initialize: { value: function (parent) { @@ -190,8 +226,10 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //Calling standard method to finish opening document this.bodyContentLoaded(null); //TODO: Move this to be set via the controller - this.application.ninja.stage.documentOffsetLeft = parseInt((this.document.body.scrollWidth - this._template.size.width)/2); - this.application.ninja.stage.documentOffsetTop = parseInt((this.document.body.scrollHeight - this._template.size.height)/2); +// this.application.ninja.stage.documentOffsetLeft = parseInt((this.document.body.scrollWidth - this._template.size.width)/2); +// this.application.ninja.stage.documentOffsetTop = parseInt((this.document.body.scrollHeight - this._template.size.height)/2); +// this.initialPaddingLeft = parseInt((this.document.body.scrollWidth - this._template.size.width)/2); +// this.initialPaddingTop = parseInt((this.document.body.scrollHeight - this._template.size.height)/2); } }, //////////////////////////////////////////////////////////////////// diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index bf48a723..79be5c14 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -119,7 +119,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { initializeFromDocument:{ value:function(){ - var documentRootChildren = null, i, stage = this.application.ninja.stage; + var i, + documentRootChildren = this.application.ninja.currentDocument.model.views.design.getLiveNodeList(true), + stage = this.application.ninja.stage, + len = documentRootChildren.length; //initialize with current document this._eltArray = []; this._planesArray = []; @@ -128,11 +131,11 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this.setWorkingPlane( [0,0,1,0] ); //Loop through all the top-level children of the current document and call drawUtils.addElement on them - if(this.application.ninja.currentDocument._liveNodeList.length > 0){ - documentRootChildren = this.application.ninja.currentDocument._liveNodeList; - var len = documentRootChildren.length, - minLeft = stage.userPaddingLeft, - minTop = stage.userPaddingTop, + if(len > 0) { + var initL = 0, + initT = 0, + minLeft = 0, + minTop = 0, docLeft = stage.documentOffsetLeft, docTop = stage.documentOffsetTop, l, @@ -151,10 +154,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { minTop = t; } } - if(minLeft !== stage.userPaddingLeft) { + if(minLeft !== initL) { stage.userPaddingLeft = minLeft; } - if(minTop !== stage.userPaddingTop) { + if(minTop !== initT) { stage.userPaddingTop = minTop; } } diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 0080bf90..24b30298 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js @@ -24,9 +24,6 @@ exports.ViewUtils = Montage.create(Component, { // keep a stack of viewport objects _viewportObjStack: { value: []}, - _userContentLeft: { value: null}, - _userContentTop: { value: null}, - /////////////////////////////////////////////////////////////////////// // Property accessors /////////////////////////////////////////////////////////////////////// @@ -39,9 +36,6 @@ exports.ViewUtils = Montage.create(Component, { }, getViewportObj: { value: function() { return this.m_viewportObj; } }, - setUserContentLeft: { value: function(value) { this._userContentLeft = value; }}, - setUserContentTop: { value: function(value) { this._userContentTop = value; }}, - getPerspectiveDistance: { value: function () { return this._perspectiveDist; } }, /////////////////////////////////////////////////////////////////////// @@ -385,7 +379,7 @@ exports.ViewUtils = Montage.create(Component, { // transform the bounds up the tree var parent = child.offsetParent; // TODO - Should have a different way to check for new template mode - if ( parent || ((child === this.application.ninja.currentDocument.documentRoot) && (child.id !== "UserContent")) ) + if ( parent || (child === this.application.ninja.currentDocument.documentRoot) ) { this.setViewportObj( child ); @@ -703,8 +697,8 @@ exports.ViewUtils = Montage.create(Component, { { // TODO - Call a routine from the user document controller to get the offsets/margins // Once we expose the document controller to ViewUtils - offset[0] += this._userContentLeft; - offset[1] += this._userContentTop; + offset[0] += this.application.ninja.stage._userContentLeft; + offset[1] += this.application.ninja.stage._userContentTop; } return offset; @@ -1282,7 +1276,6 @@ exports.ViewUtils = Montage.create(Component, { // stageManager._canvas: this.application.ninja.stage.canvas // stageManager.layoutCanvas: this.application.ninja.stage.layoutCanvas // stageManager.drawingCanvas: this.application.ninja.stage.drawingCanvas -// stageManager.userContentLeft this.application.ninja.stage.userContentLeft // viewUtils: stage.viewUtils; // snapManager stage.snapManager; // 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, { if(this.application.ninja.documentController.activeDocument.currentView === "design") { this.elementsToDraw = this.application.ninja.documentController.activeDocument.documentRoot.childNodes; } - - // Draw the elements and the 3d info - this.draw(); - this.draw3DInfo(false); +// +// // Draw the elements and the 3d info +// this.draw(); +// this.draw3DInfo(false); } }, @@ -89,7 +89,8 @@ exports.Layout = Montage.create(Component, { if(this.application.ninja.documentController.activeDocument.currentView === "design"){ // Make an array copy of the line node list which is not an array like object - this.domTree = Array.prototype.slice.call(this.application.ninja.documentController.activeDocument._liveNodeList, 0); +// this.domTree = Array.prototype.slice.call(this.application.ninja.documentController.activeDocument._liveNodeList, 0); + this.domTree = this.application.ninja.currentDocument.model.views.design.getLiveNodeList(true); // Index of the current container containerIndex = this.domTree.indexOf(this.application.ninja.currentSelectedContainer); 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, { value: drawUtils }, - _userContentLeft: { - value: null - }, - - userContentLeft: { - get: function() { return this._userContentLeft; }, - set: function(value) { - if(value != null) { - viewUtils.setUserContentLeft(value); - } - } - }, - - _userContentTop: { - value: null - }, - - userContentTop: { - get: function() { return this._userContentTop; }, - set: function(value) { - if(value != null) { - viewUtils.setUserContentTop(value); - } - } - }, - deserializedFromTemplate: { value: function() { this.eventManager.addEventListener("appLoaded", this, false); - this.eventManager.addEventListener("openDocument", this, false); - this.eventManager.addEventListener("switchDocument", this, false); +// this.eventManager.addEventListener("openDocument", this, false); +// this.eventManager.addEventListener("switchDocument", this, false); // Initialize Deps // HACK @@ -76,19 +50,6 @@ exports.StageDeps = Montage.create(Component, { handleAppLoaded: { value: function() { - - Object.defineBinding(this, "userContentLeft", { - boundObject: this.stage, - boundObjectPropertyPath: "_userContentLeft", - oneway: true - }); - - Object.defineBinding(this, "userContentTop", { - boundObject: this.stage, - boundObjectPropertyPath: "_userContentTop", - oneway: true - }); - // Setup the snap manager pointer to the app model snapManager.appModel = this.application.ninja.appModel; // bind the snap properties to the snap manager @@ -105,7 +66,8 @@ exports.StageDeps = Montage.create(Component, { workingPlane = [0,0,1,0]; - snapManager.reload2DCache(); +// snapManager.reload2DCache(); + snapManager._isCacheInvalid = true; snapManager.setupDragPlaneFromPlane (workingPlane); drawUtils.initializeFromDocument(); @@ -116,9 +78,9 @@ exports.StageDeps = Montage.create(Component, { value: function(){ workingPlane = [0,0,1,0]; + snapManager._isCacheInvalid = true; snapManager.setupDragPlaneFromPlane (workingPlane); - snapManager.reload2DCache(); - +// snapManager.reload2DCache(); drawUtils.initializeFromDocument(); } 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, { this._context = this._canvas.getContext("2d"); this._drawingContext= this._drawingCanvas.getContext("2d"); - this._scrollLeft = this._iframeContainer.scrollLeft; - this._scrollTop = this._iframeContainer.scrollTop; - this._userContentLeft = this._documentOffsetLeft - this._scrollLeft + this._userContentBorder; - this._userContentTop = this._documentOffsetTop - this._scrollTop + this._userContentBorder; - - // TODO: Fix the mouse wheel scroll - // this._canvas.addEventListener("mousewheel", this, false); - // Setup event listeners this._drawingCanvas.addEventListener("mousedown", this, false); this._drawingCanvas.addEventListener("mouseup", this, false); @@ -269,30 +261,38 @@ exports.Stage = Montage.create(Component, { // Event details will contain the active document prior to opening a new one handleOpenDocument: { value: function(evt) { + var designView = this.application.ninja.currentDocument.model.views.design; + this.hideCanvas(false); // Recalculate the canvas sizes because of splitter resizing this._canvas.width = this._layoutCanvas.width = this._drawingCanvas.width = this.element.offsetWidth - 11 ; this._canvas.height = this._layoutCanvas.height = this._drawingCanvas.height = this.element.offsetHeight - 11; - - this.userContentBorder = 0; - - this._scrollLeft = 0; - this._scrollTop = 0; - this._userContentLeft = this._documentOffsetLeft; - this._userContentTop = this._documentOffsetTop; - this._maxHorizontalScroll = this.application.ninja.currentDocument.documentRoot.scrollWidth - this._canvas.width - 11; this._maxVerticalScroll = this.application.ninja.currentDocument.documentRoot.scrollHeight - this._canvas.height - 11; - this.application.ninja.currentDocument.model.views.design.iframe.contentWindow.addEventListener("scroll", this, false); - - // TODO - We will need to modify this once we support switching between multiple documents - this.application.ninja.toolsData.selectedToolInstance._configure(true); + designView.iframe.contentWindow.addEventListener("scroll", this, false); this.addPropertyChangeListener("appModel.show3dGrid", this, false); + this.stageDeps.handleOpenDocument(); this.layout.handleOpenDocument(); + + if(designView._template) { + var initialLeft = parseInt((this.canvas.width - designView._template.size.width)/2); + var initialTop = parseInt((this.canvas.height - designView._template.size.height)/2); + if(initialLeft > this.documentOffsetLeft) { + this.userPaddingLeft = -initialLeft; + } + if(initialTop > this.documentOffsetTop) { + this.userPaddingTop = -initialTop; + } + } + + this.centerStage(); + + // TODO - We will need to modify this once we support switching between multiple documents + this.application.ninja.toolsData.selectedToolInstance._configure(true); } }, @@ -485,10 +485,7 @@ exports.Stage = Montage.create(Component, { // Need to clear the snap cache and set up the drag plane //snapManager.setupDragPlaneFromPlane( workingPlane ); this.stageDeps.snapManager._isCacheInvalid = true; - - this.needsDraw = true; - this.layout.draw(); - //this._toolsList.action("DrawHandles"); + this.updatedStage = true; } }, @@ -517,16 +514,15 @@ exports.Stage = Montage.create(Component, { */ centerStage: { value: function() { - if(this.application.ninja.currentDocument.documentRoot.id === "UserContent") { - this._iframeContainer.scrollLeft = this._documentOffsetLeft - (this._iframeContainer.offsetWidth - this.application.ninja.currentDocument.documentRoot.parentNode.offsetWidth)/2; - this._iframeContainer.scrollTop = this._documentOffsetTop - (this._iframeContainer.offsetHeight - this.application.ninja.currentDocument.documentRoot.parentNode.offsetHeight)/2; - - this._scrollLeft = this._iframeContainer.scrollLeft; - this._scrollTop = this._iframeContainer.scrollTop; + var designView = this.application.ninja.currentDocument.model.views.design; + if(designView._template) { + designView.document.body.scrollLeft = this._documentOffsetLeft - parseInt((this.canvas.width - designView._template.size.width)/2); + designView.document.body.scrollTop = this._documentOffsetTop - parseInt((this.canvas.height - designView._template.size.height)/2); } else { - this._scrollLeft = this._userContentLeft = this.application.ninja.currentDocument.model.views.design.document.body.scrollLeft = 0; - this._scrollTop = this._userContentTop = this.application.ninja.currentDocument.model.views.design.document.body.scrollTop = 0; + designView.document.body.scrollLeft = this._documentOffsetLeft; + designView.document.body.scrollTop = this._documentOffsetTop; } + this.handleScroll(); } }, -- cgit v1.2.3 From 5914c5b2209c4b8daac4249bb76cda5c9314c4e6 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 24 May 2012 00:07:23 -0700 Subject: Cleaning up referencing to 'documentRoot' and '_document' Moved to reference new model in DOM architecture rework. This should not affect anything, just moving the references, and also the setting to the render methods in the design view. --- .../layout/bread-crumb.reel/bread-crumb.js | 4 +- js/controllers/document-controller.js | 2 +- js/controllers/selection-controller.js | 6 +- js/controllers/styles-controller.js | 36 +- js/document/_toDelete/html-document.js | 874 +++++++++++++++++++++ js/document/_toDelete/text-document.js | 198 +++++ js/document/document-html.js | 34 +- js/document/html-document.js | 874 --------------------- js/document/models/html.js | 5 + js/document/text-document.js | 198 ----- js/document/views/design.js | 8 + js/helper-classes/3D/draw-utils.js | 12 +- js/helper-classes/3D/snap-manager.js | 6 +- js/helper-classes/3D/view-utils.js | 44 +- js/mediators/element-mediator.js | 4 +- js/ninja.reel/ninja.js | 14 +- .../CSSPanel/CSSPanelBase.reel/CSSPanelBase.js | 2 +- .../Timeline/TimelinePanel.reel/TimelinePanel.js | 6 +- .../Timeline/TimelineTrack.reel/TimelineTrack.js | 4 +- .../components-panel.reel/components-panel.js | 4 +- js/panels/css-panel/styles-view-delegate.js | 2 +- js/panels/properties.reel/properties.js | 12 +- .../properties.reel/sections/custom.reel/custom.js | 2 +- .../sections/position-size.reel/position-size.js | 8 +- .../sections/three-d-view.reel/three-d-view.js | 2 +- js/stage/layout.js | 6 +- js/stage/stage.reel/stage.js | 28 +- js/stage/tool-handle.js | 4 +- js/tools/PanTool.js | 16 +- js/tools/Rotate3DToolBase.js | 12 +- js/tools/RotateStage3DTool.js | 8 +- js/tools/SelectionTool.js | 6 +- js/tools/Translate3DToolBase.js | 4 +- js/tools/ZoomTool.js | 2 +- js/tools/drawing-tool-base.js | 12 +- js/tools/modifier-tool-base.js | 8 +- 36 files changed, 1232 insertions(+), 1235 deletions(-) create mode 100755 js/document/_toDelete/html-document.js create mode 100755 js/document/_toDelete/text-document.js delete mode 100755 js/document/html-document.js delete mode 100755 js/document/text-document.js (limited to 'js') diff --git a/js/components/layout/bread-crumb.reel/bread-crumb.js b/js/components/layout/bread-crumb.reel/bread-crumb.js index d2a6b1e4..2db775eb 100755 --- a/js/components/layout/bread-crumb.reel/bread-crumb.js +++ b/js/components/layout/bread-crumb.reel/bread-crumb.js @@ -23,7 +23,7 @@ exports.Breadcrumb = Montage.create(Component, { value: function(){ if(!this.application.ninja.documentController.activeDocument) { this.disabled = true; - this.application.ninja.currentSelectedContainer = (this.application.ninja.currentDocument ? this.application.ninja.currentDocument.documentRoot : null); + this.application.ninja.currentSelectedContainer = (this.application.ninja.currentDocument ? this.application.ninja.currentDocument.model.documentRoot : null); } } }, @@ -65,7 +65,7 @@ exports.Breadcrumb = Montage.create(Component, { parentNode = this.container; - while(parentNode !== this.application.ninja.currentDocument.documentRoot) { + while(parentNode !== this.application.ninja.currentDocument.model.documentRoot) { this.containerElements.unshift({"node": parentNode, "nodeUuid":parentNode.uuid, "label": parentNode.nodeName}); parentNode = parentNode.parentNode; } diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 4edcff48..f84e4da5 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -475,7 +475,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.activeDocument = doc; // Initialize the documentRoot styles - this.initializeRootStyles(doc.documentRoot); + this.initializeRootStyles(doc.model.documentRoot); // Flag to stop stylesheet dirty event this._hackInitialStyles = false; diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js index 1092615a..7bef0db8 100755 --- a/js/controllers/selection-controller.js +++ b/js/controllers/selection-controller.js @@ -114,7 +114,7 @@ exports.SelectionController = Montage.create(Component, { value: function(event) { var selected = [], childNodes = [], self = this; - childNodes = this.application.ninja.currentDocument.documentRoot.childNodes; + childNodes = this.application.ninja.currentDocument.model.documentRoot.childNodes; childNodes = Array.prototype.slice.call(childNodes, 0); childNodes.forEach(function(item) { if(self.isNodeTraversable(item)) { @@ -256,10 +256,10 @@ exports.SelectionController = Montage.create(Component, { for(var i=0, uuid; this.application.ninja.selectedElements[i];i++) { // Check for multiple selection and excluding inner elements - if(item.parentNode && item.parentNode !== this.application.ninja.currentDocument.documentRoot) { + if(item.parentNode && item.parentNode !== this.application.ninja.currentDocument.model.documentRoot) { var outerElement = item.parentNode; - while(outerElement.parentNode && outerElement.parentNode !== this.application.ninja.currentDocument.documentRoot) { + while(outerElement.parentNode && outerElement.parentNode !== this.application.ninja.currentDocument.model.documentRoot) { outerElement = outerElement.parentNode; } diff --git a/js/controllers/styles-controller.js b/js/controllers/styles-controller.js index dcbe0eaf..04e87ba7 100755 --- a/js/controllers/styles-controller.js +++ b/js/controllers/styles-controller.js @@ -99,7 +99,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { // Setter will handle null case this.defaultStylesheet = this.getSheetFromElement(this.CONST.DEFAULT_SHEET_ID); - this.userStyleSheets = nj.toArray(document._document.styleSheets).filter(function(sheet) { + this.userStyleSheets = nj.toArray(document.model.views.design.document.styleSheets).filter(function(sheet) { return sheet !== this._stageStylesheet; }, this); @@ -132,7 +132,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { else if(this._activeDocument.model && this._activeDocument.model.views && this._activeDocument.model.views.design){ ///// Use the last stylesheet in the document as the default - var sheets = this._activeDocument._document.styleSheets, + var sheets = this._activeDocument.model.views.design.document.styleSheets, lastIndex = sheets.length-1; ///// If the only sheet is the stage stylesheet, this will be true @@ -887,7 +887,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getAnimationRuleWithName : { value: function(name, document) { - var doc = document || this._activeDocument._document, + var doc = document || this._activeDocument.model.views.design.document, animRules = this.getDocumentAnimationRules(doc), rule, i; @@ -909,7 +909,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getDocumentAnimationRules : { value: function(document) { - var sheets = (document) ? document.styleSheets : this._activeDocument._document.styleSheets, + var sheets = (document) ? document.styleSheets : this._activeDocument.model.views.design.document.styleSheets, rules = []; nj.toArray(sheets).forEach(function(sheet) { @@ -1272,7 +1272,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { createStylesheet : { value: function(id, document) { - var doc = document || this._activeDocument._document, + var doc = document || this._activeDocument.model.views.design.document, sheetElement, sheet; sheetElement = nj.make('style', { @@ -1329,7 +1329,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getSheetFromElement : { value : function(element, context) { - var doc = context || this._activeDocument._document, + var doc = context || this._activeDocument.model.views.design.document, el = (typeof element === 'string') ? nj.$(element, doc) : element; if(el && el.sheet) { @@ -1572,7 +1572,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { getStyleTest : function() { var properties = ['background-position', 'width', 'height']; - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); properties.forEach(function(prop) { console.log('Getting value for "' + prop + '": ' + stylesController.getElementStyle(el, prop, true)); @@ -1591,7 +1591,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { }); }, getMatchingRulesTest : function() { - var el = stylesController.activeDocument._document.getElementById('Div_1'), + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'), mRules; this.addRulesTest(); @@ -1606,7 +1606,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { ///// apply a new style using setElementStyle, and print out the new ///// value. - var el = stylesController.activeDocument._document.getElementById('Div_1'), + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'), bg; console.log('----- Set Element Style Test -----'); @@ -1631,14 +1631,14 @@ var stylesController = exports.StylesController = Montage.create(Component, { var rules = ['#UserContent div { background-color: blue }']; rules.forEach(function(rule) { stylesController.addRule(rule); }); - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); stylesController.setElementStyle(el, 'color', 'red'); ///// the #Div_1 rule created by tag tool should have the color style }, setElementStyle3Test : function() { ///// First, draw a div onto the stage - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); //// now add a multi-target rule overriding the bg color var rules = [ @@ -1655,14 +1655,14 @@ var stylesController = exports.StylesController = Montage.create(Component, { }, setGroupStyleTest : function() { ///// draw 2 divs on stage - var el1 = stylesController.activeDocument._document.getElementById('Div_1'); - var el2 = stylesController.activeDocument._document.getElementById('Div_2'); + var el1 = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); + var el2 = stylesController.activeDocument.model.views.design.document.getElementById('Div_2'); var dominantRule = stylesController.getDominantRuleForGroup([el1, el2], 'color'); }, setElementStylesTest : function() { ///// draw a div on stage - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); mRules = stylesController.getMatchingRules(el, true); mRules.forEach(function(rule) { @@ -1681,7 +1681,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { console.log('----- Create Override Rule Test -----'); - var el = stylesController.activeDocument._document.getElementById('Div_1'), + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'), rule = stylesController.addRule('#UserContent div { background-color: blue }'), override; @@ -1693,7 +1693,7 @@ var stylesController = exports.StylesController = Montage.create(Component, { }, deleteRulesTest : function() { // drag one div on stage - var el = stylesController.activeDocument._document.getElementById('Div_1'); + var el = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); this.addRulesTest(); mRules = stylesController.getMatchingRules(el, true); @@ -1705,8 +1705,8 @@ var stylesController = exports.StylesController = Montage.create(Component, { matchesElementsExclusivelyTest : function() { /// drag two divs on stage var rule = stylesController.addRule('#Div_1, #Div_3 { color:black; }'); - var el1 = stylesController.activeDocument._document.getElementById('Div_1'); - var el2 = stylesController.activeDocument._document.getElementById('Div_2'); + var el1 = stylesController.activeDocument.model.views.design.document.getElementById('Div_1'); + var el2 = stylesController.activeDocument.model.views.design.document.getElementById('Div_2'); console.log('Does rule match elements exclusively? ' + stylesController.matchesElementsExclusively(rule, [el1, el2])); } diff --git a/js/document/_toDelete/html-document.js b/js/document/_toDelete/html-document.js new file mode 100755 index 00000000..447d90e3 --- /dev/null +++ b/js/document/_toDelete/html-document.js @@ -0,0 +1,874 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +//////////////////////////////////////////////////////////////////////// +// +var Montage = require("montage/core/core").Montage, + TextDocument = require("js/document/text-document").TextDocument, + NJUtils = require("js/lib/NJUtils").NJUtils, + GLWorld = require("js/lib/drawing/world").World, + MaterialsModel = require("js/models/materials-model").MaterialsModel; +//////////////////////////////////////////////////////////////////////// +// +exports.HTMLDocument = Montage.create(TextDocument, { + + _selectionExclude: { value: null, enumerable: false }, + _htmlTemplateUrl: { value: "js/document/templates/montage-html/index.html", enumerable: false}, + _iframe: { value: null, enumerable: false }, + _server: { value: null, enumerable: false }, + _templateDocument: { value: null, enumerable: false }, + _selectionModel: { value: [], enumerable: false }, + _undoModel: { value: { "queue" : [], "position" : 0 }, enumerable: false}, + + _document: { value: null, enumerable: false }, + _documentRoot: { value: null, enumerable: false }, + _liveNodeList: { value: null, enumarable: false }, + _stageBG: { value: null, enumerable: false }, + _window: { value: null, enumerable: false }, + _styles: { value: null, enumerable: false }, + _stylesheets: { value: null, enumerable: false }, + _stageStyleSheetId : { value: 'nj-stage-stylesheet', enumerable: false }, + _userDocument: { value: null, enumerable: false }, + _htmlSource: {value: "", enumerable: false}, + _glData: {value: null, enumerable: false }, + _userComponents: { value: {}, enumarable: false}, + + _elementCounter: { value: 1, enumerable: false }, + _snapping : { value: true, enumerable: false }, + _layoutMode: { value: "all", enumerable: false }, + _draw3DGrid: { value: false, writable: true }, + _swfObject: { value: false, enumerable: false }, + + _zoomFactor: { value: 100, enumerable: false }, + + cssLoadInterval: { value: null, enumerable: false }, + + _savedLeftScroll: {value:null}, + _savedTopScroll: {value:null}, + + _codeViewDocument:{ + writable: true, + enumerable: true, + value:null + }, + + + //drawUtils state + _gridHorizontalSpacing: {value:0}, + _gridVerticalSpacing: {value:0}, + //end - drawUtils state + + _undoStack: { value: [] }, + undoStack: { + get: function() { + return this._undoStack; + }, + set:function(value){ + this._undoStack = value; + } + }, + + _redoStack: { value: [], enumerable: false }, + + redoStack: { + get: function() { + return this._redoStack; + }, + set:function(value){ + this._redoStack = value; + } + }, + + + // GETTERS / SETTERS + + codeViewDocument:{ + get: function() { return this._codeViewDocument; }, + set: function(value) { this._codeViewDocument = value} + }, + + savedLeftScroll:{ + get: function() { return this._savedLeftScroll; }, + set: function(value) { this._savedLeftScroll = value} + }, + + savedTopScroll:{ + get: function() { return this._savedTopScroll; }, + set: function(value) { this._savedTopScroll = value} + }, + + gridHorizontalSpacing:{ + get: function() { return this._gridHorizontalSpacing; }, + set: function(value) { this._gridHorizontalSpacing = value} + }, + + gridVerticalSpacing:{ + get: function() { return this._gridVerticalSpacing; }, + set: function(value) { this._gridVerticalSpacing = value} + }, + + selectionExclude: { + get: function() { return this._selectionExclude; }, + set: function(value) { this._selectionExclude = value; } + }, + + iframe: { + get: function() { return this._iframe; }, + set: function(value) { this._iframe = value; } + }, + + server: { + get: function() { return this._server; }, + set: function(value) { this._server = value; } + }, + + selectionModel: { + get: function() { return this._selectionModel; }, + set: function(value) { this._selectionModel = value; } + }, + + undoModel: { + get: function() { return this._undoModel; }, + set: function(value) { this._undoModel.queue = value.queue; this._undoModel.position = value.position; } + }, + + documentRoot: { + get: function() { return this._documentRoot; }, + set: function(value) { this._documentRoot = value; } + }, + + stageBG: { + get: function() { return this._stageBG; }, + set: function(value) { this._stageBG = value; } + }, + + elementCounter: { + set: function(value) { this._elementCounter = value; }, + get: function() { return this._elementCounter; } + }, + + snapping: { + get: function() { return this._snapping; }, + set: function(value) { + if(this._snapping !== value) { + this._snapping = value; + } + } + }, + + // TODO SEND THE EVENT --> Redraw the desired layout + layoutMode: { + get: function() { return this._layoutMode; }, + set: function(mode) { this._layoutMode = mode; } + }, + + draw3DGrid: { + get: function() { return this._draw3DGrid; }, + set: function(value) { + if(this._draw3DGrid !== value) { + this._draw3DGrid = value; + } + } + }, + + userComponents: { + get: function() { + return this._userComponents; + } + }, +// _drawUserComponentsOnOpen:{ +// value:function(){ +// for(var i in this._userComponentSet){ +// console.log(this._userComponentSet[i].control) +// this._userComponentSet[i].control.needsDraw = true; +// } +// } +// }, + + glData: { + get: function() { + // + var elt = this.iframe.contentWindow.document.getElementById("UserContent"); + // + if (elt) { + var matLib = MaterialsModel.exportMaterials(); + this._glData = [matLib]; + this.collectGLData(elt, this._glData ); + } else { + this._glData = null + } + // + return this._glData; + }, + set: function(value) { + var elt = this.documentRoot; + if (elt) + { + /* + // Use this code to test the runtime version of WebGL + var cvsDataMngr = Object.create(NinjaCvsRt.CanvasDataManager, {}); + cvsDataMngr.loadGLData(elt, value); + */ + + // /* + var nWorlds= value.length; + for (var i=0; i= 0) { + var endIndex = importStr.indexOf( "\n", startIndex ); + if (endIndex > 0) + id = importStr.substring( startIndex+4, endIndex ); + } + } + } + + if (id != null) + { + var canvas = this.findCanvasWithID( id, elt ); + if (canvas) + { + if (!canvas.elementModel) + { + NJUtils.makeElementModel(canvas, "Canvas", "shape", true); + } + if (canvas.elementModel) + { + if (canvas.elementModel.shapeModel.GLWorld) + canvas.elementModel.shapeModel.GLWorld.clearTree(); + + if (jObj) + { + var useWebGL = jObj.webGL; + var world = new GLWorld( canvas, useWebGL ); + world.importJSON( jObj ); + } + + this.buildShapeModel( canvas.elementModel, world ); + } + } + } + } + // */ + } + } + }, + + buildShapeModel: + { + value: function( elementModel, world ) + { + var shapeModel = elementModel.shapeModel; + shapeModel.shapeCount = 1; // for now... + shapeModel.useWebGl = world._useWebGL; + shapeModel.GLWorld = world; + var root = world.getGeomRoot(); + if (root) + { + shapeModel.GLGeomObj = root; + shapeModel.strokeSize = root._strokeWidth; + shapeModel.strokeStyle = "solid"; + //shapeModel.strokeStyleIndex + switch (root.geomType()) + { + case root.GEOM_TYPE_RECTANGLE: + elementModel.selection = "Rectangle"; + elementModel.pi = "RectanglePi"; + shapeModel.tlRadius = root._tlRadius; + shapeModel.trRadius = root._trRadius; + shapeModel.blRadius = root._blRadius; + shapeModel.brRadius = root._brRadius; + break; + + case root.GEOM_TYPE_CIRCLE: + elementModel.selection = "Oval"; + elementModel.pi = "OvalPi"; + shapeModel.innerRadius = root._innerRadius; + break; + + case root.GEOM_TYPE_LINE: + elementModel.selection = "Line"; + elementModel.pi = "LinePi"; + shapeModel.slope = root._slope; + break; + + case root.GEOM_TYPE_BRUSH_STROKE: + elementModel.selection = "BrushStroke"; + elementModel.pi = "BrushStrokePi"; + break; + + case root.GEOM_TYPE_CUBIC_BEZIER: + elementModel.selection = "Subpath"; + elementModel.pi = "SubpathPi"; + break; + + default: + console.log( "geometry type not supported for file I/O, " + root.geomType()); + break; + } + } + } + }, + + zoomFactor: { + get: function() { return this._zoomFactor; }, + set: function(value) { this._zoomFactor = value; } + }, + + /** + * Add a reference to a component instance to the userComponents hash using the + * element UUID + */ + setComponentInstance: { + value: function(instance, el) { + this.userComponents[el.uuid] = instance; + } + }, + + /** + * Returns the component instance obj from the element + */ + getComponentFromElement: { + value: function(el) { + if(el) { + if(el.uuid) return this.userComponents[el.uuid]; + } else { + return null; + } + } + }, + + /** + * search the DOM tree to find a canvas with the given id + */ + findCanvasWithID: { + value: function( id, elt ) { + var cid = elt.getAttribute( "data-RDGE-id" ); + if (cid == id) return elt; + + if (elt.children) + { + var nKids = elt.children.length; + for (var i=0; i 1) { + //Checking all styleSheets in document + for (var i in this._document.styleSheets) { + //If rules are null, assuming cross-origin issue + if(this._document.styleSheets[i].rules === null) { + //TODO: Revisit URLs and URI creation logic, very hack right now + var fileUri, cssUrl, cssData, query, prefixUrl, fileCouldDirUrl, docRootUrl; + // + docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); + //TODO: Parse out relative URLs and map them to absolute + if (this._document.styleSheets[i].href.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { + // + cssUrl = this._document.styleSheets[i].href.split(this.application.ninja.coreIoApi.rootUrl)[1]; + fileUri = this.application.ninja.coreIoApi.cloudData.root+cssUrl; + //TODO: Add error handling for reading file + cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); + // + var tag = this.iframe.contentWindow.document.createElement('style'); + tag.setAttribute('type', 'text/css'); + tag.setAttribute('data-ninja-uri', fileUri); + tag.setAttribute('data-ninja-file-url', cssUrl); + tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); + tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); + //Copying attributes to maintain same properties as the + for (var n in this._document.styleSheets[i].ownerNode.attributes) { + if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { + if (this._document.styleSheets[i].ownerNode.attributes[n].value.indexOf(docRootUrl) !== -1) { + tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheet