WenTao-Love / base2

Automatically exported from code.google.com/p/base2
0 stars 1 forks source link

classList.remove can incorrectly trigger IE's onpropertychange event. #148

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Using IE, add an onpropertychange event to a form control.
2. Use the classList.remove method to remove a non applied class.

What is the expected output? What do you see instead?
The onpropertychange event fires even though a class wasn't removed.

This can cause an infinite loop when the onpropertychange handler calls 
classList.remove.

Please provide any additional information below.
Patch for this issue:

--- src/base2/dom/html/ClassList.js     (revision 310)
+++ src/base2/dom/html/ClassList.js     (working copy)
@@ -16,8 +16,10 @@
   },

   remove: function(element, token) {
-    var regexp = new RegExp("(^|\\s)" + token + "(\\s|$)", "g");
-    element.className = trim(element.className.replace(regexp, "$2"));
+    if (ClassList.contains(element, token)) {
+      var regexp = new RegExp("(^|\\s)" + token + "(\\s|$)", "g");
+      element.className = trim(element.className.replace(regexp, "$2"));
+    }
   },

   toggle: function(element, token) {

Original issue reported on code.google.com by pdeb...@staff.iinet.net.au on 1 May 2013 at 4:07