<commit_before>// StyleDocco documentation user interface elements
// ==================================================================
// Dropdown, search, display settings.

(function() {

'use strict';

/*global index:false*/

// Helper functions. Using `Array.prototype` to make them work on NodeLists.
var filter = function(arr, it) { return Array.prototype.filter.call(arr, it); };
var forEach = function(arr, it) { return Array.prototype.forEach.call(arr, it); };

// Parse `key=value; key=value` strings (for cookies).
var keyvalParse = function(str) {
  var obj = {};
  var pairs = str.split(';');
  for (var i = 0; pairs.length > i; i++) {
    var kvs = pairs[i].trim().split('=');
    obj[kvs[0]] = kvs[1];
  }
  return obj;
};
var postMessage = function(target, msg) {
  target.contentDocument.defaultView.postMessage(msg, '*');
};

var headEl = document.getElementsByTagName('head')[0];
var bodyEl = document.getElementsByTagName('body')[0];

var settingsEl = bodyEl.getElementsByClassName('settings')[0];
var resizeableElOffset = 30; // `.resizeable` padding
var resizeableEls = bodyEl.getElementsByClassName('resizeable');
var resizePreviews = function(width) {
  document.cookie = 'preview-width=' + width;
  forEach(resizeableEls, function(el) {
    if (width === 'auto') width = el.parentNode.offsetWidth;
    el.style.width = width + 'px';
    // TODO: Add CSS transitions and update height after `transitionend` event
    postMessage(el.getElementsByTagName('iframe')[0], 'getHeight');
  });
};

window.addEventListener('message', function (ev) {
  if (ev.data == null || !ev.source) return;
  var data = ev.data;
  var sourceFrameEl = document.getElementsByName(ev.source.name)[0];
  // Set iframe height
  if (data.height != null && sourceFrameEl) {
    sourceFrameEl.parentNode.style.height = (data.height + resizeableElOffset) + 'px';
  }
}, false);

var previewWidth = keyvalParse(document.cookie)['preview-width'];
if (previewWidth) {
  resizePreviews(previewWidth);
  forEach(settingsEl.getElementsByClassName('is-active'), function(el) {
    el.classList.remove('is-active');
  });
  settingsEl.querySelector('button[data-width="' + previewWidth + '"]')
    .classList.add('is-active');
}
// Resizing buttons
if (settingsEl) {
  settingsEl.addEventListener('click', function(event) {
    if (event.target.tagName.toLowerCase() !== 'button') return;
    event.preventDefault();
    var btn = event.target;
    forEach(btn.parentNode.getElementsByClassName('is-active'), function(el) {
      el.classList.remove('is-active');<commit_msg>Fix settings buttons<commit_after>// StyleDocco documentation user interface elements
// ==================================================================
// Dropdown, search, display settings.

(function() {

'use strict';

/*global index:false*/

// Helper functions. Using `Array.prototype` to make them work on NodeLists.
var filter = function(arr, it) { return Array.prototype.filter.call(arr, it); };
var forEach = function(arr, it) { return Array.prototype.forEach.call(arr, it); };

// Parse `key=value; key=value` strings (for cookies).
var keyvalParse = function(str) {
  var obj = {};
  var pairs = str.split(';');
  for (var i = 0; pairs.length > i; i++) {
    var kvs = pairs[i].trim().split('=');
    obj[kvs[0]] = kvs[1];
  }
  return obj;
};
var postMessage = function(target, msg) {
  target.contentDocument.defaultView.postMessage(msg, '*');
};

var headEl = document.getElementsByTagName('head')[0];
var bodyEl = document.getElementsByTagName('body')[0];

var settingsEl = bodyEl.getElementsByClassName('settings')[0];
var resizeableElOffset = 30; // `.resizeable` padding
var resizeableEls = bodyEl.getElementsByClassName('resizeable');
var resizePreviews = function(width) {
  document.cookie = 'preview-width=' + width;
  forEach(resizeableEls, function(el) {
    if (width === 'auto') width = el.parentNode.offsetWidth;
    el.style.width = width + 'px';
    // TODO: Add CSS transitions and update height after `transitionend` event
    postMessage(el.getElementsByTagName('iframe')[0], 'getHeight');
  });
};

window.addEventListener('message', function (ev) {
  if (ev.data == null || !ev.source) return;
  var data = ev.data;
  var sourceFrameEl = document.getElementsByName(ev.source.name)[0];
  // Set iframe height
  if (data.height != null && sourceFrameEl) {
    sourceFrameEl.parentNode.style.height = (data.height + resizeableElOffset) + 'px';
  }
}, false);

var previewWidth = keyvalParse(document.cookie)['preview-width'];
if (previewWidth) {
  resizePreviews(previewWidth);
  forEach(settingsEl.getElementsByClassName('is-active'), function(el) {
    el.classList.remove('is-active');
  });
  var btn = settingsEl.querySelector('button[data-width="' + previewWidth + '"]');
  if (btn) { btn.classList.add('is-active'); }
}
// Resizing buttons
if (settingsEl) {
  settingsEl.addEventListener('click', function(event) {
    var tagName = event.target.tagName.toLowerCase();
    if (tagName === 'button') var btn = event.target;
    else if (tagName === 'i') var btn = event.target.parentNode;
    else return;
    if (btn.tagName.toLowerCase() !== 'button') return;
    event.preventDefault();
    forEach(btn.parentNode.getElementsByClassName('is-active'), function(el) {
      el.classList.remove('is-active');
{'fraction_non_alphanumeric': 0.18426501035196688, 'fraction_numerical': 0.003764351590438547, 'mean_word_length': 4.782372143634385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7510429', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1633, 'n_words': 364}