<commit_before>// FIXME: legacy study-page.js

import $$, { domGet } from "@lib/dom";
import { kk_globals_get } from "@app/root-bundle";
import VueInstance from "@lib/helpers/vue-instance";
import actb from "@old/autocomplete.js";
import AjaxPanel from "@old/ajaxpanel";
import EventDelegator from "@old/eventdelegator";
import EditFlashcardDialog from "@old/components/EditFlashcardDialog";
import KoohiiDictList from "@/vue/KoohiiDictList.vue";
import KoohiiEditStory from "@/vue/KoohiiEditStory.vue";
import SharedStoriesComponent from "@old/components/SharedStoriesComponent";

const CLASS_ACTIVE = "active";

export default {
  elEditFlashcard: null as Element | null,
  oEditFlashcard: null as EditFlashcardDialog | null,

  elSearch: (null as any) as HTMLInputElement,

  dictVisible: false,
  dictPanel: null as AjaxPanel | null,

  initialize() {
    // references
    this.elSearch = domGet<HTMLInputElement>("txtSearch")!;

    // quick search autocomplete
    const actb1 = new actb(this.elSearch, window.kwlist);
    actb1.onChangeCallback = this.quicksearchOnChangeCallback.bind(this);
    actb1.onPressEnterCallback = this.quicksearchEnterCallback.bind(this);

    actb1.actb_extracolumns = function(iRow) {
      return `<span class="f">${iRow +
        1}</span><span class="k cj-k" lang="ja" xml:lang="ja">&#${window.kklist.charCodeAt(
        iRow
      )};</span>`;
    };

    // clicking in quick search box selects the text
    $$(this.elSearch).on("focus", (evt: Event) => {
      if (this.elSearch.value !== "") {
        this.elSearch.select();
      }
    });

    // auto focus search box
    if (this.elSearch && this.elSearch.value === "") {
      this.elSearch.focus();
    }

    let elEditStory = domGet("JsEditStoryInst")!;
    window.Koohii.Refs.vueEditStory = VueInstance(
      KoohiiEditStory,
      elEditStory,
      kk_globals_get("EDITSTORY_PROPS")
    );

    const elDictStudy = domGet("DictStudy");
    elDictStudy && this.initDictionary(elDictStudy);

    const elSharedStories = domGet("SharedStoriesComponent");
    if (elSharedStories) {
      new SharedStoriesComponent(this, elSharedStories);
    }

    const elEditFlashcard = domGet("EditFlashcard");
    if (elEditFlashcard) {
      this.elEditFlashcard = elEditFlashcard;
      var ed = new (EventDelegator as IEventDelegator)(
        elEditFlashcard,
        "click"
      );
      ed.on("JsEditFlashcard", this.onEditFlashcard, this);
    }

    console.log("@entry study ...done");
  },

  initDictionary(el: Element) {
    $$("#DictHead").on("click", this.toggleDictionary.bind(this));
    this.dictVisible = false;
    this.dictPanel = null;
  },

  toggleDictionary(evt: Event) {<commit_msg>Fix entry-study initialize() to not assume Study page (it is a common bundle)<commit_after>// FIXME: legacy study-page.js

import $$, { domGet } from "@lib/dom";
import { kk_globals_get } from "@app/root-bundle";
import VueInstance from "@lib/helpers/vue-instance";
import actb from "@old/autocomplete.js";
import AjaxPanel from "@old/ajaxpanel";
import EventDelegator from "@old/eventdelegator";
import EditFlashcardDialog from "@old/components/EditFlashcardDialog";
import KoohiiDictList from "@/vue/KoohiiDictList.vue";
import KoohiiEditStory from "@/vue/KoohiiEditStory.vue";
import SharedStoriesComponent from "@old/components/SharedStoriesComponent";

const CLASS_ACTIVE = "active";

export default {
  elEditFlashcard: null as Element | null,
  oEditFlashcard: null as EditFlashcardDialog | null,

  elSearch: (null as any) as HTMLInputElement,

  dictVisible: false,
  dictPanel: null as AjaxPanel | null,

  initialize() {
    // references
    this.elSearch = domGet<HTMLInputElement>("txtSearch")!;

    // quick search autocomplete
    if (this.elSearch) {
      const actb1 = new actb(this.elSearch, window.kwlist);
      actb1.onChangeCallback = this.quicksearchOnChangeCallback.bind(this);
      actb1.onPressEnterCallback = this.quicksearchEnterCallback.bind(this);

      actb1.actb_extracolumns = function(iRow) {
        return `<span class="f">${iRow +
          1}</span><span class="k cj-k" lang="ja" xml:lang="ja">&#${window.kklist.charCodeAt(
          iRow
        )};</span>`;
      };

      // clicking in quick search box selects the text
      $$(this.elSearch).on("focus", (evt: Event) => {
        if (this.elSearch.value !== "") {
          this.elSearch.select();
        }
      });
    }

    // auto focus search box
    if (this.elSearch && this.elSearch.value === "") {
      this.elSearch.focus();
    }

    const elEditStory = domGet("JsEditStoryInst")!;
    if (elEditStory) {
      window.Koohii.Refs.vueEditStory = VueInstance(
        KoohiiEditStory,
        elEditStory,
        kk_globals_get("EDITSTORY_PROPS")
      );
    }

    const elDictStudy = domGet("DictStudy");
    elDictStudy && this.initDictionary(elDictStudy);

    const elSharedStories = domGet("SharedStoriesComponent");
    if (elSharedStories) {
      new SharedStoriesComponent(this, elSharedStories);
    }

    const elEditFlashcard = domGet("EditFlashcard");
    if (elEditFlashcard) {
      this.elEditFlashcard = elEditFlashcard;
      var ed = new (EventDelegator as IEventDelegator)(
        elEditFlashcard,
        "click"
      );
      ed.on("JsEditFlashcard", this.onEditFlashcard, this);
    }

    console.log("@entry study ...done");
  },

  initDictionary(el: Element) {
    $$("#DictHead").on("click", this.toggleDictionary.bind(this));
    this.dictVisible = false;
    this.dictPanel = null;
  },

  toggleDictionary(evt: Event) {
{'fraction_non_alphanumeric': 0.13244795405599424, 'fraction_numerical': 0.0017946877243359654, 'mean_word_length': 3.5493877551020407, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4416094', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1751, 'n_words': 364}