aboutsummaryrefslogtreecommitdiff
path: root/js/stage/stage-view.reel/stage-view.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/stage/stage-view.reel/stage-view.js')
-rwxr-xr-xjs/stage/stage-view.reel/stage-view.js123
1 files changed, 105 insertions, 18 deletions
diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js
index 727c16eb..d8e1e46b 100755
--- a/js/stage/stage-view.reel/stage-view.js
+++ b/js/stage/stage-view.reel/stage-view.js
@@ -28,7 +28,12 @@ exports.StageView = Montage.create(Component, {
28 templateDidLoad: { 28 templateDidLoad: {
29 value: function() { 29 value: function() {
30 this.eventManager.addEventListener("appLoaded", this, false); 30 this.eventManager.addEventListener("appLoaded", this, false);
31 //console.log(this.application.ninja.documentController._documents); 31 }
32 },
33
34 didDraw:{
35 value: function() {
36 if(!this.application.ninja.documentController._textHolder) this.application.ninja.documentController._textHolder = this.element;
32 } 37 }
33 }, 38 },
34 39
@@ -46,9 +51,33 @@ exports.StageView = Montage.create(Component, {
46 } 51 }
47 }, 52 },
48 53
54 /**
55 * Creates a text area which will contain the content of the opened text document.
56 */
57 createTextAreaElement: {
58 value: function(uuid) {
59
60
61 var codeMirrorDiv = document.createElement("div");
62 codeMirrorDiv.id = "codeMirror_" + uuid;
63 codeMirrorDiv.style.display = "block";
64 this.element.appendChild(codeMirrorDiv);
65
66 var textArea = document.createElement("textarea");
67 textArea.id = "code";
68 textArea.name = "code";
69
70 codeMirrorDiv.appendChild(textArea);
71
72 return textArea;
73 }
74 },
75
49 // Temporary function to create a Codemirror text view 76 // Temporary function to create a Codemirror text view
50 createTextView: { 77 createTextView: {
51 value: function(doc) { 78 value: function(doc) {
79 var documentController = this.application.ninja.documentController;
80
52 this.application.ninja.documentController._hideCurrentDocument(); 81 this.application.ninja.documentController._hideCurrentDocument();
53 82
54 this.application.ninja.currentDocument.container.parentNode.style["display"] = "none"; 83 this.application.ninja.currentDocument.container.parentNode.style["display"] = "none";
@@ -56,8 +85,6 @@ exports.StageView = Montage.create(Component, {
56 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe 85 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
57 this.application.ninja.documentController.activeDocument = doc; 86 this.application.ninja.documentController.activeDocument = doc;
58 87
59 this.element.appendChild(doc.textArea);
60
61 var type; 88 var type;
62 89
63 switch(doc.documentType) { 90 switch(doc.documentType) {
@@ -69,18 +96,21 @@ exports.StageView = Montage.create(Component, {
69 break; 96 break;
70 } 97 }
71 98
72 //remove any previous Codemirror div 99 //hide other Codemirror divs
73 var codemirrorDiv = this.element.querySelector(".CodeMirror"); 100 this.hideOtherCodeView(doc.uuid);
74 if(!!codemirrorDiv){
75 codemirrorDiv.parentNode.removeChild(codemirrorDiv);
76 }
77 101
78 var codeM = CodeMirror.fromTextArea(doc.textArea, { 102
103 //fix hack
104 document.getElementById("codeMirror_"+doc.uuid).style.display="block";
105
106
107
108 doc.editor = CodeMirror.fromTextArea(doc.textArea, {
79 lineNumbers: true, 109 lineNumbers: true,
80 mode: type, 110 mode: type,
81 onCursorActivity: function() { 111 onCursorActivity: function() {
82 this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.hline, null); 112 //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null);
83 this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.editor.getCursor().line, "activeline"); 113 //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline");
84 } 114 }
85 }); 115 });
86 116
@@ -91,19 +121,61 @@ exports.StageView = Montage.create(Component, {
91 } 121 }
92 }, 122 },
93 123
124
125
94 switchCodeView:{ 126 switchCodeView:{
95 value: function(doc){ 127 value: function(doc){
96 128
97 this.application.ninja.documentController._hideCurrentDocument(); 129 //if dirty SAVE codemirror into textarea
130 //this.application.ninja.documentController.activeDocument.editor.save();
98 131
99 //remove any previous Codemirror div 132 //remove the codemirror div
100 var codemirrorDiv = this.element.querySelector(".CodeMirror"); 133 var codemirrorDiv = this.application.ninja.documentController.activeDocument.container.querySelector(".CodeMirror");
101 if(!!codemirrorDiv){ 134 if(!!codemirrorDiv){
102 codemirrorDiv.parentNode.removeChild(codemirrorDiv); 135 codemirrorDiv.parentNode.removeChild(codemirrorDiv);
136 this.application.ninja.documentController.activeDocument.editor = null;
103 } 137 }
104 138
139 this.application.ninja.documentController._hideCurrentDocument();
140
141 this.application.ninja.documentController.activeDocument = doc;
142
143 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
144 this.application.ninja.documentController._showCurrentDocument();
145
105 var type; 146 var type;
147 switch(doc.documentType) {
148 case "css" :
149 type = "css";
150 break;
151 case "js" :
152 type = "javascript";
153 break;
154 }
155
156 //add the codemirror div again for editting
157 doc.editor = CodeMirror.fromTextArea(doc.textArea, {
158 lineNumbers: true,
159 mode: type,
160 onCursorActivity: function() {
161 //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null);
162 //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline");
163 }
164 });
165
166 //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline");
167
106 168
169 }
170 },
171 refreshCodeDocument:{
172 value:function(doc){
173
174 }
175 },
176 addCodeDocument:{
177 value:function(doc){
178 var type;
107 switch(doc.documentType) { 179 switch(doc.documentType) {
108 case "css" : 180 case "css" :
109 type = "css"; 181 type = "css";
@@ -117,13 +189,28 @@ exports.StageView = Montage.create(Component, {
117 lineNumbers: true, 189 lineNumbers: true,
118 mode: type, 190 mode: type,
119 onCursorActivity: function() { 191 onCursorActivity: function() {
120 this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.hline, null); 192 //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null);
121 this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(this.application.ninja.documentController._codeEditor.editor.getCursor().line, "activeline"); 193 //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline");
122 } 194 }
123 }); 195 });
196 }
197 },
198 hideCodeDocument:{
199 value:function(docUuid){
200 //hide the previous Codemirror div
124 201
125 //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline"); 202 }
126 203 },
204 hideOtherCodeView:{
205 value:function(docUuid){
206 var i=0;
207 if(this.element.hasChildNodes()){
208 for(i=0;i<this.element.childNodes.length;i++){
209 if(this.element.childNodes[i].id !== ("codeMirror_"+docUuid)){
210 this.element.childNodes[i].style.display = "none";
211 }
212 }
213 }
127 } 214 }
128 } 215 }
129}); \ No newline at end of file 216}); \ No newline at end of file