diff options
author | Jose Antonio Marquez | 2012-02-28 15:03:23 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-28 15:03:23 -0800 |
commit | 2ce9f65c3a34937928f08690606962af3085c74f (patch) | |
tree | 89399786aa88cdc2e0d7012a757f8316647a8d20 /js | |
parent | 933ed4c880128eed80bdc6372eb1dfdb23af4c37 (diff) | |
download | ninja-2ce9f65c3a34937928f08690606962af3085c74f.tar.gz |
CSS attributes
Setting up logic to include attributes in <link> for the <style> duplicates and add attributes created in Ninja back to <link> tag on save.
Diffstat (limited to 'js')
-rwxr-xr-x | js/document/html-document.js | 35 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 27 |
2 files changed, 61 insertions, 1 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index 75628731..6853f4d7 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -409,6 +409,33 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
409 | } | 409 | } |
410 | 410 | ||
411 | 411 | ||
412 | |||
413 | |||
414 | //Temporarily checking for disabled special case | ||
415 | var stags = this.iframe.contentWindow.document.getElementsByTagName('style'), | ||
416 | ltags = this.iframe.contentWindow.document.getElementsByTagName('link'); | ||
417 | // | ||
418 | for (var m = 0; m < ltags.length; m++) { | ||
419 | if (ltags[m].getAttribute('data-ninja-template') === null) { | ||
420 | if (ltags[m].getAttribute('disabled')) { | ||
421 | ltags[m].removeAttribute('disabled'); | ||
422 | ltags[m].setAttribute('data-ninja-disabled', 'true'); | ||
423 | } | ||
424 | } | ||
425 | } | ||
426 | // | ||
427 | for (var n = 0; n < stags.length; n++) { | ||
428 | if (stags[n].getAttribute('data-ninja-template') === null) { | ||
429 | if (stags[n].getAttribute('disabled')) { | ||
430 | stags[n].removeAttribute('disabled'); | ||
431 | stags[n].setAttribute('data-ninja-disabled', 'true'); | ||
432 | } | ||
433 | } | ||
434 | } | ||
435 | |||
436 | |||
437 | |||
438 | |||
412 | //Adding a handler for the main user document reel to finish loading | 439 | //Adding a handler for the main user document reel to finish loading |
413 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); | 440 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); |
414 | 441 | ||
@@ -428,7 +455,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
428 | setTimeout(function () { | 455 | setTimeout(function () { |
429 | 456 | ||
430 | 457 | ||
431 | |||
432 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 458 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
433 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 459 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
434 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | 460 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -453,6 +479,12 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
453 | tag.setAttribute('data-ninja-file-url', cssUrl); | 479 | tag.setAttribute('data-ninja-file-url', cssUrl); |
454 | tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); | 480 | tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); |
455 | tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); | 481 | tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); |
482 | //Copying attributes to maintain same properties as the <link> | ||
483 | for (var n in this._document.styleSheets[i].ownerNode.attributes) { | ||
484 | if (this._document.styleSheets[i].ownerNode.attributes[n].value && this._document.styleSheets[i].ownerNode.attributes[n].name !== 'disabled') { | ||
485 | tag.setAttribute(this._document.styleSheets[i].ownerNode.attributes[n].name, this._document.styleSheets[i].ownerNode.attributes[n].value); | ||
486 | } | ||
487 | } | ||
456 | tag.innerHTML = cssData.content; | 488 | tag.innerHTML = cssData.content; |
457 | //Looping through DOM to insert style tag at location of link element | 489 | //Looping through DOM to insert style tag at location of link element |
458 | query = this._templateDocument.html.querySelectorAll(['link']); | 490 | query = this._templateDocument.html.querySelectorAll(['link']); |
@@ -465,6 +497,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
465 | } | 497 | } |
466 | } | 498 | } |
467 | } else { | 499 | } else { |
500 | console.log('ERROR: Cross-Domain-Stylesheet detected, unable to load in Ninja'); | ||
468 | /* | 501 | /* |
469 | //None local stylesheet, probably on a CDN (locked) | 502 | //None local stylesheet, probably on a CDN (locked) |
470 | tag = this.iframe.contentWindow.document.createElement('style'); | 503 | tag = this.iframe.contentWindow.document.createElement('style'); |
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 | } |