aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-28 14:01:05 -0800
committerPushkar Joshi2012-02-28 14:01:05 -0800
commit63307c9abf120985d979a40a53a0598d3f0d5c5a (patch)
tree57d9cffd7aa0959ea31fe0fa2d89a9080198bcb3 /js/mediators
parente1a65d0c2a13e12ee53be98c731616e35aa07a41 (diff)
parent7c9291a5bab4abd849547f8878f6fb962fc88250 (diff)
downloadninja-63307c9abf120985d979a40a53a0598d3f0d5c5a.tar.gz
Merge branch 'master' into pentool
Conflicts: manifest.json
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js12
-rw-r--r--js/mediators/io-mediator.js166
-rwxr-xr-xjs/mediators/keyboard-mediator.js8
3 files changed, 166 insertions, 20 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..30180155 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -195,18 +195,125 @@ exports.IoMediator = Montage.create(Component, {
195 } 195 }
196 }, 196 },
197 //////////////////////////////////////////////////////////////////// 197 ////////////////////////////////////////////////////////////////////
198 //TODO: Expand to allow more templates 198 //TODO: Expand to allow more templates, clean up variables
199 parseNinjaTemplateToHtml: { 199 parseNinjaTemplateToHtml: {
200 enumerable: false, 200 enumerable: false,
201 value: function (template) { 201 value: function (template) {
202 // 202 //Injecting head and body into old document
203 template.document.content.document.body.innerHTML = template.body; 203 template.document.content.document.body.innerHTML = template.body;
204 template.document.content.document.head.innerHTML = template.head; 204 template.document.content.document.head.innerHTML = template.head;
205 //TODO: Remove temp fix for styles 205 //Getting all CSS (style or link) tags
206 if (template.style) { 206 var styletags = template.document.content.document.getElementsByTagName('style'),
207 template.document.content.document.head.getElementsByTagName('style')[0].innerHTML = this.getCssFromRules(template.style.cssRules); 207 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
210 for (var j in styletags) {
211 if (styletags[j].getAttribute) {
212 if(styletags[j].getAttribute('data-ninja-uri') !== null && !styletags[j].getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll
213 try {
214 //Checking head first
215 template.document.content.document.head.removeChild(styletags[j]);
216 } catch (e) {
217 try {
218 //Checking body if not in head
219 template.document.content.document.body.removeChild(styletags[j]);
220 } catch (e) {
221 //Error, not found!
222 }
223 }
224
225 }
226 }
208 } 227 }
209 return template.document.content.document.documentElement.outerHTML; 228 //TODO: Add logic to only enble tags we disabled
229 for (var l in linktags) {
230 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll
231 linktags[l].removeAttribute('disabled');
232 }
233 }
234 //Checking for type of save: styles = <style> only | css = <style> and <link> (all CSS)
235 if (template.styles) {
236 //Getting all style tags
237 var styleCounter = 0,
238 docStyles = template.document.content.document.getElementsByTagName('style');
239 //Looping through all style tags
240 for(var i in template.styles) {
241 if (template.styles[i].ownerNode) {
242 if (template.styles[i].ownerNode.getAttribute) {
243 //Checking for node not to be loaded from file
244 if (template.styles[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.styles[i].ownerNode.getAttribute('data-ninja-template')) {
245 //Inseting data from rules array into tag as string
246 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules);
247 //Syncing <style> tags count since it might be mixed with <link>
248 styleCounter++;
249 }
250 }
251 }
252 }
253 } else if (template.css) {
254 //Getting all style and link tags
255 var styleCounter = 0,
256 docStyles = template.document.content.document.getElementsByTagName('style'),
257 docLinks = template.document.content.document.getElementsByTagName('link');
258 for(var i in template.css) {
259 if (template.css[i].ownerNode) {
260 if (template.css[i].ownerNode.getAttribute) {
261 if (template.css[i].ownerNode.getAttribute('data-ninja-uri') === null && !template.css[i].ownerNode.getAttribute('data-ninja-template')) {//TODO: Use querySelectorAll
262 //Inseting data from rules array into <style> as string
263 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules);
264 styleCounter++;
265 } else {
266 //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)});
268 }
269 }
270 }
271 }
272 }
273 //Checking for webGL elements in document
274 if (template.webgl.length) {
275 //
276 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script');
277 //
278 for (var i in scripts) {
279 if (scripts[i].getAttribute) {
280 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll
281 matchingtags.push(scripts[i]);
282 }
283 }
284 }
285 //
286 if (matchingtags.length) {
287 if (matchingtags.length === 1) {
288 webgltag = matchingtags[0];
289 } else {
290 //TODO: Add logic to handle multiple tags, perhaps combine to one
291 webgltag = matchingtags[matchingtags.length-1]; //Saving all data to last one...
292 }
293 }
294 //
295 if (!webgltag) {
296 webgltag = template.document.content.document.createElement('script');
297 webgltag.setAttribute('data-ninja-webgl', 'true');
298 template.document.content.document.head.appendChild(webgltag);
299 }
300 //TODO: Add version and other data for RDGE
301 json = '\n({\n\t"version": "X.X.X.X",\n\t"data": [';
302 //Looping through data to create escaped array
303 for (var j=0; template.webgl[j]; j++) {
304 if (j === 0) {
305 json += '\n\t\t\t"'+escape(template.webgl[j])+'"';
306 } else {
307 json += ',\n\t\t\t"'+escape(template.webgl[j])+'"';
308 }
309 }
310 //Closing array (make-shift JSON string to validate data in <script> tag)
311 json += '\n\t\t]\n})\n';
312 //Setting string in tag
313 webgltag.innerHTML = json;
314 }
315 //
316 return this.getPretyHtml(template.document.content.document.documentElement.outerHTML.replace(url, ''));
210 } 317 }
211 }, 318 },
212 //////////////////////////////////////////////////////////////////// 319 ////////////////////////////////////////////////////////////////////
@@ -215,21 +322,54 @@ exports.IoMediator = Montage.create(Component, {
215 enumerable: false, 322 enumerable: false,
216 value: function (list) {