From 7bdcab084d1991361ba8d37a7435efd229648630 Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Tue, 1 May 2012 10:12:40 -0700
Subject: Setting up new architecture for I/O
---
js/document/helpers/url-parser.js | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100755 js/document/helpers/url-parser.js
(limited to 'js/document/helpers')
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
new file mode 100755
index 00000000..878c79e9
--- /dev/null
+++ b/js/document/helpers/url-parser.js
@@ -0,0 +1,24 @@
+/*
+This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
+ */
+
+////////////////////////////////////////////////////////////////////////
+//
+var Montage = require("montage/core/core").Montage,
+ Component = require("montage/ui/component").Component;
+////////////////////////////////////////////////////////////////////////
+//
+exports.UrlParser = Montage.create(Component, {
+ ////////////////////////////////////////////////////////////////////
+ //
+ hasTemplate: {
+ enumerable: false,
+ value: false
+ }
+ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+});
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
\ No newline at end of file
--
cgit v1.2.3
From 4ba680a7e9168d0f505a81e42a287dfbc54b4d7d Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Tue, 1 May 2012 15:26:37 -0700
Subject: Preliminary IO to new DOM view
---
js/document/helpers/url-parser.js | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
(limited to 'js/document/helpers')
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
index 878c79e9..a1a7406a 100755
--- a/js/document/helpers/url-parser.js
+++ b/js/document/helpers/url-parser.js
@@ -14,8 +14,29 @@ exports.UrlParser = Montage.create(Component, {
////////////////////////////////////////////////////////////////////
//
hasTemplate: {
- enumerable: false,
value: false
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ parseStyles: {
+ value: function (styles) {
+ //
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ loadLocalStyleSheet: {
+ value: function (path) {
+ //
+ }
+ }
+ ,
+ ////////////////////////////////////////////////////////////////////
+ //
+ loadExternalStyleSheet: {
+ value: function (path) {
+ //
+ }
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
--
cgit v1.2.3
From d4976b9e129f690b3255d5c0347c410234f7cefa Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Mon, 7 May 2012 16:15:35 -0700
Subject: Extracting CSS methods to parsing class.
Need to do the same with webGL.
---
js/document/helpers/url-parser.js | 57 +++++++++++++++++++++++++++++++------
js/document/helpers/webgl-parser.js | 23 +++++++++++++++
2 files changed, 72 insertions(+), 8 deletions(-)
create mode 100755 js/document/helpers/webgl-parser.js
(limited to 'js/document/helpers')
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
index a1a7406a..5e71d148 100755
--- a/js/document/helpers/url-parser.js
+++ b/js/document/helpers/url-parser.js
@@ -18,24 +18,65 @@ exports.UrlParser = Montage.create(Component, {
},
////////////////////////////////////////////////////////////////////
//
- parseStyles: {
- value: function (styles) {
+ parseStyleUrls: {
+ value: function (css, href, local) {
//
+ if (local) {
+ var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0];
+ } else {
+ //TODO: Add logic for external URLs
+ }
+ //TODO: Clean up functions
+ css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this));
+ //
+ function parseToNinjaUrl (prop) {
+ //
+ return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this));
+ }
+ //
+ function prefixWithNinjaUrl (url) {
+ //
+ 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)) {
+ url = fileCouldDirUrl+url;
+ }
+ //
+ return url;
+ }
+ //
+ return css;
}
},
////////////////////////////////////////////////////////////////////
//
loadLocalStyleSheet: {
- value: function (path) {
- //
+ value: function (href) {
+ //Getting file URI (not URL since we must load through I/O API)
+ var css = {}, file;
+ css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1];
+ css.fileUri = this.application.ninja.coreIoApi.cloudData.root + css.cssUrl;
+ //Loading data from CSS file
+ file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri});
+ //Checking for file to be writable on disk
+ css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly;
+ //Returning loaded file
+ if (file && file.content) {
+ //Getting file contents
+ css.content = this.parseStyleUrls(file.content, href, true);
+ //Returning CSS object
+ return css;
+ } else {
+ return false;
+ }
}
- }
- ,
+ },
////////////////////////////////////////////////////////////////////
//
loadExternalStyleSheet: {
- value: function (path) {
- //
+ value: function (href) {
+ //Loading external file
+ var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false});
+ //Returning file
+ return file;
}
}
////////////////////////////////////////////////////////////////////
diff --git a/js/document/helpers/webgl-parser.js b/js/document/helpers/webgl-parser.js
new file mode 100755
index 00000000..b52ea52b
--- /dev/null
+++ b/js/document/helpers/webgl-parser.js
@@ -0,0 +1,23 @@
+/*
+This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
+ */
+
+////////////////////////////////////////////////////////////////////////
+//
+var Montage = require("montage/core/core").Montage,
+ Component = require("montage/ui/component").Component;
+////////////////////////////////////////////////////////////////////////
+//
+exports.webGlDocumentParser = Montage.create(Component, {
+ ////////////////////////////////////////////////////////////////////
+ //
+ hasTemplate: {
+ value: false
+ }
+ ////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////
+});
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
\ No newline at end of file
--
cgit v1.2.3
From f031c950361251e45f4c2e6795bcb832985e9d25 Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Mon, 7 May 2012 16:31:04 -0700
Subject: Moving webGL to own helper class
Cleaning up webGL for better working files.
---
js/document/helpers/webgl-helper.js | 218 ++++++++++++++++++++++++++++++++++++
js/document/helpers/webgl-parser.js | 23 ----
2 files changed, 218 insertions(+), 23 deletions(-)
create mode 100755 js/document/helpers/webgl-helper.js
delete mode 100755 js/document/helpers/webgl-parser.js
(limited to 'js/document/helpers')
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 @@
+/*
+This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
+ */
+
+////////////////////////////////////////////////////////////////////////
+//
+var Montage = require("montage/core/core").Montage,
+ Component = require("montage/ui/component").Component,
+ MaterialsModel = require("js/models/materials-model").MaterialsModel,
+ NJUtils = require("js/lib/NJUtils").NJUtils,
+ GLWorld = require("js/lib/drawing/world").World;
+////////////////////////////////////////////////////////////////////////
+//
+exports.webGlDocumentHelper = Montage.create(Component, {
+ ////////////////////////////////////////////////////////////////////
+ //
+ hasTemplate: {
+ value: false
+ },
+ ////////////////////////////////////////////////////////////////////
+ //This is set when the design view is ready, for local reference
+ iframe: {
+ value: null
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ _glData: {
+ value: null
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ glData: {
+ //
+ get: function() {
+ //
+ var elt = this.iframe.contentWindow.document.body;
+ //
+ if (elt) {
+ var matLib = MaterialsModel.exportMaterials();
+ this._glData = [matLib];
+ this.collectGLData(elt, this._glData );
+ } else {
+ this._glData = null
+ }
+ //
+ return this._glData;
+ },
+ //
+ set: function(value) {
+ //
+ var elt = this.iframe.contentWindow.document.body;
+ //
+ if (elt) {
+ /*
+ // Use this code to test the runtime version of WebGL
+ var cdm = new NinjaCvsRt.CanvasDataManager();
+ cdm.loadGLData(elt, value, null );
+ */
+
+ //
+ var i, nWorlds= value.length;
+ //
+ for (i = 0; i < nWorlds; i++) {
+ // get the data for the next canvas
+ var importStr = value[i], id, jObj, index = importStr.indexOf(';'), matLibStr, matLibObj, startIndex, endIndex, canvas, useWebGL, world;
+ // determine if it is the new (JSON) or old style format
+ if ((importStr[0] === 'v') && (index < 24)) {
+ // JSON format. pull off the
+ importStr = importStr.substr(index+1);
+ jObj = JSON.parse(importStr);
+ id = jObj.id;
+ } else {
+ // at this point the data could be either the materials library or
+ // an old style world. We can determine which by converting the string
+ // to an object via JSON.parse. That operation will fail if the string
+ // is an old style world.
+ matLibStr = 'materialLibrary;';
+ index = importStr.indexOf(matLibStr);
+ if (index == 0) {
+ importStr = importStr.substr(matLibStr.length);
+ matLibObj = JSON.parse(importStr);
+ MaterialsModel.importMaterials(matLibObj);
+ } else {
+ startIndex = importStr.indexOf("id: ");
+ if (startIndex >= 0) {
+ endIndex = importStr.indexOf("\n", startIndex);
+ if (endIndex > 0) id = importStr.substring(startIndex+4, endIndex);
+ }
+ }
+ }
+ //
+ if (id != null) {
+ //
+ canvas = this.findCanvasWithID(id, elt);
+ //
+ if (canvas) {
+ //
+ if (!canvas.elementModel) {
+ NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
+ }
+ //
+ if (canvas.elementModel) {
+ if (canvas.elementModel.shapeModel.GLWorld) {
+ canvas.elementModel.shapeModel.GLWorld.clearTree();
+ }
+ //
+ if (jObj) {
+ useWebGL = jObj.webGL;
+ world = new GLWorld(canvas, useWebGL);
+ world.importJSON(jObj);
+ }
+ //
+ this.buildShapeModel(canvas.elementModel, world);
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ ////////////////////////////////////////////////////////////////////
+ //
+ findCanvasWithID: {
+ value: function(id, elt) {
+ //
+ var i, child, nKids, foundElt, cid = elt.getAttribute("data-RDGE-id");
+ //
+ if (cid == id) return elt;
+ //
+ if (elt.children) {
+ nKids = elt.children.length;
+ for (i=0; i
-This file contains proprietary software owned by Motorola Mobility, Inc.
-No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
-(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
- */
-
-////////////////////////////////////////////////////////////////////////
-//
-var Montage = require("montage/core/core").Montage,
- Component = require("montage/ui/component").Component;
-////////////////////////////////////////////////////////////////////////
-//
-exports.webGlDocumentParser = Montage.create(Component, {
- ////////////////////////////////////////////////////////////////////
- //
- hasTemplate: {
- value: false
- }
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
-});
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
\ No newline at end of file
--
cgit v1.2.3