deemixer/public/js/modules/search.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-04-28 18:42:22 +00:00
import MainSearch from './components/main-search.js'
import Utils from './utils.js'
2020-04-23 19:03:12 +00:00
import QualityModal from './quality-modal.js'
import Downloads from './downloads.js'
import { socket } from './socket.js'
2020-04-28 18:42:22 +00:00
import Tabs from './tabs.js'
2020-04-23 19:03:12 +00:00
2020-04-28 18:42:22 +00:00
function linkListeners() {
document.getElementById('content').addEventListener('scroll', Utils.debounce(handleContentScroll, 100))
document.getElementById('searchbar').addEventListener('keyup', handleSearchBarKeyup)
}
2020-04-23 19:03:12 +00:00
2020-04-28 18:42:22 +00:00
// Load more content when the search page is at the end
function handleContentScroll(event) {
let contentElement = event.target
2020-04-23 19:03:12 +00:00
2020-04-28 18:42:22 +00:00
if (contentElement.scrollTop + contentElement.clientHeight >= contentElement.scrollHeight) {
if (
main_selected === 'search_tab' &&
['track_search', 'album_search', 'artist_search', 'playlist_search'].indexOf(search_selected) != -1
) {
MainSearch.scrolledSearch(search_selected.split('_')[0])
2020-04-23 19:03:12 +00:00
}
}
2020-04-28 18:42:22 +00:00
}
2020-04-23 19:03:12 +00:00
2020-04-28 18:42:22 +00:00
function handleSearchBarKeyup(e) {
if (e.keyCode == 13) {
let term = this.value
if (Utils.isValidURL(term)) {
if (e.ctrlKey) {
QualityModal.open(term)
2020-04-23 19:03:12 +00:00
} else {
2020-04-28 18:42:22 +00:00
if (window.main_selected == 'analyzer_tab') {
Tabs.analyzeLink(term)
2020-04-23 19:03:12 +00:00
} else {
2020-04-28 18:42:22 +00:00
Downloads.sendAddToQueue(term)
2020-04-23 19:03:12 +00:00
}
}
2020-04-28 18:42:22 +00:00
} else {
if (term != MainSearch.query || main_selected == 'search_tab') {
document.getElementById('search_tab_content').style.display = 'none'
socket.emit('mainSearch', { term: term })
} else {
document.getElementById('search_all_tab').click()
document.getElementById('search_tab_content').style.display = 'block'
document.getElementById('main_search_tablink').click()
}
2020-04-23 19:03:12 +00:00
}
}
}
2020-04-28 18:42:22 +00:00
export default {
linkListeners
}