<commit_before>/* eslint-disable no-unused-vars */
import { isMobile } from '../util/env';
import * as dom from '../util/dom';

const title = dom.$.title;
/**
 * Toggle button
 * @param {Element} el Button to be toggled
 * @void
 */
export function btn(el) {
  const toggle = _ => dom.body.classList.toggle('close');

  el = dom.getNode(el);
  if (el === null || el === undefined) {
    return;
  }

  dom.on(el, 'click', e => {
    e.stopPropagation();
    toggle();
  });

  isMobile &&
    dom.on(
      dom.body,
      'click',
      _ => dom.body.classList.contains('close') && toggle()
    );
}

export function collapse(el) {
  el = dom.getNode(el);
  if (el === null || el === undefined) {
    return;
  }

  dom.on(el, 'click', ({ target }) => {
    if (
      target.nodeName === 'A' &&
      target.nextSibling &&
      target.nextSibling.classList.contains('app-sub-sidebar')
    ) {
      dom.toggleClass(target.parentNode, 'collapse');
    }
  });
}

export function sticky() {
  const cover = dom.getNode('section.cover');
  if (!cover) {
    return;
  }

  const coverHeight = cover.getBoundingClientRect().height;

  if (window.pageYOffset >= coverHeight || cover.classList.contains('hidden')) {
    dom.toggleClass(dom.body, 'add', 'sticky');
  } else {
    dom.toggleClass(dom.body, 'remove', 'sticky');
  }
}

/**
 * Get and active link
 * @param  {Object} router Router
 * @param  {String|Element} el Target element
 * @param  {Boolean} isParent Active parent
 * @param  {Boolean} autoTitle Automatically set title
 * @return {Element} Active element<commit_msg>Update sidebar.js<commit_after>/* eslint-disable no-unused-vars */
import { isMobile } from '../util/env';
import * as dom from '../util/dom';

const title = dom.$.title;
/**
 * Toggle button
 * @param {Element} el Button to be toggled
 * @void
 */
export function btn(el) {
  const toggle = _ => dom.body.classList.toggle('close');

  el = dom.getNode(el);
  if (el === null || el === undefined) {
    return;
  }

  dom.on(el, 'click', e => {
    e.stopPropagation();
    toggle();
  });

  isMobile &&
    dom.on(
      dom.body,
      'click',
      _ => dom.body.classList.contains('close') && toggle()
    );
}

export function collapse(el) {
  el = dom.getNode(el);
  if (el === null || el === undefined) {
    return;
  }

  dom.on(el, 'click', ({ target }) => {
    if (
      target.nodeName === 'A' &&
      target.nextSibling &&      
      target.nextSibling.classList &&
      target.nextSibling.classList.contains('app-sub-sidebar')
    ) {
      dom.toggleClass(target.parentNode, 'collapse');
    }
  });
}

export function sticky() {
  const cover = dom.getNode('section.cover');
  if (!cover) {
    return;
  }

  const coverHeight = cover.getBoundingClientRect().height;

  if (window.pageYOffset >= coverHeight || cover.classList.contains('hidden')) {
    dom.toggleClass(dom.body, 'add', 'sticky');
  } else {
    dom.toggleClass(dom.body, 'remove', 'sticky');
  }
}

/**
 * Get and active link
 * @param  {Object} router Router
 * @param  {String|Element} el Target element
 * @param  {Boolean} isParent Active parent
 * @param  {Boolean} autoTitle Automatically set title
 * @return {Element} Active element
{'fraction_non_alphanumeric': 0.1745488487865588, 'fraction_numerical': 0.0, 'mean_word_length': 3.00373599003736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2328543', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1070, 'n_words': 245}