<commit_before>var MS = (function (MS) {
// Start MS augmentation.
var widgets = MS.widgets = MS.widgets || {};
widgets.ModalPopup = Class.create({
  /** Configuration. Empty values will fall back to the CSS. */
  options : {
    title : "",
    displayCloseButton : true,
    screenColor : "",
    borderColor : "",
    titleColor : "",
    backgroundColor : "",
    screenOpacity : "0.5",
    verticalPosition : "center",
    horizontalPosition : "center",
    removeOnClose : false,
    onClose : Prototype.emptyFunction
  },
  /** Constructor. Registers the key listener that pops up the dialog. */
  initialize : function(content, shortcuts, options) {
    /** Shortcut configuration. Action name -&gt; {method: function(evt), keys: string[]}. */
    this.shortcuts = {
      "show" : { method : this.showDialog, keys : ['Ctrl+G', 'Meta+G']},
      "close" : { method : this.closeDialog, keys : ['Esc']}
    },

    this.content = content || "Hello world!";
    // Add the new shortcuts
    this.shortcuts = Object.extend(Object.clone(this.shortcuts), shortcuts || { });
    // Add the custom options
    this.options = Object.extend(Object.clone(this.options), options || { });
    // Register a shortcut for showing the dialog.
    this.registerShortcuts("show");
  },
  /** Create the dialog, if it is not already loaded. Otherwise, just make it visible again. */
  createDialog : function(event) {
    this.dialog = new Element('div', {'class': 'xdialog-modal-container'});
    // A full-screen semi-transparent screen covering the main document
    var screen = new Element('div', {'class': 'xdialog-screen'}).setStyle({
      opacity : this.options.screenOpacity,
      backgroundColor : this.options.screenColor
    });
    this.dialog.update(screen);
    // The dialog chrome
    this.dialogBox = new Element('div', {'class': 'xdialog-box'});
    // Insert the content
    this.dialogBox._x_contentPlug = new Element('div', {'class' : 'content'});
    this.dialogBox.update(this.dialogBox._x_contentPlug);
    this.dialogBox._x_contentPlug.update(this.content);
    // Add the dialog title
    if (this.options.title) {
      var title = new Element('div', {'class': 'xdialog-title'}).update(this.options.title);
      title.setStyle({"color" : this.options.titleColor, "backgroundColor" : this.options.borderColor});
      this.dialogBox.insertBefore(title, this.dialogBox.firstChild);
    }
    // Add the close button
    if (this.options.displayCloseButton) {
      var closeButton = new Element('div', {'class': 'xdialog-close', 'title': 'Close'}).update("&#215;");
      closeButton.setStyle({"color": this.options.titleColor});
      closeButton.observe("click", this.closeDialog.bindAsEventListener(this));
      this.dialogBox.insertBefore(closeButton, this.dialogBox.firstChild);
    }
    this.dialog.appendChild(this.dialogBox);
    this.dialogBox.setStyle({
      "textAlign": "left",
      "borderColor": this.options.borderColor,
      "backgroundColor" : this.options.backgroundColor
    });
    this.positionDialog();
    // Append to the end of the document body.
    document.body.appendChild(this.dialog);
    this.dialog.hide();
  },
  positionDialog : function() {
    switch(this.options.verticalPosition) {
      case "top":
        this.dialogBox.setStyle({"top": (document.viewport.getScrollOffsets().top + 6) + "px"});
        break;
      case "bottom":
        this.dialogBox.setStyle({"bottom": ".5em"});
        break;
      default:
        // TODO: smart alignment according to the actual height
        this.dialogBox.setStyle({"top": "35%"});
        break;
    }
    switch(this.options.horizontalPosition) {
      case "left":
        this.dialog.setStyle({"textAlign": "left"});
        break;
      case "right":
        this.dialog.setStyle({"textAlign": "right"});
        break;
      default:
        this.dialog.setStyle({"textAlign": "center"});
        this.dialogBox.setStyle({"margin": "auto"});
      break;
    }
  },
  /** Set a class name to the dialog box */
  setClass : function(className) {
    this.dialogBox.addClassName('xdialog-box-' + className);
  },
  /** Remove a class name from the dialog box */
  removeClass : function(className) {
    this.dialogBox.removeClassName('xdialog-box-' + className);
  },
  /** Set the content of the dialog box */
  setContent : function(content) {
     this.content = content;
     this.dialogBox._x_contentPlug.update(this.content);
  },
  /** Called when the dialog is displayed. Enables the key listeners and gives focus to the (cleared) input. */
  showDialog : function(event) {
    if (event) {
      Event.stop(event);
    }
    // Only do this if the dialog is not already active.
    if (!widgets.ModalPopup.active) {
      widgets.ModalPopup.active = true;
      if (!this.dialog) {
        // The dialog wasn't loaded, create it.
        this.createDialog();
      }
      // Start listening to keyboard events
      this.attachKeyListeners();
      // In IE, position: fixed does not work.
      /*if (Prototype.Browser.IE6x) {
        this.dialog.setStyle({top : document.viewport.getScrollOffsets().top + "px"});
        this.dialog._x_scrollListener = this.onScroll.bindAsEventListener(this);
        Event.observe(window, "scroll", this.dialog._x_scrollListener);
        $$("select").each(function(item) {
          item._x_initiallyVisible = item.style.visibility;
          item.style.visibility = 'hidden';
        });
      }*/
      // Display the dialog
      this.dialog.show();
    }
  },
  onScroll : function(event) {
    this.dialog.setStyle({top : document.viewport.getScrollOffsets().top + "px"});
  },
  /** Called when the dialog is closed. Disables the key listeners, hides the UI and re-enables the 'Show' behavior. */
  closeDialog : function(event) {
    if (event) {
      Event.stop(event);
    }
    /*if (window.browser.isIE6x) {
      Event.stopObserving(window, "scroll", this.dialog._x_scrollListener);
      $$("select").each(function(item) {
        item.style.visibility = item._x_initiallyVisible;
      });
    }*/
    // Call optional callback<commit_msg>[Issue #11] If the page content is very short (e.g. the demo page) the screen behind the modal popup ends abruptly Fixed<commit_after>var MS = (function (MS) {
// Start MS augmentation.
var widgets = MS.widgets = MS.widgets || {};
widgets.ModalPopup = Class.create({
  /** Configuration. Empty values will fall back to the CSS. */
  options : {
    title : "",
    displayCloseButton : true,
    screenColor : "",
    borderColor : "",
    titleColor : "",
    backgroundColor : "",
    screenOpacity : "0.5",
    verticalPosition : "center",
    horizontalPosition : "center",
    removeOnClose : false,
    onClose : Prototype.emptyFunction
  },
  /** Constructor. Registers the key listener that pops up the dialog. */
  initialize : function(content, shortcuts, options) {
    /** Shortcut configuration. Action name -&gt; {method: function(evt), keys: string[]}. */
    this.shortcuts = {
      "show" : { method : this.showDialog, keys : ['Ctrl+G', 'Meta+G']},
      "close" : { method : this.closeDialog, keys : ['Esc']}
    },

    this.content = content || "Hello world!";
    // Add the new shortcuts
    this.shortcuts = Object.extend(Object.clone(this.shortcuts), shortcuts || { });
    // Add the custom options
    this.options = Object.extend(Object.clone(this.options), options || { });
    // Register a shortcut for showing the dialog.
    this.registerShortcuts("show");
  },
  /** Create the dialog, if it is not already loaded. Otherwise, just make it visible again. */
  createDialog : function(event) {
    this.dialog = new Element('div', {'class': 'xdialog-modal-container'});
    // A full-screen semi-transparent screen covering the main document
    this.screen = new Element('div', {'class': 'xdialog-screen'}).setStyle({
      opacity : this.options.screenOpacity,
      backgroundColor : this.options.screenColor
    });
    this.dialog.update(this.screen);
    // The dialog chrome
    this.dialogBox = new Element('div', {'class': 'xdialog-box'});
    // Insert the content
    this.dialogBox._x_contentPlug = new Element('div', {'class' : 'content'});
    this.dialogBox.update(this.dialogBox._x_contentPlug);
    this.dialogBox._x_contentPlug.update(this.content);
    // Add the dialog title
    if (this.options.title) {
      var title = new Element('div', {'class': 'xdialog-title'}).update(this.options.title);
      title.setStyle({"color" : this.options.titleColor, "backgroundColor" : this.options.borderColor});
      this.dialogBox.insertBefore(title, this.dialogBox.firstChild);
    }
    // Add the close button
    if (this.options.displayCloseButton) {
      var closeButton = new Element('div', {'class': 'xdialog-close', 'title': 'Close'}).update("&#215;");
      closeButton.setStyle({"color": this.options.titleColor});
      closeButton.observe("click", this.closeDialog.bindAsEventListener(this));
      this.dialogBox.insertBefore(closeButton, this.dialogBox.firstChild);
    }
    this.dialog.appendChild(this.dialogBox);
    this.dialogBox.setStyle({
      "textAlign": "left",
      "borderColor": this.options.borderColor,
      "backgroundColor" : this.options.backgroundColor
    });
    this.positionDialog();
    // Append to the end of the document body.
    document.body.appendChild(this.dialog);
    this.dialog.hide();
    Event.observe(window, 'resize', function(event) {
      if (this.dialog.visible()) {
        this.updateScreenSize();
      }
    }.bindAsEventListener(this));
  },
  positionDialog : function() {
    switch(this.options.verticalPosition) {
      case "top":
        this.dialogBox.setStyle({"top": (document.viewport.getScrollOffsets().top + 6) + "px"});
        break;
      case "bottom":
        this.dialogBox.setStyle({"bottom": ".5em"});
        break;
      default:
        // TODO: smart alignment according to the actual height
        this.dialogBox.setStyle({"top": "35%"});
        break;
    }
    switch(this.options.horizontalPosition) {
      case "left":
        this.dialog.setStyle({"textAlign": "left"});
        break;
      case "right":
        this.dialog.setStyle({"textAlign": "right"});
        break;
      default:
        this.dialog.setStyle({"textAlign": "center"});
        this.dialogBox.setStyle({"margin": "auto"});
      break;
    }
  },
  updateScreenSize : function() {
    var __getNewDimension = function (eltToFit, dimensionAccessFunction, position) {
      var crtDimension = $(document.documentElement)[dimensionAccessFunction]();
      var viewportDimension = document.viewport.getScrollOffsets()[position] + document.viewport[dimensionAccessFunction]();
      if (eltToFit) {
        var limit = eltToFit.cumulativeOffset()[position] + eltToFit[dimensionAccessFunction]();
      }
      var result = '';
      if (limit && crtDimension < limit) {
        result = limit + 'px';
      }
      if (limit && limit < viewportDimension) {
        result = viewportDimension + 'px';
      }
      return result;
    };
    this.screen.style.width  = __getNewDimension(this.dialogBox, 'getWidth', 'left');
    this.screen.style.height = __getNewDimension(this.dialogBox, 'getHeight', 'top');
  },
  /** Set a class name to the dialog box */
  setClass : function(className) {
    this.dialogBox.addClassName('xdialog-box-' + className);
  },
  /** Remove a class name from the dialog box */
  removeClass : function(className) {
    this.dialogBox.removeClassName('xdialog-box-' + className);
  },
  /** Set the content of the dialog box */
  setContent : function(content) {
     this.content = content;
     this.dialogBox._x_contentPlug.update(this.content);
  },
  /** Called when the dialog is displayed. Enables the key listeners and gives focus to the (cleared) input. */
  showDialog : function(event) {
    if (event) {
      Event.stop(event);
    }
    // Only do this if the dialog is not already active.
    if (!widgets.ModalPopup.active) {
      widgets.ModalPopup.active = true;
      if (!this.dialog) {
        // The dialog wasn't loaded, create it.
        this.createDialog();
      }
      // Start listening to keyboard events
      this.attachKeyListeners();
      // In IE, position: fixed does not work.
      /*if (Prototype.Browser.IE6x) {
        this.dialog.setStyle({top : document.viewport.getScrollOffsets().top + "px"});
        this.dialog._x_scrollListener = this.onScroll.bindAsEventListener(this);
        Event.observe(window, "scroll", this.dialog._x_scrollListener);
        $$("select").each(function(item) {
          item._x_initiallyVisible = item.style.visibility;
          item.style.visibility = 'hidden';
        });
      }*/
      // Display the dialog
      this.dialog.show();
      this.updateScreenSize();
    }
  },
  onScroll : function(event) {
    this.dialog.setStyle({top : document.viewport.getScrollOffsets().top + "px"});
  },
  /** Called when the dialog is closed. Disables the key listeners, hides the UI and re-enables the 'Show' behavior. */
  closeDialog : function(event) {
    if (event) {
      Event.stop(event);
    }
    /*if (window.browser.isIE6x) {
      Event.stopObserving(window, "scroll", this.dialog._x_scrollListener);
      $$("select").each(function(item) {
        item.style.visibility = item._x_initiallyVisible;
      });
    }*/
    // Call optional callback
{'fraction_non_alphanumeric': 0.14663084844414595, 'fraction_numerical': 0.0017909111260353706, 'mean_word_length': 3.0173860911270984, 'pattern_counts': {'":': 28, '<': 5, '<?xml version=': 0, '>': 3, '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': '4903074', 'n_tokens_mistral': 3965, 'n_tokens_neox': 3882, 'n_words': 900}