aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js26
1 files changed, 25 insertions, 1 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index deb748c7..35e0ca5a 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -144,6 +144,9 @@ exports.IoMediator = Montage.create(Component, {
144 case 'html': 144 case 'html':
145 file.document.content.document.body.innerHTML = file.body; 145 file.document.content.document.body.innerHTML = file.body;
146 file.document.content.document.head.innerHTML = file.head; 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 }
147 contents = file.document.content.document.documentElement.outerHTML; 150 contents = file.document.content.document.documentElement.outerHTML;
148 break; 151 break;
149 default: 152 default:
@@ -151,7 +154,6 @@ exports.IoMediator = Montage.create(Component, {
151 } 154 }
152 // 155 //
153 save = this.fio.saveFile({uri: file.document.uri, contents: contents}) 156 save = this.fio.saveFile({uri: file.document.uri, contents: contents})
154 console.log(save);
155 } 157 }
156 }, 158 },
157 //////////////////////////////////////////////////////////////////// 159 ////////////////////////////////////////////////////////////////////
@@ -174,6 +176,28 @@ exports.IoMediator = Montage.create(Component, {
174 //Creating return object 176 //Creating return object
175 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc}; 177 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc};
176 } 178 }
179 },
180 ////////////////////////////////////////////////////////////////////
181 //Method to return a string from CSS rules (to be saved to a file)
182 getCssFromRules: {
183 enumerable: false,
184 value: function (list) {
185 //Variable to store CSS definitions
186 var i, str, css = '';
187 //Looping through list
188 if (list && list.length > 0) {
189 //Adding each list item to string and also adding breaks
190 for (i = 0; list[i]; i++) {
191 str = list[i].cssText+' ';
192 str = str.replace( new RegExp( "{", "gi" ), "{\n\t" );
193 str = str.replace( new RegExp( "}", "gi" ), "}\n" );
194 str = str.replace( new RegExp( ";", "gi" ), ";\n\t" );
195 css += '\n'+str;
196 }
197 }
198 //Returning the CSS string
199 return css;
200 }
177 } 201 }
178 //////////////////////////////////////////////////////////////////// 202 ////////////////////////////////////////////////////////////////////
179}); 203});