Merge pull request #189 from anru/domutil
Add L.DomUtil.removeClass method
This commit is contained in:
commit
c726d6f3cb
@ -23,6 +23,36 @@ describe('DomUtil', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#addClass, #removeClass, #hasClass', function() {
|
||||
it('should has defined class for test element', function() {
|
||||
el.className = 'bar foo baz ';
|
||||
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy();
|
||||
expect(L.DomUtil.hasClass(el, 'bar')).toBeTruthy();
|
||||
expect(L.DomUtil.hasClass(el, 'baz')).toBeTruthy();
|
||||
expect(L.DomUtil.hasClass(el, 'boo')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should properly addClass and removeClass for element', function() {
|
||||
el.className = '';
|
||||
L.DomUtil.addClass(el, 'foo');
|
||||
|
||||
expect(el.className).toEqual('foo');
|
||||
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy();
|
||||
|
||||
L.DomUtil.addClass(el, 'bar');
|
||||
expect(el.className).toEqual('foo bar');
|
||||
expect(L.DomUtil.hasClass(el, 'foo')).toBeTruthy();
|
||||
|
||||
L.DomUtil.removeClass(el, 'foo');
|
||||
expect(el.className).toEqual('bar');
|
||||
expect(L.DomUtil.hasClass(el, 'foo')).toBeFalsy();
|
||||
|
||||
el.className = 'foo bar barz';
|
||||
L.DomUtil.removeClass(el, 'bar');
|
||||
expect(el.className).toEqual('foo barz');
|
||||
})
|
||||
});
|
||||
|
||||
describe('#setPosition', noSpecs);
|
||||
|
||||
describe('#getStyle', noSpecs);
|
||||
|
@ -67,6 +67,13 @@ L.DomUtil = {
|
||||
}
|
||||
},
|
||||
|
||||
removeClass: function(el, name) {
|
||||
el.className = el.className.replace(/(\w+)\s*/g, function(w, match) {
|
||||
if (match == name) return '';
|
||||
return w;
|
||||
}).replace(/^\s+/, '');
|
||||
},
|
||||
|
||||
setOpacity: function(el, value) {
|
||||
if (L.Browser.ie) {
|
||||
el.style.filter = 'alpha(opacity=' + Math.round(value * 100) + ')';
|
||||
|
Loading…
Reference in New Issue
Block a user