diff options
author | Valerio Virgillito | 2012-02-28 15:16:12 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-28 15:16:12 -0800 |
commit | ee52f197d1eb53a5ff30b54b8df1d2b53014eb0e (patch) | |
tree | d7f55a3552b363b3a82857491e8acdd7b48f2a80 /js/mediators/io-mediator.js | |
parent | 8e370cc72aa85de594a5d55ae89947a70af414ca (diff) | |
parent | da83f44b0ecf379b0950a88d1c378fbedb80e386 (diff) | |
download | ninja-ee52f197d1eb53a5ff30b54b8df1d2b53014eb0e.tar.gz |
Merge pull request #80 from joseeight/FileIO-Build-Candidate
Adding CSS <link> attributes support to I/O
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r-- | js/mediators/io-mediator.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 733e44b2..6b26668b 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -260,6 +260,17 @@ exports.IoMediator = Montage.create(Component, { | |||
260 | var styleCounter = 0, | 260 | var styleCounter = 0, |
261 | docStyles = template.document.content.document.getElementsByTagName('style'), | 261 | docStyles = template.document.content.document.getElementsByTagName('style'), |
262 | docLinks = template.document.content.document.getElementsByTagName('link'); | 262 | docLinks = template.document.content.document.getElementsByTagName('link'); |
263 | //Removing Ninja Data Attributes | ||
264 | for (var n in docLinks) { | ||
265 | if (docLinks[n].attributes) { | ||
266 | for (var m in docLinks[n].attributes) { | ||
267 | if (docLinks[n].attributes[m].name && docLinks[n].attributes[m].name.indexOf('data-ninja')!=-1) { | ||
268 | docLinks[n].removeAttribute(docLinks[n].attributes[m].name); | ||
269 | } | ||
270 | } | ||
271 | } | ||
272 | } | ||
273 | // | ||
263 | for(var i in template.css) { | 274 | for(var i in template.css) { |
264 | if (template.css[i].ownerNode) { | 275 | if (template.css[i].ownerNode) { |
265 | if (template.css[i].ownerNode.getAttribute) { | 276 | if (template.css[i].ownerNode.getAttribute) { |
@@ -268,6 +279,22 @@ exports.IoMediator = Montage.create(Component, { | |||
268 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); | 279 | docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); |
269 | styleCounter++; | 280 | styleCounter++; |
270 | } else { | 281 | } else { |
282 | //Checking for attributes to be added to tag upon saving | ||
283 | for (var k in docLinks) { | ||
284 | if (docLinks[k].getAttribute) { | ||
285 | if (docLinks[k].getAttribute('href') && ('/'+docLinks[k].getAttribute('href')) === template.css[i].ownerNode.getAttribute('data-ninja-file-url')) { | ||
286 | for (var l in template.css[i].ownerNode.attributes) { | ||
287 | if (template.css[i].ownerNode.attributes[l].value) { | ||
288 | if (template.css[i].ownerNode.attributes[l].name.indexOf('data-ninja')!=-1) { | ||
289 | //Ninja attribute... | ||
290 | } else { | ||
291 | docLinks[k].setAttribute(template.css[i].ownerNode.attributes[l].name, template.css[i].ownerNode.attributes[l].value); | ||
292 | } | ||
293 | } | ||
294 | } | ||
295 | } | ||
296 | } | ||
297 | } | ||
271 | //Saving data from rules array converted to string into <link> file | 298 | //Saving data from rules array converted to string into <link> file |
272 | var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('data-ninja-uri'), contents: this.getCssFromRules(template.css[i].cssRules)}); | 299 | var save = this.fio.saveFile({uri: template.css[i].ownerNode.getAttribute('data-ninja-uri'), contents: this.getCssFromRules(template.css[i].cssRules)}); |
273 | } | 300 | } |