diff --git a/js/script.js b/js/script.js index 2f567ba..3a39100 100644 --- a/js/script.js +++ b/js/script.js @@ -47,25 +47,28 @@ $('body').on('click', '.js-remember-label', function (ev) { $('body').on('click', '.check', function () { 'use strict'; - var $img = $(this); - if($img.attr("src") === "./img/pressed-check.png") { - $img.attr("src", "./img/unpressed-check.png"); - $img.removeClass("is-checked"); - } else if($img.attr("src") === "./img/unpressed-check.png") { - $img.attr("src", "./img/pressed-check.png"); - $img.addClass("is-checked"); - } }); $('body').on('click', '.js-auth-li-enabled', function (ev) { 'use strict'; ev.preventDefault(); ev.stopPropagation(); + + var $this = $(this); - if ($this.find('.js-auth-checkbox').is(':checked') === true) { - $this.find('.js-auth-checkbox').prop( "checked", false ); + var $hiddenCheckbox = $this.find('.js-auth-checkbox'); + var $img = $this.find('.check'); + var newStatus = $hiddenCheckbox.prop('checked') ? "unchecked" : "checked"; + + if(newStatus === 'checked') { + + $img.attr('src', './img/pressed-check.png'); + $img.addClass("is-checked"); + $hiddenCheckbox.prop( "checked", true ); } else { - $this.find('.js-auth-checkbox').prop( "checked", true ); + $img.attr("src", "./img/unpressed-check.png"); + $img.removeClass("is-checked"); + $hiddenCheckbox.prop( "checked", false ); } });