<commit_before>/* global BookReader */
/**
 * Plugin for chapter markers in BookReader. Fetches from openlibrary.org
 * Could be forked, or extended to alter behavior
 */

jQuery.extend(BookReader.defaultOptions, {
  olHost: 'https://openlibrary.org',
  enableChaptersPlugin: true,
  bookId: '',
});

/** @override Extend the constructor to add search properties */
BookReader.prototype.setup = (function (super_) {
  return function (options) {
    super_.call(this, options);

    this.olHost = options.olHost;
    this.enableChaptersPlugin = options.enableChaptersPlugin;
    this.bookId = options.bookId;
  };
})(BookReader.prototype.setup);

/** @override Extend to call Open Library for TOC */
BookReader.prototype.init = (function(super_) {
  return function() {
    super_.call(this);
    if (this.enableChaptersPlugin && this.ui !== 'embed') {
      this.getOpenLibraryRecord();
    }
    if (this.enableMobileNav) {
      this.bind(BookReader.eventNames.mobileNavOpen,
        () => {
          this.updateTOCState(this.firstIndex, this._tocEntries);
          if($('table-contents-list').parent().hasClass('mm-opened')){
            this.updateTOCState(this.firstIndex, this._tocEntries);
          }
        }
      )
      $(".BRmobileMenu__tableContents").click(
        () => {
          this.updateTOCState(this.firstIndex, this._tocEntries);
        }
      );
    }
  }
})(BookReader.prototype.init);

/**
 * Adds chapter marker to navigation scrubber
 *
 * @param {string} chapterTitle
 * @param {string} pageNumber
 * @param {number} pageIndex
 */
BookReader.prototype.addChapter = function(chapterTitle, pageNumber, pageIndex) {
  const uiStringPage = 'Page'; // i18n
  const percentThrough = BookReader.util.cssPercentage(pageIndex, this.getNumLeafs() - 1);
  const jumpToChapter = (event) => {
    this.jumpToIndex($(event.target).data('pageIndex'));
    $('.current-chapter').removeClass('current-chapter');
    $(event.target).addClass('current-chapter');
  }
  const title = `${chapterTitle} | `;
  const pageStr = `${uiStringPage} ${pageNumber}`;

  //adding items to mobile table of contents
  const mobileChapter = $(`<li></li>`).append($(`<span class='BRTOCElementTitle'></span>`).text(title))
    .append($(`<span class='BRTOCElementPage'></span>`).text(pageStr));
  mobileChapter.addClass('BRtable-contents-el')
    .appendTo(this.$('.table-contents-list'))
    .data({ pageIndex });

  //adds .BRchapters to the slider only if pageIndex exists
  if(pageIndex != undefined){
    $(`<div><div>${title}</div></div>`)
      .addClass('BRchapter')
      .css({ left: percentThrough })
      .appendTo(this.$('.BRnavline'))
      .data({ pageIndex })
      .bt({
        contentSelector: '$(this).find("> div")',
        trigger: 'hover',
        closeWhenOthersOpen: true,
        cssStyles: {
          padding: '12px 14px',
          backgroundColor: '#fff',
          border: '4px solid rgb(216,216,216)',
          color: 'rgb(52,52,52)'
        },
        shrinkToFit: false,
        width: '230px',
        padding: 0,
        spikeGirth: 0,
        spikeLength: 0,
        overlap: '0px',
        overlay: false,
        killTitle: false,
        offsetParent: null,
        positions: ['top'],
        fill: 'white',
        windowMargin: 10,
        strokeWidth: 0,
        cornerRadius: 0,
        centerPointX: 0,
        centerPointY: 0,
        shadow: false
      })
      .hover(event => {
      // remove hover effect from other markers then turn on just for this
        this.$('.BRsearch,.BRchapter').removeClass('front');
        $(event.target).addClass('front');
      },
      event => $(event.target).removeClass('front')
      )
      .bind('click', jumpToChapter);

    //adding clickable properties to mobile chapters
    mobileChapter.bind('click', jumpToChapter)
      .addClass('chapter-clickable')
      .attr("data-event-click-tracking","BRTOCPanel|GoToChapter");
  }

};

/*
 * Remove all chapters.
 */
BookReader.prototype.removeChapters = function() {
  this.$('.BRnavpos .BRchapter').remove();
};

/**
 * Update the table of contents based on array of TOC entries.
 * @param {TocEntry[]} tocEntries
 */
BookReader.prototype.updateTOC = function(tocEntries) {
  this.removeChapters();
  if(this.enableMobileNav && tocEntries.length > 0){
    this.$(".BRmobileMenu__tableContents").show();
  }
  for (let i = 0; i < tocEntries.length; i++) {
    this.addChapterFromEntry(tocEntries[i]);
  }
  this._tocEntries = tocEntries;
  $('.table-contents-list').children().each((i, el) => {
    tocEntries[i].mobileHTML = el;
  })
};<commit_msg>fixed clicking on text span in toc-el did not work<commit_after>/* global BookReader */
/**
 * Plugin for chapter markers in BookReader. Fetches from openlibrary.org
 * Could be forked, or extended to alter behavior
 */

