aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorArmen Kesablyan2012-05-17 14:01:38 -0700
committerArmen Kesablyan2012-05-17 14:01:38 -0700
commit6c8f3525b839e82cf43df43700a0160ee2c5458f (patch)
tree3fb801fa54b759c5568d75bb467e02652ce77c3e /js/mediators
parente8ae5db7ce7023b638375cbc27a3f7b7a2f77b23 (diff)
parent342c97ac9b727b22a7b0bfefca4d2a168bc3055b (diff)
downloadninja-6c8f3525b839e82cf43df43700a0160ee2c5458f.tar.gz
Merge branch 'refs/heads/dom-architecture' into binding
Conflicts: css/ninja.css scss/imports/scss/_toolbar.scss Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js88
-rwxr-xr-xjs/mediators/keyboard-mediator.js45
2 files changed, 61 insertions, 72 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 8346c75e..b1916446 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -219,11 +219,27 @@ exports.IoMediator = Montage.create(Component, {
219 parseNinjaTemplateToHtml: { 219 parseNinjaTemplateToHtml: {
220 enumerable: false, 220 enumerable: false,
221 value: function (template, ninjaWrapper) { 221 value: function (template, ninjaWrapper) {
222 var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); 222 //TODO: Improve reference for rootUrl
223 var regexRootUrl,
224 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])),
225 mjsCreator = template.mjsTemplateCreator.create(),
226 mJsSerialization,
227 montageTemplate;
228 //
229 montageTemplate = mjsCreator.initWithDocument(template.document);
230 //Setting up expression for parsing URLs
223 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); 231 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi');
224 //Injecting head and body into old document 232 //Injecting head and body into old document
225 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); 233 if (montageTemplate._ownerSerialization.length > 0) {
226 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); 234 template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, '');
235 template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, '');
236 //
237 mJsSerialization = montageTemplate._ownerSerialization;
238 } else {
239 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
240 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
241 }
242
227 //Copying attributes to maintain same properties as the <body> 243 //Copying attributes to maintain same properties as the <body>
228 for (var n in template.body.attributes) { 244 for (var n in template.body.attributes) {
229 if (template.body.attributes[n].value) { 245 if (template.body.attributes[n].value) {
@@ -233,19 +249,6 @@ exports.IoMediator = Montage.create(Component, {
233 } 249 }
234 //TODO: Add attribute copying for <HEAD> and <HTML> 250 //TODO: Add attribute copying for <HEAD> and <HTML>
235 251
236 /*
237//Testing using montage clean up method
238 var mjscode, mjsTemp = TemplateCreator.create();
239
240 //mjscode = mjsTemp.initWithHeadAndBodyElements(template.head, template.body);
241 //mjscode = mjsTemp.initWithDocument(template.file.content.document);
242 mjscode = mjsTemp.initWithDocument(template.document);
243
244 console.log(template.head, mjscode._document.head);
245 template.file.content.document.head.innerHTML = mjscode._document.head.innerHTML.replace(regexRootUrl, '');
246 template.file.content.document.body.innerHTML = mjscode._document.body.innerHTML.replace(regexRootUrl, '');
247*/
248
249 252
250 253
251 254
@@ -433,7 +436,7 @@ exports.IoMediator = Montage.create(Component, {
433 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) { 436 if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) {
434 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags 437 webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
435 } 438 }
436 if (scripts[i].getAttribute('type') !== 'text/montage-serialization') { 439 if (scripts[i].getAttribute('type') === 'text/montage-serialization') {
437 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags 440 mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
438 } 441 }
439 if (scripts[i].getAttribute('data-mjs-lib') !== null) { 442 if (scripts[i].getAttribute('data-mjs-lib') !== null) {
@@ -525,21 +528,10 @@ function loadWebGL (e) {\n\
525 528
526 529
527 530
528 531
529 532 //Checking for Montage
530 533 if (mJsSerialization) {
531 // 534 //Copy Montage library if needed
532
533 /*
534for (var m in template.mjs) {
535 mjsComponents.push(template.mjs[m]);
536 mjsCounter++;
537 }
538 //
539 if (template.mjs && mjsCounter > 0) {
540 var mjsDirName, mjsVersion,
541 mjscode = temp.initWithHeadAndBodyElements(template.file.content.document.documentElement.head, template.file.content.document.documentElement.body, mjsComponents)._ownerSerialization;
542 //Copy Montage library if needed
543 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { 535 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
544 //Checking for Montage library to be available 536 //Checking for Montage library to be available
545 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') { 537 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
@@ -547,7 +539,7 @@ for (var m in template.mjs) {
547 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; 539 mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
548 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName); 540 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName);
549 //TODO: Fix to allow no overwrite and nested locations 541 //TODO: Fix to allow no overwrite and nested locations
550 var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/"}}' }); 542 var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' });
551 } else { 543 } else {
552 //TODO: Error handle no available library to copy 544 //TODO: Error handle no available library to copy
553 } 545 }
@@ -556,27 +548,30 @@ for (var m in template.mjs) {
556 if (!mjslibtag) { 548 if (!mjslibtag) {
557 mjslibtag = template.file.content.document.createElement('script'); 549 mjslibtag = template.file.content.document.createElement('script');
558 mjslibtag.setAttribute('type', 'text/javascript'); 550 mjslibtag.setAttribute('type', 'text/javascript');
559 mjslibtag.setAttribute('src', mjsDirName + '/montage.js'); 551 mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js');
560 mjslibtag.setAttribute('data-mjs-lib', 'true'); 552 mjslibtag.setAttribute('data-mjs-lib', 'true');
561 template.file.content.document.head.appendChild(mjslibtag); 553 if (ninjaWrapper) {
554 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag);
555 } else {
556 template.file.content.document.head.appendChild(mjslibtag);
557 }
558
562 } 559 }
563 // 560 //
564 if (!mjstag) { 561 if (!mjstag) {
565 mjstag = template.file.content.document.createElement('script'); 562 mjstag = template.file.content.document.createElement('script');
566 mjstag.setAttribute('type', 'text/montage-serialization'); 563 mjstag.setAttribute('type', 'text/montage-serialization');
567 template.file.content.document.head.appendChild(mjstag); 564 if (ninjaWrapper) {
565 template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjstag);
566 } else {
567 template.file.content.document.head.appendChild(mjstag);
568 }
569
568 } 570 }
569 // 571 //
570 mjstag.innerHTML = mjscode; 572 mjstag.innerHTML = mJsSerialization;
571 } 573 mjsCreator = null;
572*/ 574 }
573
574
575
576
577
578
579
580 //Cleaning URLs from HTML 575 //Cleaning URLs from HTML
581 var cleanHTML; 576 var cleanHTML;
582 if (ninjaWrapper) { 577 if (ninjaWrapper) {
@@ -597,7 +592,6 @@ for (var m in template.mjs) {
597 cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div'); 592 cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div');
598 cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div'); 593 cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div');
599 } 594 }
600
601 // 595 //
602 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); 596 return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
603 } 597 }
diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js
index 49960f58..23a2ce75 100755
--- a/js/mediators/keyboard-mediator.js
+++ b/js/mediators/keyboard-mediator.js
@@ -67,7 +67,7 @@ exports.KeyboardMediator = Montage.create(Component, {
67 document.addEventListener("keydown", this, false); 67 document.addEventListener("keydown", this, false);
68 document.addEventListener("keyup", this, false); 68 document.addEventListener("keyup", this, false);
69 69
70 this.addEventListener("change@appModel.livePreview", this.handleLivePreview, false); 70 this.addPropertyChangeListener("appModel.livePreview", this.handleLivePreview, false);
71 } 71 }
72 }, 72 },
73 73
@@ -111,35 +111,35 @@ exports.KeyboardMediator = Montage.create(Component, {
111 // Shortcut for Selection Tool is V 111 // Shortcut for Selection Tool is V
112 if(evt.keyCode === Keyboard.V) { 112 if(evt.keyCode === Keyboard.V) {
113 evt.preventDefault(); 113 evt.preventDefault();
114 this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[0]}); 114 this.application.ninja.handleSelectTool({ "detail": this.application.ninja.toolsData.defaultToolsData[this.application.ninja.toolsData.selectionToolIndex] });
115 return; 115 return;
116 } 116 }
117 117
118 // Shortcut for Tag Tool is D 118 // Shortcut for Tag Tool is D
119 if(evt.keyCode === Keyboard.D){ 119 if(evt.keyCode === Keyboard.D){
120 evt.preventDefault(); 120 evt.preventDefault();
121 this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[4]}); 121 this.application.ninja.handleSelectTool({ "detail": this.application.ninja.toolsData.defaultToolsData[this.application.ninja.toolsData.tagToolIndex] });
122 return; 122 return;
123 } 123 }
124 124
125 // Shortcut for Rotate Tool is W 125 // Shortcut for Rotate Tool is W
126 if(evt.keyCode === Keyboard.W){ 126 if(evt.keyCode === Keyboard.W){
127 evt.preventDefault(); 127 evt.preventDefault();
128 this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[2]}); 128 this.application.ninja.handleSelectTool({ "detail": this.application.ninja.toolsData.defaultToolsData[this.application.ninja.toolsData.rotate3DToolIndex] });
129 return; 129 return;
130 } 130 }
131 131
132 // Shortcut for Translate Tool is G 132 // Shortcut for Translate Tool is G