diff options
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/element-mediator.js | 19 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 39 |
2 files changed, 58 insertions, 0 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 9aefbca6..95aec2a3 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -105,6 +105,25 @@ exports.ElementMediator = Montage.create(NJComponent, { | |||
105 | } | 105 | } |
106 | }, | 106 | }, |
107 | 107 | ||
108 | deleteElements: { | ||
109 | value: function(items) { | ||
110 | // Add the Undo/Redo | ||
111 | var len, el; | ||
112 | |||
113 | len = items.length; | ||
114 | |||
115 | if(len) { | ||
116 | |||
117 | for(var i = len - 1; i >= 0; i--) { | ||
118 | el = items[i]._element || items[i]; | ||
119 | this._removeElement(el); | ||
120 | } | ||
121 | |||
122 | NJevent( "deleteSelection", items ); | ||
123 | } | ||
124 | } | ||
125 | }, | ||
126 | |||
108 | _removeElement: { | 127 | _removeElement: { |
109 | value: function(el, rules) { | 128 | value: function(el, rules) { |
110 | ElementController.removeElement(el, rules); | 129 | ElementController.removeElement(el, rules); |
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 | }); |