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.js118
1 files changed, 59 insertions, 59 deletions
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
index 9c663e8a..353593eb 100755
--- a/js/document/helpers/url-parser.js
+++ b/js/document/helpers/url-parser.js
@@ -30,81 +30,81 @@ POSSIBILITY OF SUCH DAMAGE.
30 30
31//////////////////////////////////////////////////////////////////////// 31////////////////////////////////////////////////////////////////////////
32// 32//
33var Montage = require("montage/core/core").Montage, 33var Montage = require("montage/core/core").Montage,
34 Component = require("montage/ui/component").Component; 34 Component = require("montage/ui/component").Component;
35//////////////////////////////////////////////////////////////////////// 35////////////////////////////////////////////////////////////////////////
36// 36//
37exports.UrlParser = Montage.create(Component, { 37exports.UrlParser = Montage.create(Component, {
38 //////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////
39 // 39 //
40 hasTemplate: { 40 hasTemplate: {
41 value: false 41 value: false
42 }, 42 },
43 //////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////
44 // 44 //
45 parseStyleUrls: { 45 parseStyleUrls: {
46 value: function (css, href, local) { 46 value: function (css, href, local) {
47 // 47 //
48 if (local) { 48 if (local) {
49 var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0]; 49 var fileCouldDirUrl = href.split(href.split('/')[href.split('/').length-1])[0];
50 } else { 50 } else {
51 //TODO: Add logic for external URLs 51 //TODO: Add logic for external URLs
52 } 52 }
53 //TODO: Clean up functions 53 //TODO: Clean up functions
54 css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this)); 54 css = css.replace(/url\(()(.+?)\1\)/g, parseToNinjaUrl.bind(this));
55 // 55 //
56 function parseToNinjaUrl (prop) { 56 function parseToNinjaUrl (prop) {
57 // 57 //
58 return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this)); 58 return prop.replace(/[^()\\""\\'']+/g, prefixWithNinjaUrl.bind(this));
59 } 59 }
60 // 60 //
61 function prefixWithNinjaUrl (url) { 61 function prefixWithNinjaUrl (url) {
62 // 62 //
63 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)) { 63 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)) {
64 url = fileCouldDirUrl+url; 64 url = fileCouldDirUrl+url;
65 } 65 }
66 // 66 //
67 return url; 67 return url;
68 } 68 }
69 // 69 //
70 return css; 70 return css;
71 } 71 }
72 }, 72 },
73 //////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////
74 // 74 //
75 loadLocalStyleSheet: { 75 loadLocalStyleSheet: {
76 value: function (href) { 76 value: function (href) {
77 //Getting file URI (not URL since we must load through I/O API) 77 //Getting file URI (not URL since we must load through I/O API)
78 var css = {}, file; 78 var css = {}, file;
79 css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1]; 79 css.cssUrl = href.split(this.application.ninja.coreIoApi.rootUrl)[1];
80 css.fileUri = this.application.ninja.coreIoApi.cloudData.root + unescape(css.cssUrl); 80 css.fileUri = this.application.ninja.coreIoApi.cloudData.root + unescape(css.cssUrl);
81 //Loading data from CSS file 81 //Loading data from CSS file
82 file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri}); 82 file = this.application.ninja.coreIoApi.readFile({uri: css.fileUri});
83 //Checking for file to be writable on disk 83 //Checking for file to be writable on disk
84 css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly; 84 css.writable = JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: css.fileUri}).content).readOnly;
85 //Returning loaded file 85 //Returning loaded file
86 if (file && file.content) { 86 if (file && file.content) {
87 //Getting file contents 87 //Getting file contents
88 css.content = this.parseStyleUrls(file.content, href, true); 88 css.content = this.parseStyleUrls(file.content, href, true);
89 //Returning CSS object 89 //Returning CSS object
90 return css; 90 return css;
91 } else { 91 } else {
92 return false; 92 return false;
93 } 93 }
94 } 94 }
95 }, 95 },
96 //////////////////////////////////////////////////////////////////// 96 ////////////////////////////////////////////////////////////////////
97 // 97 //
98 loadExternalStyleSheet: { 98 loadExternalStyleSheet: {
99 value: function (href) { 99 value: function (href) {
100 //Loading external file 100 //Loading external file
101 var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false}); 101 var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false});
102 //Returning file 102 //Returning file
103 return file; 103 return file;
104 } 104 }
105 } 105 }
106 //////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////
107 //////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////
108}); 108});
109//////////////////////////////////////////////////////////////////////// 109////////////////////////////////////////////////////////////////////////
110//////////////////////////////////////////////////////////////////////// 110////////////////////////////////////////////////////////////////////////