<commit_before>define([
  'dialog-polyfill',
  'jquery',
  'DoughBaseComponent',
  'eventsWithPromises'
], function (
  dialogPolyfill,
  $,
  DoughBaseComponent,
  eventsWithPromises
) {
  'use strict';

  var DialogProto,
      defaultConfig = {
        uiEvents: {
          'click': 'show'
        },
        selectors: {
          dialog: '[data-dough-dialog]',
          target: '[data-dough-dialog-target]',
          trigger: '[data-dough-dialog-trigger]',
          container: '[data-dough-dialog-container]',
          containerInner: '[data-dough-dialog-container-inner]',
          content: '[data-dough-dialog-content]',
          contentInner: '[data-dough-dialog-content-inner]',
          close: '[data-dough-dialog-close]',
          activeClass: 'is-active',
          inactiveClass: 'is-inactive',
          dialogOpenBodyClass: 'js-dialog-active'
        }
      };

  function Dialog($el, config) {
    Dialog.baseConstructor.call(this, $el, config, defaultConfig);
    this.isShown = false;
  }

  DoughBaseComponent.extend(Dialog);

  DialogProto = Dialog.prototype;

  DialogProto.init = function(initialised) {
    this.context = this.$el.attr('data-dough-dialog-context');
    this._cacheComponentElements();
    this._setupDialog();
    this._setupUIEvents();
    this._setupAppEvents();
    this._initialisedSuccess(initialised);
  };

  DialogProto._cacheComponentElements = function() {
    var targetSrc;
    this.$trigger = this.$el;
    targetSrc = this.$el.attr('data-dough-dialog-trigger') || this.$el.attr('data-dough-dialog-context');
    this.$target = $('[data-dough-dialog-target="' + targetSrc + '"]');
  };

  DialogProto._setupDialog = function() {
    this.$dialog = $('<dialog data-dough-dialog class="dialog is-inactive" />');
    this.$dialogContainer = $('<div data-dough-dialog-container class="dialog__container" />');
    this.$dialogContainerInner = $('<div data-dough-dialog-container-inner class="dialog__container-inner" />');
    this.$dialogContent = $('<div data-dough-dialog-content class="dialog__content" />');
    this.$dialogContentInner = $('<div data-dough-dialog-content-inner class="dialog__content-inner" />');
    this.$dialogClose = $('<button data-dough-dialog-close class="dialog__close"><span class="dialog__close-text visually-hidden">Close</span></button>');
    this.$dialog
      .appendTo('body')
      .append(this.$dialogContainer);

    this.$dialogContainer.append(this.$dialogContainerInner);
    this.$dialogContainerInner.append(this.$dialogContent);
    this.$dialogContent.append(this.$dialogContentInner);
    this.$dialogContentInner.append(this.$dialogClose);
    this.dialog = this.$dialog[0];

    if(typeof window.HTMLDialogElement === 'undefined') {
      dialogPolyfill.registerDialog(this.dialog);
    }
  };

  DialogProto._setupUIEvents = function() {
    this.$dialog
      .on('click', this.config.selectors.close, $.proxy(this.close, this, false))
      .on('cancel', $.proxy(this._handleCancel, this));
  };

  DialogProto._setupAppEvents = function() {
    eventsWithPromises.subscribe('dialog:close', $.proxy(this._handleClose, this));
    eventsWithPromises.subscribe('dialog:show', $.proxy(function(eventData) {
      if(eventData && eventData.emitter === this.context) {
        this.show(eventData.modal || true, eventData.id || null);
      }
    }, this));
  };

  DialogProto._handleCancel = function() {
    this.close(true);
  };

  DialogProto._handleClose = function(eventData) {
    console.log(eventData);
    if(eventData && eventData.emitter === this.context) {
      this.close();
    }
  };

  DialogProto._detachTarget = function() {
    this.$locationMarker = $('<span />').insertBefore(this.$target);
    this.$target.detach();
  };

  DialogProto._attachTarget = function() {
    this.$target.insertBefore(this.$locationMarker);
    this.$locationMarker.remove();<commit_msg>Remove console.log<commit_after>define([
  'dialog-polyfill',
  'jquery',
  'DoughBaseComponent',
  'eventsWithPromises'
], function (
  dialogPolyfill,
  $,
  DoughBaseComponent,
  eventsWithPromises
) {
  'use strict';

  var DialogProto,
      defaultConfig = {
        uiEvents: {
          'click': 'show'
        },
        selectors: {
          dialog: '[data-dough-dialog]',
          target: '[data-dough-dialog-target]',
          trigger: '[data-dough-dialog-trigger]',
          container: '[data-dough-dialog-container]',
          containerInner: '[data-dough-dialog-container-inner]',
          content: '[data-dough-dialog-content]',
          contentInner: '[data-dough-dialog-content-inner]',
          close: '[data-dough-dialog-close]',
          activeClass: 'is-active',
          inactiveClass: 'is-inactive',
          dialogOpenBodyClass: 'js-dialog-active'
        }
      };

  function Dialog($el, config) {
    Dialog.baseConstructor.call(this, $el, config, defaultConfig);
    this.isShown = false;
  }

  DoughBaseComponent.extend(Dialog);

  DialogProto = Dialog.prototype;

  DialogProto.init = function(initialised) {
    this.context = this.$el.attr('data-dough-dialog-context');
    this._cacheComponentElements();
    this._setupDialog();
    this._setupUIEvents();
    this._setupAppEvents();
    this._initialisedSuccess(initialised);
  };

  DialogProto._cacheComponentElements = function() {
    var targetSrc;
    this.$trigger = this.$el;
    targetSrc = this.$el.attr('data-dough-dialog-trigger') || this.$el.attr('data-dough-dialog-context');
    this.$target = $('[data-dough-dialog-target="' + targetSrc + '"]');
  };

  DialogProto._setupDialog = function() {
    this.$dialog = $('<dialog data-dough-dialog class="dialog is-inactive" />');
    this.$dialogContainer = $('<div data-dough-dialog-container class="dialog__container" />');
    this.$dialogContainerInner = $('<div data-dough-dialog-container-inner class="dialog__container-inner" />');
    this.$dialogContent = $('<div data-dough-dialog-content class="dialog__content" />');
    this.$dialogContentInner = $('<div data-dough-dialog-content-inner class="dialog__content-inner" />');
    this.$dialogClose = $('<button data-dough-dialog-close class="dialog__close"><span class="dialog__close-text visually-hidden">Close</span></button>');
    this.$dialog
      .appendTo('body')
      .append(this.$dialogContainer);

    this.$dialogContainer.append(this.$dialogContainerInner);
    this.$dialogContainerInner.append(this.$dialogContent);
    this.$dialogContent.append(this.$dialogContentInner);
    this.$dialogContentInner.append(this.$dialogClose);
    this.dialog = this.$dialog[0];

    if(typeof window.HTMLDialogElement === 'undefined') {
      dialogPolyfill.registerDialog(this.dialog);
    }
  };

  DialogProto._setupUIEvents = function() {
    this.$dialog
      .on('click', this.config.selectors.close, $.proxy(this.close, this, false))
      .on('cancel', $.proxy(this._handleCancel, this));
  };

  DialogProto._setupAppEvents = function() {
    eventsWithPromises.subscribe('dialog:close', $.proxy(this._handleClose, this));
    eventsWithPromises.subscribe('dialog:show', $.proxy(function(eventData) {
      if(eventData && eventData.emitter === this.context) {
        this.show(eventData.modal || true, eventData.id || null);
      }
    }, this));
  };

  DialogProto._handleCancel = function() {
    this.close(true);
  };

  DialogProto._handleClose = function(eventData) {
    if(eventData && eventData.emitter === this.context) {
      this.close();
    }
  };

  DialogProto._detachTarget = function() {
    this.$locationMarker = $('<span />').insertBefore(this.$target);
    this.$target.detach();
  };

  DialogProto._attachTarget = function() {
    this.$target.insertBefore(this.$locationMarker);
    this.$locationMarker.remove();
{'fraction_non_alphanumeric': 0.16445930307316445, 'fraction_numerical': 0.00025716857400025716, 'mean_word_length': 3.5726043503821283, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '17851', 'n_tokens_mistral': 2333, 'n_tokens_neox': 2296, 'n_words': 321}