aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js22
1 files changed, 12 insertions, 10 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 1691e3e4..9353027d 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -485,17 +485,18 @@ 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, tag, query; 488 var fileUri, cssUrl, cssData, query, prefixUrl;
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;
495 fileUri = fileUri.replace(/\/\//gi, '/');
495 //Loading the data from the file 496 //Loading the data from the file
496 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); 497 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
497 //Creating tag with file content 498 //Creating tag with file content
498 tag = this.iframe.contentWindow.document.createElement('style'); 499 var tag = this.iframe.contentWindow.document.createElement('style');
499 tag.setAttribute('type', 'text/css'); 500 tag.setAttribute('type', 'text/css');
500 tag.setAttribute('data-ninja-uri', fileUri); 501 tag.setAttribute('data-ninja-uri', fileUri);
501 tag.setAttribute('data-ninja-file-url', cssUrl); 502 tag.setAttribute('data-ninja-file-url', cssUrl);
@@ -503,13 +504,14 @@ exports.HTMLDocument = Montage.create(TextDocument, {
503 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); 504 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]);
504 //Copying attributes to maintain same properties as the <link> 505 //Copying attributes to maintain same properties as the <link>
505 for (var n in this._document.styleSheets[i].ownerNode.attributes) { 506 for (var n in this._document.styleSheets[i].ownerNode.attributes) {
506 if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { 507 if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled' && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') {
507 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); 508 tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value);
508 } 509 }
509 } 510 }
510 //TODO: Parse out relative URLs and map them to absolute 511 //TODO: Fix regEx to have logic for all possible URLs strings
511 //console.log(cssData.content); 512 prefixUrl = '('+cssUrl.split(cssUrl.split('/')[cssUrl.split('/').length-1])[0]+'../';
512 tag.innerHTML = cssData.content; 513 prefixUrl = prefixUrl.replace('(/', '(');
514 tag.innerHTML = cssData.content.replace(/\(\.\.\//gi, prefixUrl);
513 //Looping through DOM to insert style tag at location of link element 515 //Looping through DOM to insert style tag at location of link element
514 query = this._templateDocument.html.querySelectorAll(['link']); 516 query = this._templateDocument.html.querySelectorAll(['link']);
515 for (var j in query) { 517 for (var j in query) {
@@ -522,15 +524,15 @@ exports.HTMLDocument = Montage.create(TextDocument, {
522 } 524 }
523 } else { 525 } else {
524 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); 526 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja');
525 /* 527 //None local stylesheet, probably on a CDN (locked)
526//None local stylesheet, probably on a CDN (locked)
527 tag = this.iframe.contentWindow.document.createElement('style'); 528 tag = this.iframe.contentWindow.document.createElement('style');
528 tag.setAttribute('type', 'text/css'); 529 tag.setAttribute('type', 'text/css');
529 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); 530 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href);
530 tag.setAttribute('data-ninja-file-read-only', "true"); 531 tag.setAttribute('data-ninja-file-read-only', "true");
531 tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); 532 tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]);
532 533
533 //TODO: Figure out cross-domain XHR issue, might need cloud to handle 534 /*
535//TODO: Figure out cross-domain XHR issue, might need cloud to handle
534 var xhr = new XMLHttpRequest(); 536 var xhr = new XMLHttpRequest();
535 xhr.open("GET", this._document.styleSheets[i].href, true); 537 xhr.open("GET", this._document.styleSheets[i].href, true);
536 xhr.send(); 538 xhr.send();
@@ -538,6 +540,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
538 if (xhr.readyState === 4) { 540 if (xhr.readyState === 4) {
539 console.log(xhr); 541 console.log(xhr);
540 } 542 }
543*/
541 //tag.innerHTML = xhr.responseText //xhr.response; 544 //tag.innerHTML = xhr.responseText //xhr.response;
542 545
543 //Currently no external styles will load if unable to load via XHR request 546 //Currently no external styles will load if unable to load via XHR request
@@ -552,7 +555,6 @@ exports.HTMLDocument = Montage.create(TextDocument, {
552 this._templateDocument.head.insertBefore(tag, query[j]); 555 this._templateDocument.head.insertBefore(tag, query[j]);
553 } 556 }
554 } 557 }
555*/
556 } 558 }
557 } 559 }
558 } 560 }