Merge pull request #189 from anru/domutil

Add L.DomUtil.removeClass method
This commit is contained in:
Vladimir Agafonkin 2011-07-20 04:27:12 -07:00
commit c726d6f3cb
2 changed files with 37 additions and 0 deletions

View File

@ -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);

View File

@ -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) + ')';