Skip to content

Commit 151a0eb

Browse files
committed
Fixed JavaScript compatibility issues in several places. Everything now works in IE < 9.
1 parent 4e60cc9 commit 151a0eb

File tree

7 files changed

+62
-41
lines changed

7 files changed

+62
-41
lines changed

src/core/Util.js

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,62 @@
1-
/*
2-
* Utility functions that make life easier.
3-
*/
1+
2+
/*global CSSLint*/
43

54
/*
6-
* Adds all properties from supplier onto receiver,
7-
* overwriting if the same name already exists on
8-
* reciever.
9-
* @param {Object} The object to receive the properties.
10-
* @param {Object} The object to provide the properties.
11-
* @return {Object} The receiver
5+
* Utility functions that make life easier.
126
*/
13-
function mix(receiver, supplier){
14-
var prop;
7+
CSSLint.Util = {
8+
/*
9+
* Adds all properties from supplier onto receiver,
10+
* overwriting if the same name already exists on
11+
* reciever.
12+
* @param {Object} The object to receive the properties.
13+
* @param {Object} The object to provide the properties.
14+
* @return {Object} The receiver
15+
*/
16+
mix: function(receiver, supplier){
17+
var prop;
1518

16-
for (prop in supplier){
17-
if (supplier.hasOwnProperty(prop)){
18-
receiver[prop] = supplier[prop];
19+
for (prop in supplier){
20+
if (supplier.hasOwnProperty(prop)){
21+
receiver[prop] = supplier[prop];
22+
}
1923
}
20-
}
2124

22-
return prop;
23-
}
25+
return prop;
26+
},
2427

25-
/*
26-
* Polyfill for array indexOf() method.
27-
* @param {Array} values The array to search.
28-
* @param {Variant} value The value to search for.
29-
* @return {int} The index of the value if found, -1 if not.
30-
*/
31-
function indexOf(values, value){
32-
if (values.indexOf){
33-
return values.indexOf(value);
34-
} else {
35-
for (var i=0, len=values.length; i < len; i++){
36-
if (values[i] === value){
37-
return i;
28+
/*
29+
* Polyfill for array indexOf() method.
30+
* @param {Array} values The array to search.
31+
* @param {Variant} value The value to search for.
32+
* @return {int} The index of the value if found, -1 if not.
33+
*/
34+
indexOf: function(values, value){
35+
if (values.indexOf){
36+
return values.indexOf(value);
37+
} else {
38+
for (var i=0, len=values.length; i < len; i++){
39+
if (values[i] === value){
40+
return i;
41+
}
42+
}
43+
return -1;
44+
}
45+
},
46+
47+
/*
48+
* Polyfill for array forEach() method.
49+
* @param {Array} values The array to operate on.
50+
* @param {Function} func The function to call on each item.
51+
* @return {void}
52+
*/
53+
forEach: function(values, func) {
54+
if (values.forEach){
55+
return values.forEach(func);
56+
} else {
57+
for (var i=0, len=values.length; i < len; i++){
58+
func(values[i], i, values);
3859
}
3960
}
40-
return -1;
4161
}
42-
}
62+
};

src/formatters/checkstyle-xml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ CSSLint.addFormatter({
6565

6666
if (messages.length > 0) {
6767
output.push("<file name=\""+filename+"\">");
68-
messages.forEach(function (message, i) {
68+
CSSLint.Util.forEach(messages, function (message, i) {
6969
//ignore rollups for now
7070
if (!message.rollup) {
7171
output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +

src/formatters/compact.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CSSLint.addFormatter({
4545
return options.quiet ? "" : filename + ": Lint Free!";
4646
}
4747

48-
messages.forEach(function(message, i) {
48+
CSSLint.Util.forEach(messages, function(message, i) {
4949
if (message.rollup) {
5050
output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n";
5151
} else {

src/formatters/csslint-xml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CSSLint.addFormatter({
5151

5252
if (messages.length > 0) {
5353
output.push("<file name=\""+filename+"\">");
54-
messages.forEach(function (message, i) {
54+
CSSLint.Util.forEach(messages, function (message, i) {
5555
if (message.rollup) {
5656
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
5757
} else {

src/formatters/lint-xml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ CSSLint.addFormatter({
5252
if (messages.length > 0) {
5353

5454
output.push("<file name=\""+filename+"\">");
55-
messages.forEach(function (message, i) {
55+
CSSLint.Util.forEach(messages, function (message, i) {
5656
if (message.rollup) {
5757
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
5858
} else {

src/formatters/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CSSLint.addFormatter({
4747
shortFilename = filename.substring(pos+1);
4848
}
4949

50-
messages.forEach(function (message, i) {
50+
CSSLint.Util.forEach(messages, function (message, i) {
5151
output = output + "\n\n" + shortFilename;
5252
if (message.rollup) {
5353
output += "\n" + (i+1) + ": " + message.type;

src/rules/compatible-vendor-prefixes.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ CSSLint.addRule({
8585
"writing-mode" : "epub ms"
8686
};
8787

88+
8889
for (prop in compatiblePrefixes) {
8990
if (compatiblePrefixes.hasOwnProperty(prop)) {
9091
variations = [];
@@ -102,7 +103,7 @@ CSSLint.addRule({
102103

103104
parser.addListener("property", function (event) {
104105
var name = event.property.text;
105-
if (applyTo.indexOf(name) > -1) {
106+
if (CSSLint.Util.indexOf(applyTo, name) > -1) {
106107
properties.push(name);
107108
}
108109
});
@@ -130,14 +131,14 @@ CSSLint.addRule({
130131
for (prop in compatiblePrefixes) {
131132
if (compatiblePrefixes.hasOwnProperty(prop)) {
132133
variations = compatiblePrefixes[prop];
133-
if (variations.indexOf(name) > -1) {
134+
if (CSSLint.Util.indexOf(variations, name) > -1) {
134135
if (propertyGroups[prop] === undefined) {
135136
propertyGroups[prop] = {
136137
full : variations.slice(0),
137138
actual : []
138139
};
139140
}
140-
if (propertyGroups[prop].actual.indexOf(name) === -1) {
141+
if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name) === -1) {
141142
propertyGroups[prop].actual.push(name);
142143
}
143144
}
@@ -154,7 +155,7 @@ CSSLint.addRule({
154155
if (full.length > actual.length) {
155156
for (i = 0, len = full.length; i < len; i++) {
156157
item = full[i];
157-
if (actual.indexOf(item) === -1) {
158+
if (CSSLint.Util.indexOf(actual, item) === -1) {
158159
propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length == 2) ? actual.join(" and ") : actual.join(", ");
159160
reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", event.selectors[0].line, event.selectors[0].col, rule);
160161
}

0 commit comments

Comments
 (0)