From d87cded11dcc0faf41a4a3e6b587e5549c0da6df Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 22 Mar 2012 16:23:40 -0700 Subject: Adding Ninja URL method to io-mediator --- js/document/html-document.js | 65 ++++---------------------------------------- js/mediators/io-mediator.js | 56 +++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 64 deletions(-) diff --git a/js/document/html-document.js b/js/document/html-document.js index d4db6e2f..ed1569d4 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -520,67 +520,13 @@ exports.HTMLDocument = Montage.create(TextDocument, { } // if(!this.documentRoot.Ninja) this.documentRoot.Ninja = {}; - //Inserting user's document into template - - - - - - - - - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - //TODO: Clean up and make public method to prepend properties with Ninja URL - 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)); - 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)); - // - //var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - // - function ninjaUrlRedirect (prop) { - //Checking for property value to not contain a full direct URL - 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)) { - //Checking for attributes and type of source - if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { //From HTML attribute - // - prop = prop.replace(/"([^"]*)"/gi, ninjaUrlPrepend.bind(this)); - } else if (prop.indexOf('url') !== -1) { //From CSS property - //TODO: Add functionality - var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl); - function cssUrlToNinjaUrl (s) { - if (s !== 'url') { - s = docRootUrl + s; - } - return s; - } - } - } - return prop; - } - // - function ninjaUrlPrepend (url) { - var docRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); - if (url.indexOf('data:image') !== -1) { - return url; - } else { - return '"'+docRootUrl+url.replace(/\"/gi, '')+'"'; - } - } - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - - - + //TODO: Clean up, using for prototyping + 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)); + 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)); + var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; //TODO: Use querySelectorAll @@ -603,7 +549,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { - //Temporarily checking for disabled special case var stags = this.iframe.contentWindow.document.getElementsByTagName('style'), ltags = this.iframe.contentWindow.document.getElementsByTagName('link'); @@ -628,7 +573,6 @@ exports.HTMLDocument = Montage.create(TextDocument, { - //Adding a handler for the main user document reel to finish loading this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); @@ -687,6 +631,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { // fileCouldDirUrl = this._document.styleSheets[i].href.split(this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1])[0]; + //TODO: Make public version of this.application.ninja.ioMediator.getNinjaPropUrlRedirect with dynamic ROOT tag.innerHTML = cssData.content.replace(/url\(()(.+?)\1\)/g, detectUrl); function detectUrl (prop) { diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index d81f4543..df0a41df 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -470,8 +470,6 @@ function loadWebGL (e) {\n\ getUrlfromNinjaUrl: { enumerable: false, value: function (url, fileRootUrl, fileUrl) { - //console.log("Params: ", url, fileRootUrl, fileUrl); - //console.log("Getting: " + url); // if (url.indexOf(fileRootUrl) !== -1) { url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); @@ -499,13 +497,63 @@ function loadWebGL (e) {\n\ // url = (path+newURL).replace(/\/\//gi, '/'); } - //console.log("Returning: " + url); - //console.log("-----"); // return url; } }, //////////////////////////////////////////////////////////////////// + // + getDocRootUrl: { + value: function () { + return this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]).replace(/\/\//gi, '/')); + } + }, + //////////////////////////////////////////////////////////////////// + // + getNinjaPropUrlRedirect: { + enumerable: false, + value: function (prop/* , root */) { + //Checking for property value to not contain a full direct URL + 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)) { + //Checking for attributes and type of source + if (prop.indexOf('href') !== -1 || prop.indexOf('src') !== -1) { + //From HTML attribute + //if (root) { + //prop = (root+prop).replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this)); + //} else { + prop = prop.replace(/"([^"]*)"/gi, this.getNinjaUrlPrepend.bind(this)); + //} + } else if (prop.indexOf('url') !== -1) { + //From CSS property + //if (root) { + //prop = (root+prop).replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this)); + //} else { + prop = prop.replace(/[^()\\""\\'']+/g, cssUrlToNinjaUrl.bind(this)); + //} + function cssUrlToNinjaUrl (s) { + if (s !== 'url') { + s = this.getDocRootUrl() + s; + } + return s; + } + } + } + return prop; + } + }, + //////////////////////////////////////////////////////////////////// + // + getNinjaUrlPrepend: { + enumerable: false, + value: function (url) { + if (url.indexOf('data:') !== -1) { + return url; + } else { + return '"'+this.getDocRootUrl()+url.replace(/\"/gi, '')+'"'; + } + } + }, + //////////////////////////////////////////////////////////////////// //Method to return a string from CSS rules (to be saved to a file) getCssFromRules: { enumerable: false, -- cgit v1.2.3 From 6c61c52bd86c90ce16107a6381ff242de9032211 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 26 Apr 2012 10:12:58 -0700 Subject: Fixing duplicate layer bug --- js/mediators/drag-drop-mediator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js index eedab8fc..12f8dc70 100755 --- a/js/mediators/drag-drop-mediator.js +++ b/js/mediators/drag-drop-mediator.js @@ -133,7 +133,7 @@ exports.DragDropMediator = Montage.create(Component, { 'left' : (parseInt(e.currentTarget.filePosition.x) - parseInt(this.application.ninja.stage.userContentLeft)) + 'px' }; // - self.application.ninja.elementMediator.addElements(element, rules); + //self.application.ninja.elementMediator.addElements(element, rules); } else { //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT } -- cgit v1.2.3 From 7f5eb2105c2e5e0970072af88fa90baded7e55d6 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 26 Apr 2012 11:05:24 -0700 Subject: Fixing duplicate layer error --- js/mediators/drag-drop-mediator.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js index 12f8dc70..b0aba5b6 100755 --- a/js/mediators/drag-drop-mediator.js +++ b/js/mediators/drag-drop-mediator.js @@ -115,25 +115,25 @@ exports.DragDropMediator = Montage.create(Component, { // if (e.currentTarget.fileType.indexOf('svg') !== -1) { element = NJUtils.makeNJElement('embed', 'SVG', 'block');//TODO: Verify this is proper + element.type = 'image/svg+xml'; element.src = url+'/'+fileName; - element.type = 'image/svg+xml'; } else { element = NJUtils.makeNJElement('image', 'image', 'image'); element.src = url+'/'+fileName; } - //TODO: Remove temp fix for elements to redraw on drop - + //Adding element once it is loaded element.onload = function () { - self.application.ninja.elementMediator.addElements(element, rules); + element.onload = null; + self.application.ninja.elementMediator.addElements(element, rules, true); }; - // + //Setting rules of element rules = { 'position': 'absolute', 'top' : (parseInt(e.currentTarget.filePosition.y) - parseInt(this.application.ninja.stage.userContentTop)) + 'px', 'left' : (parseInt(e.currentTarget.filePosition.x) - parseInt(this.application.ninja.stage.userContentLeft)) + 'px' }; - // - //self.application.ninja.elementMediator.addElements(element, rules); + // + self.application.ninja.elementMediator.addElements(element, rules, false); } else { //TODO: HANDLE ERROR ON SAVING FILE TO BE ADDED AS ELEMENT } -- cgit v1.2.3