aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/selection-controller.js
diff options
context:
space:
mode:
authorAnanya Sen2012-05-31 10:13:40 -0700
committerAnanya Sen2012-05-31 10:13:40 -0700
commit286457b4f23974277274ba388afd283e8aa085cb (patch)
treec21bf791e7c4f572d12f97987ea6b89e74da67fe /js/controllers/selection-controller.js
parent4d9b481c58090e8f1fc7b0e9d73a81b0f49cccc8 (diff)
parentd49c909cff7f0c5e5d0b127ad84a2fefc6677dc6 (diff)
downloadninja-286457b4f23974277274ba388afd283e8aa085cb.tar.gz
Merge branch 'refs/heads/ninja-internal-master' into cut-copy-paste
Conflicts: js/controllers/styles-controller.js Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/controllers/selection-controller.js')
-rwxr-xr-xjs/controllers/selection-controller.js40
1 files changed, 20 insertions, 20 deletions
diff --git a/js/controllers/selection-controller.js b/js/controllers/selection-controller.js
index 5665b09c..75bffc5c 100755
--- a/js/controllers/selection-controller.js
+++ b/js/controllers/selection-controller.js
@@ -67,10 +67,9 @@ exports.SelectionController = Montage.create(Component, {
67 this._isDocument = true; 67 this._isDocument = true;
68 68
69 if(currentSelectionArray) { 69 if(currentSelectionArray) {
70 if(currentSelectionArray.length >= 1) { 70 this.application.ninja.selectedElements = currentSelectionArray;
71 if(currentSelectionArray.length) {
71 this._isDocument = false; 72 this._isDocument = false;
72
73 this.application.ninja.selectedElements = currentSelectionArray;
74 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument}); 73 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument});
75 } 74 }
76 } 75 }
@@ -81,10 +80,10 @@ exports.SelectionController = Montage.create(Component, {
81 80
82 handleSwitchDocument: { 81 handleSwitchDocument: {
83 value: function() { 82 value: function() {
84 if(this.application.ninja.documentController.activeDocument.currentView === "design"){ 83// if(this.application.ninja.documentController.activeDocument.currentView === "design"){
85 this._isDocument = this.application.ninja.selectedElements.length === 0; 84 this._isDocument = this.application.ninja.selectedElements.length === 0;
86 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} ); 85 NJevent("selectionChange", {"elements": this.application.ninja.selectedElements, "isDocument": this._isDocument} );
87 } 86// }
88 } 87 }
89 }, 88 },
90 89
@@ -112,12 +111,12 @@ exports.SelectionController = Montage.create(Component, {
112 111
113 handleSelectAll: { 112 handleSelectAll: {
114 value: function(event) { 113 value: function(event) {
115 var selected = [], childNodes = []; 114 var selected = [], childNodes = [], self = this;
116 115
117 childNodes = this.application.ninja.currentDocument.documentRoot.childNodes; 116 childNodes = this.application.ninja.currentDocument.model.documentRoot.childNodes;
118 childNodes = Array.prototype.slice.call(childNodes, 0); 117 childNodes = Array.prototype.slice.call(childNodes, 0);
119 childNodes.forEach(function(item) { 118 childNodes.forEach(function(item) {
120 if(item.nodeType == 1) { 119 if(self.isNodeTraversable(item)) {
121 selected.push(item); 120 selected.push(item);
122 } 121 }
123 }); 122 });
@@ -152,7 +151,6 @@ exports.SelectionController = Montage.create(Component, {
152 151
153 selectElement: { 152 selectElement: {
154 value: function(element) { 153 value: function(element) {
155
156 if(this.findSelectedElement(element) === -1) { 154 if(this.findSelectedElement(element) === -1) {
157 155
158 if(this.application.ninja.currentDocument.inExclusion(element) !== -1){ 156 if(this.application.ninja.currentDocument.inExclusion(element) !== -1){
@@ -166,7 +164,7 @@ exports.SelectionController = Montage.create(Component, {
166 164
167 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) { 165 while(outerElement.parentNode && outerElement.parentNode.uuid !== this.selectionContainer.uuid) {
168 // If element is higher up than current container then return 166 // If element is higher up than current container then return
169 if(outerElement.id === "UserContent") return; 167 if(outerElement.nodeName === "BODY") return;
170 // else keep going up the chain 168 // else keep going up the chain
171 outerElement = outerElement.parentNode; 169 outerElement = outerElement.parentNode;
172 } 170 }
@@ -247,25 +245,20 @@ exports.SelectionController = Montage.create(Component, {
247 } 245 }
248 }, 246 },
249 247
250 /**
251 * Looks into the selectionObject for the item to be found using it's id
252 *
253 * @return: Item index in the selectionObject if found
254 * -1 if not found
255 */
256 findSelectedElement: { 248 findSelectedElement: {
257 value: function(item) { 249 value: function(item) {
258 // TODO do the loop check in the select element and only use the index here 250 // TODO: Remove this function and use the stage selectable. Then only return a match in the array
259 // return this.application.ninja.selectedElements.indexOf(item); 251 //return this.application.ninja.selectedElements.indexOf(item);
260 252
253 //TODO: Make sure we don't need to loop back to the container element.
261 var itemUUID; 254 var itemUUID;
262 255
263 for(var i=0, uuid; this.application.ninja.selectedElements[i];i++) { 256 for(var i=0, uuid; this.application.ninja.selectedElements[i];i++) {
264 // Check for multiple selection and excluding inner elements 257 // Check for multiple selection and excluding inner elements
265 if(item.parentNode && item.parentNode.id !== "UserContent") { 258 if(item.parentNode && item.parentNode !== this.application.ninja.currentDocument.model.documentRoot) {
266 var outerElement = item.parentNode; 259 var outerElement = item.parentNode;
267 260
268 while(outerElement.parentNode && outerElement.parentNode.id !== "UserContent") { 261 while(outerElement.parentNode && outerElement.parentNode !== this.application.ninja.currentDocument.model.documentRoot) {
269 outerElement = outerElement.parentNode; 262 outerElement = outerElement.parentNode;
270 } 263 }
271 264
@@ -281,6 +274,13 @@ exports.SelectionController = Montage.create(Component, {
281 274
282 return -1; 275 return -1;
283 } 276 }
277 },
278
279 isNodeTraversable: {
280 value: function( item ) {
281 if(item.nodeType !== 1) return false;
282 return ((item.nodeName !== "STYLE") && (item.nodeName !== "SCRIPT"));
283 }
284 } 284 }
285 285
286}); 286});