diff options
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/document-html.js | 71 | ||||
-rwxr-xr-x | js/document/document-text.js | 4 | ||||
-rwxr-xr-x | js/document/mediators/template.js | 12 | ||||
-rwxr-xr-x | js/document/models/base.js | 22 | ||||
-rw-r--r-- | js/document/views/design-code.js | 130 |
5 files changed, 225 insertions, 14 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js index 142ffe4a..81a8912b 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js | |||
@@ -34,7 +34,8 @@ POSSIBILITY OF SUCH DAMAGE. | |||
34 | var Montage = require("montage/core/core").Montage, | 34 | var Montage = require("montage/core/core").Montage, |
35 | Component = require("montage/ui/component").Component, | 35 | Component = require("montage/ui/component").Component, |
36 | HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel, | 36 | HtmlDocumentModel = require("js/document/models/html").HtmlDocumentModel, |
37 | DesignDocumentView = require("js/document/views/design").DesignDocumentView; | 37 | DesignDocumentView = require("js/document/views/design").DesignDocumentView, |
38 | CodeDocumentView = require("js/document/views/design-code").DesignCodeView; | ||
38 | //////////////////////////////////////////////////////////////////////// | 39 | //////////////////////////////////////////////////////////////////////// |
39 | // | 40 | // |
40 | exports.HtmlDocument = Montage.create(Component, { | 41 | exports.HtmlDocument = Montage.create(Component, { |
@@ -76,7 +77,7 @@ exports.HtmlDocument = Montage.create(Component, { | |||
76 | //////////////////////////////////////////////////////////////////// | 77 | //////////////////////////////////////////////////////////////////// |
77 | // | 78 | // |
78 | init: { | 79 | init: { |
79 | value:function(file, context, callback, view, template) { | 80 | value: function(file, context, callback, view, template) { |
80 | //Storing callback data for loaded dispatch | 81 | //Storing callback data for loaded dispatch |
81 | this.loaded.callback = callback; | 82 | this.loaded.callback = callback; |
82 | this.loaded.context = context; | 83 | this.loaded.context = context; |
@@ -85,7 +86,7 @@ exports.HtmlDocument = Montage.create(Component, { | |||
85 | file: {value: file}, | 86 | file: {value: file}, |
86 | fileTemplate: {value: template}, | 87 | fileTemplate: {value: template}, |
87 | parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach | 88 | parentContainer: {value: document.getElementById("iframeContainer")}, //Saving reference to parent container of all views (should be changed to buckets approach |
88 | views: {value: {'design': DesignDocumentView.create(), 'code': null}} //TODO: Add code view logic | 89 | views: {value: {'design': DesignDocumentView.create(), 'code': CodeDocumentView.create()}} //TODO: Add code view logic |
89 | }); | 90 | }); |
90 | //Calling the any init routines in the model | 91 | //Calling the any init routines in the model |
91 | this.model.init(); | 92 | this.model.init(); |
@@ -98,6 +99,14 @@ exports.HtmlDocument = Montage.create(Component, { | |||
98 | } else { | 99 | } else { |
99 | //ERROR: Design View not initialized | 100 | //ERROR: Design View not initialized |
100 | } | 101 | } |
102 | |||
103 | |||
104 | //TODO: Make sure you have a boolean to indicate if view was initilize and handle errors (just like design view above) | ||
105 | //initialize the code view for the html document and hide it since design is the default view | ||
106 | this.model.views.code.initialize(this.model.parentContainer); | ||
107 | this.model.views.code.hide(); | ||
108 | |||
109 | |||
101 | // | 110 | // |
102 | if (view === 'design') { | 111 | if (view === 'design') { |
103 | //TODO: Remove reference and use as part of model | 112 | //TODO: Remove reference and use as part of model |
@@ -116,12 +125,63 @@ exports.HtmlDocument = Montage.create(Component, { | |||
116 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); | 125 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); |
117 | this._observer.observe(this.model.views.design.document.head, {childList: true}); | 126 | this._observer.observe(this.model.views.design.document.head, {childList: true}); |
118 | }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); | 127 | }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); |
128 | } else if (view === 'code'){ | ||
129 | //TODO: Add logic to open document in code view since it's now available | ||
119 | } else { | 130 | } else { |
120 | //TODO: Identify default view (probably code) | 131 | //TODO: Add error handling |
121 | } | 132 | } |
122 | } | 133 | } |
123 | }, | 134 | }, |
124 | //////////////////////////////////////////////////////////////////// | 135 | //////////////////////////////////////////////////////////////////// |
136 | //TODO: Make into one method to use here and one init | ||
137 | reloadView: { | ||
138 | value: function (view, template, doc) { | ||
139 | // | ||
140 | this.model.parentContainer.removeChild(this.model.views.design.iframe); | ||
141 | //Initiliazing views and hiding | ||
142 | if (this.model.views.design.initialize(this.model.parentContainer)) { | ||
143 | //Hiding iFrame, just initiliazing | ||
144 | this.model.views.design.hide(); | ||
145 | //Setting the iFrame property for reference in helper class | ||
146 | this.model.webGlHelper.iframe = this.model.views.design.iframe; | ||
147 | } else { | ||
148 | //ERROR: Design View not initialized | ||
149 | } | ||
150 | // | ||
151 | if (view === 'design') { | ||
152 | //TODO: Remove reference and use as part of model | ||
153 | this.currentView = 'design'; | ||
154 | //Setting current view object to design | ||
155 | this.model.currentView = this.model.views.design; | ||
156 | //Showing design iFrame | ||
157 | this.model.views.design.show(); | ||
158 | this.model.views.design.iframe.style.opacity = 0; | ||
159 | this.model.views.design.content = this.model.file.content; | ||
160 | //TODO: Improve reference (probably through binding values) | ||
161 | this.model.views.design._webGlHelper = this.model.webGlHelper; | ||
162 | //Rendering design view, using observers to know when template is ready | ||
163 | this.model.views.design.render(function () { | ||
164 | //Adding observer to know when template is ready | ||
165 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); | ||
166 | this._observer.observe(this.model.views.design.document.head, {childList: true}); | ||
167 | }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); | ||
168 | } else if(view === 'code'){ | ||
169 | //TODO: Add logic to handle external changed files | ||
170 | //Checking for template type and not saving external data | ||
171 | if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) { | ||
172 | this.model.views.code.load(this.application.ninja.ioMediator.tmplt.parseNinjaTemplateToHtml(false, doc, true, null).content); | ||
173 | } else { | ||
174 | this.model.views.code.load(this.application.ninja.ioMediator.tmplt.parseNinjaTemplateToHtml(false, doc, false, null).content); | ||
175 | } | ||
176 | //Setting current view object to code | ||
177 | this.currentView = 'code'; | ||
178 | this.model.currentView = this.model.views.code; | ||
179 | } else { | ||
180 | //TODO: Identify default view (probably code) - Error handling | ||
181 | } | ||
182 | } | ||
183 | }, | ||
184 | //////////////////////////////////////////////////////////////////// | ||
125 | // | 185 | // |
126 | handleTemplateReady: { | 186 | handleTemplateReady: { |
127 | value: function (e) { | 187 | value: function (e) { |
@@ -130,6 +190,8 @@ exports.HtmlDocument = Montage.create(Component, { | |||
130 | this._observer = null; | 190 | this._observer = null; |
131 | } | 191 | } |
132 | }, | 192 | }, |
193 | //////////////////////////////////////////////////////////////////// | ||
194 | // | ||
133 | handleViewReady: { | 195 | handleViewReady: { |
134 | value: function(mObjects) { | 196 | value: function(mObjects) { |
135 | this.model.mObjects = mObjects; | 197 | this.model.mObjects = mObjects; |
@@ -138,7 +200,6 @@ exports.HtmlDocument = Montage.create(Component, { | |||
138 | if(typeof this.model.domContainer !== "undefined") { | 200 | if(typeof this.model.domContainer !== "undefined") { |
139 | this.model.domContainer = this.model.documentRoot; | 201 | this.model.domContainer = this.model.documentRoot; |
140 | } | 202 | } |
141 | |||
142 | //Making callback after view is loaded | 203 | //Making callback after view is loaded |
143 | this.loaded.callback.call(this.loaded.context, this); | 204 | this.loaded.callback.call(this.loaded.context, this); |
144 | } | 205 | } |
diff --git a/js/document/document-text.js b/js/document/document-text.js index 1fe43494..d06bdefb 100755 --- a/js/document/document-text.js +++ b/js/document/document-text.js | |||
@@ -51,13 +51,13 @@ exports.TextDocument = Montage.create(Component, { | |||
51 | //////////////////////////////////////////////////////////////////// | 51 | //////////////////////////////////////////////////////////////////// |
52 | // | 52 | // |
53 | init:{ | 53 | init:{ |
54 | value: function(file, context, callback, view){ | 54 | value: function(file, context, callback, view, parentContainer){ |
55 | // | 55 | // |
56 | var codeDocumentView = CodeDocumentView.create(), container = null; //TODO: Why is this initilzied to null? | 56 | var codeDocumentView = CodeDocumentView.create(), container = null; //TODO: Why is this initilzied to null? |
57 | //Creating instance of Text Document Model | 57 | //Creating instance of Text Document Model |
58 | this.model = Montage.create(TextDocumentModel,{ | 58 | this.model = Montage.create(TextDocumentModel,{ |
59 | file: {value: file}, | 59 | file: {value: file}, |
60 | parentContainer: {value: document.getElementById("codeViewContainer")}, //TODO: Remove reference to this element, should be dynamic | 60 | parentContainer: {value: parentContainer}, //TODO: Remove reference to this element, should be dynamic |
61 | views: {value: {'code': codeDocumentView, 'design': null}} //TODO: Add check if file might have design view, if so, then create it | 61 | views: {value: {'code': codeDocumentView, 'design': null}} //TODO: Add check if file might have design view, if so, then create it |
62 | }); | 62 | }); |
63 | //TODO: Add design view logic | 63 | //TODO: Add design view logic |
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 4065f471..c68cfe72 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js | |||
@@ -47,7 +47,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
47 | // | 47 | // |
48 | getAppTemplatesUrlRegEx: { | 48 | getAppTemplatesUrlRegEx: { |
49 | value: function () { | 49 | value: function () { |
50 | var regex = new RegExp(chrome.extension.getURL(this.application.ninja.currentDocument.model.views.design.iframe.src.split(chrome.extension.getURL('/'))[1]).replace(/\//gi, '\\\/'), 'gi'); | 50 | var regex = new RegExp(chrome.extension.getURL(this.application.ninja.currentDocument.model.views.design.document.baseURI.split(chrome.extension.getURL('/'))[1]).replace(/\//gi, '\\\/'), 'gi'); |
51 | return regex; | 51 | return regex; |
52 | } | 52 | } |
53 | }, | 53 | }, |
@@ -326,7 +326,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
326 | } | 326 | } |
327 | } | 327 | } |
328 | } | 328 | } |
329 | } else if (template.css) { | 329 | } else if (template.css && saveExternalData) { |
330 | //Getting all style and link tags | 330 | //Getting all style and link tags |
331 | var styleCounter = 0, | 331 | var styleCounter = 0, |
332 | docStyles = template.file.content.document.getElementsByTagName('style'), | 332 | docStyles = template.file.content.document.getElementsByTagName('style'), |
@@ -480,7 +480,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
480 | //Copy webGL library if needed | 480 | //Copy webGL library if needed |
481 | for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { | 481 | for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) { |
482 | //Checking for RDGE library to be available | 482 | //Checking for RDGE library to be available |
483 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') { | 483 | if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE' && saveExternalData) { |
484 | rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); | 484 | rdgeDirName = (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name + this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase(); |
485 | rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; | 485 | rdgeVersion = this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version; |
486 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName, function(result) {libsobserver.canvasCopied = result; this.libCopied(libsobserver);}.bind(this)); | 486 | this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(template.file.root, rdgeDirName, function(result) {libsobserver.canvasCopied = result; this.libCopied(libsobserver);}.bind(this)); |
@@ -564,7 +564,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
564 | webgllibtag.setAttribute('data-ninja-canvas-json', this.application.ninja.coreIoApi.rootUrl+'/'+cvsDataFileUrl); | 564 | webgllibtag.setAttribute('data-ninja-canvas-json', this.application.ninja.coreIoApi.rootUrl+'/'+cvsDataFileUrl); |
565 | webgllibtag.setAttribute('data-ninja-canvas-libpath', rdgeDirName); | 565 | webgllibtag.setAttribute('data-ninja-canvas-libpath', rdgeDirName); |
566 | // | 566 | // |
567 | if (cvsDataFileCheck.status === 404 || cvsDataFileCheck.st |