diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/controllers/document-controller.js | 15 | ||||
-rwxr-xr-x | js/document/models/base.js | 18 | ||||
-rwxr-xr-x | js/document/views/design.js | 29 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 79 |
4 files changed, 83 insertions, 58 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 7721d32d..f6b850b2 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -145,18 +145,19 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
145 | value: function(event) { | 145 | value: function(event) { |
146 | // | 146 | // |
147 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ | 147 | if((typeof this.activeDocument !== "undefined") && this.application.ninja.coreIoApi.cloudAvailable()){ |
148 | // | 148 | //Currently we don't need a callback handler |
149 | this.activeDocument.model.save(this.testCallback.bind(this)); //this.fileSaveResult.bind(this) | 149 | //this.activeDocument.model.save(this.saveExecuted.bind(this)); |
150 | this.activeDocument.model.save(); | ||
150 | } else { | 151 | } else { |
151 | //Error: | 152 | //Error: cloud not available and/or no active document |
152 | } | 153 | } |
153 | } | 154 | } |
154 | }, | 155 | }, |
155 | testCallback: { | 156 | //////////////////////////////////////////////////////////////////// |
157 | // | ||
158 | saveExecuted: { | ||
156 | value: function (value) { | 159 | value: function (value) { |
157 | console.log(value); | 160 | //File saved, any callbacks or events should go here |
158 | //TODO: Move this to the model.save() | ||
159 | this.activeDocument.model.needsSave = false; | ||
160 | } | 161 | } |
161 | }, | 162 | }, |
162 | //////////////////////////////////////////////////////////////////// | 163 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/document/models/base.js b/js/document/models/base.js index df341b2f..c99e36c7 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -151,7 +151,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
151 | head: this.views.design.iframe.contentWindow.document.head, | 151 | head: this.views.design.iframe.contentWindow.document.head, |
152 | body: this.views.design.iframe.contentWindow.document.body, | 152 | body: this.views.design.iframe.contentWindow.document.body, |
153 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 153 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
154 | }, callback.bind(this)); | 154 | }, this.handleSaved.bind({callback: callback, model: this})); |
155 | } else { | 155 | } else { |
156 | //TODO: Add logic to save code view data | 156 | //TODO: Add logic to save code view data |
157 | } | 157 | } |
@@ -180,7 +180,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
180 | head: this.views.design.iframe.contentWindow.document.head, | 180 | head: this.views.design.iframe.contentWindow.document.head, |
181 | body: this.views.design.iframe.contentWindow.document.body, | 181 | body: this.views.design.iframe.contentWindow.document.body, |
182 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 182 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
183 | }, callback.bind(this)); | 183 | }, this.handleSaved.bind({callback: callback, model: this})); |
184 | } else { | 184 | } else { |
185 | //TODO: Add logic to save code view data | 185 | //TODO: Add logic to save code view data |
186 | } | 186 | } |
@@ -190,7 +190,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
190 | //////////////////////////////////////////////////////////////////// | 190 | //////////////////////////////////////////////////////////////////// |
191 | // | 191 | // |
192 | saveAs: { | 192 | saveAs: { |
193 | value: function () { | 193 | value: function (callback) { |
194 | // | 194 | // |
195 | if (this.needsSave) { | 195 | if (this.needsSave) { |
196 | //Save current file on memory | 196 | //Save current file on memory |
@@ -201,6 +201,18 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
201 | }, | 201 | }, |
202 | //////////////////////////////////////////////////////////////////// | 202 | //////////////////////////////////////////////////////////////////// |
203 | // | 203 | // |
204 | handleSaved: { | ||
205 | value: function (result) { | ||
206 | // | ||
207 | if (result.status === 204) { | ||
208 | this.model.needsSave = false; | ||
209 | } | ||
210 | // | ||
211 | if (this.callback) this.callback(result); | ||
212 | } | ||
213 | }, | ||
214 | //////////////////////////////////////////////////////////////////// | ||
215 | // | ||
204 | close: { | 216 | close: { |
205 | value: function (view, callback) { | 217 | value: function (view, callback) { |
206 | //Outcome of close (pending on save logic) | 218 | //Outcome of close (pending on save logic) |
diff --git a/js/document/views/design.js b/js/document/views/design.js index 44f1a5e8..3f58650e 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js | |||
@@ -189,8 +189,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
189 | this._bodyFragment = null; | 189 | this._bodyFragment = null; |
190 | //Calling standard method to finish opening document | 190 | //Calling standard method to finish opening document |
191 | this.bodyContentLoaded(null); | 191 | this.bodyContentLoaded(null); |
192 | 192 | //TODO: Move this to be set via the controller | |
193 | // TODO: Clean up this code | ||
194 | this.application.ninja.stage.documentOffsetLeft = parseInt((this.document.body.scrollWidth - this._template.size.width)/2); | 193 | this.application.ninja.stage.documentOffsetLeft = parseInt((this.document.body.scrollWidth - this._template.size.width)/2); |
195 | this.application.ninja.stage.documentOffsetTop = parseInt((this.document.body.scrollHeight - this._template.size.height)/2); | 194 | this.application.ninja.stage.documentOffsetTop = parseInt((this.document.body.scrollHeight - this._template.size.height)/2); |
196 | } | 195 | } |
@@ -248,17 +247,15 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
248 | } | 247 | } |
249 | } | 248 | } |
250 | } | 249 | } |
251 | //Checking and initializing webGL | 250 | //Checking for script tags then parsing check for montage and webgl |
252 | if (scripttags.length > 0) { | 251 | if (scripttags.length > 0) { |
252 | //Checking and initializing webGL | ||
253 | this.initWebGl(scripttags); | 253 | this.initWebGl(scripttags); |
254 | } //Else there is not data to parse | 254 | //Checking and initializing Montage |
255 | 255 | this.initMontage(scripttags); | |
256 | 256 | } else { | |
257 | 257 | //Else there is not data to parse | |
258 | //TODO: Load Montage Components (blocking) | 258 | } |
259 | //this.initMontage(); | ||
260 | |||
261 | |||
262 | //Makign callback if specified | 259 | //Makign callback if specified |
263 | if (this._callback) this._callback(); | 260 | if (this._callback) this._callback(); |
264 | } | 261 | } |
@@ -355,8 +352,14 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
355 | //////////////////////////////////////////////////////////////////// | 352 | //////////////////////////////////////////////////////////////////// |
356 | // | 353 | // |
357 | initMontage: { | 354 | initMontage: { |
358 | value: function () { | 355 | value: function (scripttags) { |
359 | //initWithDocument(window.document) instantiateWithOwnerAndDocument(null, window.document) | 356 | // |
357 | this.iframe.contentWindow.document.body.addEventListener('mjsTemplateReady', function () { | ||
358 | //Initializing template with user's seriliazation | ||
359 | var template = this.iframe.contentWindow.mjsTemplate.create(); | ||
360 | template.initWithDocument(this.iframe.contentWindow.document); | ||
361 | template.instantiateWithOwnerAndDocument(null, this.iframe.contentWindow.document, function (e){/*Nothing just a required extra parameter*/}); | ||
362 | }.bind(this), false); | ||
360 | } | 363 | } |
361 | }, | 364 | }, |
362 | //////////////////////////////////////////////////////////////////// | 365 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index b1916446..ade27728 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -225,7 +225,7 @@ exports.IoMediator = Montage.create(Component, { | |||
225 | mjsCreator = template.mjsTemplateCreator.create(), | 225 | mjsCreator = template.mjsTemplateCreator.create(), |
226 | mJsSerialization, | 226 | mJsSerialization, |
227 | montageTemplate; | 227 | montageTemplate; |
228 | // | 228 | //Creating instance of template creator |
229 | montageTemplate = mjsCreator.initWithDocument(template.document); | 229 | montageTemplate = mjsCreator.initWithDocument(template.document); |
230 | //Setting up expression for parsing URLs | 230 | //Setting up expression for parsing URLs |
231 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); | 231 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); |
@@ -239,7 +239,6 @@ exports.IoMediator = Montage.create(Component, { | |||
239 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); | 239 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); |
240 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); | 240 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); |
241 | } | 241 | } |
242 | |||
243 | //Copying attributes to maintain same properties as the <body> | 242 | //Copying attributes to maintain same properties as the <body> |
244 | for (var n in template.body.attributes) { | 243 | for (var n in template.body.attributes) { |
245 | if (template.body.attributes[n].value) { | 244 | if (template.body.attributes[n].value) { |
@@ -250,6 +249,7 @@ exports.IoMediator = Montage.create(Component, { | |||
250 | //TODO: Add attribute copying for <HEAD> and <HTML> | 249 | //TODO: Add attribute copying for <HEAD> and <HTML> |
251 | 250 | ||
252 | 251 | ||
252 | //console.log(template.file.content.document.getElementsByTagName('html')[0].innerHTML); | ||
253 | 253 | ||
254 | 254 | ||
255 | //Getting all CSS (style or link) tags | 255 | //Getting all CSS (style or link) tags |
@@ -266,7 +266,7 @@ exports.IoMediator = Montage.create(Component, { | |||
266 | } | 266 | } |
267 | ////////////////////////////////////////////////// | 267 | ////////////////////////////////////////////////// |
268 | 268 | ||
269 | // | 269 | //Adding to tags to be removed form template |
270 | for (var f in njtemplatetags) { | 270 | for (var f in njtemplatetags) { |
271 | if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); | 271 | if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); |
272 | } | 272 | } |
@@ -405,6 +405,31 @@ exports.IoMediator = Montage.create(Component, { | |||
405 | } | 405 | } |
406 | } | 406 | } |
407 | } | 407 | } |
408 | // | ||
409 | var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; | ||
410 | // | ||
411 | for (var i in scripts) { | ||
412 | if (scripts[i].getAttribute) { | ||
413 | if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll | ||
414 | matchingtags.push(scripts[i]); | ||
415 | } | ||
416 | if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) { | ||
417 | webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
418 | } | ||
419 | if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) { | ||
420 | webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
421 | } | ||
422 | if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { | ||
423 | webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
424 | } | ||