aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/html-document.js69
-rw-r--r--js/document/templates/montage-html/main.reel/main.js42
2 files changed, 26 insertions, 85 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 3d109fdb..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,6 +894,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
949 } 894 }
950 } 895 }
951 } 896 }
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};
952 return {mode: 'html', document: this._userDocument, 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?
@@ -972,6 +918,7 @@ exports.HTMLDocument = Montage.create(TextDocument, {
972 } 918 }
973 } 919 }
974 } 920 }
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};
975 return {mode: 'html', document: this._userDocument, 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?
diff --git a/js/document/templates/montage-html/main.reel/main.js b/js/document/templates/montage-html/main.reel/main.js
index 567f481c..019c675e 100644
--- a/js/document/templates/montage-html/main.reel/main.js
+++ b/js/document/templates/montage-html/main.reel/main.js
@@ -17,38 +17,32 @@ exports.Main = Montage.create(Component, {
17 */ 17 */
18 templateDidLoad: { 18 templateDidLoad: {
19 value: function(){ 19 value: function(){
20 window.addComponent = this.addComponentToUserDocument; 20 var self = this;
21// window.addBinding = this.addBindingToUserDocument; 21 window.addComponent = function(element, data, callback) {
22 var component;
22 23
23 // Dispatch event when this template has loaded. 24 component = require.async(data.path)
24 var newEvent = document.createEvent( "CustomEvent" ); 25 .then(function(component) {
25 newEvent.initCustomEvent( "userTemplateDidLoad", false, true ); 26 var componentRequire = component[data.name];
27 var componentInstance = componentRequire.create();
26 28
27 document.body.dispatchEvent( newEvent ); 29 componentInstance.element = element;
28
29 }
30 },
31 30
32 // Adding components to the user document by using a async require. 31 componentInstance.needsDraw = true;
33 addComponentToUserDocument:{ 32 componentInstance.ownerComponent = self;
34 value:function(element, data, callback){
35 33
36 var component; 34 callback(componentInstance, element);
35 })
36 .end();
37 37
38 component = require.async(data.path) 38 };
39 .then(function(component) {
40 var componentRequire = component[data.name];
41 var componentInstance = componentRequire.create();
42 39
43 componentInstance.element = element; 40 // Dispatch event when this template has loaded.
44 //componentInstance.deserializedFromTemplate(); 41 var newEvent = document.createEvent( "CustomEvent" );
45 componentInstance.needsDraw = true; 42 newEvent.initCustomEvent( "userTemplateDidLoad", false, true );
46 43
47 callback(componentInstance, element); 44 document.body.dispatchEvent( newEvent );
48 })
49 .end();
50 45
51 } 46 }
52 } 47 }
53