jQuery.extend(BookReader.defaultOptions, {
  olHost: 'https://openlibrary.org',
  enableChaptersPlugin: true,
  bookId: '',
});

/** @override Extend the constructor to add search properties */
BookReader.prototype.setup = (function (super_) {
  return function (options) {
    super_.call(this, options);

    this.olHost = options.olHost;
    this.enableChaptersPlugin = options.enableChaptersPlugin;
    this.bookId = options.bookId;
  };
})(BookReader.prototype.setup);

/** @override Extend to call Open Library for TOC */
BookReader.prototype.init = (function(super_) {
  return function() {
    super_.call(this);
    if (this.enableChaptersPlugin && this.ui !== 'embed') {
      this.getOpenLibraryRecord();
    }
    if (this.enableMobileNav) {
      this.bind(BookReader.eventNames.mobileNavOpen,
        () => {
          this.updateTOCState(this.firstIndex, this._tocEntries);
          if($('table-contents-list').parent().hasClass('mm-opened')){
            this.updateTOCState(this.firstIndex, this._tocEntries);
          }
        }
      )
      $(".BRmobileMenu__tableContents").click(
        () => {
          this.updateTOCState(this.firstIndex, this._tocEntries);
        }
      );
    }
  }
})(BookReader.prototype.init);

/**
 * Adds chapter marker to navigation scrubber
 *
 * @param {string} chapterTitle
 * @param {string} pageNumber
 * @param {number} pageIndex
 */
BookReader.prototype.addChapter = function(chapterTitle, pageNumber, pageIndex) {
  const uiStringPage = 'Page'; // i18n
  const percentThrough = BookReader.util.cssPercentage(pageIndex, this.getNumLeafs() - 1);
  const jumpToChapter = (event) => {
    let $chapterEl = $(event.target);
    if(!$(event.target).hasClass('chapter-clickable')){
      $chapterEl = $(event.target).parent();
    }
    this.jumpToIndex($chapterEl.data('pageIndex'));
    $('.current-chapter').removeClass('current-chapter');
    $chapterEl.addClass('current-chapter');
  }
  const title = `${chapterTitle} | `;
  const pageStr = `${uiStringPage} ${pageNumber}`;

  //adding items to mobile table of contents
  const mobileChapter = $(`<li></li>`).append($(`<span class='BRTOCElementTitle'></span>`).text(title))
    .append($(`<span class='BRTOCElementPage'></span>`).text(pageStr));
  mobileChapter.addClass('BRtable-contents-el')
    .appendTo(this.$('.table-contents-list'))
    .data({ pageIndex });

  //adds .BRchapters to the slider only if pageIndex exists
  if(pageIndex != undefined){
    $(`<div><div>${title}</div></div>`)
      .addClass('BRchapter')
      .css({ left: percentThrough })
      .appendTo(this.$('.BRnavline'))
      .data({ pageIndex })
      .bt({
        contentSelector: '$(this).find("> div")',
        trigger: 'hover',
        closeWhenOthersOpen: true,
        cssStyles: {
          padding: '12px 14px',
          backgroundColor: '#fff',
          border: '4px solid rgb(216,216,216)',
          color: 'rgb(52,52,52)'
        },
        shrinkToFit: false,
        width: '230px',
        padding: 0,
        spikeGirth: 0,
        spikeLength: 0,
        overlap: '0px',
        overlay: false,
        killTitle: false,
        offsetParent: null,
        positions: ['top'],
        fill: 'white',
        windowMargin: 10,
        strokeWidth: 0,
        cornerRadius: 0,
        centerPointX: 0,
        centerPointY: 0,
        shadow: false
      })
      .hover(event => {
      // remove hover effect from other markers then turn on just for this
        this.$('.BRsearch,.BRchapter').removeClass('front');
        $(event.target).addClass('front');
      },
      event => $(event.target).removeClass('front')
      )
      .on('click', jumpToChapter);

    //adding clickable properties to mobile chapters
    mobileChapter.bind('click', jumpToChapter)
      .addClass('chapter-clickable')
      .attr("data-event-click-tracking","BRTOCPanel|GoToChapter")
      .children().bind('click', jumpToChapter);
  }

};

/*
 * Remove all chapters.
 */
BookReader.prototype.removeChapters = function() {
  this.$('.BRnavpos .BRchapter').remove();
};

/**
 * Update the table of contents based on array of TOC entries.
 * @param {TocEntry[]} tocEntries
 */
BookReader.prototype.updateTOC = function(tocEntries) {
  this.removeChapters();
  if(this.enableMobileNav && tocEntries.length > 0){
    this.$(".BRmobileMenu__tableContents").show();
  }
  for (let i = 0; i < tocEntries.length; i++) {
    this.addChapterFromEntry(tocEntries[i]);
  }
  this._tocEntries = tocEntries;
  $('.table-contents-list').children().each((i, el) => {
    tocEntries[i].mobileHTML = el;
  })
};
{'fraction_non_alphanumeric': 0.15920926772239347, 'fraction_numerical': 0.00807737272823892, 'mean_word_length': 3.0630397236614852, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 39, 'https://': 2, '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': '5879908', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2848, 'n_words': 579}