+2007-11-22 Timothy Hatcher <timothy@apple.com>
+
+ Reviewed by Dan Bernstein.
+
+ Fix the Element.hasStyleClass and Element.removeStyleClass helpers
+ to not find and replace substrings, but whole class names at the
+ beginning or end of the string or surrounded by whitespace.
+
+ * page/inspector/utilities.js:
+
2007-11-22 Timothy Hatcher <timothy@apple.com>
Revert part of my r27935 change that made the Tip balloons
Element.prototype.removeStyleClass = function(className)
{
- if (this.hasStyleClass(className))
- this.className = this.className.replace(className, "");
+ // Test for the simple case before using a RegExp.
+ if (this.className === className) {
+ this.className = "";
+ return;
+ }
+
+ var regex = new RegExp("(^|\\s+)" + className.escapeForRegExp() + "($|\\s+)");
+ if (regex.test(this.className))
+ this.className = this.className.replace(regex, " ");
}
Element.prototype.addStyleClass = function(className)
{
- if (!this.hasStyleClass(className))
+ if (className && !this.hasStyleClass(className))
this.className += (this.className.length ? " " + className : className);
}
Element.prototype.hasStyleClass = function(className)
{
- return this.className.indexOf(className) !== -1;
+ if (!className)
+ return false;
+ // Test for the simple case before using a RegExp.
+ if (this.className === className)
+ return true;
+ var regex = new RegExp("(^|\\s)" + className.escapeForRegExp() + "($|\\s)");
+ return regex.test(this.className);
}
Element.prototype.scrollToElement = function(element)