aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/selection-controller.js
diff options
context:
space:
mode:
authorEric Guzman2012-06-19 01:20:36 -0700
committerEric Guzman2012-06-19 01:20:36 -0700
commit2ef72cdf0e59fb3623a2c13251ac707522f3dc5a (patch)
treef69f4e3de7e4441311ef2b38770e0ce26067aac4 /js/controllers/selection-controller.js
parent5260d3dfd99d79924c4aaa3ab798e90c7d328d7d (diff)
parent1007cbf983ad0f2460a4122a492a96023fdb4439 (diff)
downloadninja-2ef72cdf0e59fb3623a2c13251ac707522f3dc5a.tar.gz
Merge branch 'binding' of github.com:dhg637/ninja-internal into binding
Conflicts: js/stage/binding-view.reel/binding-view.js
Diffstat (limited to 'js/controllers/selection-controller.js')
-rwxr-xr-xjs/controllers/selection-controller.js32
1 files changed, 6 insertions, 26 deletions
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js
index 4bca0755..b327bea4 100755
--- a/js/controllers/selection-controller.js
+++ b/js/controllers/selection-controller.js
@@ -35,11 +35,13 @@ exports.SelectionController = Montage.create(Component, {
35 35
36 if(this._currentDocument && this._currentDocument.currentView === "design") { 36 if(this._currentDocument && this._currentDocument.currentView === "design") {
37 this._currentDocument.model._selection = this.application.ninja.selectedElements; 37 this._currentDocument.model._selection = this.application.ninja.selectedElements;
38 this._currentDocument.model.selectionContainer = this.application.ninja._currentSelectedContainer;
39 } 38 }
40 39
41 this._currentDocument = value; 40 this._currentDocument = value;
42 41
42 if(this._currentDocument && this._currentDocument.currentView === "design") {
43 this.selectedElements = this._currentDocument.model.selection;
44 }
43 /* 45 /*
44 if(!value) { 46 if(!value) {
45 } else if(this._currentDocument.currentView === "design") { 47 } else if(this._currentDocument.currentView === "design") {
@@ -59,43 +61,21 @@ exports.SelectionController = Montage.create(Component, {
59 return this._selectedElements; 61 return this._selectedElements;
60 }, 62 },
61 set: function(value) { 63 set: function(value) {
62 if(this.currentDocument && this.currentDocument.currentView === "code") return;
63 64
64 if(value) { 65 if(value) {
65 this._selectedElements = value; 66 this._selectedElements = value;
66 67
67 this.application.ninja.selectedElements = this._selectedElements; 68 this.application.ninja.selectedElements = this._selectedElements;
68 this.application.ninja._currentSelectedContainer = this._selectionContainer = this.application.ninja.currentDocument.model.documentRoot;
69 69
70 if(this._selectedElements.length === 0) { 70 if(this._selectedElements.length === 0) {
71 this.executeSelectElement(); 71 this.executeSelectElement();
72 } else { 72 } else {
73 this.executeSelectElement(this._selectedElements); 73 this.executeSelectElement(this._selectedElements);
74 } 74 }
75
76
77 } 75 }
78 } 76 }
79 }, 77 },
80 78
81 // Bound property to the ninja currentSelectedContainer
82 _selectionContainer: {
83 value: null
84 },
85
86 selectionContainer: {
87 get: function() {
88 return this._selectionContainer
89 },
90 set: function(value) {
91 if(this._selectionContainer && this._selectionContainer !== value) {
92 this.executeSelectElement();
93 }
94
95 this._selectionContainer = value;
96 }
97 },
98
99 deserializedFromTemplate: { 79 deserializedFromTemplate: {
100 value: function() { 80 value: function() {
101 this.eventManager.addEventListener("elementAdded", this, false); 81 this.eventManager.addEventListener("elementAdded", this, false);
@@ -131,7 +111,7 @@ exports.SelectionController = Montage.create(Component, {
131 value: function(event) { 111 value: function(event) {
132 var selected = [], childNodes = [], self = this; 112 var selected = [], childNodes = [], self = this;
133 113
134 childNodes = this.application.ninja.currentDocument.model.documentRoot.childNodes; 114 childNodes = this.currentDocument.model.domContainer.childNodes;
135 childNodes = Array.prototype.slice.call(childNodes, 0); 115 childNodes = Array.prototype.slice.call(childNodes, 0);
136 childNodes.forEach(function(item) { 116 childNodes.forEach(function(item) {
137 if(self.isNodeTraversable(item)) { 117 if(self.isNodeTraversable(item)) {
@@ -175,12 +155,12 @@ exports.SelectionController = Montage.create(Component, {
175 if(this.isDocument) return; // If the stage is already selected do nothing. 155 if(this.isDocument) return; // If the stage is already selected do nothing.
176 this.executeSelectElement(); // Else execute selection with no element 156 this.executeSelectElement(); // Else execute selection with no element
177 } else { 157 } else {
178 if(element.parentNode.uuid === this.selectionContainer.uuid) { 158 if(element.parentNode.uuid === this.currentDocument.model.domContainer.uuid) {
179 this.executeSelectElement(element); 159 this.executeSelectElement(element);
180 } else { 160 } else {
181 var outerElement = element.parentNode; 161 var outerElement = element.parentNode;
182 162
183 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) { 163 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.currentDocument.model.domContainer.uuid) {
184 // If element is higher up than current container then return 164 // If element is higher up than current container then return
185 if(outerElement.nodeName === "BODY") return; 165 if(outerElement.nodeName === "BODY") return;
186 // else keep going up the chain 166 // else keep going up the chain