aboutsummaryrefslogtreecommitdiff
path: root/js/document/helpers/url-parser.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/helpers/url-parser.js')
-rwxr-xr-xjs/document/helpers/url-parser.js57
1 files changed, 49 insertions, 8 deletions
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
index a1a7406a..5e71d148 100755
--- a/js/document/helpers/url-parser.js
+++ b/js/document/helpers/url-parser.js
@@ -18,24 +18,65 @@ exports.UrlParser = Montage.create(Component, {
18 }, 18 },
19 //////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////
20 // 20 //
21 parseStyles: { 21 parseStyleUrls: {
22 value: function (styles) { 22 value: function (css, href, local) {
23 // 23 //
24 if (local) {
25 var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0];
26 } else {
27 //TODO: Add logic for external URLs
28 }
29 //TODO: Clean up functions
30 css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this));
31 //
32 function parseToNinjaUrl (prop) {
33 //
34 return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this));
35 }
36 //
37 function prefixWithNinjaUrl (url) {
38 //
39 if (url !== 'url' && !url.match(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi)) {
40 url = fileCouldDirUrl+url;
41 }
42 //
43 return url;
44 }
45 //
46 return css;
24 } 47 }
25 }, 48 },
26 //////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////
27 // 50 //
28 loadLocalStyleSheet: { 51 loadLocalStyleSheet: {
29 value: function (path) { 52 value: function (href) {
30 // 53 //Getting file URI (not URL since we must load through I/O API)
54 var css = {}, file;
55 css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1];
56 css.fileUri = this.application.ninja.coreIoApi.cloudData.root + css.cssUrl;
57 //Loading data from CSS file
58 file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri});
59 //Checking for file to be writable on disk
60 css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly;
61 //Returning loaded file
62 if (file && file.content) {
63 //Getting file contents
64 css.content = this.parseStyleUrls(file.content, href, true);
65 //Returning CSS object
66 return css;
67 } else {
68 return false;
69 }
31 } 70 }
32 } 71 },
33 ,
34 //////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////
35 // 73 //
36 loadExternalStyleSheet: { 74 loadExternalStyleSheet: {
37 value: function (path) { 75 value: function (href) {
38 // 76 //Loading external file
77 var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false});
78 //Returning file
79 return file;
39 } 80 }
40 } 81 }
41 //////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////