aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/selection-controller.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-05-31 12:20:03 -0700
committerPushkar Joshi2012-05-31 12:20:03 -0700
commit4bc52365b1f81a386c3c59fd7c6ad874bb387cb5 (patch)
treec5b17297aba04bd54a59cf6214d29486e089031b /js/controllers/selection-controller.js
parent75a862d305bc4502e22bc5aa65fa271143b8cf6c (diff)
parent6042bdc5f2aada4412912fd01602d32c9088dc26 (diff)
downloadninja-4bc52365b1f81a386c3c59fd7c6ad874bb387cb5.tar.gz
Merge branch 'master' into pentool
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});