aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-08-07 13:27:19 -0700
committerNivesh Rajbhandari2012-08-07 13:27:19 -0700
commitda71ec8bf450438a4dc904cb348e548d01dfcb3f (patch)
tree36bae4f77a61c2c6690566c79d07f5b6bc2c3936 /js/document
parent923e760bf4a16baa82e81da6d38e671620664e8f (diff)
parent91c440a04f0108d05e663d1696027ca5601b25bc (diff)
downloadninja-da71ec8bf450438a4dc904cb348e548d01dfcb3f.tar.gz
Merge branch 'refs/heads/ninja-mqg734-master' into LineInCanvas
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/document-html.js84
-rwxr-xr-xjs/document/document-text.js4
-rwxr-xr-xjs/document/mediators/template.js6
-rwxr-xr-xjs/document/models/base.js57
-rwxr-xr-xjs/document/views/code.js4
-rw-r--r--js/document/views/design-code.js106
-rwxr-xr-xjs/document/views/design.js4
7 files changed, 248 insertions, 17 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js
index 142ffe4a..f3163339 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -34,7 +34,8 @@ POSSIBILITY OF SUCH DAMAGE.
34var Montage = require("montage/core/core").Montage, 34var Montage = require("montage/core/core").Montage,
35 Component = require("montage/ui/component").Component, 35 Component = require("montage/ui/component").Component,
36 HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel, 36 HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel,
37 DesignDocumentView = require("js/document/views/design").DesignDocumentView; 37 DesignDocumentView = require("js/document/views/design").DesignDocumentView,
38 CodeDocumentView = require("js/document/views/design-code").DesignCodeView;
38//////////////////////////////////////////////////////////////////////// 39////////////////////////////////////////////////////////////////////////
39// 40//
40exports.HtmlDocument = Montage.create(Component, { 41exports.HtmlDocument = Montage.create(Component, {
@@ -76,7 +77,7 @@ exports.HtmlDocument = Montage.create(Component, {
76 //////////////////////////////////////////////////////////////////// 77 ////////////////////////////////////////////////////////////////////
77 // 78 //
78 init: { 79 init: {
79 value:function(file, context, callback, view, template) { 80 value: function(file, context, callback, view, template) {
80 //Storing callback data for loaded dispatch 81 //Storing callback data for loaded dispatch
81 this.loaded.callback = callback; 82 this.loaded.callback = callback;
82 this.loaded.context = context; 83 this.loaded.context = context;
@@ -85,7 +86,7 @@ exports.HtmlDocument = Montage.create(Component, {
85 file: {value: file}, 86 file: {value: file},
86 fileTemplate: {value: template}, 87 fileTemplate: {value: template},
87 parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach 88 parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach
88 views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic 89 views: {value: {'design': DesignDocumentView.create(), 'code': CodeDocumentView.create()}} //TODO: Add code view logic
89 }); 90 });
90 //Calling the any init routines in the model 91 //Calling the any init routines in the model
91 this.model.init(); 92 this.model.init();
@@ -98,6 +99,14 @@ exports.HtmlDocument = Montage.create(Component, {
98 } else { 99 } else {
99 //ERROR: Design View not initialized 100 //ERROR: Design View not initialized
100 } 101 }
102
103
104 //TODO: Make sure you have a boolean to indicate if view was initilize and handle errors (just like design view above)
105 //initialize the code view for the html document and hide it since design is the default view
106 this.model.views.code.initialize(this.model.parentContainer);
107 this.model.views.code.hide();
108
109
101 // 110 //
102 if (view === 'design') { 111 if (view === 'design') {
103 //TODO: Remove reference and use as part of model 112 //TODO: Remove reference and use as part of model
@@ -116,12 +125,64 @@ exports.HtmlDocument = Montage.create(Component, {
116 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); 125 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this));
117 this._observer.observe(this.model.views.design.document.head, {childList: true}); 126 this._observer.observe(this.model.views.design.document.head, {childList: true});
118 }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); 127 }.bind(this), template, {viewCallback: this.handleViewReady, context: this});
128 } else if (view === 'code'){
129 //TODO: Add logic to open document in code view since it's now available
119 } else { 130 } else {
120 //TODO: Identify default view (probably code) 131 //TODO: Add error handling
121 } 132 }
122 } 133 }
123 }, 134 },
124 //////////////////////////////////////////////////////////////////// 135 ////////////////////////////////////////////////////////////////////
136 //TODO: Make into one method to use here and one init
137 reloadView: {
138 value: function (view, template, doc) {
139 //
140 this.model.parentContainer.removeChild(this.model.views.design.iframe);
141 //Initiliazing views and hiding
142 if (this.model.views.design.initialize(this.model.parentContainer)) {
143 //Hiding iFrame, just initiliazing
144 this.model.views.design.hide();
145 //Setting the iFrame property for reference in helper class
146 this.model.webGlHelper.iframe = this.model.views.design.iframe;
147 } else {
148 //ERROR: Design View not initialized
149 }
150 //
151 if (view === 'design') {
152 //TODO: Remove reference and use as part of model
153 this.currentView = 'design';
154 //Setting current view object to design
155 this.model.currentView = this.model.views.design;
156 //Showing design iFrame
157 this.model.views.design.show();
158 this.model.views.design.iframe.style.opacity = 0;
159 this.model.views.design.content = this.application.ninja.ioMediator.tmplt.parseHtmlToNinjaTemplate(doc);
160 //TODO: Improve reference (probably through binding values)
161 this.model.views.design._webGlHelper = this.model.webGlHelper;
162 //Rendering design view, using observers to know when template is ready
163 this.model.views.design.render(function () {
164 //Adding observer to know when template is ready
165 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this));
166 this._observer.observe(this.model.views.design.document.head, {childList: true});
167 }.bind(this), template, {viewCallback: this.handleReloadViewReady, context: this});
168 } else if(view === 'code'){
169 //TODO: Add logic to handle external changed files
170 //Checking for template type and not saving external data
171 if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) {
172 this.model.views.code.load(this.application.ninja.ioMediator.tmplt.parseNinjaTemplateToHtml(false, doc, true, null).content);
173 } else {
174 this.model.views.code.load(this.application.ninja.ioMediator.tmplt.parseNinjaTemplateToHtml(false, doc, false, null).content);
175 }
176 //Setting current view object to code
177 this.currentView = 'code';
178 this.model.currentView = this.model.views.code;
179 this.model.currentViewIdentifier = this.model.currentView.identifier;
180 } else {
181 //TODO: Identify default view (probably code) - Error handling
182 }
183 }
184 },
185 ////////////////////////////////////////////////////////////////////
125 // 186 //
126 handleTemplateReady: { 187 handleTemplateReady: {
127 value: function (e) { 188 value: function (e) {
@@ -130,6 +191,8 @@ exports.HtmlDocument = Montage.create(Component, {
130 this._observer = null; 191 this._observer = null;
131 } 192 }
132 }, 193 },
194 ////////////////////////////////////////////////////////////////////
195 //
133 handleViewReady: { 196 handleViewReady: {
134 value: function(mObjects) { 197 value: function(mObjects) {
135 this.model.mObjects = mObjects; 198 this.model.mObjects = mObjects;
@@ -138,11 +201,22 @@ exports.HtmlDocument = Montage.create(Component, {
138 if(typeof this.model.domContainer !== "undefined") { 201 if(typeof this.model.domContainer !== "undefined") {
139 this.model.domContainer = this.model.documentRoot; 202 this.model.domContainer = this.model.documentRoot;
140 } 203 }
141 204 this.model.currentViewIdentifier = this.model.currentView.identifier;
142 //Making callback after view is loaded 205 //Making callback after view is loaded
143 this.loaded.callback.call(this.loaded.context, this); 206 this.loaded.callback.call(this.loaded.context, this);
144 } 207 }
145 }, 208 },
209 handleReloadViewReady: {
210 value: function(mObjects) {
211 this.model.mObjects = mObjects;
212 // TODO: Find a better way to initialize this property
213 // Assign the domContainer to be the document root on open
214 if(typeof this.model.domContainer !== "undefined") {
215 this.model.domContainer = this.model.documentRoot;
216 }
217 this.model.currentViewIdentifier = this.model.currentView.identifier;
218 }
219 },
146 //////////////////////////////////////////////////////////////////// 220 ////////////////////////////////////////////////////////////////////
147 // 221 //
148 closeDocument: { 222 closeDocument: {
diff --git a/js/document/document-text.js b/js/document/document-text.js
index 1fe43494..d06bdefb 100755
--- a/js/document/document-text.js
+++ b/js/document/document-text.js
@@ -51,13 +51,13 @@ exports.TextDocument = Montage.create(Component, {
51 //////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////
52 // 52 //
53 init:{ 53 init:{
54 value: function(file, context, callback, view){ 54 value: function(file, context, callback, view, parentContainer){
55 // 55 //
56 var codeDocumentView = CodeDocumentView.create(), container = null; //TODO: Why is this initilzied to null? 56 var codeDocumentView = CodeDocumentView.create(), container = null; //TODO: Why is this initilzied to null?
57 //Creating instance of Text Document Model 57 //Creating instance of Text Document Model
58 this.model = Montage.create(TextDocumentModel,{ 58 this.model = Montage.create(TextDocumentModel,{
59 file: {value: file}, 59 file: {value: file},
60 parentContainer: {value: document.getElementById("codeViewContainer")}, //TODO: Remove reference to this element, should be dynamic 60 parentContainer: {value: parentContainer}, //TODO: Remove reference to this element, should be dynamic
61 views: {value: {'code': codeDocumentView, 'design': null}} //TODO: Add check if file might have design view, if so, then create it 61 views: {value: {'code': codeDocumentView, 'design': null}} //TODO: Add check if file might have design view, if so, then create it
62 }); 62 });
63 //TODO: Add design view logic 63 //TODO: Add design view logic
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index 4065f471..3f7f53b8 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -47,7 +47,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
47 // 47 //
48 getAppTemplatesUrlRegEx: { 48 getAppTemplatesUrlRegEx: {
49 value: function () { 49 value: function () {
50 var regex = new RegExp(chrome.extension.getURL(this.application.ninja.currentDocument.model.views.design.iframe.src.split(chrome.extension.getURL('/'))[1]).replace(/\//gi, '\\\/'), 'gi'); 50 var regex = new RegExp(chrome.extension.getURL(this.application.ninja.currentDocument.model.views.design.document.baseURI.split(chrome.extension.getURL('/'))[1]).replace(/\//gi, '\\\/'), 'gi');
51 return regex; 51 return regex;
52 } 52 }
53 }, 53 },
@@ -326,7 +326,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
326 } 326 }
327 } 327 }
328 } 328 }
329 } else if (template.css) { 329 } else if (template.css && saveExternalData) {
330 //Getting all style and link tags 330</