aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/controllers/document-controller.js8
-rwxr-xr-xjs/document/html-document.js73
-rw-r--r--js/document/templates/montage-html/main.reel/main.js11
-rw-r--r--js/mediators/io-mediator.js58
-rwxr-xr-xjs/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js8
5 files changed, 78 insertions, 80 deletions
diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js
index 539fd13e..d5556fa8 100755
--- a/js/controllers/document-controller.js
+++ b/js/controllers/document-controller.js
@@ -64,10 +64,16 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
64 64
65 this.eventManager.addEventListener("styleSheetDirty", this, false); 65 this.eventManager.addEventListener("styleSheetDirty", this, false);
66 66
67 this.eventManager.addEventListener("addComponentFirstDraw", this, false);
67 } 68 }
68 }, 69 },
69 70
70 71 handleAddComponentFirstDraw: {
72 value: function (e) {
73 //TODO: Add logic to reparse the document for dynamically added styles
74 console.log(e);
75 }
76 },
71 77
72 78
73 79
diff --git a/js/document/html-document.js b/js/document/html-document.js
index aa57d848..8f9d2870 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -564,67 +564,13 @@ exports.HTMLDocument = Montage.create(TextDocument, {
564 } 564 }
565 // 565 //
566 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; 566 if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {};
567 //Inserting user's document into template
568
569
570
571
572
573
574
575
576
577 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
578 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
579 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
580
581 //TODO: Clean up and make public method to prepend properties with Ninja URL
582 this._templateDocument.head.innerHTML = (this._userDocument.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, ninjaUrlRedirect.bind(this))).replace(/url\(([^"]*)(.+?)\1\)/g, ninjaUrlRedirect.bind(this));
583 this._templateDocument.body.innerHTML = (this._userDocument.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, ninjaUrlRedirect.bind(this))).replace(/url\(([^"]*)(.+?)\1\)/g, ninjaUrlRedirect.bind(this));
584 //
585 //var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
586 //
587 function ninjaUrlRedirect (prop) {
588 //Checking for property value to not contain a full direct URL
589 if (!prop.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
590 //Checking for attributes and type of source
591 if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { //From HTML attribute
592 //
593 prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this));
594 } else if (prop.indexOf('url') !== -1) { //From CSS property
595 //TODO: Add functionality
596 var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
597 prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl);
598 function cssUrlToNinjaUrl (s) {
599 if (s !== 'url') {
600 s = docRootUrl + s;
601 }
602 return s;
603 }
604 }
605 }
606 return prop;
607 }
608 //
609 function ninjaUrlPrepend (url) {
610 var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
611 if (url.indexOf('data:image') !== -1) {
612 return url;
613 } else {
614 return '"'+docRootUrl+url.replace(/\"/gi, '')+'"';
615 }
616 }
617 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
618 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
619 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
620
621
622
623
624
625 567
626 568
627 569
570 //TODO: Clean up, using for prototyping
571 this._templateDocument.head.innerHTML = (this._userDocument.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator));
572 this._templateDocument.body.innerHTML = (this._userDocument.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator));
573
628 574
629 575
630 var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll 576 var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll
@@ -647,7 +593,6 @@ exports.HTMLDocument = Montage.create(TextDocument, {
647 593
648 594
649 595
650
651 //Temporarily checking for disabled special case 596 //Temporarily checking for disabled special case
652 var stags = this.iframe.contentWindow.document.getElementsByTagName('style'), 597 var stags = this.iframe.contentWindow.document.getElementsByTagName('style'),
653 ltags = this.iframe.contentWindow.document.getElementsByTagName('link'); 598 ltags = this.iframe.contentWindow.document.getElementsByTagName('link');
@@ -672,7 +617,6 @@ exports.HTMLDocument = Montage.create(TextDocument, {
672 617
673 618
674 619
675
676 //Adding a handler for the main user document reel to finish loading 620 //Adding a handler for the main user document reel to finish loading
677 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); 621 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
678 622
@@ -731,6 +675,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
731 // 675 //
732 fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; 676 fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0];
733 677
678 //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT
734 tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); 679 tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl);
735 680
736 function detectUrl (prop) { 681 function detectUrl (prop) {
@@ -926,7 +871,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
926 //TODO: Add logic to handle save before preview 871 //TODO: Add logic to handle save before preview
927 this.application.ninja.documentController.handleExecuteSaveAll(null); 872 this.application.ninja.documentController.handleExecuteSaveAll(null);
928 //Temp check for webGL Hack 873 //Temp check for webGL Hack
929 if (this.application.ninja.documentController.activeDocument.glData.length && this.application.ninja.documentController.activeDocument.glData.length > 0) { 874 if (this.application.ninja.documentController.activeDocument.glData.length && this.application.ninja.documentController.activeDocument.glData.length > 1) {//TODO: Should be 0, temp hack fix
930 setTimeout(function () {window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);}.bind(this), 3500); 875 setTimeout(function () {window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);}.bind(this), 3500);
931 } else { 876 } else {
932 window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]); 877 window.open(this.application.ninja.coreIoApi.rootUrl+this.application.ninja.documentController._activeDocument.uri.split(this.application.ninja.coreIoApi.cloudData.root)[1]);
@@ -949,7 +894,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
949 } 894 }
950 } 895 }
951 } 896 }
952 return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 897 //return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
898 return {mode: 'html', document: this._userDocument, webgl: this.glData, styles: styles, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
953 } else if (this.currentView === "code"){ 899 } else if (this.currentView === "code"){
954 //TODO: Would this get call when we are in code of HTML? 900 //TODO: Would this get call when we are in code of HTML?
955 } else { 901 } else {
@@ -972,7 +918,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
972 } 918 }
973 } 919 }
974 } 920 }
975 return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML}; 921 //return {mode: 'html', document: this._userDocument, mjs: this._userComponents, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
922 return {mode: 'html', document: this._userDocument, webgl: this.glData, css: css, head: this._templateDocument.head.innerHTML, body: this._templateDocument.body.innerHTML};
976 } else if (this.currentView === "code"){ 923 } else if (this.currentView === "code"){
977 //TODO: Would this get call when we are in code of HTML? 924 //TODO: Would this get call when we are in code of HTML?
978 } else { 925 } else {
diff --git a/js/document/templates/montage-html/main.reel/main.js b/js/document/templates/montage-html/main.reel/main.js
index 2970f37a..019c675e 100644
--- a/js/document/templates/montage-html/main.reel/main.js
+++ b/js/document/templates/montage-html/main.reel/main.js
@@ -31,8 +31,6 @@ exports.Main = Montage.create(Component, {
31 componentInstance.needsDraw = true; 31 componentInstance.needsDraw = true;
32 componentInstance.ownerComponent = self; 32 componentInstance.ownerComponent = self;
33 33
34 componentInstance.addEventListener("firstDraw", self, false);
35
36 callback(componentInstance, element); 34 callback(componentInstance, element);
37 }) 35 })
38 .end(); 36 .end();
@@ -46,14 +44,5 @@ exports.Main = Montage.create(Component, {
46 document.body.dispatchEvent( newEvent ); 44 document.body.dispatchEvent( newEvent );
47 45
48 } 46 }
49 },
50
51 handleFirstDraw: {
52 value: function() {
53 var newEvent = document.createEvent( "CustomEvent" );
54 newEvent.initCustomEvent( "addComponentFirstDraw", false, true );
55
56 document.body.dispatchEvent( newEvent );
57 }
58 } 47 }
59}); \ No newline at end of file 48}); \ No newline at end of file
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 18a517a5..1efbb8bb 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -348,7 +348,7 @@ exports.IoMediator = Montage.create(Component, {
348 } 348 }
349