Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81143 views
1
//.CommonJS
2
var CSSOM = {
3
CSSRule: require("./CSSRule").CSSRule,
4
CSSStyleSheet: require("./CSSStyleSheet").CSSStyleSheet,
5
MediaList: require("./MediaList").MediaList
6
};
7
///CommonJS
8
9
10
/**
11
* @constructor
12
* @see http://dev.w3.org/csswg/cssom/#cssimportrule
13
* @see http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSImportRule
14
*/
15
CSSOM.CSSImportRule = function CSSImportRule() {
16
CSSOM.CSSRule.call(this);
17
this.href = "";
18
this.media = new CSSOM.MediaList;
19
this.styleSheet = new CSSOM.CSSStyleSheet;
20
};
21
22
CSSOM.CSSImportRule.prototype = new CSSOM.CSSRule;
23
CSSOM.CSSImportRule.prototype.constructor = CSSOM.CSSImportRule;
24
CSSOM.CSSImportRule.prototype.type = 3;
25
26
Object.defineProperty(CSSOM.CSSImportRule.prototype, "cssText", {
27
get: function() {
28
var mediaText = this.media.mediaText;
29
return "@import url(" + this.href + ")" + (mediaText ? " " + mediaText : "") + ";";
30
},
31
set: function(cssText) {
32
var i = 0;
33
34
/**
35
* @import url(partial.css) screen, handheld;
36
* || |
37
* after-import media
38
* |
39
* url
40
*/
41
var state = '';
42
43
var buffer = '';
44
var index;
45
var mediaText = '';
46
for (var character; character = cssText.charAt(i); i++) {
47
48
switch (character) {
49
case ' ':
50
case '\t':
51
case '\r':
52
case '\n':
53
case '\f':
54
if (state === 'after-import') {
55
state = 'url';
56
} else {
57
buffer += character;
58
}
59
break;
60
61
case '@':
62
if (!state && cssText.indexOf('@import', i) === i) {
63
state = 'after-import';
64
i += 'import'.length;
65
buffer = '';
66
}
67
break;
68
69
case 'u':
70
if (state === 'url' && cssText.indexOf('url(', i) === i) {
71
index = cssText.indexOf(')', i + 1);
72
if (index === -1) {
73
throw i + ': ")" not found';
74
}
75
i += 'url('.length;
76
var url = cssText.slice(i, index);
77
if (url[0] === url[url.length - 1]) {
78
if (url[0] === '"' || url[0] === "'") {
79
url = url.slice(1, -1);
80
}
81
}
82
this.href = url;
83
i = index;
84
state = 'media';
85
}
86
break;
87
88
case '"':
89
if (state === 'url') {
90
index = cssText.indexOf('"', i + 1);
91
if (!index) {
92
throw i + ": '\"' not found";
93
}
94
this.href = cssText.slice(i + 1, index);
95
i = index;
96
state = 'media';
97
}
98
break;
99
100
case "'":
101
if (state === 'url') {
102
index = cssText.indexOf("'", i + 1);
103
if (!index) {
104
throw i + ': "\'" not found';
105
}
106
this.href = cssText.slice(i + 1, index);
107
i = index;
108
state = 'media';
109
}
110
break;
111
112
case ';':
113
if (state === 'media') {
114
if (buffer) {
115
this.media.mediaText = buffer.trim();
116
}
117
}
118
break;
119
120
default:
121
if (state === 'media') {
122
buffer += character;
123
}
124
break;
125
}
126
}
127
}
128
});
129
130
131
//.CommonJS
132
exports.CSSImportRule = CSSOM.CSSImportRule;
133
///CommonJS
134
135