diff options
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r-- | js/mediators/io-mediator.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 2f286e5e..47069cfb 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -138,6 +138,23 @@ exports.IoMediator = Montage.create(Component, { | |||
138 | enumerable: false, | 138 | enumerable: false, |
139 | value: function (file, callback) { | 139 | value: function (file, callback) { |
140 | // | 140 | // |
141 | var contents, save; | ||
142 | // | ||
143 | switch (file.mode) { | ||
144 | case 'html': | ||
145 | file.document.content.document.body.innerHTML = file.body; | ||
146 | file.document.content.document.head.innerHTML = file.head; | ||
147 | if (file.style) { | ||
148 | file.document.content.document.head.getElementsByTagName('style')[0].innerHTML = this.getCssFromRules(file.style.cssRules); | ||
149 | } | ||
150 | contents = file.document.content.document.documentElement.outerHTML; | ||
151 | break; | ||
152 | default: | ||
153 | contents = file.content; | ||
154 | break; | ||
155 | } | ||
156 | // | ||
157 | save = this.fio.saveFile({uri: file.document.uri, contents: contents}) | ||
141 | } | 158 | } |
142 | }, | 159 | }, |
143 | //////////////////////////////////////////////////////////////////// | 160 | //////////////////////////////////////////////////////////////////// |
@@ -160,6 +177,28 @@ exports.IoMediator = Montage.create(Component, { | |||
160 | //Creating return object | 177 | //Creating return object |
161 | return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc}; | 178 | return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc}; |
162 | } | 179 | } |
180 | }, | ||
181 | //////////////////////////////////////////////////////////////////// | ||
182 | //Method to return a string from CSS rules (to be saved to a file) | ||
183 | getCssFromRules: { | ||
184 | enumerable: false, | ||
185 | value: function (list) { | ||
186 | //Variable to store CSS definitions | ||
187 | var i, str, css = ''; | ||
188 | //Looping through list | ||
189 | if (list && list.length > 0) { | ||
190 | //Adding each list item to string and also adding breaks | ||
191 | for (i = 0; list[i]; i++) { | ||
192 | str = list[i].cssText+' '; | ||
193 | str = str.replace( new RegExp( "{", "gi" ), "{\n\t" ); | ||
194 | str = str.replace( new RegExp( "}", "gi" ), "}\n" ); | ||
195 | str = str.replace( new RegExp( ";", "gi" ), ";\n\t" ); | ||
196 | css += '\n'+str; | ||
197 | } | ||
198 | } | ||
199 | //Returning the CSS string | ||
200 | return css; | ||
201 | } | ||
163 | } | 202 | } |
164 | //////////////////////////////////////////////////////////////////// | 203 | //////////////////////////////////////////////////////////////////// |
165 | }); | 204 | }); |