aboutsummaryrefslogtreecommitdiff
path: root/point/libs/require-css
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2014-08-10 17:28:37 +0200
committerPacien TRAN-GIRARD2014-08-10 17:28:37 +0200
commite7bf5952d0729b37e677168b6e8fbd1ce58ed1a2 (patch)
tree189988e3e272b806262d1df6b87f1da089ef4af8 /point/libs/require-css
parenta32e898c8d7ad3774f5654e88bb24d5c26482137 (diff)
downloadwhatsthepoint-master.tar.gz
First versionHEADmaster
Diffstat (limited to 'point/libs/require-css')
-rw-r--r--point/libs/require-css/css.min.js63
-rw-r--r--point/libs/require-css/normalize.js142
2 files changed, 205 insertions, 0 deletions
diff --git a/point/libs/require-css/css.min.js b/point/libs/require-css/css.min.js
new file mode 100644
index 0000000..1be578e
--- /dev/null
+++ b/point/libs/require-css/css.min.js
@@ -0,0 +1,63 @@
1define(function () {
2 if (typeof window == "undefined")return{load: function (n, r, load) {
3 load()
4 }};
5 var head = document.getElementsByTagName("head")[0];
6 var engine = window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)/) || 0;
7 var useImportLoad = false;
8 var useOnload = true;
9 if (engine[1] || engine[7])useImportLoad = parseInt(engine[1]) < 6 || parseInt(engine[7]) <= 9; else if (engine[2])useOnload = false; else if (engine[4])useImportLoad = parseInt(engine[4]) < 18;
10 var cssAPI = {};
11 cssAPI.pluginBuilder = "./css-builder";
12 var curStyle;
13 var createStyle = function () {
14 curStyle = document.createElement("style");
15 head.appendChild(curStyle)
16 };
17 var importLoad = function (url, callback) {
18 createStyle();
19 var curSheet = curStyle.styleSheet || curStyle.sheet;
20 if (curSheet && curSheet.addImport) {
21 curSheet.addImport(url);
22 curStyle.onload = callback
23 } else {
24 curStyle.textContent = '@import "' + url + '";';
25 var loadInterval = setInterval(function () {
26 try {
27 curStyle.sheet.cssRules;
28 clearInterval(loadInterval);
29 callback()
30 } catch (e) {
31 }
32 }, 10)
33 }
34 };
35 var linkLoad = function (url, callback) {
36 var link = document.createElement("link");
37 link.type = "text/css";
38 link.rel = "stylesheet";
39 if (useOnload)link.onload = function () {
40 link.onload = function () {
41 };
42 setTimeout(callback, 7)
43 }; else var loadInterval = setInterval(function () {
44 for (var i = 0; i < document.styleSheets.length; i++) {
45 var sheet = document.styleSheets[i];
46 if (sheet.href == link.href) {
47 clearInterval(loadInterval);
48 return callback()
49 }
50 }
51 }, 10);
52 link.href = url;
53 head.appendChild(link)
54 };
55 cssAPI.normalize = function (name, normalize) {
56 if (name.substr(name.length - 4, 4) == ".css")name = name.substr(0, name.length - 4);
57 return normalize(name)
58 };
59 cssAPI.load = function (cssId, req, load, config) {
60 (useImportLoad ? importLoad : linkLoad)(req.toUrl(cssId + ".css"), load)
61 };
62 return cssAPI
63}); \ No newline at end of file
diff --git a/point/libs/require-css/normalize.js b/point/libs/require-css/normalize.js
new file mode 100644
index 0000000..ee82b2c
--- /dev/null
+++ b/point/libs/require-css/normalize.js
@@ -0,0 +1,142 @@
1//>>excludeStart('excludeRequireCss', pragmas.excludeRequireCss)
2/*
3 * css.normalize.js
4 *
5 * CSS Normalization
6 *
7 * CSS paths are normalized based on an optional basePath and the RequireJS config
8 *
9 * Usage:
10 * normalize(css, fromBasePath, toBasePath);
11 *
12 * css: the stylesheet content to normalize
13 * fromBasePath: the absolute base path of the css relative to any root (but without ../ backtracking)
14 * toBasePath: the absolute new base path of the css relative to the same root
15 *
16 * Absolute dependencies are left untouched.
17 *
18 * Urls in the CSS are picked up by regular expressions.
19 * These will catch all statements of the form:
20 *
21 * url(*)
22 * url('*')
23 * url("*")
24 *
25 * @import '*'
26 * @import "*"
27 *
28 * (and so also @import url(*) variations)
29 *
30 * For urls needing normalization
31 *
32 */
33
34define(function () {
35
36 // regular expression for removing double slashes
37 // eg http://www.example.com//my///url/here -> http://www.example.com/my/url/here
38 var slashes = /([^:])\/+/g
39 var removeDoubleSlashes = function (uri) {
40 return uri.replace(slashes, '$1/');
41 }
42
43 // given a relative URI, and two absolute base URIs, convert it from one base to another
44 var protocolRegEx = /[^\:\/]*:\/\/([^\/])*/;
45 var absUrlRegEx = /^(\/|data:)/;
46
47 function convertURIBase(uri, fromBase, toBase) {
48 if (uri.match(absUrlRegEx) || uri.match(protocolRegEx))
49 return uri;
50 uri = removeDoubleSlashes(uri);
51 // if toBase specifies a protocol path, ensure this is the same protocol as fromBase, if not
52 // use absolute path at fromBase
53 var toBaseProtocol = toBase.match(protocolRegEx);
54 var fromBaseProtocol = fromBase.match(protocolRegEx);
55 if (fromBaseProtocol && (!toBaseProtocol || toBaseProtocol[1] != fromBaseProtocol[1] || toBaseProtocol[2] != fromBaseProtocol[2]))
56 return absoluteURI(uri, fromBase);
57
58 else {
59 return relativeURI(absoluteURI(uri, fromBase), toBase);
60 }
61 };
62
63 // given a relative URI, calculate the absolute URI
64 function absoluteURI(uri, base) {
65 if (uri.substr(0, 2) == './')
66 uri = uri.substr(2);
67
68 // absolute urls are left in tact
69 if (uri.match(absUrlRegEx) || uri.match(protocolRegEx))
70 return uri;
71
72 var baseParts = base.split('/');
73 var uriParts = uri.split('/');
74
75 baseParts.pop();
76
77 while (curPart = uriParts.shift())
78 if (curPart == '..')
79 baseParts.pop();
80 else
81 baseParts.push(curPart);
82
83 return baseParts.join('/');
84 };
85
86
87 // given an absolute URI, calculate the relative URI
88 function relativeURI(uri, base) {
89
90 // reduce base and uri strings to just their difference string
91 var baseParts = base.split('/');
92 baseParts.pop();
93 base = baseParts.join('/') + '/';
94 i = 0;
95 while (base.substr(i, 1) == uri.substr(i, 1))
96 i++;
97 while (base.substr(i, 1) != '/')
98 i--;
99 base = base.substr(i + 1);
100 uri = uri.substr(i + 1);
101
102 // each base folder difference is thus a backtrack
103 baseParts = base.split('/');
104 var uriParts = uri.split('/');
105 out = '';
106 while (baseParts.shift())
107 out += '../';
108
109 // finally add uri parts
110 while (curPart = uriParts.shift())
111 out += curPart + '/';
112
113 return out.substr(0, out.length - 1);
114 };
115
116 var normalizeCSS = function (source, fromBase, toBase) {
117
118 fromBase = removeDoubleSlashes(fromBase);
119 toBase = removeDoubleSlashes(toBase);
120
121 var urlRegEx = /@import\s*("([^"]*)"|'([^']*)')|url\s*\(\s*(\s*"([^"]*)"|'([^']*)'|[^\)]*\s*)\s*\)/ig;
122 var result, url, source;
123
124 while (result = urlRegEx.exec(source)) {
125 url = result[3] || result[2] || result[5] || result[6] || result[4];
126 var newUrl;
127 newUrl = convertURIBase(url, fromBase, toBase);
128 var quoteLen = result[5] || result[6] ? 1 : 0;
129 source = source.substr(0, urlRegEx.lastIndex - url.length - quoteLen - 1) + newUrl + source.substr(urlRegEx.lastIndex - quoteLen - 1);
130 urlRegEx.lastIndex = urlRegEx.lastIndex + (newUrl.length - url.length);
131 }
132
133 return source;
134 };
135
136 normalizeCSS.convertURIBase = convertURIBase;
137 normalizeCSS.absoluteURI = absoluteURI;
138 normalizeCSS.relativeURI = relativeURI;
139
140 return normalizeCSS;
141});
142//>>excludeEnd('excludeRequireCss')