1function fn_change_options(obj_id, id, option_id) 2{ 3 var $ = Tygh.$; 4 // Change cart status 5 var cart_changed = true; 6 7 var params = []; 8 var update_ids = []; 9 var cache_query = true; 10 var defaultValues = {}; 11 12 var parents = $('.cm-reload-' + obj_id); 13 $.each(parents, function(id, parent_elm) { 14 var reload_id = $(parent_elm).prop('id'); 15 update_ids.push(reload_id); 16 17 defaultValues[reload_id] = {}; 18 19 var elms = $(':input:not([type=radio]):not([type=checkbox])', parent_elm); 20 $.each(elms, function(id, elm) { 21 if (elm.type != 'submit' && elm.type != 'file' && !($(this).hasClass('cm-hint') && elm.value == elm.defaultValue) && elm.name.length != 0) { 22 if (elm.name == 'no_cache' && elm.value) { 23 cache_query = false; 24 } 25 params.push({name: elm.name, value: elm.value}); 26 } 27 }); 28 29 elms = $(':input', parent_elm); 30 $.each(elms, function(id, elm) { 31 if ($(elm).is('select')) { 32 var elm_id = $(elm).prop('id'); 33 34 $('option', elm).each(function() { 35 if (this.defaultSelected) { 36 defaultValues[reload_id][elm_id] = this.value; 37 } 38 }); 39 40 } else if ($(elm).is('input[type=radio], input[type=checkbox]')) { 41 defaultValues[reload_id][elm_id] = elm.defaultChecked; 42 } else { 43 defaultValues[reload_id][elm_id] = elm.defaultValue; 44 } 45 46 }); 47 }); 48 49 var radio = $('input[type=radio]:checked, input[type=checkbox]', parents); 50 $.each(radio, function(id, elm) { 51 if ($(elm).prop('disabled')) { 52 return true; 53 } 54 var value = elm.value; 55 if ($(elm).is('input[type=checkbox]:checked')) { 56 if (!$(elm).hasClass('cm-no-change')) { 57 value = $(elm).val(); 58 } 59 } else if ($(elm).is('input[type=checkbox]')) { 60 if (!$(elm).hasClass('cm-no-change')) { 61 value = 'unchecked'; 62 } else { 63 value = ''; 64 } 65 } 66 67 params.push({name: elm.name, value: value}); 68 }); 69 70 var url = fn_url('products.options?changed_option[' + id + ']=' + option_id); 71 72 for (var i = 0; i < params.length; i++) { 73 url += '&' + params[i]['name'] + '=' + encodeURIComponent(params[i]['value']); 74 } 75 76 $.ceAjax('request', url, { 77 result_ids: update_ids.join(',').toString(), 78 caching: cache_query, 79 force_exec: true, 80 pre_processing: fn_pre_process_form_files, 81 callback: function(data, params) { 82 fn_post_process_form_files(data, params); 83 84 var parents = $('.cm-reload-' + obj_id); 85 $.each(parents, function(id, parent_elm) { 86 if (data.html[$(parent_elm).prop('id')]) { 87 var reload_id = $(parent_elm).prop('id'); 88 89 var elms = $(':input', parent_elm); 90 91 if (defaultValues[reload_id] != null) { 92 $.each(elms, function(id, elm) { 93 var elm_id = $(elm).prop('id'); 94 95 if (defaultValues[reload_id][elm_id] != null) { 96 if ($(elm).is('select')) { 97 var selected = {}; 98 var is_selected = false; 99 $('option', elm).each(function() { 100 selected[this.value] = this.defaultSelected; 101 this.defaultSelected = (defaultValues[reload_id][elm_id] == this.value) ? true : false; 102 }); 103 $('option', elm).each(function() { 104 this.selected = selected[this.value]; 105 if (this.selected == true) { 106 is_selected = true; 107 } 108 }); 109 if (!is_selected) { 110 $('option', elm).get(0).selected = true; 111 } 112 } else if ($(elm).is('input[type=radio], input[type=checkbox]')) { 113 var checked = elm.defaultChecked; 114 elm.defaultChecked = defaultValues[reload_id][elm_id]; 115 elm.checked = checked; 116 } else { 117 var value = elm.defaultValue; 118 elm.defaultValue = defaultValues[reload_id][elm_id]; 119 elm.value = value; 120 } 121 } 122 }); 123 } 124 } 125 }); 126 127 }, 128 method: 'post' 129 }); 130 131} 132 133function fn_set_option_value(id, option_id, value) 134{ 135 var $ = Tygh.$; 136 137 var elm = $('#option_' + id + '_' + option_id); 138 if (elm.prop('disabled')) { 139 return false;
140 } 141 if (elm.prop('type') == 'select-one') { 142 elm.val(value).change(); 143 } else { 144 elms = $('#option_' + id + '_' + option_id + '_group'); 145 if ($.browser.msie) { 146 $('input[type=radio][value=' + value + ']', elms).prop('checked', true); 147 } 148 $('input[type=radio][value=' + value + ']', elms).click(); 149 } 150 151 return true; 152} 153 154function fn_pre_process_form_files(data, params) 155{ 156 var $ = Tygh.$; 157 if (data.html) { 158 // Create temporarily div element 159 $(Tygh.body).append('<div id="file_container" class="hidden"></div>'); 160 var container = {}; 161 container = $('#file_container'); 162 163 // Move files blocks to the temporarily created container 164 for (var k in data.html) { 165 $('#' + k + ' .fileuploader').each(function(idx, elm){ 166 var jelm = $(elm); 167 var jparent = jelm.parents('.control-group'); 168 jparent.appendTo(container); 169 jparent.prop('id', 'moved_' + jparent.prop('id')); 170 }); 171 } 172 } 173} 174 175function fn_post_process_form_files(data, params) 176{ 177 var $ = Tygh.$; 178 var container = {}; 179 container = $('#file_container'); 180 181 $('div.control-group', container).each(function(idx, elm){ 182 var jelm = $(elm); 183 var elm_id = jelm.prop('id').replace('moved_', ''); 184 var target = $('#' + elm_id); 185 target.html(''); 186 jelm.children().appendTo(target); 187 }); 188 189 container.remove(); 190} 191 192function fn_change_variant_image(prefix, opt_id, var_id) 193{ 194 var $ = Tygh.$; 195 var images = $('[id*=variant_image_' + prefix + '_' + opt_id + ']'); 196 images.removeClass('product-variant-image-selected').addClass('product-variant-image-unselected'); 197 198 if (typeof(var_id) == 'undefined') { 199 var_id = $('select[id*=_' + prefix + '_' + opt_id + ']').val(); 200 } 201 $('[id*=variant_image_' + prefix + '_' + opt_id + '_' + var_id + ']').removeClass('product-variant-image-unselected').addClass('product-variant-image-selected'); 202}
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.