1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
/* <copyright>
Copyright (c) 2012, Motorola Mobility LLC.
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Motorola Mobility LLC nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
</copyright> */
////////////////////////////////////////////////////////////////////////
//
var Montage = require("montage/core/core").Montage,
Component = require("montage/ui/component").Component,
HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel,
DesignDocumentView = require("js/document/views/design").DesignDocumentView,
CodeDocumentView = require("js/document/views/design-code").DesignCodeView;
////////////////////////////////////////////////////////////////////////
//
exports.HtmlDocument = Montage.create(Component, {
////////////////////////////////////////////////////////////////////
//
hasTemplate: {
value: false
},
////////////////////////////////////////////////////////////////////
//
model: {
value: null
},
////////////////////////////////////////////////////////////////////
//
loaded: {
value: {callback: null, context: null}
},
////////////////////////////////////////////////////////////////////
//
_observer: {
value: null
},
////////////////////////////////////////////////////////////////////
//
exclusionList: {
value: ["HTML", "BODY", "NINJA-CONTENT", "NINJA-VIEWPORT"]
},
////////////////////////////////////////////////////////////////////
//
inExclusion: {
value: function(element) {
if(this.exclusionList.indexOf(element.nodeName) === -1) {
return -1;
}
return 1;
}
},
////////////////////////////////////////////////////////////////////
//
init: {
value: function(file, context, callback, view, template) {
//Storing callback data for loaded dispatch
this.loaded.callback = callback;
this.loaded.context = context;
//Creating instance of HTML Document Model
this.model = Montage.create(HtmlDocumentModel,{
file: {value: file},
fileTemplate: {value: template},
parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach
views: {value: {'design': DesignDocumentView.create(), 'code': CodeDocumentView.create()}} //TODO: Add code view logic
});
//Calling the any init routines in the model
this.model.init();
//Initiliazing views and hiding
if (this.model.views.design.initialize(this.model.parentContainer)) {
//Hiding iFrame, just initiliazing
this.model.views.design.hide();
//Setting the iFrame property for reference in helper class
this.model.webGlHelper.iframe = this.model.views.design.iframe;
} else {
//ERROR: Design View not initialized
}
//TODO: Make sure you have a boolean to indicate if view was initilize and handle errors (just like design view above)
//initialize the code view for the html document and hide it since design is the default view
this.model.views.code.initialize(this.model.parentContainer);
this.model.views.code.hide();
//
if (view === 'design') {
//TODO: Remove reference and use as part of model
this.currentView = 'design';
//Setting current view object to design
this.model.currentView = this.model.views.design;
//Showing design iFrame
this.model.views.design.show();
this.model.views.design.iframe.style.opacity = 0;
this.model.views.design.content = this.model.file.content;
//TODO: Improve reference (probably through binding values)
this.model.views.design._webGlHelper = this.model.webGlHelper;
//Rendering design view, using observers to know when template is ready
this.model.views.design.render(function () {
//Adding observer to know when template is ready
this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this));
this._observer.observe(this.model.views.design.document.head, {childList: true});
}.bind(this), template, {viewCallback: this.handleViewReady, context: this});
} else if (view === 'code'){
//TODO: Add logic to open document in code view since it's now available
} else {
//TODO: Add error handling
}
}
},
////////////////////////////////////////////////////////////////////
//TODO: Make into one method to use here and one init
reloadView: {
value: function (view, template, doc) {
//
this.model.parentContainer.removeChild(this.model.views.design.iframe);
//Initiliazing views and hiding
if (this.model.views.design.initialize(this.model.parentContainer)) {
//Hiding iFrame, just initiliazing
this.model.views.design.hide();
//Setting the iFrame property for reference in helper class
this.model.webGlHelper.iframe = this.model.views.design.iframe;
} else {
//ERROR: Design View not initialized
}
//
if (view === 'design') {
//TODO: Remove reference and use as part of model
this.currentView = 'design';
//Setting current view object to design
this.model.currentView = this.model.views.design;
//Showing design iFrame
this.model.views.design.show();
this.model.views.design.iframe.style.opacity = 0;
this.model.views.design.content = this.model.file.content;
//TODO: Improve reference (probably through binding values)
this.model.views.design._webGlHelper = this.model.webGlHelper;
//Rendering design view, using observers to know when template is ready
this.model.views.design.render(function () {
//Adding observer to know when template is ready
this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this));
this._observer.observe(this.model.views.design.document.head, {childList: true});
}.bind(this), template, {viewCallback: this.handleViewReady, context: this});
} else if(view === 'code'){
//TODO: Add logic to handle external changed files
//Checking for template type and not saving external data
if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) {
this.model.views.code.load(this.application.ninja.ioMediator.tmplt.parseNinjaTemplateToHtml(false, doc, true, null).content);
} else {
this.model.views.code.load(this.application.ninja.ioMediator.tmplt.parseNinjaTemplateToHtml(false, doc, false, null).content);
}
//Setting current view object to code
this.currentView = 'code';
this.model.currentView = this.model.views.code;
} else {
//TODO: Identify default view (probably code) - Error handling
}
}
},
////////////////////////////////////////////////////////////////////
//
handleTemplateReady: {
value: function (e) {
//Removing observer, only needed on initial load
this._observer.disconnect();
this._observer = null;
}
},
////////////////////////////////////////////////////////////////////
//
handleViewReady: {
value: function(mObjects) {
this.model.mObjects = mObjects;
// TODO: Find a better way to initialize this property
// Assign the domContainer to be the document root on open
if(typeof this.model.domContainer !== "undefined") {
this.model.domContainer = this.model.documentRoot;
}
//Making callback after view is loaded
this.loaded.callback.call(this.loaded.context, this);
}
},
////////////////////////////////////////////////////////////////////
//
closeDocument: {
value: function (context, callback) {
//Closing document (sending null to close all views)
this.model.close(null, function () {if (callback) callback.call(context, this);}.bind(this));
}
},
////////////////////////////////////////////////////////////////////
//
serializeDocument: {
value: function () {
// Serialize the current scroll position
//TODO: Move these properties to the design view class
this.model.scrollLeft = this.application.ninja.stage._scrollLeft;
this.model.scrollTop = this.application.ninja.stage._scrollTop;
this.model.userContentLeft = this.application.ninja.stage._userContentLeft;
this.model.userContentTop = this.application.ninja.stage._userContentTop;
// Serialize the selection, the container and grid
//TODO: Move this property to the design view class
this.model.selection = this.application.ninja.selectedElements.slice(0);
// Pause the videos
//TODO: Move these to be handled on the show/hide methods in the view
this.model.views.design.pauseVideos();
}
},
////////////////////////////////////////////////////////////////////
//
deserializeDocument: {
value: function () {
// Deserialize the current scroll position
//TODO: Move these properties to the design view class
this.application.ninja.stage._scrollLeft = this.model.scrollLeft;
this.application.ninja.stage._scrollTop = this.model.scrollTop;
this.application.ninja.stage._userContentLeft = this.model.userContentLeft;
this.application.ninja.stage._userContentTop = this.model.userContentTop;
// Serialize the undo
// TODO: Save the montage undo queue
}
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
});
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
|