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.js65
-rw-r--r--js/document/templates/montage-html/main.reel/main.js11
-rw-r--r--js/mediators/io-mediator.js56
-rwxr-xr-xjs/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js8
5 files changed, 72 insertions, 76 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..7ab4272b 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) {
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..cbed3a99 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -532,8 +532,6 @@ function loadWebGL (e) {\n\
532 getUrlfromNinjaUrl: { 532 getUrlfromNinjaUrl: {
533 enumerable: false, 533 enumerable: false,
534 value: function (url, fileRootUrl, fileUrl) { 534 value: function (url, fileRootUrl, fileUrl) {
535 //console.log("Params: ", url, fileRootUrl, fileUrl);
536 //console.log("Getting: " + url);
537 // 535 //
538 if (url.indexOf(fileRootUrl) !== -1) { 536 if (url.indexOf(fileRootUrl) !== -1) {
539 url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); 537 url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), '');
@@ -561,13 +559,63 @@ function loadWebGL (e) {\n\
561 // 559 //
562 url = (path+newURL).replace(/\/\//gi, '/'); 560 url = (path+newURL).replace(/\/\//gi, '/');
563 } 561 }
564 //console.log("Returning: " + url);
565 //console.log("-----");
566 // 562 //
567 return url; 563 return url;
568 } 564 }
569 }, 565 },
570 //////////////////////////////////////////////////////////////////// 566 ////////////////////////////////////////////////////////////////////
567 //
568 getDocRootUrl: {
569 value: function () {
570 return this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/'));
571 }
572 },
573 ////////////////////////////////////////////////////////////////////
574 //
575 getNinjaPropUrlRedirect: {
576 enumerable: false,
577 value: function (prop/* , root */) {
578 //Checking for property value to not contain a full direct URL
579 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)) {
580 //Checking for attributes and type of source
581 if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) {
582 //From HTML attribute
583 //if (root) {
584 //prop = (root+prop).replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this));
585 //} else {
586