From 78ba609c5ce4271cbb0f7deb1492a7806c757313 Mon Sep 17 00:00:00 2001 From: Thomas Citharel <tcit@tcit.fr> Date: Tue, 20 Feb 2018 09:31:36 +0100 Subject: [PATCH] Clean commented out code, fix a console warning and idents and typos Signed-off-by: Thomas Citharel <tcit@tcit.fr> --- js/app/date_poll.js | 65 ++++++++------------------------------------- 1 file changed, 11 insertions(+), 54 deletions(-) diff --git a/js/app/date_poll.js b/js/app/date_poll.js index 0e6fd892..058b6a41 100644 --- a/js/app/date_poll.js +++ b/js/app/date_poll.js @@ -151,11 +151,7 @@ $(document).ready(function () { // Button "Copy hours of the first day" - function addHour(last_hour,add_button){ -// last_hour : Jquery selector on the last hour of the day selected -// add_button : Jquery selector on the linked button - - //var last_hour = $(this).children('div').children('div:last').prev(); + function addHour(last_hour, add_button) { // for and id var di_hj = last_hour.children('.hours').attr('id').split('-'); @@ -178,16 +174,16 @@ $(document).ready(function () { .replace(/value="(.*?)"/g, 'value=""') + '</div>'; - // After 11 + button is disable + // After 11 + button is disabled if (hj < 99) { last_hour.after(new_hour_html); $('#d' + di + '-h' + (hj + 1)).focus(); add_button.prev('.remove-an-hour').removeClass('disabled'); - if (hj == 98) { + if (hj === 98) { add_button.addClass('disabled'); } } -} + } $('#copyhours').on('click', function () { @@ -197,15 +193,11 @@ $(document).ready(function () { $selected_days.find('fieldset:gt(0)').each(function () { - - while($(this).find('.hours').length<first_day_hours.length){ - var last_hour = $(this).children('div').children('div:last').prev(); - var add_button = $(this).find('.add-an-hour'); - addHour(last_hour,add_button); - - } - - + while($(this).find('.hours').length < first_day_hours.length){ + var last_hour = $(this).children('div').children('div:last').prev(); + var add_button = $(this).find('.add-an-hour'); + addHour(last_hour, add_button); + } for (var i = 0; i < first_day_hours.length; i++) { $(this).find('.hours:eq(' + i + ')').val(first_day_hours[i]); // fill hours @@ -217,44 +209,9 @@ $(document).ready(function () { $(document).on('click', '.add-an-hour', function () { var last_hour = $(this).parent('div').parent('div').prev(); - addHour(last_hour,this); - - - /* - // for and id - var di_hj = last_hour.children('.hours').attr('id').split('-'); - var di = parseInt(di_hj[0].replace('d', '')); - var hj = parseInt(di_hj[1].replace('h', '')); - - // label, title and placeholder - var last_hour_label = last_hour.children('.hours').attr('placeholder'); - var hour_text = last_hour_label.substring(0, last_hour_label.indexOf(' ')); - - // RegEx for multiple replace - var re_label = new RegExp(last_hour_label, 'g'); - var re_id = new RegExp('"d' + di + '-h' + hj + '"', 'g'); - - // HTML code of the new hour - var new_hour_html = - '<div class="col-sm-2">' + - last_hour.html().replace(re_label, hour_text + ' ' + (hj + 2)) - .replace(re_id, '"d' + di + '-h' + (hj + 1) + '"') - .replace(/value="(.*?)"/g, 'value=""') + - '</div>'; - - // After 11 + button is disable - if (hj < 99) { - last_hour.after(new_hour_html); - $('#d' + di + '-h' + (hj + 1)).focus(); - $(this).prev('.remove-an-hour').removeClass('disabled'); - if (hj == 98) { - $(this).addClass('disabled'); - } - } - */ + addHour(last_hour, $(this)); }); - // Buttons "Remove an hour" $(document).on('click', '.remove-an-hour', function () { @@ -381,4 +338,4 @@ $(document).ready(function () { if ($selected_days.find('fieldset').length > 1) { $removeaday_and_copyhours.removeClass('disabled'); } -}); \ No newline at end of file +}); -- GitLab