aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-03-26 15:37:41 -0700
committerJose Antonio Marquez2012-03-26 15:37:41 -0700
commit9d88d2827c6c1cc10f64575bd3c2f5f21dd0d89d (patch)
treeaf3b114d6a83ae62dfcead8bd61bc62efe0c9516 /js/document
parentb1ba63e509f77b14c05b89ea193f4d706a28ac9b (diff)
parent309dde5a8c4599cef6a1052c1ff9ee1ad8ec5858 (diff)
downloadninja-9d88d2827c6c1cc10f64575bd3c2f5f21dd0d89d.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into Document
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js177
-rw-r--r--js/document/templates/montage-html/main.reel/main.js42
2 files changed, 102 insertions, 117 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index d4db6e2f..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
@@ -520,67 +564,13 @@ exports.HTMLDocument = Montage.create(TextDocument, {
520 } 564 }
521 // 565 //
522 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 566 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
523 //Inserting user's document into template
524
525
526
527
528
529
530
531
532
533 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
534 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
535 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
536
537 //TODO: Clean up and make public method to prepend properties with Ninja URL
538 this._templateDocument.head.innerHTML = (this._userDocument.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, ninjaUrlRedirect.bind(this))).replace(/url\(([^"]*)(.+?)\1\)/g, ninjaUrlRedirect.bind(this));
539 this._templateDocument.body.innerHTML = (this._userDocument.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, ninjaUrlRedirect.bind(this))).replace(/url\(([^"]*)(.+?)\1\)/g, ninjaUrlRedirect.bind(this));
540 //
541 //var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
542 //
543 function ninjaUrlRedirect (prop) {
544 //Checking for property value to not contain a full direct URL
545 if (!prop.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
546 //Checking for attributes and type of source
547 if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { //From HTML attribute
548 //
549 prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this));
550 } else if (prop.indexOf('url') !== -1) { //From CSS property
551 //TODO: Add