diff options
author | Ananya Sen | 2012-05-18 16:56:16 -0700 |
---|---|---|
committer | Ananya Sen | 2012-05-18 16:56:16 -0700 |
commit | 7a22f7b368ef549a5b30c58a0f3900685b764bdb (patch) | |
tree | 44951af31368a5b287057e5cdddf0469cdc30298 /js/controllers/document-controller.js | |
parent | 65cea92d839bcd25ea9094a0798190a4dc4bea35 (diff) | |
download | ninja-7a22f7b368ef549a5b30c58a0f3900685b764bdb.tar.gz |
integrated open code view document in new dom architecture
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/controllers/document-controller.js')
-rwxr-xr-x | js/controllers/document-controller.js | 65 |
1 files changed, 24 insertions, 41 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index cf46e73e..a795d652 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js | |||
@@ -13,7 +13,8 @@ var Montage = require("montage/core/core").Montage, | |||
13 | TextDocument = require("js/document/text-document").TextDocument; | 13 | TextDocument = require("js/document/text-document").TextDocument; |
14 | 14 | ||
15 | // New Document Objects | 15 | // New Document Objects |
16 | var Document = require("js/document/document-html").HtmlDocument; | 16 | var Document_HTML = require("js/document/document-html").HtmlDocument; |
17 | var Document_Text = require("js/document/document-text").TextDocument; | ||
17 | //////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////// |
18 | // | 19 | // |
19 | var DocumentController = exports.DocumentController = Montage.create(Component, { | 20 | var DocumentController = exports.DocumentController = Montage.create(Component, { |
@@ -320,32 +321,30 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
320 | 321 | ||
321 | //////////////////////////////////////////////////////////////////// | 322 | //////////////////////////////////////////////////////////////////// |
322 | openDocument: { | 323 | openDocument: { |
323 | value: function(doc) { | 324 | value: function(file) { |
324 | var template, dimensions; | 325 | var template, dimensions; |
325 | if (doc.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { | 326 | |
326 | dimensions = (doc.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x'); | ||
327 | dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])}; | ||
328 | template = {type: 'banner', size: dimensions}; | ||
329 | } | ||
330 | // TODO: HACKS to remove | 327 | // TODO: HACKS to remove |
331 | this.documentHackReference = doc; | 328 | this.documentHackReference = file; |
332 | document.getElementById("iframeContainer").style.overflow = "hidden"; | 329 | document.getElementById("iframeContainer").style.overflow = "hidden"; |
333 | // | 330 | // |
334 | switch (doc.extension) { | 331 | switch (file.extension) { |
335 | case 'html': | 332 | case 'html': |
333 | |||
334 | if (file.content.body.indexOf('Ninja-Banner Dimensions@@@') !== -1) { | ||
335 | dimensions = (file.content.body.split('Ninja-Banner Dimensions@@@'))[1].split('-->')[0].split('x'); | ||
336 | dimensions = {width: parseInt(dimensions[0]), height: parseInt(dimensions[1])}; | ||
337 | template = {type: 'banner', size: dimensions}; | ||
338 | } | ||
339 | |||
336 | //Open in designer view | 340 | //Open in designer view |
337 | this._hackRootFlag = false; | 341 | this._hackRootFlag = false; |
338 | Montage.create(Document).init(doc, this, this._onOpenDocument, 'design', template); | 342 | Montage.create(Document_HTML).init(file, this, this._onOpenDocument, 'design', template); |
339 | break; | 343 | break; |
340 | default: | 344 | default: |
341 | //Open in code view | 345 | //Open in code view |
342 | var code = Montage.create(TextDocument, {"source": {value: doc.content}}), docuuid = Uuid.generate(), textArea; | 346 | Montage.create(Document_Text).init(file, this, this._onOpenTextDocument, 'code'); |
343 | textArea = this.application.ninja.stage.stageView.createTextAreaElement(docuuid); | 347 | break; |
344 | code.initialize(doc, docuuid, textArea, textArea.parentNode); | ||
345 | //code.init(doc.name, doc.uri, doc.extension, null, docuuid); | ||
346 | code.textArea.value = doc.content; | ||
347 | this.application.ninja.stage.stageView.createTextView(code); | ||
348 | break; | ||
349 | } | 348 | } |
350 | } | 349 | } |
351 | }, | 350 | }, |
@@ -514,9 +513,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
514 | _onOpenTextDocument: { | 513 | _onOpenTextDocument: { |
515 | value: function(doc) { | 514 | value: function(doc) { |
516 | if(this.activeDocument) { | 515 | if(this.activeDocument) { |
516 | |||
517 | if(this.activeDocument.currentView === "design"){ | 517 | if(this.activeDocument.currentView === "design"){ |
518 | this.activeDocument.saveAppState(); | 518 | this.activeDocument.saveAppState(); |
519 | this.activeDocument.container.parentNode.style["display"] = "none"; | 519 | this.activeDocument.parentContainer.style["display"] = "none"; |
520 | this.application.ninja.stage.hideCanvas(true); | 520 | this.application.ninja.stage.hideCanvas(true); |
521 | this.application.ninja.stage.stageView.hideRulers(); | 521 | this.application.ninja.stage.stageView.hideRulers(); |
522 | } | 522 | } |
@@ -526,28 +526,11 @@ var DocumentController = exports.DocumentController = Montage.create(Component, | |||
526 | 526 | ||
527 | this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe | 527 | this.application.ninja.stage._scrollFlag = false; // TODO HACK to prevent type error on Hide/Show Iframe |
528 | this.activeDocument = doc; | 528 | this.activeDocument = doc; |
529 | 529 | //hide the iframe when switching to code view | |
530 | var type; | 530 | document.getElementById("iframeContainer").style.display = "none"; |
531 | 531 | doc.model.views.code.showCodeViewBar(true); | |
532 | switch(doc.documentType) { | 532 | this.application.ninja.codeEditorController.applySettings(); |
533 | case "css" : | 533 | doc.model.views.code.collapseAllPanels(); |
534 | type = "css"; | ||
535 | break; | ||
536 | case "js" : | ||
537 | type = "javascript"; | ||
538 | break; | ||
539 | } | ||
540 | |||
541 | DocumentController._codeEditor.editor = CodeMirror.fromTextArea(doc.textArea, { | ||
542 | lineNumbers: true, | ||
543 | mode: type, | ||
544 | onCursorActivity: function() { | ||
545 | DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.hline, null); | ||
546 | DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(DocumentController._codeEditor.editor.getCursor().line, "activeline"); | ||
547 | } | ||
548 | }); | ||
549 | DocumentController._codeEditor.hline = DocumentController._codeEditor.editor.setLineClass(0, "activeline"); | ||
550 | |||
551 | } | 534 | } |
552 | }, | 535 | }, |
553 | 536 | ||