(el, cls, add)
| 521 | |
| 522 | |
| 523 | function clmod(el, cls, add) { |
| 524 | if (!el) |
| 525 | return false; |
| 526 | |
| 527 | if (el.classList) { |
| 528 | var have = el.classList.contains(cls); |
| 529 | if (add == 't') |
| 530 | add = !have; |
| 531 | |
| 532 | if (!add == !have) |
| 533 | return false; |
| 534 | |
| 535 | el.classList[add ? 'add' : 'remove'](cls); |
| 536 | return true; |
| 537 | } |
| 538 | |
| 539 | var re = new RegExp('\\s*\\b' + cls + '\\s*\\b', 'g'), |
| 540 | n1 = el.className; |
| 541 | |
| 542 | if (add == 't') |
| 543 | add = !re.test(n1); |
| 544 | |
| 545 | var n2 = n1.replace(re, ' ') + (add ? ' ' + cls : ''); |
| 546 | |
| 547 | if (n1 == n2) |
| 548 | return false; |
| 549 | |
| 550 | el.className = n2; |
| 551 | return true; |
| 552 | } |
| 553 | |
| 554 | |
| 555 | function clgot(el, cls) { |
no test coverage detected