aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-01 14:53:06 -0700
committerJose Antonio Marquez2012-06-01 14:53:06 -0700
commitb5f82a7548a88b4f63477393879ce3cd75ef4ff7 (patch)
tree620f6048234deee8f1d0ee696bd653528e4f6152 /js
parentf34752a034c7bf9060c7a286975df51f4e1a1e04 (diff)
downloadninja-b5f82a7548a88b4f63477393879ce3cd75ef4ff7.tar.gz
Add logic to allow dynamic placement of canvas json file
Save to and read from any path on disk (webGL/Canvas data only)
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/mediators/template.js84
1 files changed, 78 insertions, 6 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index 86055a1f..aa23c00f 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -197,6 +197,25 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
197 } 197 }
198 } 198 }
199 } 199 }
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 //TODO: Make proper CSS method
216
217
218
200 //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS) 219 //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS)
201 if (template.styles) { 220 if (template.styles) {
202 //Getting all style tags 221 //Getting all style tags
@@ -293,10 +312,26 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
293 } 312 }
294 } 313 }
295 } 314 }
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331 //TODO: Make proper webGL/Canvas method
332
296 // 333 //
297 var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag; 334 var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag;
298 //this.getDataDirectory(template.file.root)
299 //this.getNinjaDirectory(template.file.root)
300 // 335 //
301 for (var i in scripts) { 336 for (var i in scripts) {
302 if (scripts[i].getAttribute) { 337 if (scripts[i].getAttribute) {
@@ -319,9 +354,9 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
319 } 354 }
320 //Checking for webGL elements in document 355 //Checking for webGL elements in document
321 if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix 356 if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix
322 var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1; 357 var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc;
323 // 358 //
324 if (cvsDataDir && !matchingtags.length) { 359 if (cvsDataDir && !matchingtags.length && !webgllibtag) {
325 fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]; 360 fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0];
326 if (!this._getUserDirectory(fileCvsDir)) { 361 if (!this._getUserDirectory(fileCvsDir)) {
327 fileCvsDirAppend = fileCvsDir+cvsDirCounter; 362 fileCvsDirAppend = fileCvsDir+cvsDirCounter;
@@ -331,6 +366,8 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
331 } 366 }
332 //TODO: Allow user overwrite 367 //TODO: Allow user overwrite
333 fileCvsDir += '/'; 368 fileCvsDir += '/';
369 } else if (webgllibtag && webgllibtag.getAttribute && webgllibtag.getAttribute('data-ninja-canvas-json') !== null) {
370 fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json');
334 } 371 }
335 //Copy webGL library if needed 372 //Copy webGL library if needed
336 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { 373 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
@@ -411,9 +448,15 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
411 //Closing array (make-shift JSON string to validate data in <script> tag) 448 //Closing array (make-shift JSON string to validate data in <script> tag)
412 json += '\n\t\t]\n})\n'; 449 json += '\n\t\t]\n})\n';
413 //Setting string in tag 450 //Setting string in tag
414 if (fileCvsDir) { 451 if (fileCvsDir || fileOrgDataSrc) {
452 //
453 var cvsDataFilePath, cvsDataFileUrl, cvsDataFileCheck, cvsDataFileOperation;
415 // 454 //
416 var cvsDataFilePath = fileCvsDir+'data.json', cvsDataFileUrl, cvsDataFileCheck, cvsDataFileOperation; 455 if (fileOrgDataSrc) {
456 cvsDataFilePath = fileOrgDataSrc;
457 } else {
458 cvsDataFilePath = fileCvsDir+'data.json';
459 }
417 // 460 //
418 cvsDataFileUrl = this.getNinjaPropUrlRedirect(cvsDataFilePath.split(this.application.ninja.coreIoApi.cloudData.root+'/')[1]), 461 cvsDataFileUrl = this.getNinjaPropUrlRedirect(cvsDataFilePath.split(this.application.ninja.coreIoApi.cloudData.root+'/')[1]),
419 cvsDataFileCheck = this.application.ninja.coreIoApi.fileExists({uri: cvsDataFilePath}), 462 cvsDataFileCheck = this.application.ninja.coreIoApi.fileExists({uri: cvsDataFilePath}),
@@ -434,6 +477,22 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
434 webgltag.innerHTML = json; 477 webgltag.innerHTML = json;
435 } 478 }
436 } 479 }
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494 //TODO: Make proper Montage method
495
437 //Checking for Montage 496 //Checking for Montage
438 if (mJsSerialization) { 497 if (mJsSerialization) {
439 //Copy Montage library if needed 498 //Copy Montage library if needed
@@ -491,6 +550,19 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
491 mjstag.innerHTML = mJsSerialization; 550 mjstag.innerHTML = mJsSerialization;
492 mjsCreator = null; 551 mjsCreator = null;
493 } 552 }
553
554
555
556
557
558
559
560
561
562
563
564
565
494 //Cleaning URLs from HTML 566 //Cleaning URLs from HTML
495 var cleanHTML; 567 var cleanHTML;
496 if (ninjaWrapper) { 568 if (ninjaWrapper) {