diff options
Diffstat (limited to 'js/document/models')
-rwxr-xr-x | js/document/models/base.js | 112 | ||||
-rwxr-xr-x | js/document/models/html.js | 67 | ||||
-rwxr-xr-x | js/document/models/text.js | 3 |
3 files changed, 115 insertions, 67 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js index 6d9d2e89..9c26bd2a 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -62,6 +62,17 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
62 | }, | 62 | }, |
63 | //////////////////////////////////////////////////////////////////// | 63 | //////////////////////////////////////////////////////////////////// |
64 | // | 64 | // |
65 | _selection: { | ||
66 | value: [] | ||
67 | }, | ||
68 | //////////////////////////////////////////////////////////////////// | ||
69 | // | ||
70 | selection: { | ||
71 | get: function() {return this._selection;}, | ||
72 | set: function(value) {this._selection = value;} | ||
73 | }, | ||
74 | //////////////////////////////////////////////////////////////////// | ||
75 | // | ||
65 | fileTemplate: { | 76 | fileTemplate: { |
66 | value: null | 77 | value: null |
67 | }, | 78 | }, |
@@ -77,6 +88,24 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
77 | }, | 88 | }, |
78 | //////////////////////////////////////////////////////////////////// | 89 | //////////////////////////////////////////////////////////////////// |
79 | // | 90 | // |
91 | libs: { | ||
92 | value: null | ||
93 | }, | ||
94 | |||
95 | _mObjects: { | ||
96 | value: [] | ||
97 | }, | ||
98 | |||
99 | mObjects: { | ||
100 | get: function() { | ||
101 | return this._mObjects; | ||
102 | }, | ||
103 | set: function(value) { | ||
104 | this._mObjects = value; | ||
105 | } | ||
106 | }, | ||
107 | //////////////////////////////////////////////////////////////////// | ||
108 | // | ||
80 | switchViewTo: { | 109 | switchViewTo: { |
81 | value: function (view) { | 110 | value: function (view) { |
82 | // | 111 | // |
@@ -85,11 +114,20 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
85 | //////////////////////////////////////////////////////////////////// | 114 | //////////////////////////////////////////////////////////////////// |
86 | //TODO: Add API to allow other browser support | 115 | //TODO: Add API to allow other browser support |
87 | browserPreview: { | 116 | browserPreview: { |
88 | value: function (browser) { | 117 | value: function (browser, screen, context) { |
118 | //Making call to show feedback screen | ||
119 | if (screen) screen.show(context); | ||
89 | //Generating URL for document | 120 | //Generating URL for document |
90 | var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; | 121 | var url = this.application.ninja.coreIoApi.rootUrl + this.file.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]; |
91 | //TODO: Add logic to prompt user to save (all) before preview | 122 | //TODO: Add logic to prompt user to save (all) before preview |
92 | this.saveAll(function (result) { | 123 | this.saveAll(null,function (success) { |
124 | //Making call to show feedback screen | ||
125 | if (screen) screen.hide(context); | ||
126 | //TODO: Add error handling logic | ||
127 | if (!success) { | ||
128 | console.log('Error!'); | ||
129 | return; | ||
130 | } | ||
93 | //Currently only supporting current browser (Chrome, obviously) | 131 | //Currently only supporting current browser (Chrome, obviously) |
94 | switch (this.browser) { | 132 | switch (this.browser) { |
95 | case 'chrome': | 133 | case 'chrome': |
@@ -111,28 +149,30 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
111 | } | 149 | } |
112 | }, | 150 | }, |
113 | //////////////////////////////////////////////////////////////////// | 151 | //////////////////////////////////////////////////////////////////// |
114 | // | 152 | //Gets all stylesheets in document |
115 | getStyleSheets: { | 153 | getStyleSheets: { |
116 | value: function () { | 154 | value: function () { |
117 | // | 155 | //Array to store styles (style and link tags) |
118 | var styles = []; | 156 | var styles = []; |
119 | // | 157 | //Looping through document sytles |
120 | for (var k in this.views.design.iframe.contentWindow.document.styleSheets) { | 158 | for (var k in this.views.design.iframe.contentWindow.document.styleSheets) { |
159 | //Check for styles to has proper propeties | ||
121 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) { | 160 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode && this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute) { |
161 | //Check for ninja-template styles, if so, exclude | ||
122 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) { | 162 | if (this.views.design.iframe.contentWindow.document.styleSheets[k].ownerNode.getAttribute('data-ninja-template') === null) { |
123 | styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]); | 163 | styles.push(this.views.design.iframe.contentWindow.document.styleSheets[k]); |
124 | } | 164 | } |
125 | } | 165 | } |
126 | } | 166 | } |
127 | // | 167 | //Returning filtered results |
128 | return styles; | 168 | return styles; |
129 | } | 169 | } |
130 | }, | 170 | }, |
131 | //////////////////////////////////////////////////////////////////// | 171 | //////////////////////////////////////////////////////////////////// |
132 | // | 172 | // |
133 | save: { | 173 | save: { |
134 | value: function (callback) { | 174 | value: function (callback, libCopyCallback) { |
135 | // | 175 | //TODO: Implement on demand logic |
136 | if (this.needsSave) { | 176 | if (this.needsSave) { |
137 | //Save | 177 | //Save |
138 | } else { | 178 | } else { |
@@ -141,8 +181,9 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
141 | // | 181 | // |
142 | if (this.currentView === this.views.design) { | 182 | if (this.currentView === this.views.design) { |
143 | // | 183 | // |
144 | this.application.ninja.ioMediator.fileSave({ | 184 | var save = this.application.ninja.ioMediator.fileSave({ |
145 | mode: 'html', | 185 | mode: 'html', |
186 | libs: this.libs, | ||
146 | file: this.file, | 187 | file: this.file, |
147 | webgl: this.webGlHelper.glData, | 188 | webgl: this.webGlHelper.glData, |
148 | styles: this.getStyleSheets(), | 189 | styles: this.getStyleSheets(), |
@@ -151,7 +192,18 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
151 | head: this.views.design.iframe.contentWindow.document.head, | 192 | head: this.views.design.iframe.contentWindow.document.head, |
152 | body: this.views.design.iframe.contentWindow.document.body, | 193 | body: this.views.design.iframe.contentWindow.document.body, |
153 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 194 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
154 | }, this.handleSaved.bind({callback: callback, model: this})); | 195 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); |
196 | //TODO: Improve detection during save routine | ||
197 | if (save) { | ||
198 | if (save.montageId) { | ||
199 | this.libs.montageId = save.montageId; | ||
200 | this.libs.montage = true; | ||
201 | } | ||
202 | if (save.canvasId) { | ||
203 | this.libs.canvasId = save.canvasId; | ||
204 | this.libs.canvas = true; | ||
205 | } | ||
206 | } | ||
155 | } else { | 207 | } else { |
156 | //TODO: Add logic to save code view data | 208 | //TODO: Add logic to save code view data |
157 | } | 209 | } |
@@ -160,8 +212,8 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
160 | //////////////////////////////////////////////////////////////////// | 212 | //////////////////////////////////////////////////////////////////// |
161 | // | 213 | // |
162 | saveAll: { | 214 | saveAll: { |
163 | value: function (callback) { | 215 | value: function (callback, libCopyCallback) { |
164 | // | 216 | //TODO: Implement on demand logic |
165 | if (this.needsSave) { | 217 | if (this.needsSave) { |
166 | //Save | 218 | //Save |
167 | } else { | 219 | } else { |
@@ -170,8 +222,9 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
170 | // | 222 | // |
171 | if (this.currentView === this.views.design) { | 223 | if (this.currentView === this.views.design) { |
172 | // | 224 | // |
173 | this.application.ninja.ioMediator.fileSave({ | 225 | var save = this.application.ninja.ioMediator.fileSave({ |
174 | mode: 'html', | 226 | mode: 'html', |
227 | libs: this.libs, | ||
175 | file: this.file, | 228 | file: this.file, |
176 | webgl: this.webGlHelper.glData, | 229 | webgl: this.webGlHelper.glData, |
177 | css: this.getStyleSheets(), | 230 | css: this.getStyleSheets(), |
@@ -180,7 +233,18 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
180 | head: this.views.design.iframe.contentWindow.document.head, | 233 | head: this.views.design.iframe.contentWindow.document.head, |
181 | body: this.views.design.iframe.contentWindow.document.body, | 234 | body: this.views.design.iframe.contentWindow.document.body, |
182 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator | 235 | mjsTemplateCreator: this.views.design.iframe.contentWindow.mjsTemplateCreator |
183 | }, this.handleSaved.bind({callback: callback, model: this})); | 236 | }, this.handleSaved.bind({callback: callback, model: this}), libCopyCallback); |
237 | //TODO: Improve detection during save routine | ||
238 | if (save) { | ||
239 | if (save.montageId) { | ||
240 | this.libs.montageId = save.montageId; | ||
241 | this.libs.montage = true; | ||
242 | } | ||
243 | if (save.canvasId) { | ||
244 | this.libs.canvasId = save.canvasId; | ||
245 | this.libs.canvas = true; | ||
246 | } | ||
247 | } | ||
184 | } else { | 248 | } else { |
185 | //TODO: Add logic to save code view data | 249 | //TODO: Add logic to save code view data |
186 | } | 250 | } |
@@ -191,47 +255,49 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
191 | // | 255 | // |
192 | saveAs: { | 256 | saveAs: { |
193 | value: function (callback) { | 257 | value: function (callback) { |
194 | // | 258 | //TODO: Implement on demand logic |
195 | if (this.needsSave) { | 259 | if (this.needsSave) { |
196 | //Save current file on memory | 260 | //Save current file on memory |
197 | } else { | 261 | } else { |
198 | //Copy file from disk | 262 | //Copy file from disk |
199 | } | 263 | } |
264 | //TODO: Add functionality | ||
200 | } | 265 | } |
201 | }, | 266 | }, |
202 | //////////////////////////////////////////////////////////////////// | 267 | //////////////////////////////////////////////////////////////////// |
203 | // | 268 | // |