diff options
author | Ananya Sen | 2012-02-27 14:24:49 -0800 |
---|---|---|
committer | Ananya Sen | 2012-02-27 14:24:49 -0800 |
commit | 15d00c49b522aa471d1ccfbbd33f5c0e721eb89e (patch) | |
tree | 5c352c198ed7404f3fe0a9c5915e1727d3003f9f /js/mediators | |
parent | 604ace9cfc9fae6b6c121259523a9060c5306161 (diff) | |
parent | 7e63b5d0b6990b6c0ec0385d35534b91982ac672 (diff) | |
download | ninja-15d00c49b522aa471d1ccfbbd33f5c0e721eb89e.tar.gz |
Merge branch 'refs/heads/FileIO-jose' into FileIO
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 106 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 4 |
2 files changed, 86 insertions, 24 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index c4f3b361..7efed29b 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -146,22 +146,27 @@ exports.IoMediator = Montage.create(Component, { | |||
146 | //Copy webGL library if needed | 146 | //Copy webGL library if needed |
147 | if (file.webgl.length > 0) { | 147 | if (file.webgl.length > 0) { |
148 | for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { | 148 | for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { |
149 | //if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Assets' || this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { | 149 | //Checking for RDGE library to be available |
150 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { | 150 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { |
151 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(file.document.root, (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase()); | 151 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(file.document.root, (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase()); |
152 | } else { | ||
153 | //TODO: Error handle no available library to copy | ||
152 | } | 154 | } |
153 | } | 155 | } |
154 | } | 156 | } |
155 | // | 157 | |
158 | //TODO: Add check for Monatage library to copy | ||
159 | |||
160 | //Getting content from function to properly handle saving assets (as in external if flagged) | ||
156 | contents = this.parseNinjaTemplateToHtml(file); | 161 | contents = this.parseNinjaTemplateToHtml(file); |
157 | break; | 162 | break; |
158 | default: | 163 | default: |
159 | contents = file.content; | 164 | contents = file.content; |
160 | break; | 165 | break; |
161 | } | 166 | } |
162 | // | 167 | //Making call to save file |
163 | save = this.fio.saveFile({uri: file.document.uri, contents: contents}); | 168 | save = this.fio.saveFile({uri: file.document.uri, contents: contents}); |
164 | // | 169 | //Checking for callback |
165 | if (callback) callback(save); | 170 | if (callback) callback(save); |
166 | } | 171 | } |
167 | }, | 172 | }, |
@@ -170,7 +175,7 @@ exports.IoMediator = Montage.create(Component, { | |||
170 | fileSaveAs: { | 175 | fileSaveAs: { |
171 | enumerable: false, | 176 | enumerable: false, |
172 | value: function (copyTo, copyFrom, callback) { | 177 | value: function (copyTo, copyFrom, callback) { |
173 | // | 178 | //TODO: Implement Save As functionality |
174 | } | 179 | } |
175 | }, | 180 | }, |
176 | //////////////////////////////////////////////////////////////////// | 181 | //////////////////////////////////////////////////////////////////// |
@@ -178,7 +183,7 @@ exports.IoMediator = Montage.create(Component, { | |||
178 | fileDelete: { | 183 | fileDelete: { |
179 | enumerable: false, | 184 | enumerable: false, |
180 | value: function (file, callback) { | 185 | value: function (file, callback) { |
181 | // | 186 | //TODO: Implement Delete functionality |
182 | } | 187 | } |
183 | }, | 188 | }, |
184 | //////////////////////////////////////////////////////////////////// | 189 | //////////////////////////////////////////////////////////////////// |
@@ -195,22 +200,21 @@ exports.IoMediator = Montage.create(Component, { | |||
195 | } | 200 | } |
196 | }, | 201 | }, |
197 | //////////////////////////////////////////////////////////////////// | 202 | //////////////////////////////////////////////////////////////////// |
198 | //TODO: Expand to allow more templates | 203 | //TODO: Expand to allow more templates, clean up variables |
199 | parseNinjaTemplateToHtml: { | 204 | parseNinjaTemplateToHtml: { |
200 | enumerable: false, | 205 | enumerable: false, |
201 | value: function (template) { | 206 | value: function (template) { |
202 | //TODO: Clean up variables | ||
203 | //Injecting head and body into old document | 207 | //Injecting head and body into old document |
204 | template.document.content.document.body.innerHTML = template.body; | 208 | template.document.content.document.body.innerHTML = template.body; |
205 | template.document.content.document.head.innerHTML = template.head; | 209 | template.document.content.document.head.innerHTML = template.head; |
206 | //Getting all CSS (style or link) tags | 210 | //Getting all CSS (style or link) tags |
207 | var styletags = template.document.content.document.getElementsByTagName('style'), | 211 | var styletags = template.document.content.document.getElementsByTagName('style'), |
208 | linktags = template.document.content.document.getElementsByTagName('link'), | 212 | linktags = template.document.content.document.getElementsByTagName('link'), |
209 | url = new RegExp(window.location.protocol+'//'+window.location.host+'/js/document/templates/montage-html/', 'gi'); | 213 | url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi'); //TODO: Make public into var |
210 | //Looping through link tags and removing file recreated elements | 214 | //Looping through link tags and removing file recreated elements |
211 | for (var j in styletags) { | 215 | for (var j in styletags) { |
212 | if (styletags[j].getAttribute) { | 216 | if (styletags[j].getAttribute) { |
213 | if(styletags[j].getAttribute('ninjauri') !== null) { | 217 | if(styletags[j].getAttribute('data-ninja-uri') !== null && !styletags[j].getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll |
214 | try { | 218 | try { |
215 | //Checking head first | 219 | //Checking head first |
216 | template.document.content.document.head.removeChild(styletags[j]); | 220 | template.document.content.document.head.removeChild(styletags[j]); |
@@ -228,7 +232,7 @@ exports.IoMediator = Montage.create(Component, { | |||
228 | } | 232 | } |
229 | //TODO: Add logic to only enble tags we disabled | 233 | //TODO: Add logic to only enble tags we disabled |
230 | for (var l in linktags) { | 234 | for (var l in linktags) { |
231 | if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) { | 235 | if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll |
232 | linktags[l].removeAttribute('disabled'); | 236 | linktags[l].removeAttribute('disabled'); |
233 | } | 237 | } |
234 | } | 238 | } |
@@ -242,7 +246,7 @@ exports.IoMediator = Montage.create(Component, { | |||
242 | if (template.styles[i].ownerNode) { | 246 | if (template.styles[i].ownerNode) { |
243 | if (template.styles[i].ownerNode.getAttribute) { | 247 | if (template.styles[i].ownerNode.getAttribute) { |
244 | //Checking for node not to be loaded from file | 248 | //Checking for node not to be loaded from file |
245 | if (template.styles[i].ownerNode.getAttribute('ninjauri') === null) { | 249 | if (template.styles[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.styles[i].ownerNode.getAttribute('data-ninja-template')) { |
246 | //Inseting data from rules array into tag as string | 250 | //Inseting data from rules array into tag as string |
247 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules); | 251 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules); |
248 | //Syncing <style> tags count since it might be mixed with <link> | 252 | //Syncing <style> tags count since it might be mixed with <link> |
@@ -259,20 +263,62 @@ exports.IoMediator = Montage.create(Component, { | |||
259 | for(var i in template.css) { | 263 | for(var i in template.css) { |
260 | if (template.css[i].ownerNode) { | 264 | if (template.css[i].ownerNode) { |
261 | if (template.css[i].ownerNode.getAttribute) { | 265 | if (template.css[i].ownerNode.getAttribute) { |
262 | if (template.css[i].ownerNode.getAttribute('ninjauri') === null) { | 266 | if (template.css[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.css[i].ownerNode.getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll |
263 | //Inseting data from rules array into <style> as string | 267 | //Inseting data from rules array into <style> as string |
264 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); | 268 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); |
265 | styleCounter++; | 269 | styleCounter++; |
266 | } else { | 270 | } else { |
267 | //Saving data from rules array converted to string into <link> file | 271 | //Saving data from rules array converted to string into <link> file |
268 | var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('ninjauri'), contents: this.getCssFromRules(template.css[i].cssRules)}); | 272 | var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('data-ninja-uri'), contents: this.getCssFromRules(template.css[i].cssRules)}); |
269 | } | 273 | } |
270 | } | 274 | } |
271 | } | 275 | } |
272 | } | 276 | } |
273 | } | 277 | } |
278 | //Checking for webGL elements in document | ||
279 | if (template.webgl.length) { | ||
280 | // | ||
281 | var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script'); | ||
282 | // | ||
283 | for (var i in scripts) { | ||
284 | if (scripts[i].getAttribute) { | ||
285 | if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll | ||
286 | matchingtags.push(scripts[i]); | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | // | ||
291 | if (matchingtags.length) { | ||
292 | if (matchingtags.length === 1) { | ||
293 | webgltag = matchingtags[0]; | ||
294 | } else { | ||
295 | //TODO: Add logic to handle multiple tags, perhaps combine to one | ||
296 | webgltag = matchingtags[matchingtags.length-1]; //Saving all data to last one... | ||
297 | } | ||
298 | } | ||
299 | // | ||
300 | if (!webgltag) { | ||
301 | webgltag = template.document.content.document.createElement('script'); | ||
302 | webgltag.setAttribute('data-ninja-webgl', 'true'); | ||
303 | template.document.content.document.head.appendChild(webgltag); | ||
304 | } | ||
305 | //TODO: Add version and other data for RDGE | ||
306 | json = '\n({\n\t"version": "X.X.X.X",\n\t"data": ['; | ||
307 | //Looping through data to create escaped array | ||
308 | for (var j=0; template.webgl[j]; j++) { | ||
309 | if (j === 0) { | ||
310 | json += '\n\t\t\t"'+escape(template.webgl[j])+'"'; | ||
311 | } else { | ||
312 | json += ',\n\t\t\t"'+escape(template.webgl[j])+'"'; | ||
313 | } | ||
314 | } | ||
315 | //Closing array (make-shift JSON string to validate data in <script> tag) | ||
316 | json += '\n\t\t]\n})\n'; | ||
317 | //Setting string in tag | ||
318 | webgltag.innerHTML = json; | ||
319 | } | ||
274 | // | 320 | // |
275 | return template.document.content.document.documentElement.outerHTML.replace(url, ''); | 321 | return this.getPrettyHtml(template.document.content.document.documentElement.outerHTML.replace(url, '')); |
276 | } | 322 | } |
277 | }, | 323 | }, |
278 | //////////////////////////////////////////////////////////////////// | 324 | //////////////////////////////////////////////////////////////////// |
@@ -286,20 +332,36 @@ exports.IoMediator = Montage.create(Component, { | |||
286 | if (list && list.length > 0) { | 332 | if (list && list.length > 0) { |
287 | //Adding each list item to string and also adding breaks | 333 | //Adding each list item to string and also adding breaks |
288 | for (i = 0; list[i]; i++) { | 334 | for (i = 0; list[i]; i++) { |
289 | str = list[i].cssText+' '; | 335 | css += list[i].cssText; |
290 | str = str.replace( new RegExp( "{", "gi" ), "{\n\t" ); | ||
291 | str = str.replace( new RegExp( "}", "gi" ), "}\n" ); | ||
292 | str = str.replace( new RegExp( ";", "gi" ), ";\n\t" ); | ||
293 | css += '\n'+str; | ||
294 | } |