diff options
Diffstat (limited to 'js/document/html-document.js')
-rwxr-xr-x | js/document/html-document.js | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js index f260b665..d38709e3 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js | |||
@@ -23,6 +23,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
23 | 23 | ||
24 | _document: { value: null, enumerable: false }, | 24 | _document: { value: null, enumerable: false }, |
25 | _documentRoot: { value: null, enumerable: false }, | 25 | _documentRoot: { value: null, enumerable: false }, |
26 | _liveNodeList: { value: null, enumarable: false }, | ||
26 | _stageBG: { value: null, enumerable: false }, | 27 | _stageBG: { value: null, enumerable: false }, |
27 | _window: { value: null, enumerable: false }, | 28 | _window: { value: null, enumerable: false }, |
28 | _styles: { value: null, enumerable: false }, | 29 | _styles: { value: null, enumerable: false }, |
@@ -403,6 +404,12 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
403 | this._document = this.iframe.contentWindow.document; | 404 | this._document = this.iframe.contentWindow.document; |
404 | this._window = this.iframe.contentWindow; | 405 | this._window = this.iframe.contentWindow; |
405 | // | 406 | // |
407 | for (var k in this._document.styleSheets) { | ||
408 | if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { | ||
409 | this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true'); | ||
410 | } | ||
411 | } | ||
412 | // | ||
406 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; | 413 | if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; |
407 | //Inserting user's document into template | 414 | //Inserting user's document into template |
408 | this._templateDocument.head.innerHTML = this._userDocument.content.head; | 415 | this._templateDocument.head.innerHTML = this._userDocument.content.head; |
@@ -411,7 +418,16 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
411 | //Adding a handler for the main user document reel to finish loading | 418 | //Adding a handler for the main user document reel to finish loading |
412 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); | 419 | this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); |
413 | 420 | ||
414 | 421 | // Live node list of the current loaded document | |
422 | this._liveNodeList = this.documentRoot.getElementsByTagName('*'); | ||
423 | |||
424 | // TODO Move this to the appropriate location | ||
425 | var len = this._liveNodeList.length; | ||
426 | |||
427 | for(var i = 0; i < len; i++) { | ||
428 | NJUtils.makeModelFromElement(this._liveNodeList[i]); | ||
429 | } | ||
430 | |||
415 | /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once | 431 | /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once |
416 | 432 | ||
417 | //TODO: When re-written, the best way to initialize the document is to listen for the DOM tree being modified | 433 | //TODO: When re-written, the best way to initialize the document is to listen for the DOM tree being modified |
@@ -438,8 +454,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
438 | cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); | 454 | cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri}); |
439 | //Creating tag with file content | 455 | //Creating tag with file content |
440 | tag = this.iframe.contentWindow.document.createElement('style'); | 456 | tag = this.iframe.contentWindow.document.createElement('style'); |
457 | tag.setAttribute('type', 'text/css'); | ||
441 | tag.setAttribute('ninjauri', fileUri); | 458 | tag.setAttribute('ninjauri', fileUri); |
442 | tag.setAttribute('ninjafileurl', cssUrl); | 459 | tag.setAttribute('ninjafileurl', cssUrl); |
460 | tag.setAttribute('ninjafilename', cssUrl.split('/')[cssUrl.split('/').length-1]); | ||
443 | tag.innerHTML = cssData.content; | 461 | tag.innerHTML = cssData.content; |
444 | //Looping through DOM to insert style tag at location of link element | 462 | //Looping through DOM to insert style tag at location of link element |
445 | query = this._templateDocument.html.querySelectorAll(['link']); | 463 | query = this._templateDocument.html.querySelectorAll(['link']); |
@@ -454,12 +472,11 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
454 | } | 472 | } |
455 | } | 473 | } |
456 | } | 474 | } |
475 | //////////////////////////////////////////////////////////////////////////// | ||
476 | //////////////////////////////////////////////////////////////////////////// | ||
457 | 477 | ||
458 | //TODO: Revisit this logic | 478 | //TODO: Check if this is needed |
459 | this._styles = this._document.styleSheets[1]; | 479 | this._stylesheets = this._document.styleSheets; |
460 | this._stylesheets = this._document.styleSheets; // Entire stlyesheets array | ||
461 | |||
462 | //console.log(this._document.styleSheets); | ||
463 | 480 | ||
464 | //////////////////////////////////////////////////////////////////////////// | 481 | //////////////////////////////////////////////////////////////////////////// |
465 | //////////////////////////////////////////////////////////////////////////// | 482 | //////////////////////////////////////////////////////////////////////////// |
@@ -566,7 +583,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
566 | enumerable: false, | 583 | enumerable: false, |
567 | value: function () { | 584 | value: function () { |
568 | //TODO: Add logic to handle save before preview | 585 | //TODO: Add logic to handle save before preview |
569 | this.save(); | 586 | this.saveAll(); |
570 | //Launching 'blank' tab for testing movie | 587 | //Launching 'blank' tab for testing movie |
571 | chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]}); | 588 | chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]}); |
572 | } | 589 | } |
@@ -578,7 +595,38 @@ exports.HTMLDocument = Montage.create(TextDocument, { | |||
578 | value: function () { | 595 | value: function () { |
579 | //TODO: Add code view logic and also styles for HTML | 596 | //TODO: Add code view logic and also styles for HTML |
580 | if (this.currentView === 'design') { | 597 | if (this.currentView === 'design') { |
581 | return {mode: 'html', document: this._userDocument, webgl: this.glData, style: this._styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; | 598 | var styles = []; |
599 | for (var k in this._document.styleSheets) { | ||
600 | if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) { | ||
601 | if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) { | ||
602 | styles.push(this._document.styleSheets[k]); | ||
603 | } | ||
604 | } | ||
605 | } | ||
606 | return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; | ||
607 | } else if (this.currentView === "code"){ | ||
608 | //TODO: Would this get call when we are in code of HTML? | ||
609 | } else { | ||
610 | //Error | ||
611 | } | ||
612 | } | ||
613 | }, | ||
614 | //////////////////////////////////////////////////////////////////// | ||
615 | // | ||
616 | saveAll: { | ||
617 | enumerable: false, | ||
618 | value: function () { | ||
619 | //TODO: Add code view logic and also styles for HTML | ||
620 | if (this.currentView === 'design') { | ||
621 | var css = []; | ||
622 | for (var k in this._document.styleSheets) { | ||
623 | if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) { | ||
624 | if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) { | ||
625 | css.push(this._document.styleSheets[k]); | ||
626 | } | ||
627 | } | ||
628 | } | ||
629 | return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; | ||
582 | } else if (this.currentView === "code"){ | 630 | } else if (this.currentView === "code"){ |
583 | //TODO: Would this get call when we are in code of HTML? | 631 | //TODO: Would this get call when we are in code of HTML? |
584 | } else { | 632 | } else { |