aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/document-html.js17
-rwxr-xr-xjs/document/models/base.js13
-rwxr-xr-xjs/document/models/html.js197
-rwxr-xr-xjs/document/views/design.js32
4 files changed, 242 insertions, 17 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js
index f3c135ed..79fe461b 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -63,7 +63,7 @@ exports.HtmlDocument = Montage.create(Component, {
63 //////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////
64 // 64 //
65 init: { 65 init: {
66 value:function(file, context, callback, view) { 66 value:function(file, context, callback, view, template) { //TODO: Add template support logic
67 //Storing callback data for loaded dispatch 67 //Storing callback data for loaded dispatch
68 this.loaded.callback = callback; 68 this.loaded.callback = callback;
69 this.loaded.context = context; 69 this.loaded.context = context;
@@ -85,16 +85,19 @@ exports.HtmlDocument = Montage.create(Component, {
85 this.model.views.design.show(); 85 this.model.views.design.show();
86 this.model.views.design.iframe.style.opacity = 0; 86 this.model.views.design.iframe.style.opacity = 0;
87 this.model.views.design.content = this.model.file.content; 87 this.model.views.design.content = this.model.file.content;
88 //TODO: Improve reference
89 this.model.views.design.model = this.model;
90 //
88 //TODO: Clean up 91 //TODO: Clean up
89 this.model.views.design.render(function () { 92 this.model.views.design.render(function () {
90 //TODO: Identify and remove usage of '_document' 93 //TODO: Identify and remove usage of '_document'
91 this._document = this.model.views.design.document; 94 this._document = this.model.views.design.document;
92 //TODO: Check for needed 95 //TODO: Remove usage, seems as not needed
93 this.documentRoot = this.model.views.design.document.body; 96 this.documentRoot = this.model.views.design.document.body;
94 //TODO: Why is this needed? 97 //TODO: Why is this needed?
95 this._liveNodeList = this.documentRoot.getElementsByTagName('*'); 98 this._liveNodeList = this.model.views.design.document.body.getElementsByTagName('*');
96 //Initiliazing document model 99 //Initiliazing document model
97 document.application.njUtils.makeElementModel(this.documentRoot, "Body", "body"); 100 document.application.njUtils.makeElementModel(this.model.views.design.document.body, "Body", "body");
98 //Adding observer to know when template is ready 101 //Adding observer to know when template is ready
99 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); 102 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this));
100 this._observer.observe(this.model.views.design.document.head, {childList: true}); 103 this._observer.observe(this.model.views.design.document.head, {childList: true});
@@ -115,11 +118,7 @@ exports.HtmlDocument = Montage.create(Component, {
115 this.loaded.callback.call(this.loaded.context, this); 118 this.loaded.callback.call(this.loaded.context, this);
116 //Setting opacity to be viewable after load 119 //Setting opacity to be viewable after load
117 this.model.views.design.iframe.style.opacity = 1; 120 this.model.views.design.iframe.style.opacity = 1;
118 121 //TODO: Remove, this is a temp hard-coded hack
119
120
121
122
123 this.application.ninja.appModel.show3dGrid = true; 122 this.application.ninja.appModel.show3dGrid = true;
124 } 123 }
125 } 124 }
diff --git a/js/document/models/base.js b/js/document/models/base.js
index 3bb69f6b..746922ad 100755
--- a/js/document/models/base.js
+++ b/js/document/models/base.js
@@ -74,6 +74,19 @@ exports.BaseDocumentModel = Montage.create(Component, {
74 }, 74 },
75 //////////////////////////////////////////////////////////////////// 75 ////////////////////////////////////////////////////////////////////
76 // 76 //
77 browserPreview: {
78 value: function (browser) {
79 //
80 switch (browser) {
81 case 'chrome':
82 break;
83 default:
84 break;
85 }
86 }
87 },
88 ////////////////////////////////////////////////////////////////////
89 //
77 save: { 90 save: {
78 value: function () { 91 value: function () {
79 // 92 //
diff --git a/js/document/models/html.js b/js/document/models/html.js
index 5eedb731..e0a18850 100755
--- a/js/document/models/html.js
+++ b/js/document/models/html.js
@@ -7,7 +7,10 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 BaseDocumentModel = require("js/document/models/base").BaseDocumentModel; 10 BaseDocumentModel = require("js/document/models/base").BaseDocumentModel,
11 MaterialsModel = require("js/models/materials-model").MaterialsModel,
12 NJUtils = require("js/lib/NJUtils").NJUtils,
13 GLWorld = require("js/lib/drawing/world").World;
11//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
12// 15//
13exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { 16exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, {
@@ -16,10 +19,198 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, {
16 hasTemplate: { 19 hasTemplate: {
17 value: false 20 value: false
18 }, 21 },
19 22 ////////////////////////////////////////////////////////////////////
23 //
20 draw3DGrid: { 24 draw3DGrid: {
21 value: false 25 value: false
22 } 26 },
27 ////////////////////////////////////////////////////////////////////
28 //
29 _glData: {
30 value: null
31 },
32 ////////////////////////////////////////////////////////////////////
33 //
34 glData: {
35 //
36 get: function() {
37 //
38 var elt = this.views.design.iframe.contentWindow.document.body;
39 //
40 if (elt) {
41 var matLib = MaterialsModel.exportMaterials();
42 this._glData = [matLib];
43 this.collectGLData(elt, this._glData );
44 } else {
45 this._glData = null
46 }
47 //
48 return this._glData;
49 },
50 //
51 set: function(value) {
52 //
53 var elt = this.views.design.iframe.contentWindow.document.body;
54 //
55 if (elt) {
56 /*
57 // Use this code to test the runtime version of WebGL
58 var cdm = new NinjaCvsRt.CanvasDataManager();
59 cdm.loadGLData(elt, value, null );
60 */
61
62 //
63 var i, nWorlds= value.length;
64 //
65 for (i = 0; i < nWorlds; i++) {
66 // get the data for the next canvas
67 var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world;
68 // determine if it is the new (JSON) or old style format
69 if ((importStr[0] === 'v') && (index < 24)) {
70 // JSON format. pull off the
71 importStr = importStr.substr(index+1);
72 jObj = JSON.parse(importStr);
73 id = jObj.id;
74 } else {
75 // at this point the data could be either the materials library or
76 // an old style world. We can determine which by converting the string
77 // to an object via JSON.parse. That operation will fail if the string
78 // is an old style world.
79 matLibStr = 'materialLibrary;';
80 index = importStr.indexOf(matLibStr);
81 if (index == 0) {
82 importStr = importStr.substr(matLibStr.length);
83 matLibObj = JSON.parse(importStr);
84 MaterialsModel.importMaterials(matLibObj);
85 } else {
86 startIndex = importStr.indexOf("id: ");
87 if (startIndex >= 0) {
88 endIndex = importStr.indexOf("\n", startIndex);
89 if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex);
90 }
91 }
92 }
93 //
94 if (id != null) {
95 //
96 canvas = this.findCanvasWithID(id, elt);
97 //
98 if (canvas) {
99 //
100 if (!canvas.elementModel) {
101 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
102 }
103 //
104 if (canvas.elementModel) {
105 if (canvas.elementModel.shapeModel.GLWorld) {
106 canvas.elementModel.shapeModel.GLWorld.clearTree();
107 }
108 //
109 if (jObj) {
110 useWebGL = jObj.webGL;
111 world = new GLWorld(canvas, useWebGL);
112 world.importJSON(jObj);
113 }
114 //
115 this.buildShapeModel(canvas.elementModel, world);
116 }
117 }
118 }
119 }
120 }
121 }
122 },
123 ////////////////////////////////////////////////////////////////////
124 //
125 findCanvasWithID: {
126 value: function(id, elt) {
127 //
128 var i, child, nKids, foundElt, cid = elt.getAttribute("data-RDGE-id");
129 //
130 if (cid == id) return elt;
131 //
132 if (elt.children) {
133 nKids = elt.children.length;
134 for (i=0; i<nKids; i++) {
135 child = elt.children[i];
136 foundElt = this.findCanvasWithID( id, child );