diff options
author | Jose Antonio Marquez | 2012-02-25 16:18:27 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-25 16:18:27 -0800 |
commit | c6b44313ff8bcc17835ca77793bf425c451a4e75 (patch) | |
tree | 1f2b04f15080c78e72f043f3d1d0cae51293548c | |
parent | a8da19dde22332d352213984fcdcd10e36087df1 (diff) | |
download | ninja-c6b44313ff8bcc17835ca77793bf425c451a4e75.tar.gz |
Cleaning up ninja-data attributes
Added logic to load cross-domain CSS from CDN, but need to explore how to load without impacting permissions.
-rwxr-xr-x | js/document/html-document.js | 46 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 8 |
2 files changed, 46 insertions, 8 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index 1901079d..4059c2a5 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -381,7 +381,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
381 | // | 381 | // |
382 | for (var k in this._document.styleSheets) { | 382 | for (var k in this._document.styleSheets) { |
383 | if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { | 383 | if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { |
384 | this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true'); | 384 | this._document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true'); |
385 | } | 385 | } |
386 | } | 386 | } |
387 | // | 387 | // |
@@ -449,9 +449,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
449 | //Creating tag with file content | 449 | //Creating tag with file content |
450 | tag = this.iframe.contentWindow.document.createElement('style'); | 450 | tag = this.iframe.contentWindow.document.createElement('style'); |
451 | tag.setAttribute('type', 'text/css'); | 451 | tag.setAttribute('type', 'text/css'); |
452 | tag.setAttribute('ninjauri', fileUri); | 452 | tag.setAttribute('data-ninja-uri', fileUri); |
453 | tag.setAttribute('ninjafileurl', cssUrl); | 453 | tag.setAttribute('data-ninja-file-url', cssUrl); |
454 | tag.setAttribute('ninjafilename', cssUrl.split('/')[cssUrl.split('/').length-1]); | 454 | tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); |
455 | tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); | ||
455 | tag.innerHTML = cssData.content; | 456 | tag.innerHTML = cssData.content; |
456 | //Looping through DOM to insert style tag at location of link element | 457 | //Looping through DOM to insert style tag at location of link element |
457 | query = this._templateDocument.html.querySelectorAll(['link']); | 458 | query = this._templateDocument.html.querySelectorAll(['link']); |
@@ -463,6 +464,43 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
463 | this._templateDocument.head.insertBefore(tag, query[j]); | 464 | this._templateDocument.head.insertBefore(tag, query[j]); |
464 | } | 465 | } |
465 | } | 466 | } |
467 | } else { | ||
468 | //None local stylesheet, probably on a CDN (locked) | ||
469 | //this._document.styleSheets[i].href; | ||
470 | tag = this.iframe.contentWindow.document.createElement('style'); | ||
471 | tag.setAttribute('type', 'text/css'); | ||
472 | tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); | ||
473 | tag.setAttribute('data-ninja-file-read-only', "true"); | ||
474 | tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); | ||
475 | |||
476 | |||
477 | |||
478 | //TODO: Figure out cross-domain XHR issue, might need cloud to handle | ||
479 | /* | ||
480 | var xhr = new XMLHttpRequest(); | ||
481 | xhr.open("GET", this._document.styleSheets[i].href, true); | ||
482 | xhr.send(); | ||
483 | // | ||
484 | if (xhr.readyState === 4) { | ||
485 | console.log(xhr); | ||
486 | } | ||
487 | */ | ||
488 | |||
489 | //TODO: Add rules content | ||
490 | //tag.innerHTML = xhr.responseText //xhr.response; | ||
491 | |||
492 | |||
493 | query = this._templateDocument.html.querySelectorAll(['link']); | ||
494 | for (var j in query) { | ||
495 | if (query[j].href === this._document.styleSheets[i].href) { | ||
496 | //Disabling style sheet to reload via inserting in style tag | ||
497 | query[j].setAttribute('disabled', 'true'); | ||
498 | //Inserting tag | ||
499 | this._templateDocument.head.insertBefore(tag, query[j]); | ||
500 | } | ||
501 | } | ||
502 | |||
503 | |||
466 | } | 504 | } |
467 | } | 505 | } |
468 | } | 506 | } |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 16bb98ea..315fb6a7 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -209,7 +209,7 @@ exports.IoMediator = Montage.create(Component, { | |||
209 | //Looping through link tags and removing file recreated elements | 209 | //Looping through link tags and removing file recreated elements |
210 | for (var j in styletags) { | 210 | for (var j in styletags) { |
211 | if (styletags[j].getAttribute) { | 211 | if (styletags[j].getAttribute) { |
212 | if(styletags[j].getAttribute('ninjauri') !== null) {//TODO: Use querySelectorAll | 212 | if(styletags[j].getAttribute('data-ninja-uri') !== null) {//TODO: Use querySelectorAll |
213 | try { | 213 | try { |
214 | //Checking head first | 214 | //Checking head first |
215 | template.document.content.document.head.removeChild(styletags[j]); | 215 | template.document.content.document.head.removeChild(styletags[j]); |
@@ -241,7 +241,7 @@ exports.IoMediator = Montage.create(Component, { | |||
241 | if (template.styles[i].ownerNode) { | 241 | if (template.styles[i].ownerNode) { |
242 | if (template.styles[i].ownerNode.getAttribute) { | 242 | if (template.styles[i].ownerNode.getAttribute) { |
243 | //Checking for node not to be loaded from file | 243 | //Checking for node not to be loaded from file |
244 | if (template.styles[i].ownerNode.getAttribute('ninjauri') === null) { | 244 | if (template.styles[i].ownerNode.getAttribute('data-ninja-uri') === null) { |
245 | //Inseting data from rules array into tag as string | 245 | //Inseting data from rules array into tag as string |
246 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules); | 246 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.styles[i].cssRules); |
247 | //Syncing <style> tags count since it might be mixed with <link> | 247 | //Syncing <style> tags count since it might be mixed with <link> |
@@ -258,13 +258,13 @@ exports.IoMediator = Montage.create(Component, { | |||
258 | for(var i in template.css) { | 258 | for(var i in template.css) { |
259 | if (template.css[i].ownerNode) { | 259 | if (template.css[i].ownerNode) { |
260 | if (template.css[i].ownerNode.getAttribute) { | 260 | if (template.css[i].ownerNode.getAttribute) { |
261 | if (template.css[i].ownerNode.getAttribute('ninjauri') === null) {//TODO: Use querySelectorAll | 261 | if (template.css[i].ownerNode.getAttribute('data-ninja-uri') === null) {//TODO: Use querySelectorAll |
262 | //Inseting data from rules array into <style> as string | 262 | //Inseting data from rules array into <style> as string |
263 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); | 263 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); |
264 | styleCounter++; | 264 | styleCounter++; |
265 | } else { | 265 | } else { |
266 | //Saving data from rules array converted to string into <link> file | 266 | //Saving data from rules array converted to string into <link> file |
267 | var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('ninjauri'), contents: this.getCssFromRules(template.css[i].cssRules)}); | 267 | var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('data-ninja-uri'), contents: this.getCssFromRules(template.css[i].cssRules)}); |
268 | } | 268 | } |
269 | } | 269 | } |
270 | } | 270 | } |