forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss.js
More file actions
59 lines (51 loc) · 1.39 KB
/
css.js
File metadata and controls
59 lines (51 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { http } from '../net/http.js';
class CssHandler {
constructor() {
this.maxRetries = 0;
}
load(url, callback) {
if (typeof url === 'string') {
url = {
load: url,
original: url
};
}
http.get(url.load, {
retry: this.maxRetries > 0,
maxRetries: this.maxRetries
}, function (err, response) {
if (!err) {
callback(null, response);
} else {
callback("Error loading css resource: " + url.original + " [" + err + "]");
}
});
}
open(url, data) {
return data;
}
patch(asset, assets) {
}
}
/**
* @function
* @name createStyle
* @description Creates a <style> DOM element from a string that contains CSS.
* @param {string} cssString - A string that contains valid CSS.
* @example
* var css = 'body {height: 100;}';
* var style = pc.createStyle(css);
* document.head.appendChild(style);
* @returns {Element} The style DOM element.
*/
function createStyle(cssString) {
const result = document.createElement('style');
result.type = 'text/css';
if (result.styleSheet) {
result.styleSheet.cssText = cssString;
} else {
result.appendChild(document.createTextNode(cssString));
}
return result;
}
export { createStyle, CssHandler };