aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js106
-rwxr-xr-xjs/document/templates/montage-html/index.html1
-rwxr-xr-xjs/document/templates/montage-html/styles.css5
3 files changed, 96 insertions, 16 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index f5816f64..6394e3ce 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 },
@@ -352,29 +353,44 @@ exports.HTMLDocument = Montage.create(TextDocument, {
352 value: function(event){ 353 value: function(event){
353 //TODO: Clean up, using for prototyping save 354 //TODO: Clean up, using for prototyping save
354 this._templateDocument = {}; 355 this._templateDocument = {};
356 this._templateDocument.html = this.iframe.contentWindow.document;
355 this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead"); 357 this._templateDocument.head = this.iframe.contentWindow.document.getElementById("userHead");
356 this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent"); 358 this._templateDocument.body = this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent");
357 //TODO: Remove, also for prototyping 359 //TODO: Remove, also for prototyping
358 this.application.ninja.documentController._hackRootFlag = true; 360 this.application.ninja.documentController._hackRootFlag = true;
359 // 361 //
360 //this.documentRoot = this.iframe.contentWindow.document.getElementById("UserContent");
361 this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG"); 362 this.stageBG = this.iframe.contentWindow.document.getElementById("stageBG");
362 this.stageBG.onclick = null; 363 this.stageBG.onclick = null;
363 this._document = this.iframe.contentWindow.document; 364 this._document = this.iframe.contentWindow.document;
364 this._window = this.iframe.contentWindow; 365 this._window = this.iframe.contentWindow;
365 // 366 //
366 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 367 for (var k in this._document.styleSheets) {
368 if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) {
369 this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true');
370 }
371 }
367 // 372 //
373 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
374 //Inserting user's document into template
368 this._templateDocument.head.innerHTML = this._userDocument.content.head; 375 this._templateDocument.head.innerHTML = this._userDocument.content.head;
369 this._templateDocument.body.innerHTML = this._userDocument.content.body; 376 this._templateDocument.body.innerHTML = this._userDocument.content.body;
370 377
371 // Adding a handler for the main user document reel to finish loading. 378 //Adding a handler for the main user document reel to finish loading
372 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); 379 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
373 380
374 381 // Live node list of the current loaded document
382 this._liveNodeList = this.documentRoot.getElementsByTagName('*');
383
384 // TODO Move this to the appropriate location
385 var len = this._liveNodeList.length;
386
387 for(var i = 0; i < len; i++) {
388 NJUtils.makeModelFromElement(this._liveNodeList[i]);
389 }
390
375 /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once 391 /* this.iframe.contentWindow.document.addEventListener('DOMSubtreeModified', function (e) { */ //TODO: Remove events upon loading once
376 392
377 //TODO: When written, the best way to initialize the document is to listen for the DOM tree being modified 393 //TODO: When re-written, the best way to initialize the document is to listen for the DOM tree being modified
378 setTimeout(function () { 394 setTimeout(function () {
379 395
380 396
@@ -383,8 +399,47 @@ exports.HTMLDocument = Montage.create(TextDocument, {
383 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 399 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
384 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 400 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
385 if(this._document.styleSheets.length > 1) { 401 if(this._document.styleSheets.length > 1) {
386 this._styles = this._document.styleSheets[this._document.styleSheets.length - 1]; 402 //Checking all styleSheets in document
387 this._stylesheets = this._document.styleSheets; // Entire stlyesheets array 403 for (var i in this._document.styleSheets) {
404 //If rules are null, assuming cross-origin issue
405 if(this._document.styleSheets[i].rules === null) {
406 //TODO: Revisit URLs and URI creation logic, very hack right now
407 var fileUri, cssUrl, cssData, tag, query;
408 if (this._document.styleSheets[i].href.indexOf('js/document/templates/montage-html') !== -1) {
409 //Getting the url of the CSS file
410 cssUrl = this._document.styleSheets[i].href.split('js/document/templates/montage-html')[1];
411 //Creating the URI of the file (this is wrong should not be splitting cssUrl)
412 fileUri = this.application.ninja.coreIoApi.cloudData.root+this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+cssUrl.split('/')[1];
413 //Loading the data from the file
414 cssData = this.application.ninja.coreIoApi.readFile({uri: fileUri});
415 //Creating tag with file content
416 tag = this.iframe.contentWindow.document.createElement('style');
417 tag.setAttribute('type', 'text/css');
418 tag.setAttribute('ninjauri', fileUri);
419 tag.setAttribute('ninjafileurl', cssUrl);
420 tag.setAttribute('ninjafilename', cssUrl.split('/')[cssUrl.split('/').length-1]);
421 tag.innerHTML = cssData.content;
422 //Looping through DOM to insert style tag at location of link element
423 query = this._templateDocument.html.querySelectorAll(['link']);
424 for (var j in query) {
425 if (query[j].href === this._document.styleSheets[i].href) {
426 //Disabling style sheet to reload via inserting in style tag
427 query[j].setAttribute('disabled', 'true');
428 //Inserting tag
429 this._templateDocument.head.insertBefore(tag, query[j]);
430 }
431 }
432 }
433 }
434 }
435 ////////////////////////////////////////////////////////////////////////////
436 ////////////////////////////////////////////////////////////////////////////
437
438 //TODO: Check if this is needed
439 this._stylesheets = this._document.styleSheets;
440
441 ////////////////////////////////////////////////////////////////////////////
442 ////////////////////////////////////////////////////////////////////////////
388 443
389 //TODO Finish this implementation once we start caching Core Elements 444 //TODO Finish this implementation once we start caching Core Elements
390 // Assign a model to the UserContent and add the ViewPort reference to it. 445 // Assign a model to the UserContent and add the ViewPort reference to it.
@@ -488,7 +543,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
488 enumerable: false, 543 enumerable: false,
489 value: function () { 544 value: function () {
490 //TODO: Add logic to handle save before preview 545 //TODO: Add logic to handle save before preview
491 this.save(); 546 this.saveAll();
492 //Launching 'blank' tab for testing movie 547 //Launching 'blank' tab for testing movie
493 chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]}); 548 chrome.tabs.create({url: this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]});
494 } 549 }
@@ -500,7 +555,38 @@ exports.HTMLDocument = Montage.create(TextDocument, {
500 value: function () { 555 value: function () {
501 //TODO: Add code view logic and also styles for HTML 556 //TODO: Add code view logic and also styles for HTML
502 if (this.currentView === 'design') { 557 if (this.currentView === 'design') {
503 return {mode: 'html', document: this._userDocument, webgl: this.glData, style: this._styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 558 var styles = [];
559 for (var k in this._document.styleSheets) {
560 if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) {
561 if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) {
562 styles.push(this._document.styleSheets[k]);
563 }
564 }
565 }
566 return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
567 } else if (this.currentView === "code"){
568 //TODO: Would this get call when we are in code of HTML?
569 } else {
570 //Error
571 }
572 }
573 },
574 ////////////////////////////////////////////////////////////////////
575 //
576 saveAll: {
577 enumerable: false,
578 value: function () {
579 //TODO: Add code view logic and also styles for HTML
580 if (this.currentView === 'design') {
581 var css = [];
582 for (var k in this._document.styleSheets) {
583 if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.getAttribute) {
584 if (this._document.styleSheets[k].ownerNode.getAttribute('ninjatemplate') === null) {
585 css.push(this._document.styleSheets[k]);
586 }
587 }
588 }
589 return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
504 } else if (this.currentView === "code"){ 590 } else if (this.currentView === "code"){
505 //TODO: Would this get call when we are in code of HTML? 591 //TODO: Would this get call when we are in code of HTML?
506 } else { 592 } 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