@@ -154,59 +154,22 @@ Element.prototype.clearAndRender = function(template)
154154 return this . render ( template ) ;
155155} ;
156156
157- if ( document . createElement ( "div" ) . classList )
157+ Element . prototype . hasClass = function ( cl )
158158{
159- Element . prototype . hasClass = function ( cl )
160- {
161- return cl && this . classList . contains ( cl ) ;
162- } ;
163-
164- Element . prototype . addClass = function ( cl )
165- {
166- cl && this . classList . add ( cl ) ;
167- return this ;
168- } ;
159+ return cl && this . classList . contains ( cl ) ;
160+ } ;
169161
170- Element . prototype . removeClass = function ( cl )
171- {
172- cl && this . classList . remove ( cl ) ;
173- return this ;
174- } ;
175- }
176- else
162+ Element . prototype . addClass = function ( cl )
177163{
178- ( function ( )
179- {
180- var cache = { } ;
181- var re = null ;
182- var cln = "" ;
183- var has_class = function ( cln , cl )
184- {
185- if ( ! cache . hasOwnProperty ( cl ) )
186- cache [ cl ] = new RegExp ( "(?:^|\\s+)" + cl + "(?=\\s+|$)" ) ;
187- return ( re = cache [ cl ] ) . test ( cln ) ;
188- } ;
189-
190- this . hasClass = function ( cl )
191- {
192- return has_class ( this . getAttribute ( "class" ) , cl ) ;
193- } ;
194-
195- this . addClass = function ( cl )
196- {
197- if ( ! has_class ( cln = this . getAttribute ( "class" ) , cl ) )
198- this . setAttribute ( "class" , ( cln ? cln + " " : "" ) + cl ) ;
199- return this ;
200- } ;
164+ cl && this . classList . add ( cl ) ;
165+ return this ;
166+ } ;
201167
202- this . removeClass = function ( cl )
203- {
204- if ( has_class ( cln = this . getAttribute ( "class" ) , cl ) )
205- this . setAttribute ( "class" , cln . replace ( re , "" ) . trim ( ) ) ;
206- return this ;
207- } ;
208- } ) . apply ( Element . prototype ) ;
209- }
168+ Element . prototype . removeClass = function ( cl )
169+ {
170+ cl && this . classList . remove ( cl ) ;
171+ return this ;
172+ } ;
210173
211174/**
212175 * Swap class "from" with class "to"
0 commit comments