diff options
Diffstat (limited to 'js/document/html-document.js')
-rwxr-xr-x | js/document/html-document.js | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index 5d507476..9353027d 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,18 @@ 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; |
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; |
495 | fileUri = fileUri.replace(/\/\//gi, '/'); | ||
473 | //Loading the data from the file | 496 | //Loading the data from the file |
474 | cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); | 497 | cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); |
475 | //Creating tag with file content | 498 | //Creating tag with file content |
476 | tag = this.iframe.contentWindow.document.createElement('style'); | 499 | var tag = this.iframe.contentWindow.document.createElement('style'); |
477 | tag.setAttribute('type', 'text/css'); | 500 | tag.setAttribute('type', 'text/css'); |
478 | tag.setAttribute('data-ninja-uri', fileUri); | 501 | tag.setAttribute('data-ninja-uri', fileUri); |
479 | tag.setAttribute('data-ninja-file-url', cssUrl); | 502 | tag.setAttribute('data-ninja-file-url', cssUrl); |
@@ -481,11 +504,14 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
481 | 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]); |
482 | //Copying attributes to maintain same properties as the <link> | 505 | //Copying attributes to maintain same properties as the <link> |
483 | for (var n in this._document.styleSheets[i].ownerNode.attributes) { | 506 | 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') { | 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') { |
485 | 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); |
486 | } | 509 | } |
487 | } | 510 | } |
488 | tag.innerHTML = cssData.content; | 511 | //TODO: Fix regEx to have logic for all possible URLs strings |
512 | prefixUrl = '('+cssUrl.split(cssUrl.split('/')[cssUrl.split('/').length-1])[0]+'../'; | ||
513 | prefixUrl = prefixUrl.replace('(/', '('); | ||
514 | tag.innerHTML = cssData.content.replace(/\(\.\.\//gi, prefixUrl); | ||
489 | //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 |
490 | query = this._templateDocument.html.querySelectorAll(['link']); | 516 | query = this._templateDocument.html.querySelectorAll(['link']); |
491 | for (var j in query) { | 517 | for (var j in query) { |
@@ -498,15 +524,15 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
498 | } | 524 | } |
499 | } else { | 525 | } else { |
500 | 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'); |
501 | /* | 527 | //None local stylesheet, probably on a CDN (locked) |
502 | //None local stylesheet, probably on a CDN (locked) | ||
503 | tag = this.iframe.contentWindow.document.createElement('style'); | 528 | tag = this.iframe.contentWindow.document.createElement('style'); |
504 | tag.setAttribute('type', 'text/css'); | 529 | tag.setAttribute('type', 'text/css'); |
505 | tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); | 530 | tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); |
506 | tag.setAttribute('data-ninja-file-read-only', "true"); | 531 | tag.setAttribute('data-ninja-file-read-only', "true"); |
507 | 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]); |
508 | 533 | ||
509 | //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 | ||
510 | var xhr = new XMLHttpRequest(); | 536 | var xhr = new XMLHttpRequest(); |
511 | xhr.open("GET", this._document.styleSheets[i].href, true); | 537 | xhr.open("GET", this._document.styleSheets[i].href, true); |
512 | xhr.send(); | 538 | xhr.send(); |
@@ -514,6 +540,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
514 | if (xhr.readyState === 4) { | 540 | if (xhr.readyState === 4) { |
515 | console.log(xhr); | 541 | console.log(xhr); |
516 | } | 542 | } |
543 | */ | ||
517 | //tag.innerHTML = xhr.responseText //xhr.response; | 544 | //tag.innerHTML = xhr.responseText //xhr.response; |
518 | 545 | ||
519 | //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 |
@@ -528,7 +555,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
528 | this._templateDocument.head.insertBefore(tag, query[j]); | 555 | this._templateDocument.head.insertBefore(tag, query[j]); |
529 | } | 556 | } |
530 | } | 557 | } |
531 | */ | ||
532 | } | 558 | } |
533 | } | 559 | } |
534 | } | 560 | } |
@@ -715,6 +741,11 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
715 | } | 741 | } |
716 | 742 | ||
717 | this.draw3DGrid = this.application.ninja.appModel.show3dGrid; | 743 | this.draw3DGrid = this.application.ninja.appModel.show3dGrid; |
744 | |||
745 | //persist a clone of history per document | ||
746 | this.undoStack = this.application.ninja.undocontroller.undoQueue.slice(0); | ||
747 | this.redoStack = this.application.ninja.undocontroller.redoQueue.slice(0); | ||
748 | this.application.ninja.undocontroller.clearHistory();//clear history to give the next document a fresh start | ||
718 | } | 749 | } |
719 | }, | 750 | }, |
720 | 751 | ||
@@ -724,20 +755,24 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
724 | value: function () { | 755 | value: function () { |
725 | this.application.ninja.stage.drawUtils.gridHorizontalSpacing = this.gridHorizontalSpacing; | 756 | this.application.ninja.stage.drawUtils.gridHorizontalSpacing = this.gridHorizontalSpacing; |
726 | this.application.ninja.stage.drawUtils.gridVerticalSpacing = this.gridVerticalSpacing; | 757 | this.application.ninja.stage.drawUtils.gridVerticalSpacing = this.gridVerticalSpacing; |
727 | 758 | ||
728 | if((typeof this.selectionModel !== 'undefined') && (this.selectionModel !== null)){ | 759 | 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; | 760 | 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; | 761 | this.application.ninja.stage._iframeContainer.scrollTop = this.savedTopScroll; |
736 | this.application.ninja.stage._scrollLeft = this.savedTopScroll; | 762 | this.application.ninja.stage.handleScroll(); |
763 | } | ||
764 | |||
765 | this.application.ninja.currentSelectedContainer = this.documentRoot; | ||
766 | if(this.selectionModel){ | ||
767 | this.application.ninja.selectedElements = this.selectionModel.slice(0); | ||
737 | } | 768 | } |
738 | this.application.ninja.stage.handleScroll(); | ||
739 | 769 | ||
740 | this.application.ninja.appModel.show3dGrid = this.draw3DGrid; | 770 | this.application.ninja.appModel.show3dGrid = this.draw3DGrid; |
771 | |||
772 | this.application.ninja.undocontroller.undoQueue = this.undoStack.slice(0); | ||
773 | this.application.ninja.undocontroller.redoQueue = this.redoStack.slice(0); | ||
774 | |||
775 | |||
741 | } | 776 | } |
742 | } | 777 | } |
743 | //////////////////////////////////////////////////////////////////// | 778 | //////////////////////////////////////////////////////////////////// |