aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorAnanya Sen2012-02-23 13:52:32 -0800
committerAnanya Sen2012-02-23 13:52:32 -0800
commitec3d07c2fea4e79c68606234074f43d694982e5b (patch)
treedc7c830c361d35c04a4d9b6d55c6c36d7a5d61cd /js/document
parent7283884c39df537694b21419a3ea9e3ca7793b4b (diff)
parent287a0bad5b774a380ec6c8b3ddf24dc03234e248 (diff)
downloadninja-ec3d07c2fea4e79c68606234074f43d694982e5b.tar.gz
Merge branch 'refs/heads/FileIO-jose' into FileIO
Conflicts: js/document/html-document.js js/helper-classes/3D/snap-manager.js Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js64
-rwxr-xr-xjs/document/templates/montage-html/index.html1
-rwxr-xr-xjs/document/templates/montage-html/styles.css5
3 files changed, 56 insertions, 14 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 {
diff --git a/js/document/templates/montage-html/index.html b/js/document/templates/montage-html/index.html
index 8b3d73bb..edfab2b0 100755
--- a/js/document/templates/montage-html/index.html
+++ b/js/document/templates/montage-html/index.html
@@ -12,7 +12,6 @@
12 <title>Ninja Prototype</title> 12 <title>Ninja Prototype</title>
13 13
14 <link href="default_html.css" id="nj-stage-stylesheet" rel="stylesheet" type="text/css" media="screen"/> 14 <link href="default_html.css" id="nj-stage-stylesheet" rel="stylesheet" type="text/css" media="screen"/>
15 <link href="styles.css" id="nj-default-stylesheet" rel="stylesheet" type="text/css" media="screen"/>
16 15
17 <script type="text/javascript" data-package="." src="../../../../node_modules/montage/montage.js"></script> 16 <script type="text/javascript" data-package="." src="../../../../node_modules/montage/montage.js"></script>
18 17
diff --git a/js/document/templates/montage-html/styles.css b/js/document/templates/montage-html/styles.css
deleted file mode 100755
index 0441c1cf..00000000
--- a/js/document/templates/montage-html/styles.css
+++ /dev/null
@@ -1,5 +0,0 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ \ No newline at end of file