<commit_before>var CurrentMessageBox = null;

function ShowMessageBox(BodyHTML, Buttons, OnButtonClick)
{
  var MessageBoxModalBackground = d3.select('body').append('div').attr('class', "messagebox-modal-background");
  var MessageBox = d3.select('body').append('div').attr('class', "messagebox");
  
  var Body = MessageBox.append('div').attr('class', "messagebox-header");
  var ButtonList = MessageBox.append('div').attr('class', "messagebox-buttonlist");
  
  Body.html(BodyHTML);
  
  if(!Buttons || Buttons.constructor !== Array || Buttons.length == 0)
    Buttons = ["Okay"];
    
  for(var i=0;i<Buttons.length;++i)
  {
    var button = ButtonList.append('input').attr('type', 'button').attr('value', Buttons[i]);
    
    button.on('click', function() {
      if(typeof OnButtonClick === 'function') OnButtonClick(this.value);
			MessageBox.remove();
			MessageBoxModalBackground.remove();
			CurrentMessageBox = null;
		});
  }
  
  CurrentMessageBox = MessageBox;
	RepositionMessageBox();
}

function RepositionMessageBox()
{
	if(!CurrentMessageBox)
		return;
    
	CurrentMessageBox.style('top', (document.documentElement.clientHeight/2 - CurrentMessageBox.node().clientHeight/2) + 'px')
                   .style('left', (document.documentElement.clientWidth/2 - CurrentMessageBox.node().clientWidth/2) + 'px');
}<commit_msg>Added ability to close message boxes externally, and to not close if callback returns true<commit_after>var MessageBoxCurrent = null;
var MessageBoxCurrentModalBackground = null;
var MessageBoxCurrentCallback = null;

function ShowMessageBox(BodyHTML, Buttons, OnButtonClick)
{
  CloseMessageBox();
  var MessageBoxModalBackground = d3.select('body').append('div').attr('class', "messagebox-modal-background");
  var MessageBox = d3.select('body').append('div').attr('class', "messagebox");
  
  var Body = MessageBox.append('div').attr('class', "messagebox-header");
  var ButtonList = MessageBox.append('div').attr('class', "messagebox-buttonlist");
  
  Body.html(BodyHTML);
  
  if(!Buttons || Buttons.constructor !== Array || Buttons.length == 0)
    Buttons = ["Okay"];
    
  for(var i=0;i<Buttons.length;++i)
  {
    var button = ButtonList.append('input').attr('type', 'button').attr('value', Buttons[i]);
    
    button.on('click', function() {
      var close = true;
      if(typeof OnButtonClick === 'function' && OnButtonClick(this.value))
          close = false;
      if(close)
        CloseMessageBox();
		});
  }
  
  MessageBoxCurrent = MessageBox;
  MessageBoxCurrentModalBackground = MessageBoxModalBackground;
  MessageBoxCurrentCallback = OnButtonClick;
	RepositionMessageBox();
}

function RepositionMessageBox()
{
	if(!MessageBoxCurrent)
		return;
    
	MessageBoxCurrent.style('top', (document.documentElement.clientHeight/2 - MessageBoxCurrent.node().clientHeight/2) + 'px')
                   .style('left', (document.documentElement.clientWidth/2 - MessageBoxCurrent.node().clientWidth/2) + 'px');
}

function CloseMessageBox()
{
  if(MessageBoxCurrent)
    MessageBoxCurrent.remove();
  if(MessageBoxCurrentModalBackground)
    MessageBoxCurrentModalBackground.remove();
  MessageBoxCurrent = null;
  MessageBoxCurrentModalBackground = null;
  MessageBoxCurrentCallback = null;
}
{'fraction_non_alphanumeric': 0.15143120960295475, 'fraction_numerical': 0.0049245921822099106, 'mean_word_length': 4.803571428571429, 'pattern_counts': {'":': 0, '<': 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': '7413646', 'n_tokens_mistral': 976, 'n_tokens_neox': 959, 'n_words': 166}