in asdoc/library/closure/goog/debug/devcss/devcss.js [265:349]
goog.debug.DevCss.prototype.replaceBrowserSpecificClassNames_ = function(
cssRule) {
// If we don't match the browser token, we can stop now.
if (!cssRule.selectorText ||
!cssRule.selectorText.match(this.userAgentTokens_.ANY)) {
return;
}
// We know it will begin as a classname.
var additionalRegexString;
// Tests "Less than or equals".
var compared = this.getRuleVersionAndCompare_(
cssRule, this.userAgentTokens_.LESS_THAN_OR_EQUAL);
if (compared && compared.length) {
if (compared[0] > 0) {
return;
}
additionalRegexString =
this.userAgentTokens_.LESS_THAN_OR_EQUAL + compared[1];
}
// Tests "Less than".
compared =
this.getRuleVersionAndCompare_(cssRule, this.userAgentTokens_.LESS_THAN);
if (compared && compared.length) {
if (compared[0] > -1) {
return;
}
additionalRegexString = this.userAgentTokens_.LESS_THAN + compared[1];
}
// Tests "Greater than or equals".
compared = this.getRuleVersionAndCompare_(
cssRule, this.userAgentTokens_.GREATER_THAN_OR_EQUAL);
if (compared && compared.length) {
if (compared[0] < 0) {
return;
}
additionalRegexString =
this.userAgentTokens_.GREATER_THAN_OR_EQUAL + compared[1];
}
// Tests "Greater than".
compared = this.getRuleVersionAndCompare_(
cssRule, this.userAgentTokens_.GREATER_THAN);
if (compared && compared.length) {
if (compared[0] < 1) {
return;
}
additionalRegexString = this.userAgentTokens_.GREATER_THAN + compared[1];
}
// Tests "Equals".
compared =
this.getRuleVersionAndCompare_(cssRule, this.userAgentTokens_.EQUALS);
if (compared && compared.length) {
if (compared[0] != 0) {
return;
}
additionalRegexString = this.userAgentTokens_.EQUALS + compared[1];
}
// If we got to here without generating the additionalRegexString, then
// we did not match any of our comparison token strings, and we want a
// general browser token replacement.
if (!additionalRegexString) {
additionalRegexString = this.userAgentTokens_.ANY;
}
// We need to match at least a single whitespace character to know that
// we are matching the entire useragent string token.
var regexString = '\\.' + additionalRegexString + '\\s+';
var re = new RegExp(regexString, 'g');
var currentCssText = goog.cssom.getCssTextFromCssRule(cssRule);
// Replacing the token with '' activates the selector for this useragent.
var newCssText = currentCssText.replace(re, '');
if (newCssText != currentCssText) {
goog.cssom.replaceCssRule(cssRule, newCssText);
}
};