<commit_before>'use strict'

import CONST from './const'
import floatingNote from './floating_note'

function makeBarenoteElement(note) {
    const barenoteElement = document.createElement('a')
    barenoteElement.innerText = `${note.index + 1}`
    barenoteElement.setAttribute('id', `fnref:${note.reference}`)
    barenoteElement.setAttribute('href', `#fn:${note.reference}`)
    barenoteElement.setAttribute('class', CONST.REF_CLASS)
    barenoteElement.addEventListener('mouseover', (event) => {
        event.data = { element: barenoteElement, text: note.originalElement.innerHTML }
        floatingNote.show(event)
    })
    barenoteElement.addEventListener('mouseout', (event) => {
        floatingNote.hide()
    })
    barenoteElement.addEventListener('click', (event) => {
        note.listElement.scrollToOwnTop()

        // Cancel Event
        event.stopPropagation()
        event.preventDefault()
    })
    barenoteElement.scrollToOwnTop = scrollToOwnTop
    return barenoteElement
}<commit_msg>Support touch panel<commit_after>'use strict'

import CONST from './const'
import floatingNote from './floating_note'

function makeBarenoteElement(note) {
    let inTouch = false
    const barenoteElement = document.createElement('a')
    barenoteElement.innerText = `${note.index + 1}`
    barenoteElement.setAttribute('id', `fnref:${note.reference}`)
    barenoteElement.setAttribute('href', `#fn:${note.reference}`)
    barenoteElement.setAttribute('class', CONST.REF_CLASS)
    barenoteElement.addEventListener('touchstart', (event) => {
        event.data = { element: barenoteElement, text: note.originalElement.innerHTML }
        floatingNote.show(event)
        inTouch = true
    })
    barenoteElement.addEventListener('touchend', (event) => {
        floatingNote.hide()
        // To prevent "click" and "mouseover" events, delay to disable the flag
        setTimeout(() => {
            inTouch = false
        }, 500)
    })
    barenoteElement.addEventListener('mouseover', (event) => {
        if (inTouch) {
            return
        }
        event.data = { element: barenoteElement, text: note.originalElement.innerHTML }
        floatingNote.show(event)
    })
    barenoteElement.addEventListener('mouseout', (event) => {
        floatingNote.hide()
    })
    barenoteElement.addEventListener('click', (event) => {
        if (!inTouch) {
            note.listElement.scrollToOwnTop()
        }

        // Cancel Event
        event.stopPropagation()
        event.preventDefault()
    })
    barenoteElement.scrollToOwnTop = scrollToOwnTop
    return barenoteElement
}
{'fraction_non_alphanumeric': 0.12610195477194328, 'fraction_numerical': 0.0019164430816404753, 'mean_word_length': 3.278688524590164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '4278938', 'n_tokens_mistral': 721, 'n_tokens_neox': 756, 'n_words': 130}