Browse files

Fixed JavaScript compatibility issues in several places. Everything n…

…ow works in IE < 9.
  • Loading branch information...
1 parent 4e60cc9 commit 151a0eb80d16c881e696ac26797390851791074f @nzakas nzakas committed Feb 10, 2012
View
84 src/core/Util.js
@@ -1,42 +1,62 @@
-/*
- * Utility functions that make life easier.
- */
+
+/*global CSSLint*/
/*
- * Adds all properties from supplier onto receiver,
- * overwriting if the same name already exists on
- * reciever.
- * @param {Object} The object to receive the properties.
- * @param {Object} The object to provide the properties.
- * @return {Object} The receiver
+ * Utility functions that make life easier.
*/
-function mix(receiver, supplier){
- var prop;
+CSSLint.Util = {
+ /*
+ * Adds all properties from supplier onto receiver,
+ * overwriting if the same name already exists on
+ * reciever.
+ * @param {Object} The object to receive the properties.
+ * @param {Object} The object to provide the properties.
+ * @return {Object} The receiver
+ */
+ mix: function(receiver, supplier){
+ var prop;
- for (prop in supplier){
- if (supplier.hasOwnProperty(prop)){
- receiver[prop] = supplier[prop];
+ for (prop in supplier){
+ if (supplier.hasOwnProperty(prop)){
+ receiver[prop] = supplier[prop];
+ }
}
- }
- return prop;
-}
+ return prop;
+ },
-/*
- * Polyfill for array indexOf() method.
- * @param {Array} values The array to search.
- * @param {Variant} value The value to search for.
- * @return {int} The index of the value if found, -1 if not.
- */
-function indexOf(values, value){
- if (values.indexOf){
- return values.indexOf(value);
- } else {
- for (var i=0, len=values.length; i < len; i++){
- if (values[i] === value){
- return i;
+ /*
+ * Polyfill for array indexOf() method.
+ * @param {Array} values The array to search.
+ * @param {Variant} value The value to search for.
+ * @return {int} The index of the value if found, -1 if not.
+ */
+ indexOf: function(values, value){
+ if (values.indexOf){
+ return values.indexOf(value);
+ } else {
+ for (var i=0, len=values.length; i < len; i++){
+ if (values[i] === value){
+ return i;
+ }
+ }
+ return -1;
+ }
+ },
+
+ /*
+ * Polyfill for array forEach() method.
+ * @param {Array} values The array to operate on.
+ * @param {Function} func The function to call on each item.
+ * @return {void}
+ */
+ forEach: function(values, func) {
+ if (values.forEach){
+ return values.forEach(func);
+ } else {
+ for (var i=0, len=values.length; i < len; i++){
+ func(values[i], i, values);
}
}
- return -1;
}
-}
+};
View
2 src/formatters/checkstyle-xml.js
@@ -65,7 +65,7 @@ CSSLint.addFormatter({
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
- messages.forEach(function (message, i) {
+ CSSLint.Util.forEach(messages, function (message, i) {
//ignore rollups for now
if (!message.rollup) {
output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
View
2 src/formatters/compact.js
@@ -45,7 +45,7 @@ CSSLint.addFormatter({
return options.quiet ? "" : filename + ": Lint Free!";
}
- messages.forEach(function(message, i) {
+ CSSLint.Util.forEach(messages, function(message, i) {
if (message.rollup) {
output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n";
} else {
View
2 src/formatters/csslint-xml.js
@@ -51,7 +51,7 @@ CSSLint.addFormatter({
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
- messages.forEach(function (message, i) {
+ CSSLint.Util.forEach(messages, function (message, i) {
if (message.rollup) {
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
} else {
View
2 src/formatters/lint-xml.js
@@ -52,7 +52,7 @@ CSSLint.addFormatter({
if (messages.length > 0) {
output.push("<file name=\""+filename+"\">");
- messages.forEach(function (message, i) {
+ CSSLint.Util.forEach(messages, function (message, i) {
if (message.rollup) {
output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
} else {
View
2 src/formatters/text.js
@@ -47,7 +47,7 @@ CSSLint.addFormatter({
shortFilename = filename.substring(pos+1);
}
- messages.forEach(function (message, i) {
+ CSSLint.Util.forEach(messages, function (message, i) {
output = output + "\n\n" + shortFilename;
if (message.rollup) {
output += "\n" + (i+1) + ": " + message.type;
View
9 src/rules/compatible-vendor-prefixes.js
@@ -85,6 +85,7 @@ CSSLint.addRule({
"writing-mode" : "epub ms"
};
+
for (prop in compatiblePrefixes) {
if (compatiblePrefixes.hasOwnProperty(prop)) {
variations = [];
@@ -102,7 +103,7 @@ CSSLint.addRule({
parser.addListener("property", function (event) {
var name = event.property.text;
- if (applyTo.indexOf(name) > -1) {
+ if (CSSLint.Util.indexOf(applyTo, name) > -1) {
properties.push(name);
}
});
@@ -130,14 +131,14 @@ CSSLint.addRule({
for (prop in compatiblePrefixes) {
if (compatiblePrefixes.hasOwnProperty(prop)) {
variations = compatiblePrefixes[prop];
- if (variations.indexOf(name) > -1) {
+ if (CSSLint.Util.indexOf(variations, name) > -1) {
if (propertyGroups[prop] === undefined) {
propertyGroups[prop] = {
full : variations.slice(0),
actual : []
};
}
- if (propertyGroups[prop].actual.indexOf(name) === -1) {
+ if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name) === -1) {
propertyGroups[prop].actual.push(name);
}
}
@@ -154,7 +155,7 @@ CSSLint.addRule({
if (full.length > actual.length) {
for (i = 0, len = full.length; i < len; i++) {
item = full[i];
- if (actual.indexOf(item) === -1) {
+ if (CSSLint.Util.indexOf(actual, item) === -1) {
propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length == 2) ? actual.join(" and ") : actual.join(", ");
reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", event.selectors[0].line, event.selectors[0].col, rule);
}

0 comments on commit 151a0eb

Please sign in to comment.