Clean commented out code, fix a console warning and idents and typos

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-02-20 09:31:36 +01:00
parent 013c62eb9c
commit 78ba609c5c

View File

@ -151,11 +151,7 @@ $(document).ready(function () {
// Button "Copy hours of the first day" // Button "Copy hours of the first day"
function addHour(last_hour,add_button){ 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();
// for and id // for and id
var di_hj = last_hour.children('.hours').attr('id').split('-'); var di_hj = last_hour.children('.hours').attr('id').split('-');
@ -178,16 +174,16 @@ $(document).ready(function () {
.replace(/value="(.*?)"/g, 'value=""') + .replace(/value="(.*?)"/g, 'value=""') +
'</div>'; '</div>';
// After 11 + button is disable // After 11 + button is disabled
if (hj < 99) { if (hj < 99) {
last_hour.after(new_hour_html); last_hour.after(new_hour_html);
$('#d' + di + '-h' + (hj + 1)).focus(); $('#d' + di + '-h' + (hj + 1)).focus();
add_button.prev('.remove-an-hour').removeClass('disabled'); add_button.prev('.remove-an-hour').removeClass('disabled');
if (hj == 98) { if (hj === 98) {
add_button.addClass('disabled'); add_button.addClass('disabled');
} }
} }
} }
$('#copyhours').on('click', function () { $('#copyhours').on('click', function () {
@ -197,15 +193,11 @@ $(document).ready(function () {
$selected_days.find('fieldset:gt(0)').each(function () { $selected_days.find('fieldset:gt(0)').each(function () {
while($(this).find('.hours').length < first_day_hours.length){
while($(this).find('.hours').length<first_day_hours.length){ var last_hour = $(this).children('div').children('div:last').prev();
var last_hour = $(this).children('div').children('div:last').prev(); var add_button = $(this).find('.add-an-hour');
var add_button = $(this).find('.add-an-hour'); addHour(last_hour, add_button);
addHour(last_hour,add_button); }
}
for (var i = 0; i < first_day_hours.length; i++) { for (var i = 0; i < first_day_hours.length; i++) {
$(this).find('.hours:eq(' + i + ')').val(first_day_hours[i]); // fill hours $(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 () { $(document).on('click', '.add-an-hour', function () {
var last_hour = $(this).parent('div').parent('div').prev(); var last_hour = $(this).parent('div').parent('div').prev();
addHour(last_hour,this); 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');
}
}
*/
}); });
// Buttons "Remove an hour" // Buttons "Remove an hour"
$(document).on('click', '.remove-an-hour', function () { $(document).on('click', '.remove-an-hour', function () {
@ -381,4 +338,4 @@ $(document).ready(function () {
if ($selected_days.find('fieldset').length > 1) { if ($selected_days.find('fieldset').length > 1) {
$removeaday_and_copyhours.removeClass('disabled'); $removeaday_and_copyhours.removeClass('disabled');
} }
}); });