function changeInput(elem, all) { var parent = $(elem).closest('.comparison-group'); var input = $('#input-'+parent.attr('id')); var value = $(elem).attr('data-value') ? $(elem).attr('data-value') : $(elem).html(); var text = $(elem).html(); value = value.replace(/\s{2,}/g, ''); value = value.replace(/\t/g, ''); value = $.trim(value.toString().replace(/(\r\n|\n|\r)/g,"")); input.val(value); parent.find('.menu-content').html(text); fillInputs(parent, all); } function fillInputs(elem, all) { id = elem.attr('id'); switch(id) { case "width": initializeHeight(all); resetInput('diameter', all); resetInput('load', all); resetInput('speed', all); resetInput('brand', all); disableInput('brand', all); break; case "height": initializeDiameter(all); resetInput('load', all); resetInput('speed', all); resetInput('brand', all); disableInput('brand', all); break; case "diameter": initializeLoad(all); resetInput('speed', all); resetInput('brand', all); initializeSpeed(all); initializeBrand(all); break; case "load": initializeSpeed(all); resetInput('brand', all); initializeBrand(all); break; case "speed": resetInput('brand', all); initializeBrand(all); break; } } function resetInput(id, all) { $('#'+id).addClass('disabled'); if (id == 'load' || id == 'speed' || id == 'brand') $('#'+id+' .menu-content').html(all); else $('#'+id+' .menu-content').html('-'); $('#'+id+' ul').html(""); if (id == 'load' || id == 'speed' || id == 'brand') $('#input-'+id).val("all"); else $('#input-'+id).val(""); $('#'+id+' .dropdown-comparison').attr('data-toggle', ''); } function disableInput(id, all) { $('#'+id).addClass('disabled'); if (id == 'load' || id == 'speed' || id == 'brand') $('#'+id+' .menu-content').html(all); else $('#'+id+' .menu-content').html('-'); $('#input-'+id).val("all"); $('#'+id+' .dropdown-comparison').attr('data-toggle', ''); } function initializeHeight(all) { $('#height').removeClass('disabled'); $('#height .dropdown-comparison').attr('data-toggle', 'dropdown'); $('#height .menu-content').html('-'); $('#height ul').html(""); $('#input-height').val(""); $.ajax({ type: "GET", url: base_url+'form_sizes/get_height', data: {width: $('#input-width').val()}, dataType: 'json', success: function(data){ var heights = data.heights; $.each(heights, function(index, val) { $('#height ul').append(createMenu('height', val)); }); }, error: function(jqXHR, textStatus, errorThrown){ } }); } function initializeDiameter(all) { $('#diameter').removeClass('disabled'); $('#diameter .dropdown-comparison').attr('data-toggle', 'dropdown'); $('#diameter .menu-content').html('-'); $('#diameter ul').html(""); $('#input-diameter').val(""); $.ajax({ type: "GET", url: base_url+'form_sizes/get_diameter', data: {width: $('#input-width').val(), height: $('#input-height').val()}, dataType: 'json', success: function(data){ var diameters = data.diameters; $.each(diameters, function(index, val) { $('#diameter ul').append(createMenu('diameter', val)); }); }, error: function(jqXHR, textStatus, errorThrown){ } }); } function initializeLoad(all) { $('#load').removeClass('disabled'); $('#load .dropdown-comparison').attr('data-toggle', 'dropdown'); $('#load .menu-content').html(all); $('#load ul').html(""); $('#input-load').val("all"); $.ajax({ type: "GET", url: base_url+'form_sizes/get_load', data: {width: $('#input-width').val(), height: $('#input-height').val(), diameter: $('#input-diameter').val()}, dataType: 'json', success: function(data){ var loads = data.loads; $('#load ul').append('