diff options
author | Ananya Sen | 2012-06-07 11:59:32 -0700 |
---|---|---|
committer | Ananya Sen | 2012-06-07 11:59:32 -0700 |
commit | 7378b6846f140106490f10c02cd7cec6a19023aa (patch) | |
tree | 90b60c007696b4a73c29abbae82562f69f15c11a /js/document | |
parent | aea0e6879abfef02a827ed239ef091c3b96d6eb2 (diff) | |
parent | b75fe9369f7caec0351d298f7106c8d59572b440 (diff) | |
download | ninja-7378b6846f140106490f10c02cd7cec6a19023aa.tar.gz |
Merge branch 'refs/heads/ninja-internal-master' into cut-copy-paste
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/document-html.js | 14 | ||||
-rwxr-xr-x | js/document/helpers/webgl-helper.js | 14 | ||||
-rwxr-xr-x | js/document/mediators/template.js | 756 | ||||
-rwxr-xr-x | js/document/models/base.js | 58 | ||||
-rwxr-xr-x | js/document/models/html.js | 48 | ||||
-rw-r--r-- | js/document/templates/app/main.js | 51 | ||||
-rwxr-xr-x | js/document/templates/banner/index.html | 24 | ||||
-rwxr-xr-x | js/document/templates/html/index.html | 27 | ||||
-rwxr-xr-x | js/document/views/design.js | 92 |
9 files changed, 979 insertions, 105 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js index 33a41a8e..04565753 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js | |||
@@ -68,6 +68,8 @@ exports.HtmlDocument = Montage.create(Component, { | |||
68 | if (this.model.views.design.initialize(this.model.parentContainer)) { | 68 | if (this.model.views.design.initialize(this.model.parentContainer)) { |
69 | //Hiding iFrame, just initiliazing | 69 | //Hiding iFrame, just initiliazing |
70 | this.model.views.design.hide(); | 70 | this.model.views.design.hide(); |
71 | //Setting the iFrame property for reference in helper class | ||
72 | this.model.webGlHelper.iframe = this.model.views.design.iframe; | ||
71 | } else { | 73 | } else { |
72 | //ERROR: Design View not initialized | 74 | //ERROR: Design View not initialized |
73 | } | 75 | } |
@@ -82,13 +84,13 @@ exports.HtmlDocument = Montage.create(Component, { | |||
82 | this.model.views.design.iframe.style.opacity = 0; | 84 | this.model.views.design.iframe.style.opacity = 0; |
83 | this.model.views.design.content = this.model.file.content; | 85 | this.model.views.design.content = this.model.file.content; |
84 | //TODO: Improve reference (probably through binding values) | 86 | //TODO: Improve reference (probably through binding values) |
85 | this.model.views.design.model = this.model; | 87 | this.model.views.design._webGlHelper = this.model.webGlHelper; |
86 | //Rendering design view, using observers to know when template is ready | 88 | //Rendering design view, using observers to know when template is ready |
87 | this.model.views.design.render(function () { | 89 | this.model.views.design.render(function () { |
88 | //Adding observer to know when template is ready | 90 | //Adding observer to know when template is ready |
89 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); | 91 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); |
90 | this._observer.observe(this.model.views.design.document.head, {childList: true}); | 92 | this._observer.observe(this.model.views.design.document.head, {childList: true}); |
91 | }.bind(this), template); | 93 | }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); |
92 | } else { | 94 | } else { |
93 | //TODO: Identify default view (probably code) | 95 | //TODO: Identify default view (probably code) |
94 | } | 96 | } |
@@ -101,10 +103,14 @@ exports.HtmlDocument = Montage.create(Component, { | |||
101 | //Removing observer, only needed on initial load | 103 | //Removing observer, only needed on initial load |
102 | this._observer.disconnect(); | 104 | this._observer.disconnect(); |
103 | this._observer = null; | 105 | this._observer = null; |
104 | //Making callback after view is loaded | ||
105 | this.loaded.callback.call(this.loaded.context, this); | ||
106 | } | 106 | } |
107 | }, | 107 | }, |
108 | handleViewReady: { | ||
109 | value: function() { | ||
110 | //Making callback after view is loaded | ||
111 | this.loaded.callback.call(this.loaded.context, this); | ||
112 | } | ||
113 | }, | ||
108 | //////////////////////////////////////////////////////////////////// | 114 | //////////////////////////////////////////////////////////////////// |
109 | // | 115 | // |
110 | closeDocument: { | 116 | closeDocument: { |
diff --git a/js/document/helpers/webgl-helper.js b/js/document/helpers/webgl-helper.js index 84ddc547..6d9ced14 100755 --- a/js/document/helpers/webgl-helper.js +++ b/js/document/helpers/webgl-helper.js | |||
@@ -40,7 +40,7 @@ exports.webGlDocumentHelper = Montage.create(Component, { | |||
40 | if (elt) { | 40 | if (elt) { |
41 | var matLib = MaterialsModel.exportMaterials(); | 41 | var matLib = MaterialsModel.exportMaterials(); |
42 | this._glData = [matLib]; | 42 | this._glData = [matLib]; |
43 | this.collectGLData(elt, this._glData ); | 43 | this.collectGLData(this.iframe.contentWindow.document, this._glData ); |
44 | } else { | 44 | } else { |
45 | this._glData = null | 45 | this._glData = null |
46 | } | 46 | } |
@@ -97,10 +97,6 @@ exports.webGlDocumentHelper = Montage.create(Component, { | |||
97 | // | 97 | // |
98 | if (canvas) { | 98 | if (canvas) { |
99 | // | 99 | // |
100 | if (!canvas.elementModel) { | ||
101 | NJUtils.makeElementModel(canvas, "Canvas", "shape", true); | ||
102 | } | ||
103 | // | ||
104 | if (canvas.elementModel) { | 100 | if (canvas.elementModel) { |
105 | if (canvas.elementModel.shapeModel.GLWorld) { | 101 | if (canvas.elementModel.shapeModel.GLWorld) { |
106 | canvas.elementModel.shapeModel.GLWorld.clearTree(); | 102 | canvas.elementModel.shapeModel.GLWorld.clearTree(); |
@@ -194,6 +190,13 @@ exports.webGlDocumentHelper = Montage.create(Component, { | |||
194 | // | 190 | // |
195 | collectGLData: { | 191 | collectGLData: { |
196 | value: function( elt, dataArray ) { | 192 | value: function( elt, dataArray ) { |
193 | Array.prototype.slice.call(elt.querySelectorAll('[data-RDGE-id]'),0).forEach(function(glCanvas) { | ||
194 | dataArray.push(glCanvas.elementModel.shapeModel.GLWorld.exportJSON()); | ||
195 | }); | ||
196 | |||
197 | // Removing the old loop that went through all the elements. | ||
198 | // TODO: Remove the following code once QE has tested it. | ||
199 | /* | ||
197 | // | 200 | // |
198 | var i, data, nKids, child; | 201 | var i, data, nKids, child; |
199 | // | 202 | // |
@@ -209,6 +212,7 @@ exports.webGlDocumentHelper = Montage.create(Component, { | |||
209 | this.collectGLData( child, dataArray ); | 212 | this.collectGLData( child, dataArray ); |
210 | } | 213 | } |
211 | } | 214 | } |
215 | */ | ||
212 | } | 216 | } |
213 | } | 217 | } |
214 | //////////////////////////////////////////////////////////////////// | 218 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index c5b45ba1..068a1f48 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js | |||
@@ -6,16 +6,766 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | //////////////////////////////////////////////////////////////////////// | 7 | //////////////////////////////////////////////////////////////////////// |
8 | // | 8 | // |
9 | var Montage = require("montage/core/core").Montage, | 9 | var Montage = require("montage/core/core").Montage, |
10 | Component = require("montage/ui/component").Component; | 10 | Component = require("montage/ui/component").Component, |
11 | TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator; | ||
11 | //////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////// |
12 | // | 13 | // |
13 | exports.TemplateDocumentMediator = Montage.create(Component, { | 14 | exports.TemplateDocumentMediator = Montage.create(Component, { |
14 | //////////////////////////////////////////////////////////////////// | 15 | //////////////////////////////////////////////////////////////////// |
15 | // | 16 | // |
16 | hasTemplate: { | 17 | hasTemplate: { |
17 | enumerable: false, | ||
18 | value: false | 18 | value: false |
19 | }, | ||
20 | //////////////////////////////////////////////////////////////////// | ||
21 | // | ||
22 | getAppTemplatesUrlRegEx: { | ||
23 | value: function () { | ||
24 | var regex = new RegExp(chrome.extension.getURL(this.application.ninja.currentDocument.model.views.design.iframe.src.split(chrome.extension.getURL('/'))[1]).replace(/\//gi, '\\\/'), 'gi'); | ||
25 | return regex; | ||
26 | } | ||
27 | }, | ||
28 | //////////////////////////////////////////////////////////////////// | ||
29 | // | ||
30 | getDataDirectory: { | ||
31 | value: function (path) { | ||
32 | //TODO: Implement user overwrite | ||
33 | return this._getUserDirectory(path+'data/'); | ||
34 | } | ||
35 | }, | ||
36 | //////////////////////////////////////////////////////////////////// | ||
37 | // | ||
38 | getNinjaDirectory: { | ||
39 | value: function (path) { | ||
40 | //TODO: Implement user overwrite | ||
41 | return this._getUserDirectory(this.getDataDirectory(path)+'ninja/'); | ||
42 | } | ||
43 | }, | ||
44 | //////////////////////////////////////////////////////////////////// | ||
45 | // | ||
46 | getCanvasDirectory: { | ||
47 | value: function (path) { | ||
48 | //TODO: Implement user overwrite | ||
49 | return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/'); | ||
50 | } | ||
51 | }, | ||
52 | //////////////////////////////////////////////////////////////////// | ||
53 | // | ||
54 | _getUserDirectory: { | ||
55 | value: function (path) { | ||
56 | //Checking for data directory | ||
57 | var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory; | ||
58 | //Creating directory if doesn't exists | ||
59 | switch (check.status) { | ||
60 | case 204: //Exists | ||
61 | directory = path; | ||
62 | break; | ||
63 | case 404: //Doesn't exists | ||
64 | directory = this.application.ninja.coreIoApi.createDirectory({uri: path}); | ||
65 | //Checking for success | ||
66 | if (directory.status === 201) { | ||
67 | directory = path; | ||
68 | } else { | ||
69 | //Error | ||
70 | directory = null; | ||
71 | } | ||
72 | break; | ||
73 | default: //Error | ||
74 | directory = null; | ||
75 | break; | ||
76 | } | ||
77 | //Returning the path to the directory on disk (null for any error) | ||
78 | return directory; | ||
79 | } | ||
80 | }, | ||
81 | //////////////////////////////////////////////////////////////////// | ||
82 | // | ||
83 | parseHtmlToNinjaTemplate: { | ||
84 | value: function (html) { | ||
85 | //Creating temp object to mimic HTML | ||
86 | var doc = window.document.implementation.createHTMLDocument(), template; | ||
87 | //Setting content to temp | ||
88 | doc.getElementsByTagName('html')[0].innerHTML = html; | ||
89 | //Creating return object | ||
90 | return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc}; | ||
91 | } | ||
92 |