aboutsummaryrefslogtreecommitdiff
path: root/js/document/html-document.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-02 14:11:08 -0800
committerJose Antonio Marquez2012-03-02 14:11:08 -0800
commite24631ecac0772fc51756fe4aff9638de3b95faf (patch)
treeb70d2273e41670615aafd32477f2f83146ab5bbb /js/document/html-document.js
parentc4bfc8b79820b55cc86d755fe590ee649813232a (diff)
downloadninja-e24631ecac0772fc51756fe4aff9638de3b95faf.tar.gz
Fixing CSS URL issues
Only partially, supporting unquoted files under same root.
Diffstat (limited to 'js/document/html-document.js')
-rwxr-xr-xjs/document/html-document.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 9353027d..54647d65 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -485,14 +485,13 @@ exports.HTMLDocument = Montage.create(TextDocument, {
485 //If rules are null, assuming cross-origin issue 485 //If rules are null, assuming cross-origin issue
486 if(this._document.styleSheets[i].rules === null) { 486 if(this._document.styleSheets[i].rules === null) {
487 //TODO: Revisit URLs and URI creation logic, very hack right now 487 //TODO: Revisit URLs and URI creation logic, very hack right now
488 var fileUri, cssUrl, cssData, query, prefixUrl; 488 var fileUri, cssUrl, cssData, query, prefixUrl, fileCouldDirUrl;
489 //TODO: Parse out relative URLs and map them to absolute 489 //TODO: Parse out relative URLs and map them to absolute
490 if (this._document.styleSheets[i].href.indexOf(chrome.extension.getURL('')) !== -1) { 490 if (this._document.styleSheets[i].href.indexOf(chrome.extension.getURL('')) !== -1) {
491 //Getting the url of the CSS file 491 //Getting the url of the CSS file
492 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];//TODO: Parse out relative URLs and map them to absolute 492 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];//TODO: Parse out relative URLs and map them to absolute
493 //Creating the URI of the file (this is wrong should not be splitting cssUrl) 493 //Creating the URI of the file (this is wrong should not be splitting cssUrl)
494 fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl; 494 fileUri = (this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl).replace(/\/\//gi, '/');
495 fileUri = fileUri.replace(/\/\//gi, '/');
496 //Loading the data from the file 495 //Loading the data from the file
497 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); 496 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
498 //Creating tag with file content 497 //Creating tag with file content
@@ -508,10 +507,17 @@ exports.HTMLDocument = Montage.create(TextDocument, {
508 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); 507 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value);
509 } 508 }
510 } 509 }
510 //
511
512 fileCouldDirUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split(cssUrl.split('/')[cssUrl.split('/').length-1])[0]).replace(/\/\//gi, '/'));
513
514
511 //TODO: Fix regEx to have logic for all possible URLs strings 515 //TODO: Fix regEx to have logic for all possible URLs strings
512 prefixUrl = '('+cssUrl.split(cssUrl.split('/')[cssUrl.split('/').length-1])[0]+'../'; 516 prefixUrl = '('+fileCouldDirUrl+'../';
513 prefixUrl = prefixUrl.replace('(/', '(');
514 tag.innerHTML = cssData.content.replace(/\(\.\.\//gi, prefixUrl); 517 tag.innerHTML = cssData.content.replace(/\(\.\.\//gi, prefixUrl);
518
519
520
515 //Looping through DOM to insert style tag at location of link element 521 //Looping through DOM to insert style tag at location of link element
516 query = this._templateDocument.html.querySelectorAll(['link']); 522 query = this._templateDocument.html.querySelectorAll(['link']);
517 for (var j in query) { 523 for (var j in query) {
@@ -525,14 +531,14 @@ exports.HTMLDocument = Montage.create(TextDocument, {
525 } else { 531 } else {
526 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); 532 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja');
527 //None local stylesheet, probably on a CDN (locked) 533 //None local stylesheet, probably on a CDN (locked)
528 tag = this.iframe.contentWindow.document.createElement('style'); 534 /*
535tag = this.iframe.contentWindow.document.createElement('style');
529 tag.setAttribute('type', 'text/css'); 536 tag.setAttribute('type', 'text/css');
530 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); 537 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href);
531 tag.setAttribute('data-ninja-file-read-only', "true"); 538 tag.setAttribute('data-ninja-file-read-only', "true");
532 tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); 539 tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]);
533 540
534 /* 541 //TODO: Figure out cross-domain XHR issue, might need cloud to handle
535//TODO: Figure out cross-domain XHR issue, might need cloud to handle
536 var xhr = new XMLHttpRequest(); 542 var xhr = new XMLHttpRequest();
537 xhr.open("GET", this._document.styleSheets[i].href, true); 543 xhr.open("GET", this._document.styleSheets[i].href, true);
538 xhr.send(); 544 xhr.send();
@@ -540,7 +546,6 @@ exports.HTMLDocument = Montage.create(TextDocument, {
540 if (xhr.readyState === 4) { 546 if (xhr.readyState === 4) {
541 console.log(xhr); 547 console.log(xhr);
542 } 548 }
543*/
544 //tag.innerHTML = xhr.responseText //xhr.response; 549 //tag.innerHTML = xhr.responseText //xhr.response;
545 550
546 //Currently no external styles will load if unable to load via XHR request 551 //Currently no external styles will load if unable to load via XHR request
@@ -555,6 +560,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
555 this._templateDocument.head.insertBefore(tag, query[j]); 560 this._templateDocument.head.insertBefore(tag, query[j]);
556 } 561 }
557 } 562 }
563*/
558 } 564 }
559 } 565 }
560 } 566 }