diff options
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/html-document.js | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index 5d507476..2d7192b7 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -185,9 +185,51 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
185 | var elt = this.documentRoot; | 185 | var elt = this.documentRoot; |
186 | if (elt) | 186 | if (elt) |
187 | { | 187 | { |
188 | console.log( "load canvas data: " , value ); | 188 | var loadForRuntime = false; |
189 | var cdm = new CanvasDataManager(); | 189 | if (loadForRuntime) |
190 | cdm.loadGLData(elt, value); | 190 | { |
191 | //console.log( "load canvas data: " , value ); | ||
192 | var cdm = new CanvasDataManager(); | ||
193 | cdm.loadGLData(elt, value, NJUtils); | ||
194 | } | ||
195 | else | ||
196 | { | ||
197 | var nWorlds= value.length; | ||
198 | for (var i=0; i<nWorlds; i++) | ||
199 | { | ||
200 | var importStr = value[i]; | ||
201 | var startIndex = importStr.indexOf( "id: " ); | ||
202 | if (startIndex >= 0) | ||
203 | { | ||
204 | var endIndex = importStr.indexOf( "\n", startIndex ); | ||
205 | if (endIndex > 0) | ||
206 | { | ||
207 | var id = importStr.substring( startIndex+4, endIndex ); | ||
208 | if (id) | ||
209 | { | ||
210 | var canvas = this.findCanvasWithID( id, elt ); | ||
211 | if (canvas) | ||
212 | { | ||
213 | if (!canvas.elementModel) | ||
214 | { | ||
215 | NJUtils.makeElementModel(canvas, "Canvas", "shape", true); | ||
216 | } | ||
217 | |||
218 | if (canvas.elementModel) | ||
219 | { | ||
220 | if (canvas.elementModel.shapeModel.GLWorld) | ||
221 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | ||
222 | |||
223 | var world = new GLWorld( canvas ); | ||
224 | canvas.elementModel.shapeModel.GLWorld = world; | ||
225 | world.import( importStr ); | ||
226 | } | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | } | ||
191 | } | 233 | } |
192 | } | 234 | } |
193 | }, | 235 | }, |
@@ -219,6 +261,27 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
219 | } | 261 | } |
220 | } | 262 | } |
221 | }, | 263 | }, |
264 | |||
265 | /** | ||
266 | * search the DOM tree to find a canvas with the given id | ||
267 | */ | ||
268 | findCanvasWithID: { | ||
269 | value: function( id, elt ) { | ||
270 | var cid = elt.getAttribute( "data-RDGE-id" ); | ||
271 | if (cid == id) return elt; | ||
272 | |||
273 | if (elt.children) | ||
274 | { | ||
275 | var nKids = elt.children.length; | ||
276 | for (var i=0; i<nKids; i++) | ||
277 | { | ||
278 | var child = elt.children[i]; | ||
279 | var foundElt = this.findCanvasWithID( id, child ); | ||
280 | if (foundElt) return foundElt; | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | }, | ||
222 | 285 | ||
223 | 286 | ||
224 | 287 | ||