diff options
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r-- | js/mediators/io-mediator.js | 212 |
1 files changed, 148 insertions, 64 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index b1916446..e9ed86d7 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -203,6 +203,59 @@ exports.IoMediator = Montage.create(Component, { | |||
203 | }, | 203 | }, |
204 | //////////////////////////////////////////////////////////////////// | 204 | //////////////////////////////////////////////////////////////////// |
205 | // | 205 | // |
206 | getDataDirectory: { | ||
207 | value: function (path) { | ||
208 | //TODO: Implement user overwrite | ||
209 | return this._getUserDirectory(path+'data/'); | ||
210 | } | ||
211 | }, | ||
212 | //////////////////////////////////////////////////////////////////// | ||
213 | // | ||
214 | getNinjaDirectory: { | ||
215 | value: function (path) { | ||
216 | //TODO: Implement user overwrite | ||
217 | return this._getUserDirectory(this.getDataDirectory(path)+'ninja/'); | ||
218 | } | ||
219 | }, | ||
220 | //////////////////////////////////////////////////////////////////// | ||
221 | // | ||
222 | getCanvasDirectory: { | ||
223 | value: function (path) { | ||
224 | //TODO: Implement user overwrite | ||
225 | return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/'); | ||
226 | } | ||
227 | }, | ||
228 | //////////////////////////////////////////////////////////////////// | ||
229 | // | ||
230 | _getUserDirectory: { | ||
231 | value: function (path) { | ||
232 | //Checking for data directory | ||
233 | var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory; | ||
234 | //Creating directory if doesn't exists | ||
235 | switch (check.status) { | ||
236 | case 204: //Exists | ||
237 | directory = path; | ||
238 | break; | ||
239 | case 404: //Doesn't exists | ||
240 | directory = this.application.ninja.coreIoApi.createDirectory({uri: path}); | ||
241 | //Checking for success | ||
242 | if (directory.status === 201) { | ||
243 | directory = path; | ||
244 | } else { | ||
245 | //Error | ||
246 | directory = null; | ||
247 | } | ||
248 | break; | ||
249 | default: //Error | ||
250 | directory = null; | ||
251 | break; | ||
252 | } | ||
253 | //Returning the path to the directory on disk (null for any error) | ||
254 | return directory; | ||
255 | } | ||
256 | }, | ||
257 | //////////////////////////////////////////////////////////////////// | ||
258 | // | ||
206 | parseHtmlToNinjaTemplate: { | 259 | parseHtmlToNinjaTemplate: { |
207 | enumerable: false, | 260 | enumerable: false, |
208 | value: function (html) { | 261 | value: function (html) { |
@@ -225,7 +278,7 @@ exports.IoMediator = Montage.create(Component, { | |||
225 | mjsCreator = template.mjsTemplateCreator.create(), | 278 | mjsCreator = template.mjsTemplateCreator.create(), |
226 | mJsSerialization, | 279 | mJsSerialization, |
227 | montageTemplate; | 280 | montageTemplate; |
228 | // | 281 | //Creating instance of template creator |
229 | montageTemplate = mjsCreator.initWithDocument(template.document); | 282 | montageTemplate = mjsCreator.initWithDocument(template.document); |
230 | //Setting up expression for parsing URLs | 283 | //Setting up expression for parsing URLs |
231 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); | 284 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); |
@@ -239,7 +292,6 @@ exports.IoMediator = Montage.create(Component, { | |||
239 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); | 292 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); |
240 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); | 293 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); |
241 | } | 294 | } |
242 | |||
243 | //Copying attributes to maintain same properties as the <body> | 295 | //Copying attributes to maintain same properties as the <body> |
244 | for (var n in template.body.attributes) { | 296 | for (var n in template.body.attributes) { |
245 | if (template.body.attributes[n].value) { | 297 | if (template.body.attributes[n].value) { |
@@ -250,6 +302,7 @@ exports.IoMediator = Montage.create(Component, { | |||
250 | //TODO: Add attribute copying for <HEAD> and <HTML> | 302 | //TODO: Add attribute copying for <HEAD> and <HTML> |
251 | 303 | ||
252 | 304 | ||
305 | //console.log(template.file.content.document.getElementsByTagName('html')[0].innerHTML); | ||
253 | 306 | ||
254 | 307 | ||
255 | //Getting all CSS (style or link) tags | 308 | //Getting all CSS (style or link) tags |
@@ -266,7 +319,7 @@ exports.IoMediator = Montage.create(Component, { | |||
266 | } | 319 | } |
267 | ////////////////////////////////////////////////// | 320 | ////////////////////////////////////////////////// |
268 | 321 | ||
269 | // | 322 | //Adding to tags to be removed form template |
270 | for (var f in njtemplatetags) { | 323 | for (var f in njtemplatetags) { |
271 | if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); | 324 | if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); |
272 | } | 325 | } |
@@ -405,9 +458,45 @@ exports.IoMediator = Montage.create(Component, { | |||
405 | } | 458 | } |
406 | } | 459 | } |
407 | } | 460 | } |
461 | // | ||
462 | var matchingtags = [], scripts = template.file.content.document.getElementsByTagName('script'), webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag; | ||
463 | //this.getDataDirectory(template.file.root) | ||
464 | //this.getNinjaDirectory(template.file.root) | ||
465 | // | ||
466 | for (var i in scripts) { | ||
467 | if (scripts[i].getAttribute) { | ||
468 | if (scripts[i].getAttribute('data-ninja-canvas') !== null) {//TODO: Use querySelectorAll | ||
469 | matchingtags.push(scripts[i]); | ||
470 | } | ||
471 | if (scripts[i].getAttribute('data-ninja-canvas-lib') !== null) { | ||
472 | webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
473 | } | ||
474 | if (scripts[i].getAttribute('data-ninja-canvas-rdge') !== null) { | ||
475 | webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
476 | } | ||
477 | if (scripts[i].getAttribute('type') === 'text/montage-serialization') { | ||
478 | mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
479 | } | ||
480 | if (scripts[i].getAttribute('data-mjs-lib') !== null) { | ||
481 | mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
482 | } | ||
483 | } | ||
484 | } | ||
408 | //Checking for webGL elements in document | 485 | //Checking for webGL elements in document |
409 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix | 486 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix |
410 | var rdgeDirName, rdgeVersion; | 487 | var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1; |
488 | // | ||
489 | if (cvsDataDir && !matchingtags.length) { | ||
490 | fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]; | ||
491 | if (!this._getUserDirectory(fileCvsDir)) { | ||
492 | fileCvsDirAppend = fileCvsDir+cvsDirCounter; | ||
493 | while (!this._getUserDirectory(fileCvsDirAppend)) { | ||
494 | fileCvsDirAppend = fileCvsDir+(cvsDirCounter++); | ||
495 | } | ||
496 | } | ||
497 | //TODO: Allow user overwrite | ||
498 | fileCvsDir += '/'; | ||
499 | } | ||
411 | //Copy webGL library if needed | 500 | //Copy webGL library if needed |
412 | for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { | 501 | for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { |
413 | //Checking for RDGE library to be available | 502 | //Checking for RDGE library to be available |
@@ -420,31 +509,6 @@ exports.IoMediator = Montage.create(Component, { | |||
420 | } | 509 | } |
421 | } | 510 | } |
422 | // | 511 | // |
423 | var json, matchingtags = [], webgltag, scripts = template.file.content.document.getElementsByTagName('script'), webgljstag, webgllibtag, webglrdgetag, mjstag, mjslibtag; | ||
424 | // | ||
425 | for (var i in scripts) { | ||
426 | if (scripts[i].getAttribute) { | ||
427 | if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll | ||
428 | matchingtags.push(scripts[i]); | ||
429 | } | ||
430 | if (scripts[i].getAttribute('data-ninja-webgl-js') !== null) { | ||
431 | webgljstag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
432 | } | ||
433 | if (scripts[i].getAttribute('data-ninja-webgl-lib') !== null) { | ||
434 | webgllibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
435 | } | ||
436 | if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { | ||
437 | webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
438 | } | ||
439 | if (scripts[i].getAttribute('type') === 'text/montage-serialization') { | ||
440 | mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
441 | } | ||
442 | if (scripts[i].getAttribute('data-mjs-lib') !== null) { | ||
443 | mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
444 | } | ||
445 | } | ||
446 | } | ||
447 | // | ||
448 | if (matchingtags.length) { | 512 | if (matchingtags.length) { |
449 | if (matchingtags.length === 1) { | 513 | if (matchingtags.length === 1) { |
450 | webgltag = matchingtags[0]; | 514 | webgltag = matchingtags[0]; |
@@ -453,12 +517,12 @@ exports.IoMediator = Montage.create(Component, { | |||
453 | webgltag = matchingtags[matchingtags.length - 1]; //Saving all data to last one... | 517 | webgltag = matchingtags[matchingtags.length - 1]; //Saving all data to last one... |
454 | } | 518 | } |
455 | } | 519 | } |
456 | // | 520 | //TODO: Add check for file needed |
457 | if (!webglrdgetag) { | 521 | if (!webglrdgetag) { |
458 | webglrdgetag = template.file.content.document.createElement('script'); | 522 | webglrdgetag = template.file.content.document.createElement('script'); |
459 | webglrdgetag.setAttribute('type', 'text/javascript'); | 523 | webglrdgetag.setAttribute('type', 'text/javascript'); |
460 | webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); | 524 | webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); |
461 | webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); | 525 | webglrdgetag.setAttribute('data-ninja-canvas-rdge', 'true'); |
462 | if (ninjaWrapper) { | 526 | if (ninjaWrapper) { |
463 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); | 527 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); |
464 | } else { | 528 | } else { |
@@ -470,7 +534,7 @@ exports.IoMediator = Montage.create(Component, { | |||
470 | webgllibtag = template.file.content.document.createElement('script'); | 534 | webgllibtag = template.file.content.document.createElement('script'); |
471 | webgllibtag.setAttribute('type', 'text/javascript'); | 535 | webgllibtag.setAttribute('type', 'text/javascript'); |
472 | webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); | 536 | webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); |
473 | webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); | 537 | webgllibtag.setAttribute('data-ninja-canvas-lib', 'true'); |
474 | if (ninjaWrapper) { | 538 | if (ninjaWrapper) { |
475 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); | 539 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); |
476 | } else { |