diff options
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/mediators/template.js | 50 | ||||
-rwxr-xr-x | js/document/models/base.js | 10 |
2 files changed, 51 insertions, 9 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 1aac7e15..17fa553c 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js | |||
@@ -93,7 +93,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
93 | //////////////////////////////////////////////////////////////////// | 93 | //////////////////////////////////////////////////////////////////// |
94 | //TODO: Expand to allow more templates, clean up variables | 94 | //TODO: Expand to allow more templates, clean up variables |
95 | parseNinjaTemplateToHtml: { | 95 | parseNinjaTemplateToHtml: { |
96 | value: function (template, ninjaWrapper) { | 96 | value: function (template, ninjaWrapper, libCopyCallback) { |
97 | //TODO: Improve reference for rootUrl | 97 | //TODO: Improve reference for rootUrl |
98 | var regexRootUrl, | 98 | var regexRootUrl, |
99 | rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), | 99 | rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), |
@@ -332,7 +332,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
332 | 332 | ||
333 | // | 333 | // |
334 | var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], | 334 | var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], |
335 | scripts = template.file.content.document.getElementsByTagName('script'); | 335 | scripts = template.file.content.document.getElementsByTagName('script'), |
336 | libsobserver = {montage: false, canvas: false, montageCopied: null, canvasCopied: null, callback: libCopyCallback, dispatched: false}; | ||
337 | |||
336 | // | 338 | // |
337 | for (var i in scripts) { | 339 | for (var i in scripts) { |
338 | if (scripts[i].getAttribute) { | 340 | if (scripts[i].getAttribute) { |
@@ -376,7 +378,8 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
376 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { | 378 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { |
377 | rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); | 379 | rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); |
378 | rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; | 380 | rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; |
379 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName, function(result) {console.log(result)}); | 381 | libsobserver.canvas = true; |
382 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName, function(result) {libsobserver.canvasCopied = result; this.libCopied(libsobserver);}.bind(this)); | ||
380 | } else { | 383 | } else { |
381 | //TODO: Error handle no available library to copy | 384 | //TODO: Error handle no available library to copy |
382 | } | 385 | } |
@@ -502,7 +505,8 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
502 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { | 505 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { |
503 | mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); | 506 | mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); |
504 | mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; | 507 | mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; |
505 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName, function(result) {console.log(result)}); | 508 | libsobserver.montage = true; |
509 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName, function(result) {libsobserver.montageCopied = result; this.libCopied(libsobserver);}.bind(this)); | ||
506 | 510 | ||
507 | 511 | ||
508 | 512 | ||
@@ -590,6 +594,44 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
590 | }, | 594 | }, |
591 | //////////////////////////////////////////////////////////////////// | 595 | //////////////////////////////////////////////////////////////////// |
592 | // | 596 | // |
597 | libCopied: { | ||
598 | value: function (observer) { | ||
599 | if (observer.montage && observer.canvas) { | ||
600 | // | ||
601 | if (observer.montageCopied && observer.canvasCopied) { | ||
602 | if (observer.callback && !observer.dispatched) observer.callback(true); | ||
603 | observer.dispatched = true; | ||
604 | } else if (observer.montageCopied === false || observer.canvasCopied === false) { | ||
605 | if (observer.callback && !observer.dispatched) observer.callback(false); | ||
606 | observer.dispatched = true; | ||
607 | } | ||
608 | } else if (observer.montage) { | ||
609 | // | ||
610 | if (observer.montageCopied) { | ||
611 | if (observer.callback && !observer.dispatched) observer.callback(true); | ||
612 | observer.dispatched = true; | ||
613 | } else { | ||
614 | if (observer.callback && !observer.dispatched) observer.callback(false); | ||
615 | observer.dispatched = true; | ||
616 | } | ||
617 | } else if (observer.canvas && observer.canvasCopied) { | ||
618 | // | ||
619 | if (observer.canvasCopied) { | ||
620 | if (observer.callback && !observer.dispatched) observer.callback(true); | ||
621 | observer.dispatched = true; | ||
622 | } else { | ||
623 | if (observer.callback && !observer.dispatched) observer.callback(false); | ||
624 | observer.dispatched = true; | ||
625 | } | ||
626 | } else { | ||
627 | //Error | ||
628 | if (observer.callback && !observer.dispatched) observer.callback(false); | ||
629 | observer.dispatched = true; | ||
630 | } | ||
631 | } | ||
632 | }, | ||
633 | //////////////////////////////////////////////////////////////////// | ||
634 | // | ||
593 | getUrlfromNinjaUrl: { | 635 | getUrlfromNinjaUrl: { |
594 | enumerable: false, | 636 | enumerable: false, |
595 | value: function (url, fileRootUrl, fileUrl) { | 637 | value: function (url, fileRootUrl, fileUrl) { |
diff --git a/js/document/models/base.js b/js/document/models/base.js index 76a5e62b..27f7d43f 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -103,7 +103,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
103 | //Generating URL for document | 103 | //Generating URL for document |
104 | var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; | 104 | var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; |
105 | //TODO: Add logic to prompt user to save (all) before preview | 105 | //TODO: Add logic to prompt user to save (all) before preview |
106 | this.saveAll(function (result) { | 106 | this.saveAll(null,function (result) { |
107 | //Currently only supporting current browser (Chrome, obviously) | 107 | //Currently only supporting current browser (Chrome, obviously) |
108 | switch (this.browser) { | 108 | switch (this.browser) { |
109 | case 'chrome': | 109 | case 'chrome': |
@@ -145,7 +145,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
145 | //////////////////////////////////////////////////////////////////// | 145 | //////////////////////////////////////////////////////////////////// |
146 | // | 146 | // |
147 | save: { | 147 | save: { |
148 | value: function (callback) { | 148 | value: function (callback, libCopyCallback) { |
149 | // | 149 | // |
150 | if (this.needsSave) { | 150 | if (this.needsSave) { |
151 | //Save | 151 | //Save |
@@ -165,7 +165,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
165 | head: this.views.design.iframe.contentWindow.document.head, | 165 | head: this.views.design.iframe.contentWindow.document.head, |
166 | body: this.views.design.iframe.contentWindow.document.body, | 166 | body: this.views.design.iframe.contentWindow.document.body, |
167 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 167 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
168 | }, this.handleSaved.bind({callback: callback, model: this})); | 168 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); |
169 | } else { | 169 | } else { |
170 | //TODO: Add logic to save code view data | 170 | //TODO: Add logic to save code view data |
171 | } | 171 | } |
@@ -174,7 +174,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
174 | //////////////////////////////////////////////////////////////////// | 174 | //////////////////////////////////////////////////////////////////// |
175 | // | 175 | // |
176 | saveAll: { | 176 | saveAll: { |
177 | value: function (callback) { | 177 | value: function (callback, libCopyCallback) { |
178 | // | 178 | // |
179 | if (this.needsSave) { | 179 | if (this.needsSave) { |
180 | //Save | 180 | //Save |
@@ -194,7 +194,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
194 | head: this.views.design.iframe.contentWindow.document.head, | 194 | head: this.views.design.iframe.contentWindow.document.head, |
195 | body: this.views.design.iframe.contentWindow.document.body, | 195 | body: this.views.design.iframe.contentWindow.document.body, |
196 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 196 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
197 | }, this.handleSaved.bind({callback: callback, model: this})); | 197 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); |
198 | } else { | 198 | } else { |
199 | //TODO: Add logic to save code view data | 199 | //TODO: Add logic to save code view data |
200 | } | 200 | } |