From ac750fd9b9c311dcd48c6ee309607edc6fa048e1 Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Wed, 16 May 2012 14:22:18 -0700
Subject: Adding basic montage components I/O

Only for saving basic components without a reel.
---
 js/mediators/io-mediator.js | 72 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 13 deletions(-)

(limited to 'js/mediators/io-mediator.js')

diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index e6f2cc2d..6cdf70fe 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -219,11 +219,24 @@ exports.IoMediator = Montage.create(Component, {
     parseNinjaTemplateToHtml: {
         enumerable: false,
         value: function (template, ninjaWrapper) {
-            var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]));
+        	//TODO: Improve reference for rootUrl
+            var regexRootUrl,
+            	rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])),
+            	montageTemplate = template.mjsTemplateCreator.initWithDocument(template.document),
+            	mJsSerialization;
+            //Setting up expression for parsing URLs
             regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi');
             //Injecting head and body into old document
-            template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
-            template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
+            if (montageTemplate._ownerSerialization.length > 0) {
+            	template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, '');
+	            template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, '');
+	            //
+	            mJsSerialization = montageTemplate._ownerSerialization;
+            } else {
+            	template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
+	            template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
+            }
+            
             //Copying attributes to maintain same properties as the <body>
 			for (var n in template.body.attributes) {
 				if (template.body.attributes[n].value) {
@@ -233,15 +246,6 @@ exports.IoMediator = Montage.create(Component, {
 			}
             //TODO: Add attribute copying for <HEAD> and <HTML>
             
-            /*
-			var tc = this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.mjsTemplateCreator, code;
-            code = tc.initWithDocument(this.application.ninja.documentController.activeDocument.model.views.design.iframe.contentWindow.document);
-            console.log(code._ownerSerialization, code._document.getElementsByTagName('html')[0].innerHTML);
-            
-            template.file.content.document.head.innerHTML = mjscode._document.head.innerHTML.replace(regexRootUrl, '');
-            template.file.content.document.body.innerHTML = mjscode._document.body.innerHTML.replace(regexRootUrl, '');
-			*/
-            
             
             
             
@@ -521,7 +525,49 @@ function loadWebGL (e) {\n\
 
 
 
-
+			
+			//Checking for Montage
+			if (mJsSerialization) {
+				//Copy Montage library if needed
+                for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
+                    //Checking for Montage library to be available
+                    if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
+                        mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
+                        mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
+                        this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName);
+                        //TODO: Fix to allow no overwrite and nested locations
+                        var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/montage/"}}' });
+                    } else {
+                        //TODO: Error handle no available library to copy
+                    }
+                }
+                //
+                if (!mjslibtag) {
+                    mjslibtag = template.file.content.document.createElement('script');
+                    mjslibtag.setAttribute('type', 'text/javascript');
+                    mjslibtag.setAttribute('src', mjsDirName + '/montage/montage.js');
+                    mjslibtag.setAttribute('data-mjs-lib', 'true');
+                    if (ninjaWrapper) {
+                    	template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjslibtag);
+                    } else {
+                    	template.file.content.document.head.appendChild(mjslibtag);
+                    }
+                    
+                }
+                //
+                if (!mjstag) {
+                    mjstag = template.file.content.document.createElement('script');
+                    mjstag.setAttribute('type', 'text/montage-serialization');
+                    if (ninjaWrapper) {
+                    	template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(mjstag);
+                    } else {
+                    	template.file.content.document.head.appendChild(mjstag);
+                    }
+                    
+                }
+                //
+                mjstag.innerHTML = mJsSerialization;
+			}
 
 
             //
-- 
cgit v1.2.3


From a2afa558aba65b81f8b1b58687629def14ea471d Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Wed, 16 May 2012 14:37:32 -0700
Subject: Fixing reference to serialization tag

---
 js/mediators/io-mediator.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'js/mediators/io-mediator.js')

diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 6cdf70fe..7f7bd72a 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -433,7 +433,7 @@ exports.IoMediator = Montage.create(Component, {
                         if (scripts[i].getAttribute('data-ninja-webgl-rdge') !== null) {
                             webglrdgetag = scripts[i]; // TODO: Add logic to delete unneccesary tags
                         }
-                        if (scripts[i].getAttribute('type') !== 'text/montage-serialization') {
+                        if (scripts[i].getAttribute('type') === 'text/montage-serialization') {
                             mjstag = scripts[i]; // TODO: Add logic to delete unneccesary tags
                         }
                         if (scripts[i].getAttribute('data-mjs-lib') !== null) {
-- 
cgit v1.2.3


From 5cc5d29736d8bf253e3a168cdd6443e839ffb23c Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Wed, 16 May 2012 15:42:09 -0700
Subject: Fixing serialization referencing (new object per save)

---
 js/mediators/io-mediator.js | 60 +++++----------------------------------------
 1 file changed, 6 insertions(+), 54 deletions(-)

(limited to 'js/mediators/io-mediator.js')

diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 7f7bd72a..b1916446 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -222,8 +222,11 @@ exports.IoMediator = Montage.create(Component, {
         	//TODO: Improve reference for rootUrl
             var regexRootUrl,
             	rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])),
-            	montageTemplate = template.mjsTemplateCreator.initWithDocument(template.document),
-            	mJsSerialization;
+            	mjsCreator = template.mjsTemplateCreator.create(),
+            	mJsSerialization,
+            	montageTemplate;
+            //
+            montageTemplate = mjsCreator.initWithDocument(template.document);
             //Setting up expression for parsing URLs
             regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi');
             //Injecting head and body into old document
@@ -567,58 +570,8 @@ function loadWebGL (e) {\n\
                 }
                 //
                 mjstag.innerHTML = mJsSerialization;
+                mjsCreator = null;
 			}
-
-
-            //
-            
-            /*
-for (var m in template.mjs) {
-                mjsComponents.push(template.mjs[m]);
-                mjsCounter++;
-            }
-            //
-            if (template.mjs && mjsCounter > 0) {
-                var mjsDirName, mjsVersion,
-    				mjscode = temp.initWithHeadAndBodyElements(template.file.content.document.documentElement.head, template.file.content.document.documentElement.body, mjsComponents)._ownerSerialization;
-                //Copy Montage library if needed
-                for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
-                    //Checking for Montage library to be available
-                    if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Montage') {
-                        mjsDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase();
-                        mjsVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version;
-                        this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, mjsDirName);
-                        //TODO: Fix to allow no overwrite and nested locations
-                        var packjson = this.application.ninja.coreIoApi.createFile({ uri: template.file.root + 'package.json', contents: '{"mappings": {"montage": "' + mjsDirName + '/"}}' });
-                    } else {
-                        //TODO: Error handle no available library to copy
-                    }
-                }
-                //
-                if (!mjslibtag) {
-                    mjslibtag = template.file.content.document.createElement('script');
-                    mjslibtag.setAttribute('type', 'text/javascript');
-                    mjslibtag.setAttribute('src', mjsDirName + '/montage.js');
-                    mjslibtag.setAttribute('data-mjs-lib', 'true');
-                    template.file.content.document.head.appendChild(mjslibtag);
-                }
-                //
-                if (!mjstag) {
-                    mjstag = template.file.content.document.createElement('script');
-                    mjstag.setAttribute('type', 'text/montage-serialization');
-                    template.file.content.document.head.appendChild(mjstag);
-                }
-                //
-                mjstag.innerHTML = mjscode;
-            }
-*/
-
-
-
-
-
-			
-
             //Cleaning URLs from HTML
             var cleanHTML;
             if (ninjaWrapper) {
@@ -639,7 +592,6 @@ for (var m in template.mjs) {
             	cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div');
             	cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div');
             }
-            
             //
             return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), ''));
         }
-- 
cgit v1.2.3