diff options
author | Nivesh Rajbhandari | 2012-05-18 17:12:53 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-05-18 17:12:53 -0700 |
commit | 8a15ac2b4a7d528d04c73bf6d9c6e724d8c6ac50 (patch) | |
tree | 345d582d72c2064e6e4ebbd23cbb7bb6c81e96df /js/mediators | |
parent | ca70f18a62a2a2b5670be132361e3a3f5907d920 (diff) | |
parent | e7c288fe8f5d3a9e5c9f0eb0a045c6c195a0e7b8 (diff) | |
download | ninja-8a15ac2b4a7d528d04c73bf6d9c6e724d8c6ac50.tar.gz |
Merge branch 'refs/heads/dom-architecture-master' into Dom-Architecture
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 79 |
1 files changed, 44 insertions, 35 deletions
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 | } | ||
425 | if (scripts[i].getAttribute('type') === 'text/montage-serialization') { | ||
426 | mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
427 | } | ||
428 | if (scripts[i].getAttribute('data-mjs-lib') !== null) { | ||
429 | mjslibtag = scripts[i]; // TODO: Add logic to delete unneccesary tags | ||
430 | } | ||
431 | } | ||
432 | } | ||
408 | //Checking for webGL elements in document | 433 | //Checking for webGL elements in document |
409 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix | 434 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix |
410 | var rdgeDirName, rdgeVersion; | 435 | var rdgeDirName, rdgeVersion; |
@@ -420,31 +445,6 @@ exports.IoMediator = Montage.create(Component, { | |||
420 | } | 445 | } |
421 | } | 446 | } |
422 | // | 447 | // |
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) { | 448 | if (matchingtags.length) { |
449 | if (matchingtags.length === 1) { | 449 | if (matchingtags.length === 1) { |
450 | webgltag = matchingtags[0]; | 450 | webgltag = matchingtags[0]; |
@@ -510,7 +510,7 @@ function loadWebGL (e) {\n\ | |||
510 | }\ | 510 | }\ |
511 | "; | 511 | "; |
512 | //TODO: This data should be saved to a JSON file eventually | 512 | //TODO: This data should be saved to a JSON file eventually |
513 | json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": ['; | 513 | var json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": ['; |
514 | //Looping through data to create escaped array | 514 | //Looping through data to create escaped array |
515 | for (var j = 0; template.webgl[j]; j++) { | 515 | for (var j = 0; template.webgl[j]; j++) { |
516 | if (j === 0) { | 516 | if (j === 0) { |
@@ -524,11 +524,6 @@ function loadWebGL (e) {\n\ | |||
524 | //Setting string in tag | 524 | //Setting string in tag |
525 | webgltag.innerHTML = json; | 525 | webgltag.innerHTML = json; |
526 | } | 526 | } |
527 | |||
528 | |||
529 | |||
530 | |||
531 | |||
532 | //Checking for Montage | 527 | //Checking for Montage |
533 | if (mJsSerialization) { | 528 | if (mJsSerialization) { |
534 | //Copy Montage library if needed | 529 | //Copy Montage library if needed |
@@ -538,8 +533,21 @@ function loadWebGL (e) {\n\ | |||
538 | mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); | 533 | mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); |
539 | mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; | 534 | mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; |
540 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); | 535 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); |
536 | |||
537 | |||
538 | |||
541 | //TODO: Fix to allow no overwrite and nested locations | 539 | //TODO: Fix to allow no overwrite and nested locations |
542 | var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' }); | 540 | var mjsCheck, mjsPath = template.file.root + 'package.json'; |
541 | mjsCheck = this.application.ninja.coreIoApi.fileExists({uri: mjsPath}); | ||
542 | // | ||
543 | if (!mjsCheck || mjsCheck.status !== 204) { | ||
544 | var packjson = this.application.ninja.coreIoApi.createFile({ uri: mjsPath, contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' }); | ||
545 | } else { | ||
546 | //Already exists | ||
547 | } | ||
548 | |||
549 | |||
550 | |||
543 | } else { | 551 | } else { |
544 | //TODO: Error handle no available library to copy | 552 | //TODO: Error handle no available library to copy |
545 | } | 553 | } |
@@ -549,6 +557,7 @@ function loadWebGL (e) {\n\ | |||
549 | mjslibtag = template.file.content.document.createElement('script'); | 557 | mjslibtag = template.file.content.document.createElement('script'); |
550 | mjslibtag.setAttribute('type', 'text/javascript'); | 558 | mjslibtag.setAttribute('type', 'text/javascript'); |
551 | mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js'); | 559 | mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js'); |
560 | mjslibtag.setAttribute('data-package', '.'); | ||
552 | mjslibtag.setAttribute('data-mjs-lib', 'true'); | 561 | mjslibtag.setAttribute('data-mjs-lib', 'true'); |
553 | if (ninjaWrapper) { | 562 | if (ninjaWrapper) { |
554 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag); | 563 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag); |