Files
sprinkler-calculation/coding/js/custom.js
T
2026-11-16 01:39:59 +07:00

92 lines
2.6 KiB
JavaScript

$(function(){
var values = new Array();
$(document).on('change', '.form-group-multiple-selects .input-group-multiple-select:last-child select','.form-group-1', function(){
var selectsLength = $(this).parent().parent().find('.input-group-multiple-select select').length;
var optionsLength = ($(this).find('option').length)-1;
if(selectsLength < optionsLength){
var sInputGroupHtml = $(this).parent().html();
var sInputGroupClasses = $(this).parent().attr('class');
$(this).parent().parent().append('<div class="'+sInputGroupClasses+'">'+sInputGroupHtml+'</div>');
}
updateValues($(this).parent().parent());
});
$(document).on('change', '.form-group-multiple-selects .input-group-multiple-select:not(:last-child) select','.form-group-1', function(){
updateValues($(this).parent().parent());
});
$(document).on('click', '.input-group-addon-remove', function(){
var oSelectContainer = $(this).parent().parent()
$(this).parent().remove();
updateValues(oSelectContainer);
});
function updateValues(oSelectContainer){
values = new Array();
$(oSelectContainer).find('.input-group-multiple-select select').each(function(){
var value = $(this).val();
if(value != 0 && value != ""){
values.push(value);
}
});
$(oSelectContainer).find('.input-group-multiple-select select').find('option').each(function(){
var optionValue = $(this).val();
var selectValue = $(this).parent().val();
if(in_array(optionValue,values)!= -1 && selectValue != optionValue)
{
$(this).attr('disabled', 'disabled');
}
else
{
$(this).removeAttr('disabled');
}
});
}
function in_array(needle, haystack){
var found = 0;
for (var i=0, length=haystack.length;i<length;i++) {
if (haystack[i] == needle) return i;
found++;
}
return -1;
}
// Update all options for first use
$('.form-group-multiple-selects').each(function(i, e){
updateValues(e);
});
});
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("myBtn").style.display = "block";
} else {
document.getElementById("myBtn").style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}