aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js99
-rwxr-xr-xjs/mediators/keyboard-mediator.js9
2 files changed, 73 insertions, 35 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 30180155..e763c67c 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -39,6 +39,12 @@ exports.IoMediator = Montage.create(Component, {
39 enumerable: false, 39 enumerable: false,
40 value: ProjectIo 40 value: ProjectIo
41 }, 41 },
42 ////////////////////////////////////////////////////////////////////
43 //
44 appTemplatesUrl: {
45 enumerable: false,
46 value: new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi')
47 },
42 //////////////////////////////////////////////////////////////////// 48 ////////////////////////////////////////////////////////////////////
43 // 49 //
44 fileNew: { 50 fileNew: {
@@ -146,22 +152,27 @@ exports.IoMediator = Montage.create(Component, {
146 //Copy webGL library if needed 152 //Copy webGL library if needed
147 if (file.webgl.length > 0) { 153 if (file.webgl.length > 0) {
148 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { 154 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') { 155 //Checking for RDGE library to be available
150 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { 156 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()); 157 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());
158 } else {
159 //TODO: Error handle no available library to copy
152 } 160 }
153 } 161 }
154 } 162 }
155 // 163
164 //TODO: Add check for Monatage library to copy
165
166 //Getting content from function to properly handle saving assets (as in external if flagged)
156 contents = this.parseNinjaTemplateToHtml(file); 167 contents = this.parseNinjaTemplateToHtml(file);
157 break; 168 break;
158 default: 169 default:
159 contents = file.content; 170 contents = file.content;
160 break; 171 break;
161 } 172 }
162 // 173 //Making call to save file
163 save = this.fio.saveFile({uri: file.document.uri, contents: contents}); 174 save = this.fio.saveFile({uri: file.document.uri, contents: contents});
164 // 175 //Checking for callback
165 if (callback) callback(save); 176 if (callback) callback(save);
166 } 177 }
167 }, 178 },
@@ -170,7 +181,7 @@ exports.IoMediator = Montage.create(Component, {
170 fileSaveAs: { 181 fileSaveAs: {
171 enumerable: false, 182 enumerable: false,
172 value: function (copyTo, copyFrom, callback) { 183 value: function (copyTo, copyFrom, callback) {
173 // 184 //TODO: Implement Save As functionality
174 } 185 }
175 }, 186 },
176 //////////////////////////////////////////////////////////////////// 187 ////////////////////////////////////////////////////////////////////
@@ -178,7 +189,7 @@ exports.IoMediator = Montage.create(Component, {
178 fileDelete: { 189 fileDelete: {
179 enumerable: false, 190 enumerable: false,
180 value: function (file, callback) { 191 value: function (file, callback) {
181 // 192 //TODO: Implement Delete functionality
182 } 193 }
183 }, 194 },
184 //////////////////////////////////////////////////////////////////// 195 ////////////////////////////////////////////////////////////////////
@@ -204,8 +215,7 @@ exports.IoMediator = Montage.create(Component, {
204 template.document.content.document.head.innerHTML = template.head; 215 template.document.content.document.head.innerHTML = template.head;
205 //Getting all CSS (style or link) tags 216 //Getting all CSS (style or link) tags
206 var styletags = template.document.content.document.getElementsByTagName('style'), 217 var styletags = template.document.content.document.getElementsByTagName('style'),
207 linktags = template.document.content.document.getElementsByTagName('link'), 218 linktags = template.document.content.document.getElementsByTagName('link');
208 url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi');
209 //Looping through link tags and removing file recreated elements 219 //Looping through link tags and removing file recreated elements
210 for (var j in styletags) { 220 for (var j in styletags) {
211 if (styletags[j].getAttribute) { 221 if (styletags[j].getAttribute) {
@@ -255,6 +265,17 @@ exports.IoMediator = Montage.create(Component, {
255 var styleCounter = 0, 265 var styleCounter = 0,
256 docStyles = template.document.content.document.getElementsByTagName('style'), 266 docStyles = template.document.content.document.getElementsByTagName('style'),
257 docLinks = template.document.content.document.getElementsByTagName('link'); 267 docLinks = template.document.content.document.getElementsByTagName('link');
268 //Removing Ninja Data Attributes
269 for (var n in docLinks) {
270 if (docLinks[n].attributes) {
271 for (var m in docLinks[n].attributes) {
272 if (docLinks[n].attributes[m].name && docLinks[n].attributes[m].name.indexOf('data-ninja')!=-1) {
273 docLinks[n].removeAttribute(docLinks[n].attributes[m].name);
274 }
275 }
276 }
277 }
278 //
258 for(var i in template.css) { 279 for(var i in template.css) {
259 if (template.css[i].ownerNode) { 280 if (template.css[i].ownerNode) {
260 if (template.css[i].ownerNode.getAttribute) { 281 if (template.css[i].ownerNode.getAttribute) {
@@ -263,6 +284,22 @@ exports.IoMediator = Montage.create(Component, {
263 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); 284 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules);
264 styleCounter++; 285 styleCounter++;
265 } else { 286 } else {
287 //Checking for attributes to be added to tag upon saving
288 for (var k in docLinks) {
289 if (docLinks[k].getAttribute) {
290 if (docLinks[k].getAttribute('href') && ('/'+docLinks[k].getAttribute('href')) === template.css[i].ownerNode.getAttribute('data-ninja-file-url')) {
291 for (var l in template.css[i].ownerNode.attributes) {
292 if (template.css[i].ownerNode.attributes[l].value) {
293 if (template.css[i].ownerNode.attributes[l].name.indexOf('data-ninja')!=-1) {
294 //Ninja attribute...
295 } else {
296 docLinks[k].setAttribute(template.css[i].ownerNode.attributes[l].name, template.css[i].ownerNode.attributes[l].value);
297 }
298 }
299 }
300 }
301 }
302 }
266 //Saving data from rules array converted to string into <link> file 303 //Saving data from rules array converted to string into <link> file
267 var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('data-ninja-uri'), contents: this.getCssFromRules(template.css[i].cssRules)}); 304 var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('data-ninja-uri'), contents: this.getCssFromRules(template.css[i].cssRules)});
268 } 305 }
@@ -313,7 +350,7 @@ exports.IoMediator = Montage.create(Component, {
313 webgltag.innerHTML = json; 350 webgltag.innerHTML = json;
314 } 351 }
315 // 352 //
316 return this.getPretyHtml(template.document.content.document.documentElement.outerHTML.replace(url, '')); 353 return this.getPrettyHtml(template.document.content.document.documentElement.outerHTML.replace(this.appTemplatesUrl, ''));
317 } 354 }
318 }, 355 },
319 //////////////////////////////////////////////////////////////////// 356 ////////////////////////////////////////////////////////////////////
@@ -322,7 +359,7 @@ exports.IoMediator = Montage.create(Component, {
322 enumerable: false, 359 enumerable: false,
323 value: function (list) { 360 value: function (list) {
324 //Variable to store CSS definitions 361 //Variable to store CSS definitions
325 var i, str, url, css = ''; 362 var i, str, css = '';
326 //Looping through list 363 //Looping through list
327 if (list && list.length > 0) { 364 if (list && list.length > 0) {
328 //Adding each list item to string and also adding breaks 365 //Adding each list item to string and also adding breaks
@@ -330,17 +367,20 @@ exports.IoMediator = Montage.create(Component, {
330 css += list[i].cssText; 367 css += list[i].cssText;
331 } 368 }
332 } 369 }
333 //TODO: Add better logic for creating this string
334 url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi');
335 //Returning the CSS string 370 //Returning the CSS string
336 return this.getPretyCss(css.replace(url, '')); 371 return this.getPrettyCss(css.replace(this.appTemplatesUrl, ''));
337 } 372 }
338 }, 373 },
339 //////////////////////////////////////////////////////////////////// 374 ////////////////////////////////////////////////////////////////////
340 //Using prettification code from http://jsbeautifier.org 375 ////////////////////////////////////////////////////////////////////
376 //Pretty methods (minified)
341 /* 377 /*
342 Copyright (c) 2009 - 2011, Einar Lielmanis 378 is-beautify javascript code courtesy of Einar Lielmanis:
343 379 Code from https://github.com/einars/js-beautify
380 License https://github.com/einars/js-beautify/blob/master/license.txt
381 Used with author's permission, as stated below
382
383 Copyright (c) 2009 - 2011, Einar Lielmanis
344 Permission is hereby granted, free of charge, to any person 384 Permission is hereby granted, free of charge, to any person
345 obtaining a copy of this software and associated documentation 385 obtaining a copy of this software and associated documentation
346 files (the "Software"), to deal in the Software without 386 files (the "Software"), to deal in the Software without
@@ -348,30 +388,21 @@ exports.IoMediator = Montage.create(Component, {
348 copy, modify, merge, publish, distribute, sublicense, and/or sell 388 copy, modify, merge, publish, distribute, sublicense, and/or sell
349 copies of the Software, and to permit persons to whom the 389 copies of the Software, and to permit persons to whom the
350 Software is furnished to do so, subject to the following 390 Software is furnished to do so, subject to the following
351 conditions: 391 conditions:The above copyright notice and this permission notice shall be
352
353 The above copyright notice and this permission notice shall be
354 included in all copies or substantial portions of the Software. 392 included in all copies or substantial portions of the Software.
355 393 */
356 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 394 //For HTML, including any JS or CSS (single string/file)
357 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 395 getPrettyHtml: {
358 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
359 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
360 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
361 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
362 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
363 OTHER DEALINGS IN THE SOFTWARE.
364 */
365 getPretyHtml: {
366 enumerable: false,