From 6150e07fc9238cfb17f9e3d2816af586fed17b75 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 10 Jan 2019 00:29:22 +0100 Subject: [PATCH] Prevent toggle button id clash because of Snapcast using the MAC address of a device as a client (and therefore the same client connected to multiple servers may lead to inconsistent behaviour) --- platypush/backend/http/static/js/music.snapcast.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platypush/backend/http/static/js/music.snapcast.js b/platypush/backend/http/static/js/music.snapcast.js index 6fe416629f..5c57ec72b3 100644 --- a/platypush/backend/http/static/js/music.snapcast.js +++ b/platypush/backend/http/static/js/music.snapcast.js @@ -8,15 +8,16 @@ $(document).ready(function() { var createPowerToggleElement = function(data) { data = data || {}; + var inputId = data.id + '_' + parseInt(Math.random()*100000); var $powerToggle = $('
').addClass('toggle toggle--push switch-container'); var $input = $('').attr('type', 'checkbox') - .attr('id', data.id).addClass('toggle--checkbox'); + .attr('id', inputId).data('id', data.id).addClass('toggle--checkbox'); for (var attr of Object.keys(data)) { $input.data(attr, data[attr]); } - var $label = $('').attr('for', data.id).addClass('toggle--btn'); + var $label = $('').attr('for', inputId).addClass('toggle--btn'); $input.appendTo($powerToggle); $label.appendTo($powerToggle); @@ -255,7 +256,7 @@ $(document).ready(function() { var initBindings = function() { $container.on('click touch', '.toggle--checkbox', function(evt) { evt.stopPropagation(); - var id = $(this).attr('id'); + var id = $(this).data('id'); var host = $(this).parents('.snapcast-host-container').data('host'); var args = { host: host,