aboutsummaryrefslogtreecommitdiff
path: root/js/document/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/mediators')
-rwxr-xr-xjs/document/mediators/io.js18
-rwxr-xr-xjs/document/mediators/template.js620
2 files changed, 319 insertions, 319 deletions
diff --git a/js/document/mediators/io.js b/js/document/mediators/io.js
index 85d805ad..9f56a9ea 100755
--- a/js/document/mediators/io.js
+++ b/js/document/mediators/io.js
@@ -30,19 +30,19 @@ POSSIBILITY OF SUCH DAMAGE.
30 30
31//////////////////////////////////////////////////////////////////////// 31////////////////////////////////////////////////////////////////////////
32// 32//
33var Montage = require("montage/core/core").Montage, 33var Montage = require("montage/core/core").Montage,
34 Component = require("montage/ui/component").Component; 34 Component = require("montage/ui/component").Component;
35//////////////////////////////////////////////////////////////////////// 35////////////////////////////////////////////////////////////////////////
36// 36//
37exports.IoDocumentMediator = Montage.create(Component, { 37exports.IoDocumentMediator = Montage.create(Component, {
38 //////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////
39 // 39 //
40 hasTemplate: { 40 hasTemplate: {
41 enumerable: false, 41 enumerable: false,
42 value: false 42 value: false
43 } 43 }
44 //////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////
45 //////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////
46}); 46});
47//////////////////////////////////////////////////////////////////////// 47////////////////////////////////////////////////////////////////////////
48//////////////////////////////////////////////////////////////////////// 48////////////////////////////////////////////////////////////////////////
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index 982b410f..7451ffa2 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -30,16 +30,16 @@ POSSIBILITY OF SUCH DAMAGE.
30 30
31//////////////////////////////////////////////////////////////////////// 31////////////////////////////////////////////////////////////////////////
32// 32//
33var Montage = require("montage/core/core").Montage, 33var Montage = require("montage/core/core").Montage,
34 Component = require("montage/ui/component").Component, 34 Component = require("montage/ui/component").Component,
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//
39exports.TemplateDocumentMediator = Montage.create(Component, { 39exports.TemplateDocumentMediator = Montage.create(Component, {
40 //////////////////////////////////////////////////////////////////// 40 ////////////////////////////////////////////////////////////////////
41 // 41 //
42 hasTemplate: { 42 hasTemplate: {
43 value: false 43 value: false
44 }, 44 },
45 //////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////
@@ -53,55 +53,55 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
53 //////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////
54 // 54 //
55 getDataDirectory: { 55 getDataDirectory: {
56 value: function (path) { 56 value: function (path) {
57 //TODO: Implement user overwrite 57 //TODO: Implement user overwrite
58 return this._getUserDirectory(path+'data/'); 58 return this._getUserDirectory(path+'data/');
59 } 59 }
60 }, 60 },
61 //////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////
62 // 62 //
63 getNinjaDirectory: { 63 getNinjaDirectory: {
64 value: function (path) { 64 value: function (path) {
65 //TODO: Implement user overwrite 65 //TODO: Implement user overwrite
66 return this._getUserDirectory(this.getDataDirectory(path)+'ninja/'); 66 return this._getUserDirectory(this.getDataDirectory(path)+'ninja/');
67 } 67 }
68 }, 68 },
69 //////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////
70 // 70 //
71 getCanvasDirectory: { 71 getCanvasDirectory: {
72 value: function (path) { 72 value: function (path) {
73 //TODO: Implement user overwrite 73 //TODO: Implement user overwrite
74 return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/'); 74 return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/');
75 } 75 }
76 }, 76 },
77 //////////////////////////////////////////////////////////////////// 77 ////////////////////////////////////////////////////////////////////
78 // 78 //
79 _getUserDirectory: { 79 _getUserDirectory: {
80 value: function (path) { 80 value: function (path) {
81 //Checking for data directory 81 //Checking for data directory
82 var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory; 82 var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory;
83 //Creating directory if doesn't exists 83 //Creating directory if doesn't exists
84 switch (check.status) { 84 switch (check.status) {
85 case 204: //Exists 85 case 204: //Exists
86 directory = path; 86 directory = path;
87 break; 87 break;
88 case 404: //Doesn't exists 88 case 404: //Doesn't exists
89 directory = this.application.ninja.coreIoApi.createDirectory({uri: path}); 89 directory = this.application.ninja.coreIoApi.createDirectory({uri: path});
90 //Checking for success 90 //Checking for success
91 if (directory.status === 201) { 91 if (directory.status === 201) {
92 directory = path; 92 directory = path;
93 } else { 93 } else {
94 //Error 94 //Error
95 directory = null; 95 directory = null;
96 } 96 }
97 break; 97 break;
98 default: //Error 98 default: //Error
99 directory = null; 99 directory = null;
100 break; 100 break;
101 } 101 }
102 //Returning the path to the directory on disk (null for any error) 102 //Returning the path to the directory on disk (null for any error)
103 return directory; 103 return directory;
104 } 104 }
105 }, 105 },
106 //////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////
107 // 107 //
@@ -109,7 +109,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
109 value: function (html) { 109 value: function (html) {
110 //Creating temp object to mimic HTML 110 //Creating temp object to mimic HTML
111 var doc = window.document.implementation.createHTMLDocument(), template, docHtmlTag, 111 var doc = window.document.implementation.createHTMLDocument(), template, docHtmlTag,
112 hackHtml = document.createElement('html'), hackTag; 112 hackHtml = document.createElement('html'), hackTag;
113 //Setting content to temp 113 //Setting content to temp
114 doc.getElementsByTagName('html')[0].innerHTML = html; 114 doc.getElementsByTagName('html')[0].innerHTML = html;
115 //TODO: Improve this, very bad way of copying attributes (in a pinch to get it working) 115 //TODO: Improve this, very bad way of copying attributes (in a pinch to get it working)
@@ -118,13 +118,13 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
118 docHtmlTag = doc.getElementsByTagName('html')[0]; 118 docHtmlTag = doc.getElementsByTagName('html')[0];
119 //Looping through the attributes to copy them 119 //Looping through the attributes to copy them
120 if (hackTag) { 120 if (hackTag) {
121 for (var m in hackTag.attributes) { 121 for (var m in hackTag.attributes) {
122 if (hackTag.attributes[m].value) { 122 if (hackTag.attributes[m].value) {
123 docHtmlTag.setAttribute(hackTag.attributes[m].name.replace(/ninjahtmlhack/gi, 'html'), hackTag.attributes[m].value.replace(/ninjahtmlhack/gi, 'html')); 123 docHtmlTag.setAttribute(hackTag.attributes[m].name.replace(/ninjahtmlhack/gi, 'html'), hackTag.attributes[m].value.replace(/ninjahtmlhack/gi, 'html'));
124 } 124 }
125 } 125 }
126 } 126 }
127 //Garbage collection 127 //Garbage collection
128 hackHtml = hackTag = null; 128 hackHtml = hackTag = null;
129 //Creating return object 129 //Creating return object
130 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc}; 130 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc};
@@ -134,42 +134,42 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
134 //TODO: Expand to allow more templates, clean up variables 134 //TODO: Expand to allow more templates, clean up variables
135 parseNinjaTemplateToHtml: { 135 parseNinjaTemplateToHtml: {
136 value: function (saveExternalData, template, ninjaWrapper, libCopyCallback) { 136 value: function (saveExternalData, template, ninjaWrapper, libCopyCallback) {
137 //TODO: Improve reference for rootUrl 137 //TODO: Improve reference for rootUrl
138 var regexRootUrl, 138 var regexRootUrl,
139 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), 139 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])),
140 mjsCreator = template.mjsTemplateCreator.create(), 140 mjsCreator = template.mjsTemplateCreator.create(),
141 mJsSerialization, 141 mJsSerialization,
142 toremovetags = [], 142 toremovetags = [],
143 presentNodes, 143 presentNodes,
144 montageTemplate; 144 montageTemplate;
145 //Creating instance of template creator 145 //Creating instance of template creator
146 montageTemplate = mjsCreator.initWithDocument(template.document); 146 montageTemplate = mjsCreator.initWithDocument(template.document);
147 //Setting up expression for parsing URLs 147 //Setting up expression for parsing URLs
148 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); 148 regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi');
149 //Injecting head and body into old document 149 //Injecting head and body into old document
150 if (montageTemplate._ownerSerialization.length > 0) { 150 if (montageTemplate._ownerSerialization.length > 0) {
151 template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, ''); 151 template.file.content.document.head.innerHTML = montageTemplate._document.head.innerHTML.replace(regexRootUrl, '');
152 template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, ''); 152 template.file.content.document.body.innerHTML = montageTemplate._document.body.innerHTML.replace(regexRootUrl, '');
153 // 153 //
154 mJsSerialization = montageTemplate._ownerSerialization; 154 mJsSerialization = montageTemplate._ownerSerialization;
155 } else { 155 } else {
156 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); 156 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
157 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); 157 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
158 } 158 }
159 //Removes all attributes from node