|
485 | 485 | };
|
486 | 486 | };
|
487 | 487 |
|
488 |
| - var tokenRegexp = /(?:^|\s)token(?=$|\s)/; |
489 |
| - var activeRegexp = /(?:^|\s)active(?=$|\s)/g; |
490 |
| - var flippedRegexp = /(?:^|\s)flipped(?=$|\s)/g; |
| 488 | + var TOKEN_CLASS = 'token'; |
| 489 | + var ACTIVE_CLASS = 'active'; |
| 490 | + var FLIPPED_CLASS = 'flipped'; |
491 | 491 |
|
492 | 492 | /**
|
493 | 493 | * Previewer constructor
|
|
500 | 500 | var Previewer = function (type, updater, supportedLanguages, initializer) {
|
501 | 501 | this._elt = null;
|
502 | 502 | this._type = type;
|
503 |
| - this._clsRegexp = RegExp('(?:^|\\s)' + type + '(?=$|\\s)'); |
504 | 503 | this._token = null;
|
505 | 504 | this.updater = updater;
|
506 | 505 | this._mouseout = this.mouseout.bind(this);
|
|
543 | 542 | }
|
544 | 543 | };
|
545 | 544 |
|
| 545 | + /** |
| 546 | + * @param {Element} token |
| 547 | + * @returns {boolean} |
| 548 | + */ |
546 | 549 | Previewer.prototype.isDisabled = function (token) {
|
547 | 550 | do {
|
548 | 551 | if (token.hasAttribute && token.hasAttribute('data-previewers')) {
|
|
555 | 558 |
|
556 | 559 | /**
|
557 | 560 | * Checks the class name of each hovered element
|
558 |
| - * @param token |
| 561 | + * @param {Element} token |
559 | 562 | */
|
560 | 563 | Previewer.prototype.check = function (token) {
|
561 |
| - if (tokenRegexp.test(token.className) && this.isDisabled(token)) { |
| 564 | + if (token.classList.contains(TOKEN_CLASS) && this.isDisabled(token)) { |
562 | 565 | return;
|
563 | 566 | }
|
564 | 567 | do {
|
565 |
| - if (tokenRegexp.test(token.className) && this._clsRegexp.test(token.className)) { |
| 568 | + if (token.classList && token.classList.contains(TOKEN_CLASS) && token.classList.contains(this._type)) { |
566 | 569 | break;
|
567 | 570 | }
|
568 | 571 | } while(token = token.parentNode);
|
|
597 | 600 | this._token.addEventListener('mouseout', this._mouseout, false);
|
598 | 601 |
|
599 | 602 | var offset = getOffset(this._token);
|
600 |
| - this._elt.className += ' active'; |
| 603 | + this._elt.classList.add(ACTIVE_CLASS); |
601 | 604 |
|
602 | 605 | if (offset.top - this._elt.offsetHeight > 0) {
|
603 |
| - this._elt.className = this._elt.className.replace(flippedRegexp, ''); |
| 606 | + this._elt.classList.remove(FLIPPED_CLASS); |
604 | 607 | this._elt.style.top = offset.top + 'px';
|
605 | 608 | this._elt.style.bottom = '';
|
606 | 609 | } else {
|
607 |
| - this._elt.className += ' flipped'; |
| 610 | + this._elt.classList.add(FLIPPED_CLASS); |
608 | 611 | this._elt.style.bottom = offset.bottom + 'px';
|
609 | 612 | this._elt.style.top = '';
|
610 | 613 | }
|
|
619 | 622 | * Hides the previewer.
|
620 | 623 | */
|
621 | 624 | Previewer.prototype.hide = function () {
|
622 |
| - this._elt.className = this._elt.className.replace(activeRegexp, ''); |
| 625 | + this._elt.classList.remove(ACTIVE_CLASS); |
623 | 626 | };
|
624 | 627 |
|
625 | 628 | /**
|
|
0 commit comments