aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js112
-rw-r--r--js/document/templates/montage-html/main.reel/main.js42
2 files changed, 97 insertions, 57 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index ed1569d4..8f9d2870 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -9,7 +9,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 TextDocument = require("js/document/text-document").TextDocument, 10 TextDocument = require("js/document/text-document").TextDocument,
11 NJUtils = require("js/lib/NJUtils").NJUtils, 11 NJUtils = require("js/lib/NJUtils").NJUtils,
12 GLWorld = require("js/lib/drawing/world").World; 12 GLWorld = require("js/lib/drawing/world").World,
13 MaterialsModel = require("js/models/materials-model").MaterialsModel;
13//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
14// 15//
15exports.HTMLDocument = Montage.create(TextDocument, { 16exports.HTMLDocument = Montage.create(TextDocument, {
@@ -193,12 +194,9 @@ exports.HTMLDocument = Montage.create(TextDocument, {
193 var elt = this.iframe.contentWindow.document.getElementById("UserContent"); 194 var elt = this.iframe.contentWindow.document.getElementById("UserContent");
194 // 195 //
195 if (elt) { 196 if (elt) {
196 this._glData = []; 197 var matLib = MaterialsModel.exportMaterials();
197 //if (path) { 198 this._glData = [matLib];
198 //this.collectGLData(elt, this._glData, path); 199 this.collectGLData(elt, this._glData );
199 //} else {
200 this.collectGLData(elt, this._glData );
201 //}
202 } else { 200 } else {
203 this._glData = null 201 this._glData = null
204 } 202 }
@@ -219,29 +217,74 @@ exports.HTMLDocument = Montage.create(TextDocument, {
219 */ 217 */
220 218
221 // /* 219 // /*
220 // get the data for the next canvas
222 var importStr = value[i]; 221 var importStr = value[i];
223 var startIndex = importStr.indexOf( "id: " ); 222
224 if (startIndex >= 0) { 223 // determine if it is the new (JSON) or old style format
225 var endIndex = importStr.indexOf( "\n", startIndex ); 224 var id = null;
226 if (endIndex > 0) { 225 var jObj = null;
227 var id = importStr.substring( startIndex+4, endIndex ); 226 var index = importStr.indexOf( ';' );
228 if (id) { 227 if ((importStr[0] === 'v') && (index < 24))
229 var canvas = this.findCanvasWithID( id, elt ); 228 {
230 if (canvas) { 229 // JSON format. pull off the
231 if (!canvas.elementModel) { 230 importStr = importStr.substr( index+1 );
232 NJUtils.makeElementModel(canvas, "Canvas", "shape", true); 231 jObj = jObj = JSON.parse( importStr );
233 } 232 id = jObj.id;
234 if (canvas.elementModel) { 233 }
235 if (canvas.elementModel.shapeModel.GLWorld) { 234 else
236 canvas.elementModel.shapeModel.GLWorld.clearTree(); 235 {
237 } 236 // at this point the data could be either the materials library or
238 var index = importStr.indexOf( "webGL: " ); 237 // an old style world. We can determine which by converting the string
239 var useWebGL = (index >= 0) 238 // to an object via JSON.parse. That operation will fail if the string
240 var world = new GLWorld( canvas, useWebGL ); 239 // is an old style world.
241 world.import( importStr ); 240 var matLibStr = 'materialLibrary;';
242 this.buildShapeModel( canvas.elementModel, world ); 241 index = importStr.indexOf( matLibStr );
243 } 242 if (index == 0)
243 {
244 importStr = importStr.substr( matLibStr.length );
245 var matLibObj = JSON.parse( importStr );
246 MaterialsModel.importMaterials( matLibObj );
247 }
248 else
249 {
250 var startIndex = importStr.indexOf( "id: " );
251 if (startIndex >= 0) {
252 var endIndex = importStr.indexOf( "\n", startIndex );
253 if (endIndex > 0)
254 id = importStr.substring( startIndex+4, endIndex );
255 }
256 }
257 }
258
259 if (id != null)
260 {
261 var canvas = this.findCanvasWithID( id, elt );
262 if (canvas)
263 {
264 if (!canvas.elementModel)
265 {
266 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
267 }
268 if (canvas.elementModel)
269 {
270 if (canvas.elementModel.shapeModel.GLWorld)
271 canvas.elementModel.shapeModel.GLWorld.clearTree();
272
273 if (jObj)
274 {
275 var useWebGL = jObj.webGL;
276 var world = new GLWorld( canvas, useWebGL );
277 world.importJSON( jObj );
278 }
279 else
280 {
281 var index = importStr.indexOf( "webGL: " );
282 var useWebGL = (index >= 0);
283 var world = new GLWorld( canvas, useWebGL );
284 world.import( importStr );
244 } 285 }
286
287 this.buildShapeModel( canvas.elementModel, world );
245 } 288 }
246 } 289 }
247 } 290 }
@@ -265,7 +308,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
265 shapeModel.GLGeomObj = root; 308 shapeModel.GLGeomObj = root;
266 shapeModel.strokeSize = root._strokeWidth; 309 shapeModel.strokeSize = root._strokeWidth;
267 shapeModel.stroke = root._strokeColor.slice(); 310 shapeModel.stroke = root._strokeColor.slice();
268 shapeModel.strokeMaterial = root._strokeMaterial.dup(); 311 shapeModel.strokeMaterial = root._strikeMaterial ? root._strokeMaterial.dup() : null;
269 shapeModel.strokeStyle = "solid"; 312 shapeModel.strokeStyle = "solid";
270 //shapeModel.strokeStyleIndex 313 //shapeModel.strokeStyleIndex
271 //shapeModel.border 314 //shapeModel.border
@@ -276,7 +319,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
276 elementModel.selection = "Rectangle"; 319 elementModel.selection = "Rectangle";
277 elementModel.pi = "RectanglePi"; 320 elementModel.pi = "RectanglePi";
278 shapeModel.fill = root._fillColor.slice(); 321 shapeModel.fill = root._fillColor.slice();
279 shapeModel.fillMaterial = root._fillMaterial.dup(); 322 shapeModel.fillMaterial = root._fillMaterial ? root._fillMaterial.dup() : null;
280 shapeModel.tlRadius = root._tlRadius; 323 shapeModel.tlRadius = root._tlRadius;
281 shapeModel.trRadius = root._trRadius; 324 shapeModel.trRadius = root._trRadius;
282 shapeModel.blRadius = root._blRadius; 325 shapeModel.blRadius = root._blRadius;
@@ -287,7 +330,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
287 elementModel.selection = "Oval"; 330 elementModel.selection = "Oval";
288 elementModel.pi = "OvalPi"; 331 elementModel.pi = "OvalPi";
289 shapeModel.fill = root._fillColor.slice(); 332 shapeModel.fill = root._fillColor.slice();
290 shapeModel.fillMaterial = root._fillMaterial.dup(); 333 shapeModel.fillMaterial = root._fillMaterial ? root._fillMaterial.dup() : null;
291 shapeModel.innerRadius = root._innerRadius; 334 shapeModel.innerRadius = root._innerRadius;
292 break; 335 break;
293 336
@@ -382,7 +425,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
382 { 425 {
383 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld) 426 if (elt.elementModel && elt.elementModel.shapeModel && elt.elementModel.shapeModel.GLWorld)
384 { 427 {
385 var data = elt.elementModel.shapeModel.GLWorld.export(); 428 var data = elt.elementModel.shapeModel.GLWorld.exportJSON();
429 //var data = elt.elementModel.shapeModel.GLWorld.export();
386 dataArray.push( data ); 430 dataArray.push( data );
387 } 431 }
388 432
@@ -827,7 +871,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
827 //TODO: Add logic to handle save before preview 871 //TODO: Add logic to handle save before preview
828 this.application.ninja.documentController.handleExecuteSaveAll(null); 872 this.application.ninja.documentController.handleExecuteSaveAll(null);
829 //Temp check for webGL Hack 873 //Temp check for webGL Hack
830 if (this.application.ninja.documentController.activeDocument.glData.length && this.application.ninja.documentController.activeDocument.glData.length > 0) { 874 if (this.application.ninja.documentController.activeDocument.glData.length && this.application.ninja.documentController.activeDocument.glData.length > 1) {//TODO: Should be 0, temp hack fix
831 setTimeout(function () {window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);}.bind(this), 3500); 875 setTimeout(function () {window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);}.bind(this), 3500);
832 } else { 876 } else {
833 window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); 877 window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);
@@ -850,6 +894,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
850 } 894 }
851 } 895 }
852 } 896 }
897 //return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
853 return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 898 return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
854 } else if (this.currentView === "code"){ 899 } else if (this.currentView === "code"){
855 //TODO: Would this get call when we are in code of HTML? 900 //TODO: Would this get call when we are in code of HTML?
@@ -873,6 +918,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
873 } 918 }
874 } 919 }
875 } 920 }
921 //return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
876 return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 922 return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
877 } else if (this.currentView === "code"){ 923 } else if (this.currentView === "code"){
878 //TODO: Would this get call when we are in code of HTML? 924 //TODO: Would this get call when we are in code of HTML?
diff --git a/js/document/templates/montage-html/main.reel/main.js b/js/document/templates/montage-html/main.reel/main.js
index 567f481c..019c675e 100644
--- a/js/document/templates/montage-html/main.reel/main.j