<commit_before>require('../util/angular-material-core-slim');

import {MDCDialog, MDCDialogFoundation} from '@material/dialog';


/**
 * @ngdoc component
 * @name mdcDialog
 * @module mdc.dialog
 */
class MdcDialogController {
}


/**
 * @ngdoc component
 * @name mdcDialogHeader
 * @module mdc.dialog
 */


/**
 * @ngdoc component
 * @name mdcDialogTitle
 * @module mdc.dialog
 */


/**
 * @ngdoc component
 * @name mdcDialogBody
 * @module mdc.dialog
 */


/**
 * @ngdoc component
 * @name mdcDialogFooter
 * @module mdc.dialog
 */


/**
 * @ngdoc service
 * @name $mdcDialog
 * @module mdc.dialog
 */
function $mdcDialogProvider($$interimElementSlimProvider) {
  return $$interimElementSlimProvider('$mdcDialog')
    .setDefaults({
      methods: ['parent'],
      options: defaultDialogOptions,
    })
    .addPreset('alert', {
      methods: ['title', 'htmlContent', 'textContent', 'ok', 'css', 'scrollable'],
      options: presetDialogOptions,
    })
    .addPreset('confirm', {
      methods: ['title', 'htmlContent', 'textContent', 'ok', 'cancel', 'css', 'scrollable'],
      options: presetDialogOptions,
    })
    .addPreset('prompt', {
      methods: ['title', 'htmlContent', 'textContent', 'initialValue', 'placeholder',
        'ok', 'cancel', 'css', 'scrollable'],
      options: presetDialogOptions,
    });

  /* @ngInject */
  function presetDialogOptions($mdcDialog) {
    return {
      template: require('raw-loader!./mdc-dialog-service.html'),
      controller: function mdcDialogCtrl() {
        const isPrompt = this.$type === 'prompt';

        if (isPrompt && this.initialValue) {
          this.result = this.initialValue;
        }

        this.keypress = function($event) {
          if ($event.keyCode === 13) {
            $mdcDialog.hide(this.result);
          }
        };
      },
      controllerAs: 'dialog',
      bindToController: true,
    };
  }

  /* @ngInject */
  function defaultDialogOptions($mdcDialog, $injector, $document, $rootElement, $q, $interval) {
    return {
      isolateScope: true,
      onCompiling: beforeCompile,
      onShow: onShow,
      onShowing: beforeShow,
      onRemove: onRemove,
      autoWrap: true,
      transformTemplate: function(template, options) {
        return validatedTemplate(template);

        /**
         * The specified template should contain a <mdc-dialog> wrapper element
         */
        function validatedTemplate(template) {
          if (options.autoWrap && !/<\/mdc-dialog>/g.test(template)) {
            return '<mdc-dialog>' + (template || '') + '</mdc-dialog>';
          } else {
            return template || '';
          }
        }
      },
    };

    function beforeCompile(options) {
    }

    function beforeShow(scope, element, options, controller) {
      if (controller) {
        const mdcHtmlContent = controller.htmlContent || options.htmlContent || '';
        const mdcTextContent = controller.textContent || options.textContent ||
          controller.content || options.content || '';

        if (mdcHtmlContent && !$injector.has('$sanitize')) {
          throw Error('The ngSanitize module must be loaded in order to use htmlContent.');
        }

        if (mdcHtmlContent && mdcTextContent) {
          throw Error('mdc-dialog cannot have both `htmlContent` and `textContent`');
        }

        // Only assign the content if nothing throws, otherwise it'll still be compiled.
        controller.mdcHtmlContent = mdcHtmlContent;
        controller.mdcTextContent = mdcTextContent;
      }
      options.mdcDialog = new MDCDialog(element[0]);
    }

    function onShow(scope, element, options, controller) {
      options.parent = getDomElement(options.parent, $rootElement);
      angular.element(() => { // wait for the DOM refresh before trying to show the dialog
        addEventListeners(controller, options);
        options.mdcDialog.show();
      });
      options.parent.append(element);
    }

    function onRemove(scope, element, options) {
      return $q(function(resolve, reject) {
        removeEventListeners(options);
        options.mdcDialog.close();
        const interval = $interval(function() {<commit_msg>AP-132 Hook into element.ready when waiting for dialog append<commit_after>require('../util/angular-material-core-slim');

import {MDCDialog, MDCDialogFoundation} from '@material/dialog';


/**
 * @ngdoc component
 * @name mdcDialog
 * @module mdc.dialog
 */
class MdcDialogController {
}


/**
 * @ngdoc component
 * @name mdcDialogHeader
 * @module mdc.dialog
 */


/**
 * @ngdoc component
 * @name mdcDialogTitle
 * @module mdc.dialog
 */


/**
 * @ngdoc component
 * @name mdcDialogBody
 * @module mdc.dialog
 */


/**
 * @ngdoc component
 * @name mdcDialogFooter
 * @module mdc.dialog
 */


/**
 * @ngdoc service
 * @name $mdcDialog
 * @module mdc.dialog
 */
function $mdcDialogProvider($$interimElementSlimProvider) {
  return $$interimElementSlimProvider('$mdcDialog')
    .setDefaults({
      methods: ['parent'],
      options: defaultDialogOptions,
    })
    .addPreset('alert', {
      methods: ['title', 'htmlContent', 'textContent', 'ok', 'css', 'scrollable'],
      options: presetDialogOptions,
    })
    .addPreset('confirm', {
      methods: ['title', 'htmlContent', 'textContent', 'ok', 'cancel', 'css', 'scrollable'],
      options: presetDialogOptions,
    })
    .addPreset('prompt', {
      methods: ['title', 'htmlContent', 'textContent', 'initialValue', 'placeholder',
        'ok', 'cancel', 'css', 'scrollable'],
      options: presetDialogOptions,
    });

  /* @ngInject */
  function presetDialogOptions($mdcDialog) {
    return {
      template: require('raw-loader!./mdc-dialog-service.html'),
      controller: function mdcDialogCtrl() {
        const isPrompt = this.$type === 'prompt';

        if (isPrompt && this.initialValue) {
          this.result = this.initialValue;
        }

        this.keypress = function($event) {
          if ($event.keyCode === 13) {
            $mdcDialog.hide(this.result);
          }
        };
      },
      controllerAs: 'dialog',
      bindToController: true,
    };
  }

  /* @ngInject */
  function defaultDialogOptions($mdcDialog, $injector, $document, $rootElement, $q, $interval) {
    return {
      isolateScope: true,
      onCompiling: beforeCompile,
      onShow: onShow,
      onShowing: beforeShow,
      onRemove: onRemove,
      autoWrap: true,
      transformTemplate: function(template, options) {
        return validatedTemplate(template);

        /**
         * The specified template should contain a <mdc-dialog> wrapper element
         */
        function validatedTemplate(template) {
          if (options.autoWrap && !/<\/mdc-dialog>/g.test(template)) {
            return '<mdc-dialog>' + (template || '') + '</mdc-dialog>';
          } else {
            return template || '';
          }
        }
      },
    };

    function beforeCompile(options) {
    }

    function beforeShow(scope, element, options, controller) {
      if (controller) {
        const mdcHtmlContent = controller.htmlContent || options.htmlContent || '';
        const mdcTextContent = controller.textContent || options.textContent ||
          controller.content || options.content || '';

        if (mdcHtmlContent && !$injector.has('$sanitize')) {
          throw Error('The ngSanitize module must be loaded in order to use htmlContent.');
        }

        if (mdcHtmlContent && mdcTextContent) {
          throw Error('mdc-dialog cannot have both `htmlContent` and `textContent`');
        }

        // Only assign the content if nothing throws, otherwise it'll still be compiled.
        controller.mdcHtmlContent = mdcHtmlContent;
        controller.mdcTextContent = mdcTextContent;
      }
      options.mdcDialog = new MDCDialog(element[0]);
    }

    function onShow(scope, element, options, controller) {
      options.parent = getDomElement(options.parent, $rootElement);
      element.ready(() => { // wait for the DOM refresh before trying to show the dialog
        addEventListeners(controller, options);
        options.mdcDialog.show();
      });
      options.parent.append(element);
    }

    function onRemove(scope, element, options) {
      return $q(function(resolve, reject) {
        removeEventListeners(options);
        options.mdcDialog.close();
        const interval = $interval(function() {
{'fraction_non_alphanumeric': 0.13723150357995226, 'fraction_numerical': 0.0010739856801909309, 'mean_word_length': 2.7398482820169567, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '5654348', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2384, 'n_words': 534}