aboutsummaryrefslogtreecommitdiff
path: root/js/document/helpers/url-parser.js
diff options
context:
space:
mode:
authorhwc4872012-05-31 17:11:08 -0700
committerhwc4872012-05-31 17:11:08 -0700
commit1c445cf5d905f79937998cf2f1115594ea8c1074 (patch)
tree35271ad7ffec86fde9102af3dd954fa3a2974582 /js/document/helpers/url-parser.js
parent335ce503996e3ccbd2909086328d0a31fbd03370 (diff)
parent6042bdc5f2aada4412912fd01602d32c9088dc26 (diff)
downloadninja-1c445cf5d905f79937998cf2f1115594ea8c1074.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: js/io/system/ninjalibrary.json
Diffstat (limited to 'js/document/helpers/url-parser.js')
-rwxr-xr-xjs/document/helpers/url-parser.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/js/document/helpers/url-parser.js b/js/document/helpers/url-parser.js
new file mode 100755
index 00000000..5e71d148
--- /dev/null
+++ b/js/document/helpers/url-parser.js
@@ -0,0 +1,86 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7////////////////////////////////////////////////////////////////////////
8//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component;
11////////////////////////////////////////////////////////////////////////
12//
13exports.UrlParser = Montage.create(Component, {
14 ////////////////////////////////////////////////////////////////////
15 //
16 hasTemplate: {
17 value: false
18 },
19 ////////////////////////////////////////////////////////////////////
20 //
21 parseStyleUrls: {
22 value: function (css, href, local) {
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;
47 }
48 },
49 ////////////////////////////////////////////////////////////////////
50 //
51 loadLocalStyleSheet: {
52 value: function (href) {
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 }
70 }
71 },
72 ////////////////////////////////////////////////////////////////////
73 //
74 loadExternalStyleSheet: {
75 value: function (href) {
76 //Loading external file
77 var file = this.application.ninja.coreIoApi.readExternalFile({url: href, binary: false});
78 //Returning file
79 return file;
80 }
81 }
82 ////////////////////////////////////////////////////////////////////
83 ////////////////////////////////////////////////////////////////////
84});
85////////////////////////////////////////////////////////////////////////
86//////////////////////////////////////////////////////////////////////// \ No newline at end of file