aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-05-07 17:19:16 -0700
committerNivesh Rajbhandari2012-05-07 17:19:16 -0700
commit377c57c7debc98071593056be033978bd337c37e (patch)
treebade422fe2471a18944e846cfec1dd188a6cdae3 /js
parentaa8cfcfe0091651708f77300f48a7e703f92f341 (diff)
parent4d949f141247215b5f2a6ec0cfc7d2d31cf2bb1f (diff)
downloadninja-377c57c7debc98071593056be033978bd337c37e.tar.gz
Merge branch 'refs/heads/dom-architecture-master' into Dom-Architecture
Conflicts: js/document/document-html.js Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/document-html.js5
-rwxr-xr-xjs/document/helpers/url-parser.js57
-rwxr-xr-xjs/document/helpers/webgl-helper.js218
-rwxr-xr-xjs/document/models/html.js196
-rwxr-xr-xjs/document/views/design.js136
5 files changed, 328 insertions, 284 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js
index d0f5b817..567e4455 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -81,7 +81,10 @@ exports.HtmlDocument = Montage.create(Component, {
81 } 81 }
82 // 82 //
83 if (view === 'design') { 83 if (view === 'design') {
84 this.currentView = "design"; 84 //TODO: Remove reference and use as part of model
85 this.currentView = 'design';
86 //Setting current view object to design
87 this.model.currentView = this.model.views.design;
85 //Showing design iFrame 88 //Showing design iFrame
86 this.model.views.design.show(); 89 this.model.views.design.show();
87 this.model.views.design.iframe.style.opacity = 0; 90 this.model.views.design.iframe.style.opacity = 0;
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, {
18 }, 18 },
19 //////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////
20 // 20 //
21 parseStyles: { 21 parseStyleUrls: {
22 value: function (styles) { 22 value: function (css, href, local) {
23 // 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;
24 } 47 }
25 }, 48 },
26 //////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////
27 // 50 //
28 loadLocalStyleSheet: { 51 loadLocalStyleSheet: {
29 value: function (path) { 52 value: function (href) {
30 // 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 }
31 } 70 }
32 } 71 },
33 ,
34 //////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////
35 // 73 //
36 loadExternalStyleSheet: { 74 loadExternalStyleSheet: {
37 value: function (path) { 75 value: function (href) {
38 // 76 //Loading external file
77 var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false});
78 //Returning file
79 return file;
39 } 80 }
40 } 81 }
41 //////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////
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