aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/document-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-xjs/controllers/document-controller.js96
1 files changed, 59 insertions, 37 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index d88059ab..fba9fad5 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -33,6 +33,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
33 value: false 33 value: false
34 }, 34 },
35 35
36 _hackInitialStyles: {
37 value: true
38 },
39
36 _activeDocument: { value: null }, 40 _activeDocument: { value: null },
37 _iframeCounter: { value: 1, enumerable: false }, 41 _iframeCounter: { value: 1, enumerable: false },
38 _iframeHolder: { value: null, enumerable: false }, 42 _iframeHolder: { value: null, enumerable: false },
@@ -44,8 +48,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
44 return this._activeDocument; 48 return this._activeDocument;
45 }, 49 },
46 set: function(doc) { 50 set: function(doc) {
47 if(!!this._activeDocument){ this._activeDocument.isActive = false;} 51// if(!!this._activeDocument){ this._activeDocument.isActive = false;}
52
48 this._activeDocument = doc; 53 this._activeDocument = doc;
54
49 if(!!this._activeDocument){ 55 if(!!this._activeDocument){
50 if(this._documents.indexOf(doc) === -1) this._documents.push(doc); 56 if(this._documents.indexOf(doc) === -1) this._documents.push(doc);
51 this._activeDocument.isActive = true; 57 this._activeDocument.isActive = true;
@@ -95,11 +101,14 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
95 value: function (request) { 101 value: function (request) {
96 //TODO: Check if frameId is proper 102 //TODO: Check if frameId is proper
97 if (this._hackRootFlag && request.parentFrameId !== -1) { 103 if (this._hackRootFlag && request.parentFrameId !== -1) {
98 //TODO: Optimize creating string 104 //Checking for proper URL redirect (from different directories)
99 //console.log(request); 105 if (request.url.indexOf('js/document/templates/banner') !== -1) {
100 //console.log(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1], request.url); 106 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/banner/'))[1]};
101 //return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split('/')[request.url.split('/').length-1]}; 107 } else if (request.url.indexOf('js/document/templates/html') !== -1) {
102 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/'))[1]}; 108 return {redirectUrl: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+request.url.split(chrome.extension.getURL('js/document/templates/html/'))[1]};
109 } else {
110 //Error, not a valid folder
111 }
103 } 112 }
104 } 113 }
105 }, 114 },
@@ -155,13 +164,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
155 }, 164 },
156 165
157 handleExecuteNewFile: { 166 handleExecuteNewFile: {
158 value: function(event) { 167 value: function(event) {
159 var newFileSettings = event._event.settings || {}; 168 var newFileSettings = event._event.settings || {};
160 if (this.application.ninja.coreIoApi.cloudAvailable()) { 169 if (this.application.ninja.coreIoApi.cloudAvailable()) {
161 newFileSettings.callback = this.createNewFile.bind(this); 170 newFileSettings.callback = this.createNewFile.bind(this);
162 this.application.ninja.newFileController.showNewFileDialog(newFileSettings); 171 this.application.ninja.newFileController.showNewFileDialog(newFileSettings);
163 }
164 } 172 }
173 }
165 }, 174 },
166 //////////////////////////////////////////////////////////////////// 175 ////////////////////////////////////////////////////////////////////
167 // 176 //
@@ -210,13 +219,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
210 handleExecuteFileClose:{ 219 handleExecuteFileClose:{
211 value: function(event) { 220 value: function(event) {
212 if (this.activeDocument) { 221 if (this.activeDocument) {
213 this.activeDocument.closeDocument(); 222// this.activeDocument.closeDocument();
223 this.closeFile(this.activeDocument);
214 } 224 }
215 /*
216if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
217 this.closeDocument(this.activeDocument.uuid);
218 }
219*/
220 } 225 }
221 }, 226 },
222 //////////////////////////////////////////////////////////////////// 227 ////////////////////////////////////////////////////////////////////
@@ -445,7 +450,32 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
445 */ 450 */
446 451
447 } 452 }
448 }, 453 },
454
455 closeFile: {
456 value: function(document) {
457 document.closeDocument(this, this.onCloseFile);
458 }
459 },
460
461 onCloseFile: {
462 value: function(doc) {
463
464 this._documents.splice(this._documents.indexOf(doc), 1);
465
466 this._activeDocument = null;
467
468 this.application.ninja.stage.stageView.hideRulers();
469
470// document.getElementById("iframeContainer").style.display="block";
471
472 this.application.ninja.stage.hideCanvas(true);
473
474
475 NJevent("closeDocument", doc.model.file.uri);
476 //TODO: Delete object here
477 }
478 },
449 479
450 closeDocument: { 480 closeDocument: {
451 value: function(id) { 481 value: function(id) {
@@ -465,15 +495,7 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
465 if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();} 495 if(typeof doc.stopVideos !== "undefined"){doc.stopVideos();}
466 this._removeDocumentView(doc.container); 496 this._removeDocumentView(doc.container);
467 }else if(this._documents.length === 0){ 497 }else if(this._documents.length === 0){
468 if(typeof this.activeDocument.pauseAndStopVideos !== "undefined"){ 498 // See above
469 this.activeDocument.pauseAndStopVideos();
470 }
471 this.activeDocument = null;
472 this._removeDocumentView(doc.container);
473 this.application.ninja.stage.stageView.hideRulers();
474 document.getElementById("iframeContainer").style.display="block";
475
476 this.application.ninja.stage.hideCanvas(true);
477 }else{//closing inactive document tab - just clear DOM 499 }else{//closing inactive document tab - just clear DOM
478 if(typeof doc.pauseAndStopVideos !== "undefined"){ 500 if(typeof doc.pauseAndStopVideos !== "undefined"){
479 doc.pauseAndStopVideos(); 501 doc.pauseAndStopVideos();
@@ -512,6 +534,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
512 534
513 this.application.ninja.stage.stageView.showCodeViewBar(false); 535 this.application.ninja.stage.stageView.showCodeViewBar(false);
514 this.application.ninja.stage.stageView.restoreAllPanels(); 536 this.application.ninja.stage.stageView.restoreAllPanels();
537
538 // Flag to stop stylesheet dirty event
539 this._hackInitialStyles = false;
515 } 540 }
516 }, 541 },
517 542
@@ -549,12 +574,6 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
549 /** 574 /**
550 * VIEW Related Methods 575 * VIEW Related Methods
551 */ 576 */
552 // PUBLIC
553 ShowActiveDocument: {
554 value: function() {
555 this.activeDocument.iframe.style.opacity = 1.0;
556 }
557 },
558 577
559 // PRIVATE 578 // PRIVATE
560 _findDocumentByUUID: { 579 _findDocumentByUUID: {
@@ -607,7 +626,7 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
607 //hide the iframe when switching to code view 626 //hide the iframe when switching to code view
608 document.getElementById("iframeContainer").style.display = "none"; 627 document.getElementById("iframeContainer").style.display = "none";
609 } 628 }
610 } 629 }
611 } 630 }
612 }, 631 },
613 632
@@ -653,7 +672,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
653 672
654 handleStyleSheetDirty:{ 673 handleStyleSheetDirty:{
655 value:function(){ 674 value:function(){
656// this.activeDocument.model.needsSave = true; 675 if(!this._hackInitialStyles) {
676 this.activeDocument.model.needsSave = true;
677 }
657 } 678 }
658 }, 679 },
659 680
@@ -683,8 +704,9 @@ if(this.activeDocument && this.application.ninja.coreIoApi.cloudAvailable()){
683 } 704 }
684 705
685 if(needsRule) { 706 if(needsRule) {
686 rule = sc.addRule('body{}'); 707 rule = sc.addRule('.ninja-body{}');
687 sc.setStyles(rule, styles); 708 sc.setStyles(rule, styles);
709 sc.addClass(docRoot, "ninja-body");
688 } 710 }
689 } 711 }
690 } 712 }