<commit_before>if (!Midas) var Midas = {};
Midas.modal = function(url, options) {
  var w = window.isTop() ? window : top;
  w.Midas.modal.show(url, options);
  return w.Midas.modal;
};

Object.extend(Midas.modal, {
  version: 0.2,
  initialized: false,
  options: {
    title: ''
  },

  _initialize: function(options) {
    this._options = Object.clone(this.options);
    Object.extend(this._options, options || {});

    if (this.initialized) return false;

    this._build();
    this._setupObservers();
    this.initialized = true;
  },

  _build: function() {
		this.overlayElement = new Element('div', {id: 'midas_modal_overlay', style: 'display:none'});
		this.element = new Element('div', {id: 'midas_modal', style: 'display:none'});
    this.element.update('<form class="midas-modal-frame"><h1><span></span><a>&times;</a></h1><div class="midas-modal-content-container"><div class="midas-modal-content"></div></div></form>');

    this.frameElement = this.element.down('.midas-modal-frame');
    this.contentContainerElement = this.element.down('.midas-modal-content-container');
    this.contentElement = this.element.down('.midas-modal-content');

    document.body.appendChild(this.overlayElement);
    document.body.appendChild(this.element);
  },

  _setupObservers: function() {
    Event.observe(window, 'resize', this.position.bind(this));
    Event.observe(this.element.down('h1 a'), 'click', this.hide.bind(this));
    Event.observe(this.overlayElement, 'mousedown', function(e) { e.stop(); });
    Event.observe(this.overlayElement, 'mouseup', function(e) { e.stop(); });
    Event.observe(this.element, 'mouseup', function(e) { e.stop(); });
    Event.observe(this.element.down('h1'), 'mousedown', function(e) { e.stop(); });
    Event.observe(this.frameElement, 'submit', function(e) {
      if (window['midas_modal_submit']) window['midas_modal_submit'](e);
    });

    var documents = [document];
    var iframe = $('midas-iframe-window');
    if (iframe) documents.push(iframe.contentWindow.document);
    documents.each(function(doc) {
      Event.observe(doc, 'keydown', function(e) {
        if (this.showing && e.keyCode == 27) this.hide();
      }.bind(this));
    }.bind(this));
  },

  show: function(url, options) {
    this._initialize(options);

    this.contentElement.innerHTML = '';
    this.load(url);
    this.updateTitle();

		if (!this.showing) {
      this.showing = true;
      this.overlayElement.show();
      this.element.setStyle({display: 'block', visibility: 'visible', position: null});
      this.frameElement.setStyle({display: 'block', visibility: 'visible', position: null});
			this.fire('onShow');
		} else {
			this.update();
		}
  },

  update: function() {
    if (!this.initialized) throw("Midas.Modal cannot update before it's been initialized");

    this.fire('onUpdate');
  },

  hide: function(options) {
    if (!this.initialized) throw("Midas.Modal cannot hide before it's been initialized");

    if (options) {
      this._options = Object.clone(this.options);
      Object.extend(this._options, options);
    }

    this.fire('beforeHide');
    this.showing = false;

    this.element.hide();
    this.overlayElement.hide();

    if (this.controls) {
      this.controls.remove();
    }
  },

  updateTitle: function() {
    if (!this.initialized) throw("Midas.Modal cannot update the title before it's been initialized");

    var titleElement = this.element.down('h1 span');
    if (this._options['title']) {
      titleElement.show();
      titleElement.update(this._options['title'] || '&nbsp;');
    } else {
      titleElement.hide();
    }
  },

  load: function(url, options) {
    if (options) {
      this._options = Object.clone(this.options);
      Object.extend(this._options, options);
    }

    this.element.addClassName('loading');

    new Ajax.Request(url, {
      method: this._options['method'] || 'get',
      parameters: this._options['parameters'] || {},
      onSuccess: function(transport) {
        this.loaded = true;
        this.element.removeClassName('loading');
        this.contentElement.innerHTML = transport.responseText;
        transport.responseText.evalScripts();

        this.setupControls();

        this.position();
        this.fire('afterLoad');
      }.bind(this),
      onFailure: function() {
        this.hide();
        alert('Midas was unable to load "' + url + '" for the modal');
      }.bind(this)
    });
  },

  position: function() {
    if (!this.element) return;
    
    this.frameElement.setStyle('width:auto');
    this.contentElement.setStyle('height:auto');<commit_msg>modal working, but modals tests all broken<commit_after>if (!Midas) var Midas = {};
Midas.modal = function(url, options) {
  var w = window.isTop() ? window : top;
  w.Midas.modal.show(url, options);
  return w.Midas.modal;
};

Object.extend(Midas.modal, {
  version: 0.2,
  initialized: false,
  options: {
    title: ''
  },

  _initialize: function(options) {
    this._options = Object.clone(this.options);
    Object.extend(this._options, options || {});

    if (this.initialized) return false;

    this._build();
    this._setupObservers();
    this.initialized = true;
  },

  _build: function() {
		this.overlayElement = new Element('div', {id: 'midas_modal_overlay', style: 'display:none'});
		this.element = new Element('div', {id: 'midas_modal', style: 'display:none'});
    this.element.update('<form class="midas-modal-frame"><h1><span></span><a>&times;</a></h1><div class="midas-modal-content-container"><div class="midas-modal-content"></div></div></form>');

    this.frameElement = this.element.down('.midas-modal-frame');
    this.contentContainerElement = this.element.down('.midas-modal-content-container');
    this.contentElement = this.element.down('.midas-modal-content');

    document.body.appendChild(this.overlayElement);
    document.body.appendChild(this.element);
  },

  _setupObservers: function() {
    Event.observe(window, 'resize', this.position.bind(this));
    Event.observe(this.element.down('h1 a'), 'click', this.hide.bind(this));
    Event.observe(this.overlayElement, 'mousedown', function(e) { e.stop(); });
    Event.observe(this.overlayElement, 'mouseup', function(e) { e.stop(); });
    Event.observe(this.element, 'mouseup', function(e) { e.stop(); });
    Event.observe(this.element.down('h1'), 'mousedown', function(e) { e.stop(); });
    Event.observe(this.frameElement, 'submit', function(e) {
      if (window['midas_modal_submit']) window['midas_modal_submit'](e);
    });

    var documents = [document];
    var iframe = $('midas-iframe-window');
    if (iframe) documents.push(iframe.contentWindow.document);
    documents.each(function(doc) {
      Event.observe(doc, 'keydown', function(e) {
        if (this.showing && e.keyCode == 27) this.hide();
      }.bind(this));
    }.bind(this));
  },

  show: function(url, options) {
    this._initialize(options);

    this.contentElement.innerHTML = '';
    this.updateTitle();

		if (!this.showing) {
      this.showing = true;
      this.appear(url);
			this.fire('onShow');
		} else {
			this.update();
		}
  },

  appear: function(url) {
    this.visible = true;
    new Effect.Appear(this.element, {
      transition: Effect.Transitions.sinoidal,
      duration: .2,
      to: 1, // setting this to less than 100% is buggy
      afterFinish: function() {
        this.load(url);
      }.bind(this)
    });
  },

  resize: function() {
    this.contentElement.hide();
    this.contentElement.slideDown();
  },

  update: function() {
    if (!this.initialized) throw("Midas.Modal cannot update before it's been initialized");

    this.fire('onUpdate');
  },

  hide: function(options) {
    if (!this.initialized) throw("Midas.Modal cannot hide before it's been initialized");

    if (options) {
      this._options = Object.clone(this.options);
      Object.extend(this._options, options);
    }

    this.fire('beforeHide');
    this.showing = false;

    this.element.hide();
    this.overlayElement.hide();

    if (this.controls) {
      this.controls.remove();
    }
  },

  updateTitle: function() {
    if (!this.initialized) throw("Midas.Modal cannot update the title before it's been initialized");

    var titleElement = this.element.down('h1 span');
    if (this._options['title']) {
      titleElement.show();
      titleElement.update(this._options['title'] || '&nbsp;');
    } else {
      titleElement.hide();
    }
  },

  load: function(url, options) {
    if (options) {
      this._options = Object.clone(this.options);
      Object.extend(this._options, options);
    }

    this.element.addClassName('loading');

    setTimeout(function() {
      new Ajax.Request(url, {
        method: this._options['method'] || 'get',
        parameters: this._options['parameters'] || {},
        onSuccess: function(transport) {
          this.loaded = true;
          this.element.removeClassName('loading');
          this.contentElement.innerHTML = transport.responseText;
          transport.responseText.evalScripts();
          this.setupControls();

          this.position();
//          this.resize();
          this.fire('afterLoad');
        }.bind(this),
        onFailure: function() {
          this.hide();
          alert('Midas was unable to load "' + url + '" for the modal');
        }.bind(this)
      });
    }.bind(this), 1000);
  },

  position: function() {
    if (!this.element) return;
    
    this.frameElement.setStyle('width:auto');
    this.contentElement.setStyle('height:auto');
{'fraction_non_alphanumeric': 0.17347580138277813, 'fraction_numerical': 0.0028284098051539913, 'mean_word_length': 3.329705215419501, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '4794432', 'n_tokens_mistral': 3043, 'n_tokens_neox': 2940, 'n_words': 536}