aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorEric Guzman2012-02-29 16:13:19 -0800
committerEric Guzman2012-02-29 16:13:19 -0800
commit53bdb1e7773069c4cca59e88d6da91cd0f58c94a (patch)
tree44a2147fcbb43ea483f78a1e2e082919f9c81970 /js/mediators
parentb2c60efb9c6f5dfa7b0fc5c2b9feebebc805ed97 (diff)
parentb09956e4a9a35c5588cc7cd1f01efb617cbe0884 (diff)
downloadninja-53bdb1e7773069c4cca59e88d6da91cd0f58c94a.tar.gz
Merge branch 'refs/heads/master' into CSSPanelUpdates
Conflicts: js/panels/PanelContainer/PanelContainer.reel/PanelContainer.js
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js12
-rw-r--r--js/mediators/io-mediator.js207
-rwxr-xr-xjs/mediators/keyboard-mediator.js24
3 files changed, 217 insertions, 26 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..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 ////////////////////////////////////////////////////////////////////
@@ -195,18 +206,151 @@ exports.IoMediator = Montage.create(Component, {
195 } 206 }
196 }, 207 },
197 //////////////////////////////////////////////////////////////////// 208 ////////////////////////////////////////////////////////////////////
198 //TODO: Expand to allow more templates 209 //TODO: Expand to allow more templates, clean up variables
199 parseNinjaTemplateToHtml: { 210 parseNinjaTemplateToHtml: {
200 enumerable: false, 211 enumerable: false,
201 value: function (template) { 212 value: function (template) {
202 // 213 //Injecting head and body into old document
203 template.document.content.document.body.innerHTML = template.body; 214 template.document.content.document.body.innerHTML = template.body;
204 template.document.content.document.head.innerHTML = template.head; 215 template.document.content.document.head.innerHTML = template.head;
205 //TODO: Remove temp fix for styles 216 //Getting all CSS (style or link) tags
206 if (template.style) { 217 var styletags = template.document.content.document.getElementsByTagName('style'),
207 template.document.content.document.head.getElementsByTagName('style')[0].innerHTML = this.getCssFromRules(template.style.cssRules); 218 linktags = template.document.content.document.getElementsByTagName('link');
219 //Looping through link tags and removing file recreated elements
220 for (var j in styletags) {
221 if (styletags[j].getAttribute) {
222 if(styletags[j].getAttribute('data-ninja-uri') !== null && !styletags[j].getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll
223 try {
224 //Checking head first
225 template.document.content.document.head.removeChild(styletags[j]);
226 } catch (e) {
227 try {
228 //Checking body if not in head
229 template.document.content.document.body.removeChild(styletags[j]);
230 } catch (e) {
231 //Error, not found!
232 }
233 }
234
235 }
236 }
237 }
238 //TODO: Add logic to only enble tags we disabled
239 for (var l in linktags) {
240 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll
241 linktags[l].removeAttribute('disabled');
242 }
243 }
244 //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS)
245 if (template.styles) {
246 //Getting all style tags
247 var styleCounter = 0,
248 docStyles = template.document.content.document.getElementsByTagName('style');
249 //Looping through all style tags
250 for(var i in template.styles) {
251 if (template.styles[i].ownerNode) {
252 if (template.styles[i].ownerNode.getAttribute) {
253 //Checking for node not to be loaded from file
254 if (template.styles[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.styles[i].ownerNode.getAttribute('data-ninja-template')) {
255 //Inseting data from rules array into tag as string
256 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules);
257 //Syncing <style> tags count since it might be mixed with <link>
258 styleCounter++;
259 }
260 }
261 }
262 }
263