diff options
Diffstat (limited to 'js/controllers')
-rwxr-xr-x | js/controllers/document-controller.js | 77 | ||||
-rwxr-xr-x | js/controllers/elements/element-controller.js | 6 | ||||
-rwxr-xr-x | js/controllers/local-storage-controller.js | 67 | ||||
-rwxr-xr-x | js/controllers/selection-controller.js | 9 | ||||
-rwxr-xr-x | js/controllers/styles-controller.js | 44 |
5 files changed, 132 insertions, 71 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index fa611de4..02031922 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -58,6 +58,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
58 | this.eventManager.addEventListener("executeFileOpen", this, false); | 58 | this.eventManager.addEventListener("executeFileOpen", this, false); |
59 | this.eventManager.addEventListener("executeNewFile", this, false); | 59 | this.eventManager.addEventListener("executeNewFile", this, false); |
60 | this.eventManager.addEventListener("executeSave", this, false); | 60 | this.eventManager.addEventListener("executeSave", this, false); |
61 | this.eventManager.addEventListener("executeSaveAs", this, false); | ||
62 | this.eventManager.addEventListener("executeSaveAll", this, false); | ||
61 | 63 | ||
62 | this.eventManager.addEventListener("recordStyleChanged", this, false); | 64 | this.eventManager.addEventListener("recordStyleChanged", this, false); |
63 | 65 | ||
@@ -84,9 +86,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
84 | // | 86 | // |
85 | handleAppLoaded: { | 87 | handleAppLoaded: { |
86 | value: function() { | 88 | value: function() { |
87 | //Adding an intercept to resources loaded to ensure user assets load from cloud simulator | 89 | //Checking for app to be loaded through extension |
88 | if (window.chrome.app.isInstalled) { | 90 | var check; |
89 | chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); | 91 | if (chrome && chrome.app) { |
92 | check = chrome.app.getDetails(); | ||
93 | } | ||
94 | if (check !== null) { | ||
95 | //Adding an intercept to resources loaded to ensure user assets load from cloud simulator | ||
96 | chrome.webRequest.onBeforeRequest.addListener(this.handleWebRequest.bind(this), {urls: ["<all_urls>"]}, ["blocking"]); | ||
90 | } | 97 | } |
91 | } | 98 | } |
92 | }, | 99 | }, |
@@ -102,33 +109,57 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
102 | handleExecuteFileOpen: { | 109 | handleExecuteFileOpen: { |
103 | value: function(event) { | 110 | value: function(event) { |
104 | var pickerSettings = event._event.settings || {}; | 111 | var pickerSettings = event._event.settings || {}; |
105 | pickerSettings.callback = this.openFileWithURI.bind(this); | 112 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
106 | pickerSettings.pickerMode = "read"; | 113 | pickerSettings.callback = this.openFileWithURI.bind(this); |
107 | pickerSettings.inFileMode = true; | 114 | pickerSettings.pickerMode = "read"; |
108 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | 115 | pickerSettings.inFileMode = true; |
116 | this.application.ninja.filePickerController.showFilePicker(pickerSettings); | ||
117 | } | ||
109 | } | 118 | } |
110 | }, | 119 | }, |
111 | 120 | ||
112 | handleExecuteNewFile: { | 121 | handleExecuteNewFile: { |
113 | value: function(event) { | 122 | value: function(event) { |
114 | var newFileSettings = event._event.settings || {}; | 123 | var newFileSettings = event._event.settings || {}; |
115 | newFileSettings.callback = this.createNewFile.bind(this); | 124 | if (this.application.ninja.coreIoApi.cloudAvailable()) { |
116 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | 125 | newFileSettings.callback = this.createNewFile.bind(this); |
126 | this.application.ninja.newFileController.showNewFileDialog(newFileSettings); | ||
127 | } | ||
117 | } | 128 | } |
118 | }, | 129 | }, |
119 | |||
120 | |||
121 | //////////////////////////////////////////////////////////////////// | 130 | //////////////////////////////////////////////////////////////////// |
122 | //TODO: Check for appropiate structures | 131 | //TODO: Check for appropiate structures |
123 | handleExecuteSave: { | 132 | handleExecuteSave: { |
124 | value: function(event) { | 133 | value: function(event) { |
125 | if(!!this.activeDocument){ | 134 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
126 | //Text and HTML document classes should return the same save object for fileSave | 135 | //Text and HTML document classes should return the same save object for fileSave |
127 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); | 136 | this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); |
137 | } | ||
128 | } | 138 | } |
139 | }, | ||
140 | //////////////////////////////////////////////////////////////////// | ||
141 | //TODO: Check for appropiate structures | ||
142 | handleExecuteSaveAll: { | ||
143 | value: function(event) { | ||
144 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | ||
145 | //Text and HTML document classes should return the same save object for fileSave | ||
146 | this.application.ninja.ioMediator.fileSave(this.activeDocument.saveAll(), this.fileSaveResult.bind(this)); | ||
147 | } | ||
129 | } | 148 | } |
130 | }, | 149 | }, |
131 | //////////////////////////////////////////////////////////////////// | 150 | //////////////////////////////////////////////////////////////////// |
151 | handleExecuteSaveAs: { | ||
152 | value: function(event) { | ||
153 | var saveAsSettings = event._event.settings || {}; | ||
154 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | ||
155 | saveAsSettings.fileName = this.activeDocument.name; | ||
156 | saveAsSettings.folderUri = this.activeDocument.uri.substring(0, this.activeDocument.uri.lastIndexOf("/")); | ||
157 | //add callback | ||
158 | this.application.ninja.newFileController.showSaveAsDialog(saveAsSettings); | ||
159 | } | ||
160 | } | ||
161 | }, | ||
162 | |||
132 | // | 163 | // |
133 | fileSaveResult: { | 164 | fileSaveResult: { |
134 | value: function (result) { | 165 | value: function (result) { |
@@ -164,6 +195,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
164 | value:function(doc){ | 195 | value:function(doc){ |
165 | var response = doc || null;//default just for testing | 196 | var response = doc || null;//default just for testing |
166 | if(!!response && response.success && (response.status!== 500) && !!response.uri){ | 197 | if(!!response && response.success && (response.status!== 500) && !!response.uri){ |
198 | this.creatingNewFile = true;//flag for timeline to identify new file flow | ||
167 | this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); | 199 | this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); |
168 | }else if(!!response && !response.success){ | 200 | }else if(!!response && !response.success){ |
169 | //Todo: restrict directory path to the sandbox, in the dialog itself | 201 | //Todo: restrict directory path to the sandbox, in the dialog itself |
@@ -191,6 +223,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
191 | value:function(response){ | 223 | value:function(response){ |
192 | //TODO: Add UI to handle error codes, shouldn't be alert windows | 224 | //TODO: Add UI to handle error codes, shouldn't be alert windows |
193 | if(!!response && (response.status === 204)) { | 225 | if(!!response && (response.status === 204)) { |
226 | |||
227 | if((typeof this.creatingNewFile === 'undefined') || (this.creatingNewFile !== true)){//not from new file flow | ||
228 | this.creatingNewFile = false; | ||
229 | } | ||
230 | |||
194 | //Sending full response object | 231 | //Sending full response object |
195 | this.openDocument(response); | 232 | this.openDocument(response); |
196 | } else if (!!response && (response.status === 404)){ | 233 | } else if (!!response && (response.status === 404)){ |
@@ -287,7 +324,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
287 | if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab | 324 | if(this.activeDocument.uuid === id && this._documents.length > 0) {//closing the active document tab |
288 | var nextDocumentIndex = -1 ; | 325 | var nextDocumentIndex = -1 ; |
289 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ | 326 | if((this._documents.length > 0) && (closeDocumentIndex === 0)){ |
290 | nextDocumentIndex = 1; | 327 | nextDocumentIndex = 0; |
291 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ | 328 | }else if((this._documents.length > 0) && (closeDocumentIndex > 0)){ |
292 | nextDocumentIndex = closeDocumentIndex - 1; | 329 | nextDocumentIndex = closeDocumentIndex - 1; |
293 | } | 330 | } |
@@ -301,6 +338,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
301 | 338 | ||
302 | this.application.ninja.stage.hideCanvas(true); | 339 | this.application.ninja.stage.hideCanvas(true); |
303 | } | 340 | } |
341 | |||
342 | NJevent("closeDocument", doc.uri); | ||
343 | |||
344 | doc=null; | ||
304 | } | 345 | } |
305 | }, | 346 | }, |
306 | 347 | ||
@@ -308,7 +349,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
308 | // Event Detail: Contains the current ActiveDocument | 349 | // Event Detail: Contains the current ActiveDocument |
309 | _onOpenDocument: { | 350 | _onOpenDocument: { |
310 | value: function(doc){ | 351 | value: function(doc){ |
311 | //var data = DocumentManager.activeDocument; | 352 | this.application.ninja.currentDocument = doc; |
312 | this._hideCurrentDocument(); | 353 | this._hideCurrentDocument(); |
313 | this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); | 354 | this.application.ninja.stage.stageView.hideOtherDocuments(doc.uuid); |
314 | 355 | ||
@@ -392,7 +433,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
392 | value: function() { | 433 | value: function() { |
393 | if(this.activeDocument) { | 434 | if(this.activeDocument) { |
394 | if(this.activeDocument.currentView === "design"){ | 435 | if(this.activeDocument.currentView === "design"){ |
395 | this.application.ninja.stage.saveScroll(); | 436 | this.activeDocument.saveAppState(); |
396 | this.activeDocument.container.parentNode.style["display"] = "none"; | 437 | this.activeDocument.container.parentNode.style["display"] = "none"; |
397 | this.application.ninja.stage.hideCanvas(true); | 438 | this.application.ninja.stage.hideCanvas(true); |
398 | this.application.ninja.stage.stageView.hideRulers(); | 439 | this.application.ninja.stage.stageView.hideRulers(); |
@@ -409,7 +450,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
409 | this.activeDocument.container.style["display"] = "block"; | 450 | this.activeDocument.container.style["display"] = "block"; |
410 | if(this.activeDocument.currentView === "design"){ | 451 | if(this.activeDocument.currentView === "design"){ |
411 | this.activeDocument.container.parentNode.style["display"] = "block"; | 452 | this.activeDocument.container.parentNode.style["display"] = "block"; |
412 | this.application.ninja.stage.restoreScroll(); | 453 | this.activeDocument.restoreAppState(); |
413 | this.application.ninja.stage.hideCanvas(false); | 454 | this.application.ninja.stage.hideCanvas(false); |
414 | this.application.ninja.stage.stageView.showRulers(); | 455 | this.application.ninja.stage.stageView.showRulers(); |
415 | }else{ | 456 | }else{ |
diff --git a/js/controllers/elements/element-controller.js b/js/controllers/elements/element-controller.js index 46e82ace..ec0335b4 100755 --- a/js/controllers/elements/element-controller.js +++ b/js/controllers/elements/element-controller.js | |||
@@ -27,7 +27,11 @@ var ElementController = exports.ElementController = Montage.create(NJComponent, | |||
27 | 27 | ||
28 | getProperty: { | 28 | getProperty: { |
29 | value: function(el, prop, fallbackOnComputed, isStageElement) { | 29 | value: function(el, prop, fallbackOnComputed, isStageElement) { |
30 | return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement); | 30 | if(el.nodeType !== 3){ |
31 | return this.application.ninja.stylesController.getElementStyle(el, prop, fallbackOnComputed, isStageElement); | ||
32 | }else{ | ||
33 | return null; | ||
34 | } | ||
31 |