aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js79
1 files changed, 61 insertions, 18 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 5d507476..a56a7e3c 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -59,6 +59,27 @@ exports.HTMLDocument = Montage.create(TextDocument, {
59 _gridVerticalSpacing: {value:0}, 59 _gridVerticalSpacing: {value:0},
60 //end - drawUtils state 60 //end - drawUtils state
61 61
62 _undoStack: { value: [] },
63 undoStack: {
64 get: function() {
65 return this._undoStack;
66 },
67 set:function(value){
68 this._undoStack = value;
69 }
70 },
71
72 _redoStack: { value: [], enumerable: false },
73
74 redoStack: {
75 get: function() {
76 return this._redoStack;
77 },
78 set:function(value){
79 this._redoStack = value;
80 }
81 },
82
62 83
63 // GETTERS / SETTERS 84 // GETTERS / SETTERS
64 85
@@ -464,16 +485,17 @@ exports.HTMLDocument = Montage.create(TextDocument, {
464 //If rules are null, assuming cross-origin issue 485 //If rules are null, assuming cross-origin issue
465 if(this._document.styleSheets[i].rules === null) { 486 if(this._document.styleSheets[i].rules === null) {
466 //TODO: Revisit URLs and URI creation logic, very hack right now 487 //TODO: Revisit URLs and URI creation logic, very hack right now
467 var fileUri, cssUrl, cssData, tag, query; 488 var fileUri, cssUrl, cssData, query, prefixUrl, fileCouldDirUrl;
468 if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) { 489 //TODO: Parse out relative URLs and map them to absolute
490 if (this._document.styleSheets[i].href.indexOf(chrome.extension.getURL('')) !== -1) {
469 //Getting the url of the CSS file 491 //Getting the url of the CSS file
470 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1]; 492 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];//TODO: Parse out relative URLs and map them to absolute
471 //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)
472 fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1]; 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, '/');
473 //Loading the data from the file 495 //Loading the data from the file
474 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); 496 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
475 //Creating tag with file content 497 //Creating tag with file content
476 tag = this.iframe.contentWindow.document.createElement('style'); 498 var tag = this.iframe.contentWindow.document.createElement('style');
477 tag.setAttribute('type', 'text/css'); 499 tag.setAttribute('type', 'text/css');
478 tag.setAttribute('data-ninja-uri', fileUri); 500 tag.setAttribute('data-ninja-uri', fileUri);
479 tag.setAttribute('data-ninja-file-url', cssUrl); 501 tag.setAttribute('data-ninja-file-url', cssUrl);
@@ -481,11 +503,23 @@ exports.HTMLDocument = Montage.create(TextDocument, {
481 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); 503 tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]);
482 //Copying attributes to maintain same properties as the <link> 504 //Copying attributes to maintain same properties as the <link>
483 for (var n in this._document.styleSheets[i].ownerNode.attributes) { 505 for (var n in this._document.styleSheets[i].ownerNode.attributes) {
484 if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { 506 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') {
485 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);
486 } 508 }
487 } 509 }
488 tag.innerHTML = cssData.content; 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
515 //TODO: Fix regEx to have logic for all possible URLs strings (currently prefixing all url())
516 prefixUrl = 'url('+fileCouldDirUrl;
517 tag.innerHTML = cssData.content.replace(/url\(/gi, prefixUrl);
518
519 //console.log(("http://hello.com, https://google.com").replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, 'hello'))
520
521 //console.log(tag.innerHTML);
522
489 //Looping through DOM to insert style tag at location of link element 523 //Looping through DOM to insert style tag at location of link element
490 query = this._templateDocument.html.querySelectorAll(['link']); 524 query = this._templateDocument.html.querySelectorAll(['link']);
491 for (var j in query) { 525 for (var j in query) {
@@ -498,9 +532,9 @@ exports.HTMLDocument = Montage.create(TextDocument, {
498 } 532 }
499 } else { 533 } else {
500 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); 534 console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja');
535 //None local stylesheet, probably on a CDN (locked)
501 /* 536 /*
502//None local stylesheet, probably on a CDN (locked) 537tag = this.iframe.contentWindow.document.createElement('style');
503 tag = this.iframe.contentWindow.document.createElement('style');
504 tag.setAttribute('type', 'text/css'); 538 tag.setAttribute('type', 'text/css');
505 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); 539 tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href);
506 tag.setAttribute('data-ninja-file-read-only', "true"); 540 tag.setAttribute('data-ninja-file-read-only', "true");
@@ -715,6 +749,11 @@ exports.HTMLDocument = Montage.create(TextDocument, {
715 } 749 }
716 750
717 this.draw3DGrid = this.application.ninja.appModel.show3dGrid; 751 this.draw3DGrid = this.application.ninja.appModel.show3dGrid;
752
753 //persist a clone of history per document
754 this.undoStack = this.application.ninja.undocontroller.undoQueue.slice(0);
755 this.redoStack = this.application.ninja.undocontroller.redoQueue.slice(0);
756 this.application.ninja.undocontroller.clearHistory();//clear history to give the next document a fresh start
718 } 757 }
719 }, 758 },
720 759
@@ -724,20 +763,24 @@ exports.HTMLDocument = Montage.create(TextDocument, {
724 value: function () { 763 value: function () {
725 this.application.ninja.stage.drawUtils.gridHorizontalSpacing = this.gridHorizontalSpacing; 764 this.application.ninja.stage.drawUtils.gridHorizontalSpacing = this.gridHorizontalSpacing;
726 this.application.ninja.stage.drawUtils.gridVerticalSpacing = this.gridVerticalSpacing; 765 this.application.ninja.stage.drawUtils.gridVerticalSpacing = this.gridVerticalSpacing;
727 766
728 if((typeof this.selectionModel !== 'undefined') && (this.selectionModel !== null)){ 767 if((this.savedLeftScroll !== null) && (this.savedTopScroll !== null)){
729 this.application.ninja.selectedElements = this.selectionModel.slice(0);
730 }
731
732 if((this.savedLeftScroll!== null) && (this.savedTopScroll !== null)){
733 this.application.ninja.stage._iframeContainer.scrollLeft = this.savedLeftScroll; 768 this.application.ninja.stage._iframeContainer.scrollLeft = this.savedLeftScroll;
734 this.application.ninja.stage._scrollLeft = this.savedLeftScroll;
735 this.application.ninja.stage._iframeContainer.scrollTop = this.savedTopScroll; 769 this.application.ninja.stage._iframeContainer.scrollTop = this.savedTopScroll;
736 this.application.ninja.stage._scrollLeft = this.savedTopScroll; 770 this.application.ninja.stage.handleScroll();
771 }
772
773 this.application.ninja.currentSelectedContainer = this.documentRoot;
774 if(this.selectionModel){
775 this.application.ninja.selectedElements = this.selectionModel.slice(0);
737 } 776 }
738 this.application.ninja.stage.handleScroll();
739 777
740 this.application.ninja.appModel.show3dGrid = this.draw3DGrid; 778 this.application.ninja.appModel.show3dGrid = this.draw3DGrid;
779
780 this.application.ninja.undocontroller.undoQueue = this.undoStack.slice(0);
781 this.application.ninja.undocontroller.redoQueue = this.redoStack.slice(0);
782
783
741 } 784 }
742 } 785 }
743 //////////////////////////////////////////////////////////////////// 786 ////////////////////////////////////////////////////////////////////