Commit 90026dee by Скуратович Александр
2 parents c311689f 5bc64ee3
......@@ -102,13 +102,45 @@ $(document).ready(
//Маска ввода телефона
$('input[name="phone"]').inputmask({"mask": "+7 (999) 999-99-99"});
function fenix_check(el_input)
{
if ($(el_input).length==0)
el_input = $('.fenix_calc input[type="number"][min][max], .fenix_calc input[type="text"][min][max]');
$(el_input).each(
function ()
{
var inp_val = ($(this).val()).split(' ').join('');
var inp_val_int = inp_val|0;
var inp_min = $(this).attr('min')|0;
var inp_max = $(this).attr('max')|0;
var inp_range = $(this).next('input[type="range"]');
var inp_range_val = $(inp_range).val();
if (inp_val_int<inp_min)
inp_val_int=inp_min;
if (inp_val_int>inp_max)
inp_val_int=inp_max;
if ($(this).attr('type')==='number')
{
if ((inp_val).toString() != (inp_val_int).toString())
$(this).val(inp_val_int);
}
else if ((inp_val).toString() != (inp_val_int).toLocaleString())
$(this).val((inp_val_int).toLocaleString());
if ((inp_range).toString() != (inp_val_int).toString())
$(inp_range).val(inp_val_int);
}
);
$('.fenix_calc .calc_btn').toggleClass('disabled', $('.fenix_calc input[type="number"][min][max]:invalid, .fenix_calc input[type="text"][min][max]:invalid').length>0);
}
function fenix_calc (el_wrap)
{
if (el_wrap.length>0)
{
var el_table = el_wrap.find('.table_result')
fenix_check();
var el_table = el_wrap.find('.table_result');
var calc_credit = parseInt(el_wrap.find('input[name="calc_credit"]').val())|0;
var calc_inv = parseInt(el_wrap.find('input[name="calc_inv"]').val())|0;
var calc_s = parseInt(el_wrap.find('input[name="calc_s"]').val())|0;
......@@ -218,20 +250,21 @@ $(document).ready(
fenix_calc($(this).closest('.fenix_calc'));
}
).on(
[
'change.fenix',
'blur.fenix'
].join(' '),
'.fenix_calc input[type="number"][min][max], .fenix_calc input[type="text"][min][max]',
function ()
{
fenix_check(this);
}
).on(
'change.fenix',
'.fenix_calc input[type="number"][min][max]',
'.fenix_calc input[type="range"][min][max]',
function ()
{
var inp_val = $(this).val();
var inp_val_int = inp_val|0;
var inp_min = $(this).attr('min')|0;
var inp_max = $(this).attr('max')|0;
if (inp_val_int<inp_min)
inp_val_int=inp_min;
if (inp_val_int>inp_max)
inp_val_int=inp_max;
if ((inp_val).toString() != (inp_val_int).toString())
$(this).val(inp_val_int);
$(this).prev('input[type="number"][min][max], input[type="text"][min][max]').val($(this).val());
}
);
}
......
......@@ -19,15 +19,18 @@ function fenix_calc ($atts, $content)
'<div class="col-12 col-md-3">'.
'<div class="mb-3 d-none">'.
'<label for="calc_inv_'.$atts['id'].'" class="form-label mb-3">Поступление кредита, руб</label>'.
'<input type="number" class="form-control rounded-pill p-2 px-4" id="calc_credit_'.$atts['id'].'" name="calc_credit" required="required" value="0" min="0" max="10000000" />'.
'<input type="text" class="form-control rounded-pill p-2 px-4" id="calc_credit_'.$atts['id'].'" name="calc_credit" required="required" value="0" min="0" max="10000000" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\..*?)\..*/g, \'$1\').replace(/^0[^.]/, \'0\');" />'.
'<input type="range" class="form-range d-md-none" min="0" max="10000000" step="1000" id="calc_credit_range_'.$atts['id'].'" />'.
'</div>'.
'<div class="mb-3">'.
'<label for="calc_inv_'.$atts['id'].'" class="form-label mb-3">Инвестиции в проект, тыс. руб</label>'.
'<input type="number" class="form-control rounded-pill p-2 px-4" id="calc_inv_'.$atts['id'].'" name="calc_inv" required="required" value="10000000" min="10000000" max="250000000" />'.
'<input type="text" class="form-control rounded-pill p-2 px-4" id="calc_inv_'.$atts['id'].'" name="calc_inv" required="required" value="" min="10000000" max="250000000" oninput="this.value = this.value.replace(/[^0-9.]/g, \'\').replace(/(\..*?)\..*/g, \'$1\').replace(/^0[^.]/, \'0\');" />'.
'<input type="range" class="form-range d-md-none" min="10000000" max="250000000" step="1000" id="calc_inv_range_'.$atts['id'].'" />'.
'</div>'.
'<div class="mb-3">'.
'<label for="calc_s_'.$atts['id'].'" class="form-label mb-3">Площадь помещения, м<sup>2</sup></label>'.
'<input type="number" class="form-control rounded-pill p-2 px-4" id="calc_s_'.$atts['id'].'" name="calc_s" required="required" value="500" min="250" max="3000" />'.
'<input type="number" class="form-control rounded-pill p-2 px-4" id="calc_s_'.$atts['id'].'" name="calc_s" required="required" value="" min="250" max="3000" />'.
'<input type="range" class="form-range d-md-none" min="250" max="3000" step="1" id="calc_s_range_'.$atts['id'].'" />'.
'</div>'.
'<div class="mb-3">'.
'<label for="calc_period_'.$atts['id'].'" class="form-label mb-3">Срок, год</label>'.
......@@ -35,7 +38,8 @@ function fenix_calc ($atts, $content)
'</div>'.
'<div class="mb-3">'.
'<label for="calc_discont_'.$atts['id'].'" class="form-label mb-3">Ставка дисконтирования, %</label>'.
'<input type="number" class="form-control rounded-pill p-2 px-4" id="calc_discont_'.$atts['id'].'" name="calc_discont" required="required" value="15" min="0" max="100" />'.
'<input type="number" class="form-control rounded-pill p-2 px-4" id="calc_discont_'.$atts['id'].'" name="calc_discont" required="required" value="" min="0" max="100" />'.
'<input type="range" class="form-range d-md-none" min="0" max="100" step="1" id="calc_discont_range_'.$atts['id'].'" />'.
'</div>'.
'</div>'.
'<div class="col-12 col-md-9 text-center">'.
......@@ -49,7 +53,7 @@ function fenix_calc ($atts, $content)
'</div>'.
'<div class="row">'.
'<div class="col-12">'.
'<button name="calc" type="button" class="btn btn-lg btn-style-0 rounded-pill calc_btn" role="button" id="calc_btn_'.$atts['id'].'">Рассчитать</button>'.
'<button name="calc" type="button" class="btn btn-lg btn-style-0 rounded-pill calc_btn disabled d-block mx-auto mx-md-0" role="button" id="calc_btn_'.$atts['id'].'">Рассчитать</button>'.
'</div>'.
'</div>'.
'</div>';
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!