<commit_before>import Util from './util';

const Modal = (($) => {

   const NAME = 'modal';
   const DATA_KEY = 'sv.modal';
   const NO_CONFLICT = $.fn[NAME];
   const SELECTOR = '[data-modal]';
   const DISMISS_SELECTOR = '[data-modal-dismiss]';
   const MODIFIER_BASE = 'sv-modal--';
   const BACKDROP = 'sv-modal__backdrop';
   const BACKDROP_ANIMATION = 'sv-modal__backdrop--in';
   const SHOW = 'show';
   const ESCAPE_KEY = 27;
   const ANIMATION = 'sv-animation-in-progress';
   const FOCUSIN = 'focusin.sv-modal';

   const EVENTS = {
      HIDE: 'hide.sv-modal',
      HIDDEN: 'hidden.sv-modal',
      SHOW: 'show.sv-modal',
      SHOWN: 'shown.sv-modal'
   };

   class Modal {

      constructor(element) {
         this.el = element;
         this.$el = $(element);
         this._isShown = false;
         this._focus = false;
      }

      toggle() {
         return this._isShown ? this.hide() : this.show();
      }

      show() {
         if (this._isShown) {
            return;
         }

         this.$el.outerWidth(); // Used to force reflow

         const showEvent = $.Event(EVENTS.SHOW, {});

         this.$el.trigger(showEvent);

         const shownEvent = $.Event(EVENTS.SHOWN, {});

         this.$el
            .one(Util.getTranstionEndEvent(), () => {
               this.$el.trigger(shownEvent);
            })
            .addClass(MODIFIER_BASE + SHOW)
            .removeAttr('aria-hidden')
            .css('opacity', 1);

         this._showBackdrop();

         this._isShown = true;

         if (!this._focus) {
            this._focus = true;
            this.el.focus();
         }

         this._bindEvents();
      }

      hide() {
         if (!this._isShown) {
            return;
         }

         const hideModalCallback = () => {
            this.$el.removeClass(MODIFIER_BASE + SHOW);

            const hiddenEvent = $.Event(EVENTS.HIDDEN, {});
            this.$el.trigger(hiddenEvent);
         };

         const removeBackdropCallback = () => {
            this.$backdrop.remove();
         };

         const hideEvent = $.Event(EVENTS.HIDE, {});

         this.$el.trigger(hideEvent);

         this.$el
            .one(Util.getTranstionEndEvent(), hideModalCallback)
            .attr('aria-hidden', 'true')
            .css('opacity', 0)
            .off('click', DISMISS_SELECTOR);

         this.$backdrop
            .one(Util.getTranstionEndEvent(), removeBackdropCallback)
            .removeClass(BACKDROP_ANIMATION);

         this._focus = false;
         this._isShown = false;
         this._unbindEvents();
      }

      _bindEvents() {
         this.$el.on('click', DISMISS_SELECTOR, (event) => this.hide(event));

         $(document)
            .off(FOCUSIN)
            .one(FOCUSIN, (event) => {
               if (document !== event.target &&
                  this.el !== event.target &&
                  !this.$el.has(event.target).length) {
                  this.el.focus();
               }
            });

         this.$el.on('keydown', (event) => {
            if (this.$backdrop.hasClass(ANIMATION)) {
               return;
            }
            if (event.which === ESCAPE_KEY) {
               this.hide();
            }
         });
      }

      _unbindEvents() {
         this.$el
               .off('click keydown');

         $(document).off(FOCUSIN);
      }

      _showBackdrop() {
         this.$backdrop = $('<div/>', {
            class: BACKDROP
         });

         this.$el.on('click', (event) => {
            if (this.$backdrop.hasClass(ANIMATION)) {
               return;
            }

            if (event.target !== event.currentTarget) {<commit_msg>SV-22454, SV-22550, Added tab within modal functionality<commit_after>import Util from './util';

const Modal = (($) => {

   const NAME = 'modal';
   const DATA_KEY = 'sv.modal';
   const NO_CONFLICT = $.fn[NAME];
   const SELECTOR = '[data-modal]';
   const DISMISS_SELECTOR = '[data-modal-dismiss]';
   const MODIFIER_BASE = 'sv-modal--';
   const BACKDROP = 'sv-modal__backdrop';
   const BACKDROP_ANIMATION = 'sv-modal__backdrop--in';
   const SHOW = 'show';
   const ESCAPE_KEY = 27;
   const ANIMATION = 'sv-animation-in-progress';
   const FOCUSIN = 'focusin.sv-modal';
   const TAB_KEY = 9;

   const focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';

   const EVENTS = {
      HIDE: 'hide.sv-modal',
      HIDDEN: 'hidden.sv-modal',
      SHOW: 'show.sv-modal',
      SHOWN: 'shown.sv-modal'
   };

   class Modal {

      constructor(element) {
         this.el = element;
         this.$el = $(element);
         this._isShown = false;
         this._focus = false;
      }

      toggle() {
         return this._isShown ? this.hide() : this.show();
      }

      show() {
         if (this._isShown) {
            return;
         }

         this.$el.outerWidth(); // Used to force reflow

         const showEvent = $.Event(EVENTS.SHOW, {});

         this.$el.trigger(showEvent);

         const shownEvent = $.Event(EVENTS.SHOWN, {});

         this.$el
            .one(Util.getTranstionEndEvent(), () => {
               this.$el.trigger(shownEvent);
            })
            .addClass(MODIFIER_BASE + SHOW)
            .removeAttr('aria-hidden')
            .css('opacity', 1);

         this._showBackdrop();

         this._isShown = true;

         if (!this._focus) {
            this._focus = true;
            this.el.focus();
         }

         this._bindEvents();
      }

      hide() {
         if (!this._isShown) {
            return;
         }

         const hideModalCallback = () => {
            this.$el.removeClass(MODIFIER_BASE + SHOW);

            const hiddenEvent = $.Event(EVENTS.HIDDEN, {});
            this.$el.trigger(hiddenEvent);
         };

         const removeBackdropCallback = () => {
            this.$backdrop.remove();
         };

         const hideEvent = $.Event(EVENTS.HIDE, {});

         this.$el.trigger(hideEvent);

         this.$el
            .one(Util.getTranstionEndEvent(), hideModalCallback)
            .attr('aria-hidden', 'true')
            .css('opacity', 0)
            .off('click', DISMISS_SELECTOR);

         this.$backdrop
            .one(Util.getTranstionEndEvent(), removeBackdropCallback)
            .removeClass(BACKDROP_ANIMATION);

         this._focus = false;
         this._isShown = false;
         this._unbindEvents();
      }

      _bindEvents() {
         this.$el.on('click', DISMISS_SELECTOR, (event) => this.hide(event));

         $(document)
            .off(FOCUSIN)
            .one(FOCUSIN, (event) => {
               if (document !== event.target &&
                  this.el !== event.target &&
                  !this.$el.has(event.target).length) {
                  this.el.focus();
               }
            });

         let focusableElements = this.el[0].querySelectorAll(focusableElementsString);
         focusableElements = Array.prototype.slice.call(focusableElements);

         const firstElement = focusableElements[0];
         const lastElement = focusableElements[focusableElements.length - 1];

         this.$el.on('keydown', (event) => {
            if (this.$backdrop.hasClass(ANIMATION)) {
               return;
            }

            if (event.keyCode === TAB_KEY) {
               if (event.shiftKey) {
                  if (event.target === firstElement) {
                     event.preventDefault();
                     lastElement.focus();
                  }
               } else if (event.target === lastElement) {
                  event.preventDefault();
                  firstElement.focus();
               }
            }

            if (event.which === ESCAPE_KEY) {
               this.hide();
            }
         });
      }

      _unbindEvents() {
         this.$el.off('click keydown');
         $(document).off(FOCUSIN);
      }

      _showBackdrop() {
         this.$backdrop = $('<div/>', {
            class: BACKDROP
         });

         this.$el.on('click', (event) => {
            if (this.$backdrop.hasClass(ANIMATION)) {
               return;
            }

            if (event.target !== event.currentTarget) {
{'fraction_non_alphanumeric': 0.14684727883001678, 'fraction_numerical': 0.0027571325821146007, 'mean_word_length': 1.6080025007814942, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6368308', 'n_tokens_mistral': 2563, 'n_tokens_neox': 2437, 'n_words': 411}