diff options
Diffstat (limited to 'js/io/document/html-document.js')
-rwxr-xr-x | js/io/document/html-document.js | 492 |
1 files changed, 492 insertions, 0 deletions
diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js new file mode 100755 index 00000000..ac556c2d --- /dev/null +++ b/js/io/document/html-document.js | |||
@@ -0,0 +1,492 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | var Montage = require("montage/core/core").Montage, | ||
10 | BaseDocument = require("js/io/document/base-document").BaseDocument, | ||
11 | NJUtils = require("js/lib/NJUtils").NJUtils; | ||
12 | //////////////////////////////////////////////////////////////////////// | ||
13 | // | ||
14 | exports.HTMLDocument = Montage.create(BaseDocument, { | ||
15 | // PRIVATE MEMBERS | ||
16 | _selectionExclude: { value: null, enumerable: false }, | ||
17 | _htmlTemplateUrl: { value: "user-document-templates/montage-application-cloud/index.html", enumerable: false}, | ||
18 | _iframe: { value: null, enumerable: false }, | ||
19 | _server: { value: null, enumerable: false }, | ||
20 | _templateDocument: { value: null, enumerable: false }, | ||
21 | _selectionModel: { value: [], enumerable: false }, | ||
22 | _undoModel: { value: { "queue" : [], "position" : 0 }, enumerable: false}, | ||
23 | |||
24 | _document: { value: null, enumerable: false }, | ||
25 | _documentRoot: { value: null, enumerable: false }, | ||
26 | _stageBG: { value: null, enumerable: false }, | ||
27 | _window: { value: null, enumerable: false }, | ||
28 | _styles: { value: null, enumerable: false }, | ||
29 | _stylesheets: { value: null, enumerable: false }, | ||
30 | _stageStyleSheetId : { value: 'nj-stage-stylesheet', enumerable: false }, | ||
31 | _userDocument: { value: null, enumerable: false }, | ||
32 | _htmlSource: {value: "<html></html>", enumerable: false}, | ||
33 | _glData: {value: null, enumerable: false }, | ||
34 | |||
35 | _elementCounter: { value: 1, enumerable: false }, | ||
36 | _snapping : { value: true, enumerable: false }, | ||
37 | _layoutMode: { value: "all", enumerable: false }, | ||
38 | _draw3DGrid: { value: false, writable: true }, | ||
39 | _swfObject: { value: false, enumerable: false }, | ||
40 | |||
41 | _zoomFactor: { value: 100, enumerable: false }, | ||
42 | |||
43 | // PUBLIC MEMBERS | ||
44 | cssLoadInterval: { value: null, enumerable: false }, | ||
45 | |||
46 | _savedLeftScroll: {value:null}, | ||
47 | _savedTopScroll: {value:null}, | ||
48 | |||
49 | _codeViewDocument:{ | ||
50 | writable: true, | ||
51 | enumerable: true, | ||
52 | value:null | ||
53 | }, | ||
54 | |||
55 | /* | ||
56 | * PUBLIC API | ||
57 | */ | ||
58 | |||
59 | // GETTERS / SETTERS | ||
60 | |||
61 | codeViewDocument:{ | ||
62 | get: function() { return this._codeViewDocument; }, | ||
63 | set: function(value) { this._codeViewDocument = value} | ||
64 | }, | ||
65 | |||
66 | savedLeftScroll:{ | ||
67 | get: function() { return this._savedLeftScroll; }, | ||
68 | set: function(value) { this._savedLeftScroll = value} | ||
69 | }, | ||
70 | |||
71 | savedTopScroll:{ | ||
72 | get: function() { return this._savedTopScroll; }, | ||
73 | set: function(value) { this._savedTopScroll = value} | ||
74 | }, | ||
75 | |||
76 | selectionExclude: { | ||
77 | get: function() { return this._selectionExclude; }, | ||
78 | set: function(value) { this._selectionExclude = value; } | ||
79 | }, | ||
80 | |||
81 | iframe: { | ||
82 | get: function() { return this._iframe; }, | ||
83 | set: function(value) { this._iframe = value; } | ||
84 | }, | ||
85 | |||
86 | server: { | ||
87 | get: function() { return this._server; }, | ||
88 | set: function(value) { this._server = value; } | ||
89 | }, | ||
90 | |||
91 | selectionModel: { | ||
92 | get: function() { return this._selectionModel; }, | ||
93 | set: function(value) { this._selectionModel = value; } | ||
94 | }, | ||
95 | |||
96 | undoModel: { | ||
97 | get: function() { return this._undoModel; }, | ||
98 | set: function(value) { this._undoModel.queue = value.queue; this._undoModel.position = value.position; } | ||
99 | }, | ||
100 | |||
101 | documentRoot: { | ||
102 | get: function() { return this._documentRoot; }, | ||
103 | set: function(value) { this._documentRoot = value; } | ||
104 | }, | ||
105 | |||
106 | stageBG: { | ||
107 | get: function() { return this._stageBG; }, | ||
108 | set: function(value) { this._stageBG = value; } | ||
109 | }, | ||
110 | |||
111 | elementCounter: { | ||
112 | set: function(value) { this._elementCounter = value; }, | ||
113 | get: function() { return this._elementCounter; } | ||
114 | }, | ||
115 | |||
116 | snapping: { | ||
117 | get: function() { return this._snapping; }, | ||
118 | set: function(value) { | ||
119 | if(this._snapping !== value) { | ||
120 | this._snapping = value; | ||
121 | } | ||
122 | } | ||
123 | }, | ||
124 | |||
125 | // TODO SEND THE EVENT --> Redraw the desired layout | ||
126 | layoutMode: { | ||
127 | get: function() { return this._layoutMode; }, | ||
128 | set: function(mode) { this._layoutMode = mode; } | ||
129 | }, | ||
130 | |||
131 | draw3DGrid: { | ||
132 | get: function() { return this._draw3DGrid; }, | ||
133 | set: function(value) { | ||
134 | if(this._draw3DGrid !== value) { | ||
135 | this._draw3DGrid = value; | ||
136 | } | ||
137 | } | ||
138 | }, | ||
139 | |||
140 | _userComponentSet: { | ||
141 | value: {}, | ||
142 | writable: true, | ||
143 | enumerable:true | ||
144 | }, | ||
145 | |||
146 | // userComponentSet:{ | ||
147 | // enumerable: true, | ||
148 | // get: function() { | ||
149 | // return this._userComponentSet; | ||
150 | // }, | ||
151 | // set: function(value) { | ||
152 | // this._userComponentSet = value; | ||
153 | // this._drawUserComponentsOnOpen(); | ||
154 | // } | ||
155 | // }, | ||
156 | // | ||
157 | // _drawUserComponentsOnOpen:{ | ||
158 | // value:function(){ | ||
159 | // for(var i in this._userComponentSet){ | ||
160 | // console.log(this._userComponentSet[i].control) | ||
161 | // this._userComponentSet[i].control.needsDraw = true; | ||
162 | // } | ||
163 | // } | ||
164 | // }, | ||
165 | |||
166 | glData: { | ||
167 | get: function() | ||
168 | { | ||
169 | var elt = this.iframe; | ||
170 | var elt = this.iframe.contentWindow.document.getElementById("UserContent"); | ||
171 | this._glData = null; | ||
172 | if (elt) | ||
173 | { | ||
174 | this._glData = new Array(); | ||
175 | this.collectGLData( elt, this._glData ); | ||
176 | } | ||
177 | |||
178 | return this._glData | ||
179 | }, | ||
180 | |||
181 | set: function(value) | ||
182 | { | ||
183 | var nWorlds = value.length; | ||
184 | for (var i=0; i<nWorlds; i++) | ||
185 | { | ||
186 | var importStr = value[i]; | ||
187 | var startIndex = importStr.indexOf( "id: " ); | ||
188 | if (startIndex >= 0) | ||
189 | { | ||
190 | var endIndex = importStr.indexOf( "\n", startIndex ); | ||
191 | if (endIndex > 0) | ||
192 | { | ||
193 | var id = importStr.substring( startIndex+4, endIndex ); | ||
194 | var canvas = this.iframe.contentWindow.document.getElementById( id ); | ||
195 | if (canvas) | ||
196 | { | ||
197 | if (!canvas.elementModel) | ||
198 | { | ||
199 | NJUtils.makeElementModel(canvas, "Canvas", "shape", true); | ||
200 | } | ||
201 | |||
202 | if (canvas.elementModel) | ||
203 | { | ||
204 | if (canvas.elementModel.shapeModel.GLWorld) | ||
205 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | ||
206 | |||
207 | var world = new GLWorld( canvas ); | ||
208 | canvas.elementModel.shapeModel.GLWorld = world; | ||
209 | world.import( importStr ); | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | }, | ||
217 | |||
218 | zoomFactor: { | ||
219 | get: function() { return this._zoomFactor; }, | ||
220 | set: function(value) { this._zoomFactor = value; } | ||
221 | }, | ||
222 | |||
223 | //****************************************// | ||
224 | // PUBLIC METHODS | ||
225 | |||
226 | |||
227 | //////////////////////////////////////////////////////////////////// | ||
228 | // | ||
229 | initialize: { | ||
230 | value: function(file, uuid, iframe, callback) { | ||
231 | // | ||
232 | this._userDocument = file; | ||
233 | // | ||
234 | this.init(file.name, file.uri, file.extension, iframe, uuid, callback); | ||
235 | // | ||
236 | this.iframe = iframe; | ||
237 | this.selectionExclude = ["HTML", "BODY", "Viewport", "UserContent", "stageBG"]; | ||
238 | this.currentView = "design"; | ||