aboutsummaryrefslogtreecommitdiff
path: root/js/document/document-html.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/document-html.js')
-rwxr-xr-xjs/document/document-html.js84
1 files changed, 79 insertions, 5 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: {