1jQuery(function ($) { 2 3 $.fn.amigoCalc = function(options) { 4 5 var settings = $.extend({ 6 materialSel : '#material', 7 priceSel : '.amount-price .money', 8 priceMatSel : '.amount-mats-price .money', 9 matPercent : 0.8 10 }, options); 11 12 var $bricks = { 13 'socket_usual' : { type : 'normal', price : 500 }, 14 'socket_tv' : { type : 'variant', variant : { 1 : 1000, 2 : 2000 }, variant_count : 2, variant_stable : 2000, price : 500 }, 15 'socket_internet' : { type : 'variant', variant : { 1 : 1000, 2 : 2000 }, variant_count : 2, variant_stable : 2000, price : 500 }, 16 'socket_phone' : { type : 'variant', variant : { 1 : 1000 }, variant_count : 1, variant_stable : 1000, price : 500 }, 17 'switch' : { type : 'normal', price : 1000 }, 18 'lamp' : { type : 'normal', price : 500 }, 19 'spotlight' : { type : 'normal', price : 150 }, 20 'ring' : { type : 'checkbox', price : 1000 }, 21 'in_house' : { type : 'checkbox', price : 3500 }, 22 'on_land' : { type : 'checkbox', price : 1500 }, 23 'heat_floor' : { type : 'normal', price : 500} 24 } 25 26 var $concrete = { 27 'socket_usual' : { type : 'normal', price : 600 }, 28 'socket_tv' : { type : 'variant', variant : { 1 : 1200, 2 : 2400 }, variant_count : 2, variant_stable : 2400, price : 600 }, 29 'socket_internet' : { type : 'variant', variant : { 1 : 1200, 2 : 2400 }, variant_count : 2, variant_stable : 2400, price : 600 }, 30 'socket_phone' : { type : 'variant', variant : { 1 : 1200 }, variant_count : 1, variant_stable : 1200, price : 600 }, 31 'switch' : { type : 'normal', price : 1200 }, 32 'lamp' : { type : 'normal', price : 600 }, 33 'spotlight' : { type : 'normal', price : 150 }, 34 'ring' : { type : 'checkbox', price : 1200 }, 35 'in_house' : { type : 'checkbox', price : 3500 }, 36 'on_land' : { type : 'checkbox', price : 1500 }, 37 'heat_floor' : { type : 'normal', price : 600} 38 } 39 40 function setPriceFields($form, price) { 41 $form.find(settings.priceSel).html(price); 42 $(settings.priceMatSel).html(price * settings.matPercent); 43 } 44 45 function showPrice($form) { 46 var $table; 47 var material = $form.find(settings.materialSel).val(); 48 switch (material) { 49 case 'brick' : 50 $table = $bricks; 51 $form.find('.hint').addClass('is-hide'); 52 break 53 case 'concrete' : 54 $table = $concrete; 55 $form.find('.hint').addClass('is-hide'); 56 break 57 case 'none' : 58 setPriceFields($form, 0); 59 $('#material').focus(); 60 $form.find('.hint').removeClass('is-hide'); 61 return false; 62 break 63 } 64 var price = 0; 65 for (block_name in $table) { 66 var $block = $table[block_name]; 67 switch ($block.type) { 68 case 'normal' : 69 var count = parseInt($form.find('#'+block_name).val()); 70 if (count > 0) { 71 var part_price = parseInt($block.price) * count; 72 price += part_price; 73 } 74 break 75 case 'variant' : 76 var count = parseInt($form.find('#'+block_name).val()); 77 if (count > 0) { 78 var $variant = $block.variant; 79 if (count in $variant) price += $variant[count]; 80 else price += $block.variant_stable + (count - $block.variant_count) * $block.price; 81 } 82 break 83 case 'checkbox' : 84 if ($form.find('#'+block_name).is(":checked")) price += $block.price; 85 break 86 } 87 } 88 setPriceFields($form, price); 89 } 90 91 /* MAIN LOOP */ 92 return this.each(function() { 93 94 var $form = $(this); 95 $form.find('input[type="text"]').on('focus', function() { 96 $(this).val(''); 97 $(this).css('color','#000'); 98 }); 99 100 $form.find('input[type="text"]').on('blur', function() { 101 if ($(this).val() == '') { 102 $(this).val('0'); 103 } 104 }); 105 106 $form.find(settings.materialSel).on('change', function() { 107 showPrice($form); 108 }); 109 $form.find('input.count').on('change keyup', function() { 110 showPrice($form); 111 }); 112 $form.find('input[type="checkbox"]').on('change', function() { 113 showPrice($form); 114 }); 115 116 $form.find('input.count').keydown(function (e) { 117 // Allow: backspace, delete, tab, escape, enter and . 118 if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 || 119 // Allow: Ctrl+A 120 (e.keyCode == 65 && e.ctrlKey === true) || 121 // Allow: home, end, left, right, down, up 122 (e.keyCode >= 35 && e.keyCode <= 40)) { 123 // let it happen, don't do anything 124 return; 125 } 126 // Ensure that it is a number and stop the keypress 127 if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) { 128 e.preventDefault(); 129 } 130 }); 131 }); 132 }; 133 134});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.