diff options
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 5917edba..c02710c2 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -213,9 +213,11 @@ exports.IoMediator = Montage.create(Component, { | |||
213 | parseNinjaTemplateToHtml: { | 213 | parseNinjaTemplateToHtml: { |
214 | enumerable: false, | 214 | enumerable: false, |
215 | value: function (template) { | 215 | value: function (template) { |
216 | var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); | ||
217 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); | ||
216 | //Injecting head and body into old document | 218 | //Injecting head and body into old document |
217 | template.document.content.document.head.innerHTML = template.head; | 219 | template.document.content.document.head.innerHTML = template.head.replace(regexRootUrl, ''); |
218 | template.document.content.document.body.innerHTML = template.body; | 220 | template.document.content.document.body.innerHTML = template.body.replace(regexRootUrl, ''); |
219 | //Getting all CSS (style or link) tags | 221 | //Getting all CSS (style or link) tags |
220 | var styletags = template.document.content.document.getElementsByTagName('style'), | 222 | var styletags = template.document.content.document.getElementsByTagName('style'), |
221 | linktags = template.document.content.document.getElementsByTagName('link'), | 223 | linktags = template.document.content.document.getElementsByTagName('link'), |
@@ -248,7 +250,7 @@ exports.IoMediator = Montage.create(Component, { | |||
248 | for (var l in linktags) { | 250 | for (var l in linktags) { |
249 | if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll | 251 | if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll |
250 | for (var p=0; toremovetags[p]; p++) { | 252 | for (var p=0; toremovetags[p]; p++) { |
251 | if (toremovetags[p].getAttribute('data-ninja-file-url') === ('/'+linktags[l].getAttribute('href'))) { | 253 | if (toremovetags[p].getAttribute('href') === linktags[l].getAttribute('href')) { |
252 | if (!toremovetags[p].getAttribute('data-ninja-disabled')) { | 254 | if (!toremovetags[p].getAttribute('data-ninja-disabled')) { |
253 | linktags[l].removeAttribute('disabled'); | 255 | linktags[l].removeAttribute('disabled'); |
254 | } | 256 | } |
@@ -335,55 +337,50 @@ exports.IoMediator = Montage.create(Component, { | |||
335 | /////////////////////////////////////////////////////////////////////////////////////////// | 337 | /////////////////////////////////////////////////////////////////////////////////////////// |
336 | 338 | ||
337 | 339 | ||
338 | var cleanedCss, fileCouldDirUrl, pathDepth, pathToDocRoot = '../'; | 340 | var cleanedCss, |
339 | dirtyCss = this.getCssFromRules(template.css[i].cssRules), | 341 | dirtyCss = this.getCssFromRules(template.css[i].cssRules), |
340 | fileUrl = template.css[i].ownerNode.getAttribute('data-ninja-file-url'), | 342 | fileUrl = template.css[i].ownerNode.getAttribute('data-ninja-file-url'), |
341 | fileRootUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-1])[0]).replace(/\/\//gi, '/')), | 343 | fileRootUrl = this.application.ninja.coreIoApi.rootUrl+fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-1])[0], |
342 | localPath = fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-2])[0] || fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-1])[0] || fileUrl.split(fileUrl.split('/')[0])[0], | 344 | cleanedCss = dirtyCss.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaUrl.bind(this)); |
343 | documentRootURL = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); | 345 | |
344 | |||
345 | pathDepth = Math.floor(localPath.split('/').length/2); | ||
346 | |||
347 | for (var p=0; p < pathDepth; p++) { | ||
348 | pathToDocRoot += '../'; | ||
349 | } | ||
350 | |||
351 | fileCouldDirUrl = this.application.ninja.coreIoApi.rootUrl+escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1]+localPath).replace(/\/\//gi, '/')); | ||
352 | |||
353 | cleanedCss = dirtyCss.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaUrl.bind(this)); | ||
354 | 346 | ||
355 | function parseNinjaUrl (url) { | 347 | function parseNinjaUrl (url) { |
348 | //console.log("Getting: " + url); | ||
356 | // | 349 | // |
357 | if (url.indexOf(fileCouldDirUrl) !== -1 || url.indexOf(fileRootUrl) !== -1) { | 350 | if (url.indexOf(fileRootUrl) !== -1) { |
351 | url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); | ||
352 | } else { | ||
353 | var assetsDirs = (url.replace(new RegExp((this.application.ninja.coreIoApi.rootUrl).replace(/\//gi, '\\\/'), 'gi'), '')).split('/'); | ||
354 | var fileDirs = (fileUrl.split(fileUrl.split('/')[fileUrl.split('/').length-1])[0]).split('/'); | ||
355 | var counter = 0; | ||
356 | var path = ''; | ||
357 | var newURL = ''; | ||
358 | // | ||
359 | for (var p=0; p < fileDirs.length-1; p++) { | ||
360 | if (fileDirs[p] === assetsDirs[p]) { | ||
361 | counter++; | ||
362 | } | ||
363 | } | ||
358 | // | 364 | // |
359 | if (pathDepth < 1 || url.indexOf(fileRootUrl) > -1) { | 365 | for (var p=0; p < (fileDirs.length-counter)-1; p++) { |
360 | // | 366 | path += '../'; |
361 | url = url.replace(new RegExp(fileRootUrl.replace(/\//gi, '\\\/'), 'gi'), ''); | ||
362 | } else { | ||
363 | // | ||
364 | url = url.replace(new RegExp(fileCouldDirUrl.replace(/\//gi, '\\\/'), 'gi'), '../'); | ||
365 | } | 367 | } |
366 | } else { | ||
367 | // | 368 | // |
368 | if (url.indexOf(documentRootURL) !== 1) { | 369 | for (var p=counter; p < assetsDirs.length; p++) { |
369 | url = url.replace(new RegExp(documentRootURL.replace(/\//gi, '\\\/'), 'gi'), pathToDocRoot); | 370 | newURL += '/'+assetsDirs[p]; |
370 | } else if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== 1) { | ||
371 | //TODO: Add logic for files above root document folder | ||
372 | } | 371 | } |
372 | // | ||
373 | url = (path+newURL).replace(/\/\//gi, '/'); | ||
373 | } | 374 | } |
374 | //console.log("Returning: " + url); | 375 | //console.log("Returning: " + url); |
375 | //console.log("-----"); | 376 | //console.log("-----"); |
376 | return url; | 377 | return url; |
377 | } | 378 | } |
378 | 379 | ||
379 | //console.log(cleanedCss); | ||
380 | |||
381 | /////////////////////////////////////////////////////////////////////////////////////////// | 380 | /////////////////////////////////////////////////////////////////////////////////////////// |
382 | /////////////////////////////////////////////////////////////////////////////////////////// | 381 | /////////////////////////////////////////////////////////////////////////////////////////// |
383 | 382 | ||
384 | 383 | ||
385 | //return; | ||
386 | |||
387 | 384 | ||
388 | 385 | ||
389 | //Saving data from rules array converted to string into <link> file | 386 | //Saving data from rules array converted to string into <link> file |