aboutsummaryrefslogtreecommitdiff
path: root/js/document/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/helpers')
-rwxr-xr-xjs/document/helpers/url-parser.js86
-rwxr-xr-xjs/document/helpers/webgl-helper.js218
2 files changed, 304 insertions, 0 deletions
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
new file mode 100755
index 00000000..5e71d148
--- /dev/null
+++ b/js/document/helpers/url-parser.js
@@ -0,0 +1,86 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component;
11////////////////////////////////////////////////////////////////////////
12//
13exports.UrlParser = Montage.create(Component, {
14 ////////////////////////////////////////////////////////////////////
15 //
16 hasTemplate: {
17 value: false
18 },
19 ////////////////////////////////////////////////////////////////////
20 //
21 parseStyleUrls: {
22 value: function (css, href, local) {
23 //
24 if (local) {
25 var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0];
26 } else {
27 //TODO: Add logic for external URLs
28 }
29 //TODO: Clean up functions
30 css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this));
31 //
32 function parseToNinjaUrl (prop) {
33 //
34 return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this));
35 }
36 //
37 function prefixWithNinjaUrl (url) {
38 //
39 if (url !== 'url' && !url.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
40 url = fileCouldDirUrl+url;
41 }
42 //
43 return url;
44 }
45 //
46 return css;
47 }
48 },
49 ////////////////////////////////////////////////////////////////////
50 //
51 loadLocalStyleSheet: {
52 value: function (href) {
53 //Getting file URI (not URL since we must load through I/O API)
54 var css = {}, file;
55 css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1];
56 css.fileUri = this.application.ninja.coreIoApi.cloudData.root + css.cssUrl;
57 //Loading data from CSS file
58 file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri});
59 //Checking for file to be writable on disk
60 css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly;
61 //Returning loaded file
62 if (file && file.content) {
63 //Getting file contents
64 css.content = this.parseStyleUrls(file.content, href, true);
65 //Returning CSS object
66 return css;
67 } else {
68 return false;
69 }
70 }
71 },
72 ////////////////////////////////////////////////////////////////////
73 //
74 loadExternalStyleSheet: {
75 value: function (href) {
76 //Loading external file
77 var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false});
78 //Returning file
79 return file;
80 }
81 }
82 ////////////////////////////////////////////////////////////////////
83 ////////////////////////////////////////////////////////////////////
84});
85////////////////////////////////////////////////////////////////////////
86//////////////////////////////////////////////////////////////////////// \ No newline at end of file
diff --git a/js/document/helpers/webgl-helper.js b/js/document/helpers/webgl-helper.js
new file mode 100755
index 00000000..84ddc547
--- /dev/null
+++ b/js/document/helpers/webgl-helper.js
@@ -0,0 +1,218 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component,
11 MaterialsModel = require("js/models/materials-model").MaterialsModel,
12 NJUtils = require("js/lib/NJUtils").NJUtils,
13 GLWorld = require("js/lib/drawing/world").World;
14////////////////////////////////////////////////////////////////////////
15//
16exports.webGlDocumentHelper = Montage.create(Component, {
17 ////////////////////////////////////////////////////////////////////
18 //
19 hasTemplate: {
20 value: false
21 },
22 ////////////////////////////////////////////////////////////////////
23 //This is set when the design view is ready, for local reference
24 iframe: {
25 value: null
26 },
27 ////////////////////////////////////////////////////////////////////
28 //
29 _glData: {
30 value: null
31 },
32 ////////////////////////////////////////////////////////////////////
33 //
34 glData: {
35 //
36 get: function() {
37 //
38 var elt = this.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.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) {