diff options
Diffstat (limited to 'js/document/mediators/template.js')
-rwxr-xr-x | js/document/mediators/template.js | 180 |
1 files changed, 90 insertions, 90 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 6ab58e32..7451ffa2 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js | |||
@@ -35,7 +35,7 @@ var Montage = require("montage/core/core").Montage, | |||
35 | TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator, | 35 | TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator, |
36 | ClassUuid = require("js/components/core/class-uuid").ClassUuid; | 36 | ClassUuid = require("js/components/core/class-uuid").ClassUuid; |
37 | //////////////////////////////////////////////////////////////////////// | 37 | //////////////////////////////////////////////////////////////////////// |
38 | // | 38 | // |
39 | exports.TemplateDocumentMediator = Montage.create(Component, { | 39 | exports.TemplateDocumentMediator = Montage.create(Component, { |
40 | //////////////////////////////////////////////////////////////////// | 40 | //////////////////////////////////////////////////////////////////// |
41 | // | 41 | // |
@@ -167,7 +167,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
167 | for (var n in template.body.attributes) { | 167 | for (var n in template.body.attributes) { |
168 | if (template.body.attributes[n].value) { | 168 | if (template.body.attributes[n].value) { |
169 | template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); | 169 | template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | // | 172 | // |
173 | if(template.template) { | 173 | if(template.template) { |
@@ -233,7 +233,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
233 | for (var n in presentNodes) { | 233 | for (var n in presentNodes) { |
234 | // | 234 | // |
235 | if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { | 235 | if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { |
236 | toremovetags.push(presentNodes[n]); | 236 | toremovetags.push(presentNodes[n]); |
237 | } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { | 237 | } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { |
238 | //Removing attribute | 238 | //Removing attribute |
239 | presentNodes[n].removeAttribute('data-ninja-node'); | 239 | presentNodes[n].removeAttribute('data-ninja-node'); |
@@ -243,7 +243,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
243 | var styletags = template.file.content.document.getElementsByTagName('style'), | 243 | var styletags = template.file.content.document.getElementsByTagName('style'), |
244 | linktags = template.file.content.document.getElementsByTagName('link'), | 244 | linktags = template.file.content.document.getElementsByTagName('link'), |
245 | njtemplatetags = template.file.content.document.querySelectorAll('[data-ninja-template]'); | 245 | njtemplatetags = template.file.content.document.querySelectorAll('[data-ninja-template]'); |
246 | 246 | ||
247 | //Adding to tags to be removed form template | 247 | //Adding to tags to be removed form template |
248 | for (var f in njtemplatetags) { | 248 | for (var f in njtemplatetags) { |
249 | if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); | 249 | if (njtemplatetags[f].getAttribute) toremovetags.push(njtemplatetags[f]); |
@@ -266,7 +266,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
266 | //Checking head first | 266 | //Checking head first |
267 | template.file.content.document.head.removeChild(toremovetags[h]); | 267 | template.file.content.document.head.removeChild(toremovetags[h]); |
268 | } catch (e) { | 268 | } catch (e) { |
269 | 269 | ||
270 | } | 270 | } |
271 | try { | 271 | try { |
272 | //Checking body if not in head | 272 | //Checking body if not in head |
@@ -287,23 +287,23 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
287 | } | 287 | } |
288 | } | 288 | } |
289 | } | 289 | } |
290 | 290 | ||
291 | 291 | ||
292 | 292 | ||
293 | 293 | ||
294 | 294 | ||
295 | 295 | ||
296 | 296 | ||
297 | 297 | ||
298 | 298 | ||
299 | 299 | ||
300 | 300 | ||
301 | 301 | ||
302 | 302 | ||
303 | //TODO: Make proper CSS method | 303 | //TODO: Make proper CSS method |
304 | 304 | ||
305 | 305 | ||
306 | 306 | ||
307 | //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS) | 307 | //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS) |
308 | if (template.styles) { | 308 | if (template.styles) { |
309 | //Getting all style tags | 309 | //Getting all style tags |
@@ -400,24 +400,24 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
400 | } | 400 | } |
401 | } | 401 | } |
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | 405 | ||
406 | 406 | ||
407 | 407 | ||
408 | 408 | ||
409 | 409 | ||
410 | 410 | ||
411 | 411 | ||
412 | 412 | ||
413 | 413 | ||
414 | 414 | ||
415 | 415 | ||
416 | 416 | ||
417 | 417 | ||
418 | 418 | ||
419 | 419 | ||
420 | 420 | ||
421 | // | 421 | // |
422 | var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], | 422 | var webgltag, webgllibtag, webglrdgetag, mjstag, mjslibtag, matchingtags = [], |
423 | scripts = template.file.content.document.getElementsByTagName('script'), | 423 | scripts = template.file.content.document.getElementsByTagName('script'), |
@@ -445,33 +445,33 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
445 | } | 445 | } |
446 | } | 446 | } |
447 | } | 447 | } |
448 | 448 | ||
449 | 449 | ||
450 | 450 | ||
451 | 451 | ||
452 | //TODO: Make proper webGL/Canvas method | 452 | //TODO: Make proper webGL/Canvas method |
453 | 453 | ||
454 | 454 | ||
455 | //Checking for webGL elements in document | 455 | //Checking for webGL elements in document |
456 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix | 456 | if (template.webgl && template.webgl.length > 1) {//TODO: Should be length 0, hack for a temp fix |
457 | var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc; | 457 | var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc; |
458 | // | 458 | // |
459 | if (cvsDataDir && !matchingtags.length && !webgllibtag) { | 459 | if (cvsDataDir && !matchingtags.length && !webgllibtag) { |
460 | 460 | ||
461 | if (template.libs.canvasId) { | 461 | if (template.libs.canvasId) { |
462 | libsobserver.canvasId = template.libs.canvasId; | 462 | libsobserver.canvasId = template.libs.canvasId; |
463 | } else { | 463 | } else { |
464 | libsobserver.canvasId = ClassUuid.generate(); | 464 | libsobserver.canvasId = ClassUuid.generate(); |
465 | } | 465 | } |
466 | 466 | ||
467 | //Creating data directory, will include materials at a later time | 467 | //Creating data directory, will include materials at a later time |
468 | fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]+'_'+libsobserver.canvasId; | 468 | fileCvsDir = cvsDataDir+template.file.name.split('.'+template.file.extension)[0]+'_'+libsobserver.canvasId; |
469 | 469 | ||
470 | if (!this._getUserDirectory(fileCvsDir)) { | 470 | if (!this._getUserDirectory(fileCvsDir)) { |
471 | //TODO: create proper logic not to overwrite files | 471 | //TODO: create proper logic not to overwrite files |
472 | console.log('error'); | 472 | console.log('error'); |
473 | } | 473 | } |
474 | 474 | ||
475 | fileCvsDir += '/'; | 475 | fileCvsDir += '/'; |
476 | } else if (webgllibtag && webgllibtag.getAttribute && webgllibtag.getAttribute('data-ninja-canvas-json') !== null) { | 476 | } else if (webgllibtag && webgllibtag.getAttribute && webgllibtag.getAttribute('data-ninja-canvas-json') !== null) { |
477 | fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json'); | 477 | fileOrgDataSrc = template.file.root+webgllibtag.getAttribute('data-ninja-canvas-json'); |
@@ -530,10 +530,10 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
530 | template.file.content.document.head.appendChild(webgltag); | 530 | template.file.content.document.head.appendChild(webgltag); |
531 | } | 531 | } |
532 | } | 532 | } |
533 | 533 | ||
534 | //TODO: Decide if this should be over-writter or only written on creation | 534 | //TODO: Decide if this should be over-writter or only written on creation |
535 | var rootElement = 'document.body'; //TODO: Set actual root element | 535 | var rootElement = 'document.body'; //TODO: Set actual root element |
536 | 536 | ||
537 | //TODO: This data should be saved to a JSON file eventually | 537 | //TODO: This data should be saved to a JSON file eventually |
538 | var json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": ['; | 538 | var json = '\n({\n\t"version": "' + rdgeVersion + '",\n\t"directory": "' + rdgeDirName + '/",\n\t"data": ['; |
539 | //Looping through data to create escaped array | 539 | //Looping through data to create escaped array |
@@ -569,29 +569,29 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
569 | } else { | 569 | } else { |
570 | //Error | 570 | //Error |
571 | } | 571 | } |
572 | 572 | ||
573 | 573 | ||
574 | } else { | 574 | } else { |
575 | webgllibtag.setAttribute('data-ninja-canvas-libpath', rdgeDirName); | 575 | webgllibtag.setAttribute('data-ninja-canvas-libpath', rdgeDirName); |
576 | webgltag.innerHTML = json; | 576 | webgltag.innerHTML = json; |
577 | } | 577 | } |
578 | } | 578 | } |
579 | 579 | ||
580 | 580 | ||
581 | 581 | ||
582 | 582 | ||
583 | 583 | ||
584 | 584 | ||
585 | 585 | ||
586 |