<commit_before>//
// User Interface
//

// Event listeners for drawer.
var toggle = $('#toggle').on('click', toggleDrawer);
var toggle = $('#toggle').on('touchend', toggleDrawer);

// Gather control elements.
var controls = $$('#form-controls label');

// Set up each widget.
controls.forEach(function(current, index, array) {
  current.on('touchend', function toggleLabel() {
    if ($('#form-controls').classList.contains('controls--open')) {
      var widget = $('#' + current.htmlFor);

      // Collapse all controls.
      collapseControls();

      // Enable the widget that was clicked.
      widget.removeAttribute('disabled');
      if (widget.id !== 'color') {
        widget.removeAttribute('readonly');
      }

      // Whitelist which widgets can pop up.
      var toggle_widgets = ['opacity'];

      // Toggle the widget if needed.
      if (toggle_widgets.indexOf(current.htmlFor) !== -1) {
        widget.classList.toggle('visible');

        // Remove focus from color input when closing.
        if (current.htmlFor === 'color') {
          blurAll();
        }
      }
    }
  })
});

// Enable color picker on color input
jsColorPicker('#color', {
  size: 3,
  fps: 60,
  noAlpha: true,
  customBG: '#000',
  appendTo: $('label[for="color"]'),
  memoryColors: false,
  noRangeBackground: false,
  noResize: false,
  noRGBr: false,
  noRGBg: false,
  noRGBb: false,
});

// If save button is possible, create it now.
if (Modernizr.atobbtoa && Modernizr.adownload) {
  // Find control panel.
  var controls = $('#form-controls');

  // Create save button.
  var save_button = document.createElement('a');
  save_button.setAttribute('id', 'save');
  save_button.setAttribute('aria-role', 'button');
  save_button.innerHTML = '💾';

  // Add button to control panel.
  controls.appendChild(save_button);

  // Set up event listener.
  //
  // Saving the SVG can be invoked any number of times during a session.
  // The downloads are timestamped to make for easy oranization of files.
  save_button.on('click', function saveCanvas() {
    // Generate SVG
    var save_svg = $('#canvas').innerHTML.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
    var data_uri = 'data:image/svg+xml;base64,' + window.btoa(save_svg);
    var filename = 'bustashape-' + window.location.hash.replace('#', '') + '-' + Date.now() + '.svg';

    // Download SVG
    save_button.setAttribute('href', data_uri);
    save_button.setAttribute('download', filename);
  });
}


// Helper function to toggle Drawer
function toggleDrawer(e) {<commit_msg>:nail_care: hide save button on mobile for now.<commit_after>//
// User Interface
//

// Event listeners for drawer.
var toggle = $('#toggle').on('click', toggleDrawer);
var toggle = $('#toggle').on('touchend', toggleDrawer);

// Gather control elements.
var controls = $$('#form-controls label');

// Set up each widget.
controls.forEach(function(current, index, array) {
  current.on('touchend', function toggleLabel() {
    if ($('#form-controls').classList.contains('controls--open')) {
      var widget = $('#' + current.htmlFor);

      // Collapse all controls.
      collapseControls();

      // Enable the widget that was clicked.
      widget.removeAttribute('disabled');
      if (widget.id !== 'color') {
        widget.removeAttribute('readonly');
      }

      // Whitelist which widgets can pop up.
      var toggle_widgets = ['opacity'];

      // Toggle the widget if needed.
      if (toggle_widgets.indexOf(current.htmlFor) !== -1) {
        widget.classList.toggle('visible');

        // Remove focus from color input when closing.
        if (current.htmlFor === 'color') {
          blurAll();
        }
      }
    }
  })
});

// Enable color picker on color input
jsColorPicker('#color', {
  size: 3,
  fps: 60,
  noAlpha: true,
  customBG: '#000',
  appendTo: $('label[for="color"]'),
  memoryColors: false,
  noRangeBackground: false,
  noResize: false,
  noRGBr: false,
  noRGBg: false,
  noRGBb: false,
});

// If save button is possible, create it now.
//
// @TODO: During room creation, create config to either show or hide button
//        instead of always hiding when touch events are detected.
if (Modernizr.atobbtoa && Modernizr.adownload && !Modernizr.touchevents) {
  // Find control panel.
  var controls = $('#form-controls');

  // Create save button.
  var save_button = document.createElement('a');
  save_button.setAttribute('id', 'save');
  save_button.setAttribute('aria-role', 'button');
  save_button.innerHTML = '💾';

  // Add button to control panel.
  controls.appendChild(save_button);

  // Set up event listener.
  //
  // Saving the SVG can be invoked any number of times during a session.
  // The downloads are timestamped to make for easy oranization of files.
  save_button.on('click', function saveCanvas() {
    // Generate SVG
    var save_svg = $('#canvas').innerHTML.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
    var data_uri = 'data:image/svg+xml;base64,' + window.btoa(save_svg);
    var filename = 'bustashape-' + window.location.hash.replace('#', '') + '-' + Date.now() + '.svg';

    // Download SVG
    save_button.setAttribute('href', data_uri);
    save_button.setAttribute('download', filename);
  });
}


// Helper function to toggle Drawer
function toggleDrawer(e) {
{'fraction_non_alphanumeric': 0.15782543265613244, 'fraction_numerical': 0.005267118133935289, 'mean_word_length': 3.1866141732283464, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2303616', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1601, 'n_words': 441}