aboutsummaryrefslogtreecommitdiff
path: root/js/stage
diff options
context:
space:
mode:
authorAnanya Sen2012-02-02 03:30:54 -0800
committerAnanya Sen2012-02-02 03:30:54 -0800
commit87e247e74040b5e80ff40003d233d5317881102a (patch)
tree42bbe42d1af84ac35c792d720645f0a00ae6aa53 /js/stage
parent8504b61aefb25fdab931f02c4568916d2bf8345c (diff)
downloadninja-87e247e74040b5e80ff40003d233d5317881102a.tar.gz
fixed code view container, and switching code view
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/stage')
-rwxr-xr-xjs/stage/stage-view.reel/stage-view.js103
1 files changed, 58 insertions, 45 deletions
diff --git a/js/stage/stage-view.reel/stage-view.js b/js/stage/stage-view.reel/stage-view.js
index c0b0b83e..bb77b3de 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,6 +51,28 @@ 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) {
@@ -58,8 +85,6 @@ exports.StageView = Montage.create(Component, {
58 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
59 this.application.ninja.documentController.activeDocument = doc; 86 this.application.ninja.documentController.activeDocument = doc;
60 87
61 this.element.appendChild(doc.textArea);
62
63 var type; 88 var type;
64 89
65 switch(doc.documentType) { 90 switch(doc.documentType) {
@@ -71,13 +96,16 @@ exports.StageView = Montage.create(Component, {
71 break; 96 break;
72 } 97 }
73 98
74 //remove any previous Codemirror div 99 //hide other Codemirror divs
75 var codemirrorDiv = this.element.querySelector(".CodeMirror"); 100 this.hideOtherCodeView(doc.uuid);
76 if(!!codemirrorDiv){
77 codemirrorDiv.parentNode.removeChild(codemirrorDiv);
78 }
79 101
80 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, {
81 lineNumbers: true, 109 lineNumbers: true,
82 mode: type, 110 mode: type,
83 onCursorActivity: function() { 111 onCursorActivity: function() {
@@ -95,6 +123,11 @@ exports.StageView = Montage.create(Component, {
95 123
96 switchCodeView:{ 124 switchCodeView:{
97 value: function(doc){ 125 value: function(doc){
126
127 //if dirty SAVE codemirror into textarea
128 //doc.editor.save();
129
130
98 var documentController = this.application.ninja.documentController; 131 var documentController = this.application.ninja.documentController;
99 this.application.ninja.documentController._hideCurrentDocument(); 132 this.application.ninja.documentController._hideCurrentDocument();
100 133
@@ -102,36 +135,7 @@ exports.StageView = Montage.create(Component, {
102 135
103 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe 136 this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe
104 137
105 138 this.application.ninja.documentController._showCurrentDocument();
106
107 //remove any previous Codemirror div
108 var codemirrorDiv = this.element.querySelector(".CodeMirror");
109 if(!!codemirrorDiv){
110 codemirrorDiv.parentNode.removeChild(codemirrorDiv);
111 }
112
113 var type;
114
115 switch(doc.documentType) {
116 case "css" :
117 type = "css";
118 break;
119 case "js" :
120 type = "javascript";
121 break;
122 }
123
124 var codeM = CodeMirror.fromTextArea(doc.textArea, {
125 lineNumbers: true,
126 mode: type,
127 onCursorActivity: function() {
128 //documentController._codeEditor.editor.setLineClass(documentController._codeEditor.hline, null);
129 //documentController._codeEditor.hline = documentController._codeEditor.editor.setLineClass(documentController._codeEditor.editor.getCursor().line, "activeline");
130 }
131 });
132
133 //this.application.ninja.documentController._codeEditor.hline = this.application.ninja.documentController._codeEditor.editor.setLineClass(0, "activeline");
134
135 } 139 }
136 }, 140 },
137 refreshCodeDocument:{ 141 refreshCodeDocument:{
@@ -161,12 +165,21 @@ exports.StageView = Montage.create(Component, {
161 }); 165 });
162 } 166 }
163 }, 167 },
164 removeCodeDocument:{ 168 hideCodeDocument:{
165 value:function(){ 169 value:function(docUuid){
166 //remove any previous Codemirror div 170 //hide the previous Codemirror div
167 var codemirrorDiv = this.element.querySelector(".CodeMirror"); 171
168 if(!!codemirrorDiv){ 172 }
169 codemirrorDiv.parentNode.removeChild(codemirrorDiv); 173 },
174 hideOtherCodeView:{
175 value:function(docUuid){
176 var i=0;
177 if(this.element.hasChildNodes()){
178 for(i=0;i<this.element.childNodes.length;i++){
179 if(this.element.childNodes[i].id !== ("codeMirror_"+docUuid)){
180 this.element.childNodes[i].style.display = "none";
181 }
182 }
170 } 183 }
171 } 184 }
172 } 185 }