diff options
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 | 796 | ||||
-rwxr-xr-x | js/document/models/base.js | 99 | ||||
-rwxr-xr-x | js/document/models/html.js | 50 | ||||
-rw-r--r-- | js/document/templates/app/main.js | 1 | ||||
-rwxr-xr-x | js/document/templates/banner/index.html | 47 | ||||
-rwxr-xr-x | js/document/templates/html/index.html | 50 | ||||
-rwxr-xr-x | js/document/views/design.js | 106 |
9 files changed, 1071 insertions, 106 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..50fad1c3 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js | |||
@@ -6,16 +6,806 @@ 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, | ||
12 | ClassUuid = require("js/components/core/class-uuid").ClassUuid; | ||
11 | //////////////////////////////////////////////////////////////////////// | 13 | //////////////////////////////////////////////////////////////////////// |
12 | // | 14 | // |
13 | exports.TemplateDocumentMediator = Montage.create(Component, { | 15 | exports.TemplateDocumentMediator = Montage.create(Component, { |
14 | //////////////////////////////////////////////////////////////////// | 16 | //////////////////////////////////////////////////////////////////// |
15 | // | 17 | // |
16 | hasTemplate: { | 18 | hasTemplate: { |
17 | enumerable: false, | ||
18 | value: false | 19 | value: false |
20 | }, | ||
21 | //////////////////////////////////////////////////////////////////// | ||
22 | // | ||
23 | getAppTemplatesUrlRegEx: { | ||
24 | value: function () { | ||
25 | var regex = new RegExp(chrome.extension.getURL(this.application.ninja.currentDocument.model.views.design.iframe.src.split(chrome.extension.getURL('/'))[1]).replace(/\//gi, '\\\/'), 'gi'); | ||
26 | return regex; | ||
27 | } | ||
28 | }, | ||
29 | //////////////////////////////////////////////////////////////////// | ||
30 | // | ||
31 | getDataDirectory: { | ||
32 | value: function (path) { | ||
33 | //TODO: Implement user overwrite | ||
34 | return this._getUserDirectory(path+'data/'); | ||
35 | } | ||
36 | }, | ||
37 | //////////////////////////////////////////////////////////////////// | ||
38 | // | ||
39 | getNinjaDirectory: { | ||
40 | value: function (path) { | ||
41 | //TODO: Implement user overwrite | ||
42 | return this._getUserDirectory(this.getDataDirectory(path)+'ninja/'); | ||
43 | } | ||
44 | }, | ||
45 | //////////////////////////////////////////////////////////////////// | ||
46 | // | ||
47 | getCanvasDirectory: { | ||
48 | value: function (path) { | ||
49 | //TODO: Implement user overwrite | ||
50 | return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/'); | ||
51 | } | ||
52 | }, | ||
53 | //////////////////////////////////////////////////////////////////// | ||
54 | // | ||
55 | _getUserDirectory: { | ||
56 | value: function (path) { | ||
57 | //Checking for data directory | ||
58 | var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory; | ||
59 | //Creating directory if doesn't exists | ||
60 | switch (check.status) { | ||
61 | case 204: //Exists | ||
62 | directory = path; | ||
63 | break; | ||
64 | case 404: //Doesn't exists | ||
65 | directory = this.application.ninja.coreIoApi.createDirectory({uri: path}); | ||
66 | //Checking for success | ||
67 | if (directory.status === 201) { | ||
68 | directory = path; | ||
69 | } else { | ||
70 | //Error | ||
71 | directory = null; | ||
72 | } | ||
73 | break; | ||
74 | default: //Error | ||
75 | directory = null; | ||
76 | break; | ||
77 | } | ||
78 | //Returning the path to the directory on disk (null for any error) | ||
79 | return directory; | ||
80 | } | ||
81 | }, | ||
82 | //////////////////////////////////////////////////////////////////// | ||
83 | // | ||
84 | parseHtmlToNinjaTemplate: { | ||
85 | value: function (html) { | ||
86 | //Creating temp object to mimic HTML | ||
87 | var doc = window.document.implementation.createHTMLDocument(), template, docHtmlTag, | ||
88 | hackHtml = document.createElement('html'), hackTag; | ||
89 | //Setting content to temp | ||
90 | doc.getElementsByTagName('html')[0].innerHTML = html; | ||
91 | //TODO: Improve this, very bad way of copying attributes (in a pinch to get it working) | ||
92 | hackHtml.innerHTML = html.replace(/html/gi, 'ninjahtmlhack'); | ||
93 | hackTag = hackHtml.getElementsByTagName('ninjahtmlhack')[0]; | ||
94 | docHtmlTag = doc.getElementsByTagName('html')[0]; | ||
95 | //Looping through the attributes to copy them | ||
96 | if (hackTag) { | ||
97 | for (var m in hackTag.attributes) { | ||
98 | if (hackTag.attributes[m].value) { | ||
99 | docHtmlTag.setAttribute(hackTag.attributes[m].name.replace(/ninjahtmlhack/gi, 'html'), hackTag.attributes[m].value.replace(/ninjahtmlhack/gi, 'h |