diff options
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/document-html.js | 14 | ||||
-rwxr-xr-x | js/document/mediators/template.js | 33 | ||||
-rwxr-xr-x | js/document/models/base.js | 69 | ||||
-rwxr-xr-x | js/document/models/html.js | 5 | ||||
-rw-r--r-- | js/document/templates/app/main.js | 6 | ||||
-rwxr-xr-x | js/document/views/design.js | 21 |
6 files changed, 114 insertions, 34 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js index 04565753..b9c8e797 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js | |||
@@ -36,7 +36,7 @@ exports.HtmlDocument = Montage.create(Component, { | |||
36 | //////////////////////////////////////////////////////////////////// | 36 | //////////////////////////////////////////////////////////////////// |
37 | // | 37 | // |
38 | exclusionList: { | 38 | exclusionList: { |
39 | value: ["HTML", "BODY", "NINJA-CONTENT"] | 39 | value: ["HTML", "BODY", "NINJA-CONTENT", "NINJA-VIEWPORT"] |
40 | }, | 40 | }, |
41 | //////////////////////////////////////////////////////////////////// | 41 | //////////////////////////////////////////////////////////////////// |
42 | // | 42 | // |
@@ -107,6 +107,12 @@ exports.HtmlDocument = Montage.create(Component, { | |||
107 | }, | 107 | }, |
108 | handleViewReady: { | 108 | handleViewReady: { |
109 | value: function() { | 109 | value: function() { |
110 | // TODO: Find a better way to initialize this property | ||
111 | // Assign the domContainer to be the document root on open | ||
112 | if(typeof this.model.domContainer !== "undefined") { | ||
113 | this.model.domContainer = this.model.documentRoot; | ||
114 | } | ||
115 | |||
110 | //Making callback after view is loaded | 116 | //Making callback after view is loaded |
111 | this.loaded.callback.call(this.loaded.context, this); | 117 | this.loaded.callback.call(this.loaded.context, this); |
112 | } | 118 | } |
@@ -115,10 +121,8 @@ exports.HtmlDocument = Montage.create(Component, { | |||
115 | // | 121 | // |
116 | closeDocument: { | 122 | closeDocument: { |
117 | value: function (context, callback) { | 123 | value: function (context, callback) { |
118 | //Closing document and getting outcome | 124 | //Closing document (sending null to close all views) |
119 | var closed = this.model.close(null); | 125 | this.model.close(null, function () {if (callback) callback.call(context, this);}.bind(this)); |
120 | //Making callback if specified | ||
121 | if (callback) callback.call(context, this); | ||
122 | } | 126 | } |
123 | }, | 127 | }, |
124 | //////////////////////////////////////////////////////////////////// | 128 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 50fad1c3..c5b46c3a 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js | |||
@@ -145,6 +145,29 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
145 | template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); | 145 | template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | // | ||
149 | if(template.template) { | ||
150 | // | ||
151 | // TODO - Need to handle banner and animation templates. | ||
152 | //Copying attributes to maintain same properties as <ninja-content> | ||
153 | var ninjaContentTagMem = template.document.getElementsByTagName('ninja-content')[0], ninjaContentTagDoc = template.file.content.document.getElementsByTagName('ninja-content')[0]; | ||
154 | if (ninjaContentTagMem && ninjaContentTagMem.getAttribute('data-ninja-style') !== null) { | ||
155 | ninjaContentTagDoc.setAttribute('style', ninjaContentTagMem.getAttribute('data-ninja-style')); | ||
156 | ninjaContentTagDoc.removeAttribute('data-ninja-style'); | ||
157 | } else if (ninjaContentTagMem && ninjaContentTagMem.getAttribute('data-ninja-style') === null) { | ||
158 | ninjaContentTagDoc.removeAttribute('style'); | ||
159 | ninjaContentTagDoc.removeAttribute('data-ninja-style'); | ||
160 | } | ||
161 | } else { | ||
162 | if (template.body && template.body.getAttribute('data-ninja-style') !== null) { | ||
163 | template.file.content.document.body.setAttribute('style', template.body.getAttribute('data-ninja-style')); | ||
164 | template.file.content.document.body.removeAttribute('data-ninja-style'); | ||
165 | } else if (template.body && template.body.getAttribute('data-ninja-style') === null) { | ||
166 | template.file.content.document.body.removeAttribute('style'); | ||
167 | template.file.content.document.body.removeAttribute('data-ninja-style'); | ||
168 | } | ||
169 | } | ||
170 | |||
148 | wipeAttributes(template.file.content.document.head); | 171 | wipeAttributes(template.file.content.document.head); |
149 | //Copying attributes to maintain same properties as the <head> | 172 | //Copying attributes to maintain same properties as the <head> |
150 | for (var m in template.document.head.attributes) { | 173 | for (var m in template.document.head.attributes) { |
@@ -155,6 +178,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
155 | //Copying attributes to maintain same properties as the <html> | 178 | //Copying attributes to maintain same properties as the <html> |
156 | var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0]; | 179 | var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0]; |
157 | wipeAttributes(htmlTagDoc); | 180 | wipeAttributes(htmlTagDoc); |
181 | // | ||
158 | for (var m in htmlTagMem.attributes) { | 182 | for (var m in htmlTagMem.attributes) { |
159 | if (htmlTagMem.attributes[m].value) { | 183 | if (htmlTagMem.attributes[m].value) { |
160 | if (htmlTagMem.attributes[m].value.replace(/montage-app-bootstrapping/gi, '').length>0) { | 184 | if (htmlTagMem.attributes[m].value.replace(/montage-app-bootstrapping/gi, '').length>0) { |
@@ -162,10 +186,19 @@ exports.TemplateDocumentMediator = Montage.create(Component, { | |||
162 | } | 186 | } |
163 | } | 187 | } |
164 | } | 188 | } |
189 | // | ||
190 | if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') !== null) { | ||
191 | htmlTagDoc.setAttribute('style', htmlTagMem.getAttribute('data-ninja-style')); | ||
192 | htmlTagDoc.removeAttribute('data-ninja-style'); | ||
193 | } else if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') === null) { | ||
194 | htmlTagDoc.removeAttribute('style'); | ||
195 | htmlTagDoc.removeAttribute('data-ninja-style'); | ||
196 | } | ||
165 | //Getting list of current nodes (Ninja DOM) | 197 | //Getting list of current nodes (Ninja DOM) |
166 | presentNodes = template.file.content.document.getElementsByTagName('*'); | 198 | presentNodes = template.file.content.document.getElementsByTagName('*'); |
167 | //Looping through nodes to determine origin and removing if not inserted by Ninja | 199 | //Looping through nodes to determine origin and removing if not inserted by Ninja |
168 | for (var n in presentNodes) { | 200 | for (var n in presentNodes) { |
201 | // | ||
169 | if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { | 202 | if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { |
170 | toremovetags.push(presentNodes[n]); | 203 | toremovetags.push(presentNodes[n]); |
171 | } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { | 204 | } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { |
diff --git a/js/document/models/base.js b/js/document/models/base.js index 5fa06259..8ff52132 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -6,8 +6,9 @@ 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 | NinjaPrompt = require("js/components/prompt.reel").NinjaPrompt; | ||
11 | //////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////// |
12 | // | 13 | // |
13 | exports.BaseDocumentModel = Montage.create(Component, { | 14 | exports.BaseDocumentModel = Montage.create(Component, { |
@@ -65,6 +66,9 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
65 | _selection: { | 66 | _selection: { |
66 | value: [] | 67 | value: [] |
67 | }, | 68 | }, |
69 | domContainer: { | ||
70 | value: null | ||
71 | }, | ||
68 | //////////////////////////////////////////////////////////////////// | 72 | //////////////////////////////////////////////////////////////////// |
69 | // | 73 | // |
70 | selection: { | 74 | selection: { |
@@ -264,30 +268,59 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
264 | if (this.callback) this.callback(result); | 268 | if (this.callback) this.callback(result); |
265 | } | 269 | } |
266 | }, | 270 | }, |
271 | //////////////////////////////////////////////////////////////////// | ||
272 | // | ||
273 | handleSavePrompt: { | ||
274 | value: function (continueToClose, callback) { | ||
275 | //TODO: Perhaps add logic to save the file is the user wants | ||
276 | if (continueToClose) { | ||
277 | if (callback) callback(); | ||
278 | } else { | ||
279 | //User canceled | ||
280 | //this.saveAll(null, callback); | ||
281 | } | ||
282 | } | ||
283 | }, | ||
267 | //////////////////////////////////////////////////////////////////// | 284 | //////////////////////////////////////////////////////////////////// |
268 | //TODO: Implement better logic to include different views on single document | 285 | //TODO: Implement better logic to include different views on single document |
269 | close: { | 286 | close: { |
270 | value: function (view, callback) { | 287 | value: function (view, callback) { |
271 | //Outcome of close (pending on save logic) | 288 | //Checking if files needs to be saved to avoid losing data |
272 | var success; | ||
273 | // | ||
274 | if (this.needsSave) { | 289 | if (this.needsSave) { |
275 | //TODO: Prompt user to save or lose data | 290 | //Creating prompt to ask user to save the file |
291 | var prompt = NinjaPrompt.create(); | ||
292 | prompt.initialize('confirm', {message: 'Do you want to save the changes you made in the document '+this.file.name+'?\n\nYour changes will be lost if you do not save them.'}, function (result){this.handleSavePrompt(result, callback);}.bind(this)); | ||
293 | //Showing the prompt, it will make callback with user input | ||
294 | prompt.show(); | ||
276 | } else { | 295 | } else { |
277 | //Close file | 296 | //TODO: Add support for other views |
278 | success = true; | 297 | if (!view || view === 'design') { |
279 | } | 298 | this.closeView('design'); |
280 | //Checking for view mode to close | 299 | } |
281 | if (this.views.design && (!view || view === 'design')) { | 300 | //Making callback |
282 | //TODO: Create a destroy method, this is messy | 301 | if (callback) callback(); |
283 | this.views.design.pauseAndStopVideos(); | ||
284 | this.parentContainer.removeChild(this.views.design.iframe); | ||
285 | this.views.design = null; | ||
286 | } | 302 | } |
287 | //Returning result of operation | 303 | |
288 | return success; | ||
289 | } | 304 | } |
290 | } | 305 | }, |
306 | //////////////////////////////////////////////////////////////////// | ||
307 | // | ||
308 | closeView: { | ||
309 | value: function (view) { | ||
310 | //Checking for view mode to close | ||
311 | switch (view.toLowerCase()) { | ||
312 | case 'design': | ||
313 | //TODO: Make into clean method in the design view | ||
314 | this.views.design.pauseAndStopVideos(); | ||
315 | this.parentContainer.removeChild(this.views.design.iframe); | ||
316 | this.views.design = null; | ||
317 | break; | ||
318 | default: | ||
319 | //TODO: Error? | ||
320 | break; | ||
321 | } | ||
322 | } |