From 0aa60f820f4ab716b3719c487c74b966798c1b70 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Sun, 11 Nov 2018 23:56:42 +0000 Subject: [PATCH] Fix: optimize code --- htdocs/js/mympd.js | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/htdocs/js/mympd.js b/htdocs/js/mympd.js index b38e224..455b24f 100644 --- a/htdocs/js/mympd.js +++ b/htdocs/js/mympd.js @@ -565,42 +565,15 @@ function appInit() { appGoto(app.current.app, app.current.tab, app.current.view, app.current.page + '/' + event.target.getAttribute('data-tag') + '/' + app.current.search); }, false); - document.getElementById('QueueColsDropdown').addEventListener('click', function(event) { - if (event.target.nodeName == 'INPUT') { - event.stopPropagation(); - } - }, false); + var dropdowns = ['QueueColsDropdown', 'BrowseFilesystemColsDropdown', 'SearchColsDropdown', 'BrowsePlaylistsDetailColsDropdown', + 'BrowseDatabaseColsDropdown', 'PlaybackColsDropdown']; + for (var i = 0; i < dropdowns.length; i++) { + document.getElementById(dropdowns[i]).addEventListener('click', function(event) { + if (event.target.nodeName == 'INPUT') + event.stopPropagation(); + }, false); + } - document.getElementById('BrowseFilesystemColsDropdown').addEventListener('click', function(event) { - if (event.target.nodeName == 'INPUT') { - event.stopPropagation(); - } - }, false); - - document.getElementById('SearchColsDropdown').addEventListener('click', function(event) { - if (event.target.nodeName == 'INPUT') { - event.stopPropagation(); - } - }, false); - - document.getElementById('BrowsePlaylistsDetailColsDropdown').addEventListener('click', function(event) { - if (event.target.nodeName == 'INPUT') { - event.stopPropagation(); - } - }, false); - - document.getElementById('BrowseDatabaseColsDropdown').addEventListener('click', function(event) { - if (event.target.nodeName == 'INPUT') { - event.stopPropagation(); - } - }, false); - - document.getElementById('PlaybackColsDropdown').addEventListener('click', function(event) { - if (event.target.nodeName == 'INPUT') { - event.stopPropagation(); - } - }, false); - document.getElementById('search').addEventListener('submit', function() { return false; }, false); @@ -699,7 +672,6 @@ function appInit() { function parseCmd(event, href) { event.preventDefault(); - event.stopPropagation(); var cmd = href; if (typeof(href) == 'string') cmd = JSON.parse(href);