aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js12
-rw-r--r--js/mediators/io-mediator.js206
-rwxr-xr-xjs/mediators/keyboard-mediator.js24
3 files changed, 215 insertions, 27 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 51923f08..127f73e1 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -463,7 +463,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
463 getColor: { 463 getColor: {
464 value: function(el, isFill) { 464 value: function(el, isFill) {
465 if(!el.elementModel) { 465 if(!el.elementModel) {
466 NJUtils.makeElementModel2(el); 466 NJUtils.makeModelFromElement(el);
467 } 467 }
468 return el.elementModel.controller["getColor"](el, isFill); 468 return el.elementModel.controller["getColor"](el, isFill);
469 } 469 }
@@ -624,7 +624,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
624 getColor2: { 624 getColor2: {
625 value: function(el, prop, mutator) { 625 value: function(el, prop, mutator) {
626 if(!el.elementModel) { 626 if(!el.elementModel) {
627 NJUtils.makeElementModel2(el); 627 NJUtils.makeModelFromElement(el);
628 } 628 }
629 629
630 return this.getColor(el, (prop === "background")); 630 return this.getColor(el, (prop === "background"));
@@ -636,7 +636,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
636 get3DProperty: { 636 get3DProperty: {
637 value: function(el, prop) { 637 value: function(el, prop) {
638 if(!el.elementModel) { 638 if(!el.elementModel) {
639 NJUtils.makeElementModel2(el); 639 NJUtils.makeModelFromElement(el);
640 } 640 }
641 return el.elementModel.controller["get3DProperty"](el, prop); 641 return el.elementModel.controller["get3DProperty"](el, prop);
642 } 642 }
@@ -645,7 +645,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
645 get3DProperties: { 645 get3DProperties: {
646 value: function(el) { 646 value: function(el) {
647 if(!el.elementModel) { 647 if(!el.elementModel) {
648 NJUtils.makeElementModel2(el); 648 NJUtils.makeModelFromElement(el);
649 } 649 }
650// var mat = this.getMatrix(el); 650// var mat = this.getMatrix(el);
651// var dist = this.getPerspectiveDist(el); 651// var dist = this.getPerspectiveDist(el);
@@ -658,7 +658,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
658 getMatrix: { 658 getMatrix: {
659 value: function(el) { 659 value: function(el) {
660 if(!el.elementModel) { 660 if(!el.elementModel) {
661 NJUtils.makeElementModel2(el); 661 NJUtils.makeModelFromElement(el);
662 } 662 }
663 return el.elementModel.controller["getMatrix"](el); 663 return el.elementModel.controller["getMatrix"](el);
664 } 664 }
@@ -667,7 +667,7 @@ exports.ElementMediator = Montage.create(NJComponent, {
667 getPerspectiveDist: { 667 getPerspectiveDist: {
668 value: function(el) { 668 value: function(el) {
669 if(!el.elementModel) { 669 if(!el.elementModel) {
670 NJUtils.makeElementModel2(el); 670 NJUtils.makeModelFromElement(el);
671 } 671 }
672 return el.elementModel.controller["getPerspectiveDist"](el); 672 return el.elementModel.controller["getPerspectiveDist"](el);
673 } 673 }
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 56869839..6b26668b 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,18 +200,152 @@ 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 // 207 //Injecting head and body into old document
203 template.document.content.document.body.innerHTML = template.body; 208 template.document.content.document.body.innerHTML = template.body;
204 template.document.content.document.head.innerHTML = template.head; 209 template.document.content.document.head.innerHTML = template.head;
205 //TODO: Remove temp fix for styles 210 //Getting all CSS (style or link) tags
206 if (template.style) { 211 var styletags = template.document.content.document.getElementsByTagName('style'),
207 template.document.content.document.head.getElementsByTagName('style')[0].innerHTML = this.getCssFromRules(template.style.cssRules); 212 linktags = template.document.content.document.getElementsByTagName('link'),
213 url = new RegExp(chrome.extension.getURL('js/document/templates/montage-html/'), 'gi'); //TODO: Make public into var
214 //Looping through link tags and removing file recreated elements
215 for (var j in styletags) {
216 if (styletags[j].getAttribute) {
217 if(styletags[j].getAttribute('data-ninja-uri') !== null && !styletags[j].getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll
218 try {
219 //Checking head first
220 template.document.content.document.head.removeChild(styletags[j]);
221 } catch (e) {
222 try {
223 //Checking body if not in head
224 template.document.content.document.body.removeChild(styletags[j]);
225 } catch (e) {
226 //Error, not found!
227 }
228 }
229
230 }
231 }
232 }
233 //TODO: Add logic to only enble tags we disabled
234 for (var l in linktags) {
235 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll
236 linktags[l].removeAttribute('disabled');
237 }
238 }
239 //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS)
240 if (template.styles) {
241 //Getting all style tags
242 var styleCounter = 0,
243 docStyles = template.document.content.document.getElementsByTagName('style');
244 //Looping through all style tags
245 for(var i in template.styles) {
246 if (template.styles[i].ownerNode) {
247 if (template.styles[i].ownerNode.getAttribute) {
248 //Checking for node not to be loaded from file
249 if (template.styles[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.styles[i].ownerNode.getAttribute('data-ninja-template')) {
250 //Inseting data from rules array into tag as string
251 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules);
252 //Syncing <style> tags count since it might be mixed with <link>
253 styleCounter++;
254 }
255 }
256 }
257 }
258 } else if (template.css) {
259 //Getting all style and link tags
260 var styleCounter = 0,
261 docStyles = template.document.content.document.getElementsByTagName('style'),
262 docLinks = template.document.content.document.getElementsByTagName('link');
263 //Removing Ninja Data Attributes
264 for (var n in docLinks) {
265 if (docLinks[n].attributes) {
266 for (var m in docLinks[n].attributes) {
267 if (docLinks[n].attributes[m].name && docLinks[n].attributes[m].name.indexOf('data-ninja')!=-1) {
268 docLinks[n].removeAttribute(docLinks[n].attributes[m].name);
269 }
270 }
271 }
272 }
273 //
274 for(var i in template.css) {