Changeset 27981 in webkit
- Timestamp:
- Nov 22, 2007 8:45:26 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r27980 r27981 1 2007-11-22 Timothy Hatcher <timothy@apple.com> 2 3 Reviewed by Dan Bernstein. 4 5 Fix the Element.hasStyleClass and Element.removeStyleClass helpers 6 to not find and replace substrings, but whole class names at the 7 beginning or end of the string or surrounded by whitespace. 8 9 * page/inspector/utilities.js: 10 1 11 2007-11-22 Timothy Hatcher <timothy@apple.com> 2 12 -
trunk/WebCore/page/inspector/utilities.js
r27877 r27981 90 90 Element.prototype.removeStyleClass = function(className) 91 91 { 92 if (this.hasStyleClass(className)) 93 this.className = this.className.replace(className, ""); 92 // Test for the simple case before using a RegExp. 93 if (this.className === className) { 94 this.className = ""; 95 return; 96 } 97 98 var regex = new RegExp("(^|\\s+)" + className.escapeForRegExp() + "($|\\s+)"); 99 if (regex.test(this.className)) 100 this.className = this.className.replace(regex, " "); 94 101 } 95 102 96 103 Element.prototype.addStyleClass = function(className) 97 104 { 98 if ( !this.hasStyleClass(className))105 if (className && !this.hasStyleClass(className)) 99 106 this.className += (this.className.length ? " " + className : className); 100 107 } … … 102 109 Element.prototype.hasStyleClass = function(className) 103 110 { 104 return this.className.indexOf(className) !== -1; 111 if (!className) 112 return false; 113 // Test for the simple case before using a RegExp. 114 if (this.className === className) 115 return true; 116 var regex = new RegExp("(^|\\s)" + className.escapeForRegExp() + "($|\\s)"); 117 return regex.test(this.className); 105 118 } 106 119
Note: See TracChangeset
for help on using the changeset viewer.