1function fn_change_options(objId, id, optionId) { 2 var $ = Tygh.$; 3 // Change cart status 4 var cart_changed = true; 5 var self = $(':input[id*=_' + objId + '_' + optionId + ']').last()[0]; 6 var formData = []; 7 var varNames = []; 8 var updateIds = []; 9 var cacheQuery = true; 10 var defaultValues = {}; 11 var parents = $('.cm-reload-' + objId); 12 $.each(parents, function (id, parentElm) { 13 var reloadId = $(parentElm).prop('id'); 14 updateIds.push(reloadId); 15 defaultValues[reloadId] = {}; 16 var elms = $(':input:not([type=radio]):not([type=checkbox])', parentElm); 17 $.each(elms, function (id, elm) { 18 if ($(elm).prop('disabled')) { 19 return true; 20 } 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 cacheQuery = false; 24 } 25 formData.push({ 26 name: elm.name, 27 value: elm.value 28 }); 29 varNames.push(elm.name); 30 } 31 }); 32 elms = $(':input', parentElm); 33 $.each(elms, function (id, elm) { 34 var elmId = $(elm).prop('id'); 35 if (!elmId) { 36 return true; 37 } 38 if ($(elm).is('select')) { 39 $('option', elm).each(function () { 40 if (this.defaultSelected) { 41 defaultValues[reloadId][elmId] = this.value; 42 } 43 }); 44 } else if ($(elm).is('input[type=radio], input[type=checkbox]')) { 45 defaultValues[reloadId][elmId] = elm.defaultChecked; 46 } else if (!$(elm).is('input[type=file]')) { 47 defaultValues[reloadId][elmId] = elm.defaultValue; 48 } 49 }); 50 }); 51 var radio = $('input[type=radio]:checked, input[type=checkbox]', parents); 52 $.each(radio, function (id, elm) { 53 if ($(elm).prop('disabled')) { 54 return true; 55 } 56 var value = elm.value; 57 if ($(elm).is('input[type=checkbox]:checked')) { 58 if (!$(elm).hasClass('cm-no-change')) { 59 value = $(elm).val(); 60 } 61 } else if ($(elm).is('input[type=checkbox]')) { 62 if ($.inArray(elm.name, varNames) !== -1) { 63 return true; 64 } 65 if (!$(elm).hasClass('cm-no-change')) { 66 value = 'unchecked'; 67 } else { 68 value = ''; 69 } 70 } 71 formData.push({ 72 name: elm.name, 73 value: value 74 }); 75 }); 76 $.ceEvent('trigger', 'ce.product_option_changed', [objId, id, optionId, updateIds, formData]); 77 var url = Tygh.area === 'A' ? url = fn_url('order_management.options?changed_option[' + id + ']=' + optionId) : url = fn_url('products.options?changed_option[' + id + ']=' + optionId); 78 if (Tygh.area === 'A') { 79 cacheQuery = false; 80 } 81 for (var i = 0; i < formData.length; i++) { 82 url += '&' + formData[i]['name'] + '=' + encodeURIComponent(formData[i]['value']); 83 } 84 $.ceAjax('request', url, { 85 result_ids: updateIds.join(',').toString(), 86 caching: cacheQuery, 87 force_exec: true, 88 pre_processing: fn_pre_process_form_files, 89 callback: function (data, params) { 90 fn_post_process_form_files(data, params); 91 var parents = $('.cm-reload-' + objId); 92 $.each(parents, function (id, parentElm) { 93 if (data.html && data.html[$(parentElm).prop('id')]) { 94 var reloadId = $(parentElm).prop('id'), 95 elms = $(':input', parentElm), 96 checkedElms = []; 97 if (defaultValues[reloadId] != null) { 98 $.each(elms, function (id, elm) { 99 var elm_id = $(elm).prop('id'); 100 if (elm_id && defaultValues[reloadId][elm_id] != null) { 101 if ($(elm).is('select')) { 102 var selected = {}; 103 var isSelected = false; 104 $('option', elm).each(function () { 105 selected[this.value] = this.defaultSelected; 106 this.defaultSelected = defaultValues[reloadId][elm_id] == this.value ? true : false; 107 }); 108 $('option', elm).each(function () { 109 this.selected = selected[this.value]; 110 if (this.selected == true) { 111 isSelected = true; 112 } 113 }); 114 if (!isSelected) { 115 $('option', elm).get(0).selected = true; 116 } 117 } else if ($(elm).is('input[type=radio], input[type=checkbox]')) { 118 var checked = elm.defaultChecked; 119 if (checked) { 120 checkedElms.push(elm); 121 } 122 elm.defaultChecked = defaultValues[reloadId][elm_id]; 123 elm.checked = checked; 124 } else { 125 var value = elm.defaultValue; 126 elm.defaultValue = defaultValues[reloadId][elm_id]; 127 elm.value = value; 128 } 129 } 130 }); 131 $(checkedElms).prop('checked', true); 132 } 133 } 134 }); 135 136 // if notification with zero_inventory error happen, we shouldnt trigger option changes event 137 for (var notificationKey in data.notifications) { 138 if (data.notifications.hasOwnProperty(notificationKey)) { 139 var notify = data.notifications[notificationKey]; 140 if (notify.extra == 'zero_inventory') { 141 return; 142 } 143 } 144 } 145 $.ceEvent('trigger', 'ce.product_option_changed_post', [objId, id, optionId, updateIds, formData, data, params, self]); 146 }, 147 method: 'post' 148 }); 149} 150function fn_set_option_value(id, optionId, value) { 151 var $ = Tygh.$; 152 var elm = $('#option_' + id + '_' + optionId); 153 if (elm.prop('disabled')) { 154 return false;
155 } 156 if (elm.prop('type') == 'select-one') { 157 elm.val(value).change(); 158 } else { 159 elms = $('#option_' + id + '_' + optionId + '_group'); 160 if ($.browser.msie) { 161 $('input[type=radio][value=' + value + ']', elms).prop('checked', true); 162 } 163 $('input[type=radio][value=' + value + ']', elms).click(); 164 } 165 return true; 166} 167function fn_pre_process_form_files(data, params) { 168 var $ = Tygh.$; 169 if (data.html) { 170 // Create temporarily div element 171 $(Tygh.body).append('<div id="file_container" class="hidden"></div>'); 172 var container = {}; 173 container = $('#file_container'); 174 175 // Move files blocks to the temporarily created container 176 for (var k in data.html) { 177 $('#' + k + ' .fileuploader ,' + '#' + k + ' .ty-fileuploader').each(function (idx, elm) { 178 var jelm = $(elm); 179 var jparent = jelm.parents('.control-group, .ty-control-group'); 180 jparent.appendTo(container); 181 jparent.prop('id', 'moved_' + jparent.prop('id')); 182 }); 183 } 184 } 185} 186function fn_post_process_form_files(data, params) { 187 var $ = Tygh.$; 188 var container = {}; 189 container = $('#file_container'); 190 $('div.control-group, div.ty-control-group', container).each(function (idx, elm) { 191 var jelm = $(elm); 192 var elmId = jelm.prop('id').replace('moved_', ''); 193 var target = $('#' + elmId); 194 target.html(''); 195 jelm.children().appendTo(target); 196 }); 197 container.remove(); 198} 199function fn_change_variant_image(prefix, optId, varId) { 200 var $ = Tygh.$; 201 var self = this; 202 $('[id*=variant_image_' + prefix + '_' + optId + ']').removeClass('product-variant-image-selected').addClass('product-variant-image-unselected'); 203 204 // get select box variant 205 if (typeof varId === 'undefined') { 206 self = $('select[id*=_' + prefix + '_' + optId + ']')[0]; 207 varId = $(self).val(); 208 } 209 210 // get checkbox variant 211 if (typeof varId === 'undefined') { 212 var $uncheckedVariant = $('#unchecked_option_' + prefix + '_' + optId); 213 var $checkedVariant = $('#option_' + prefix + '_' + optId); 214 if ($checkedVariant.length && $checkedVariant.is(':checked')) { 215 self = $checkedVariant[0]; 216 varId = $checkedVariant.val(); 217 } else if ($uncheckedVariant.length) { 218 self = $uncheckedVariant[0]; 219 varId = $uncheckedVariant.val(); 220 } 221 } 222 $('[id*=variant_image_' + prefix + '_' + optId + '_' + varId + ']').removeClass('product-variant-image-unselected').addClass('product-variant-image-selected'); 223 var formData = [], 224 varNames = [], 225 parents = $('.cm-reload-' + prefix); 226 $.each(parents, function (id, parent_elm) { 227 var elms = $(':input:not([type=radio]):not([type=checkbox])', parent_elm); 228 $.each(elms, function (id, elm) { 229 if (elm.type !== 'submit' && elm.type !== 'file' && !($(this).hasClass('cm-hint') && elm.value === elm.defaultValue) && elm.name.length !== 0) { 230 formData.push({ 231 name: elm.name, 232 value: elm.value 233 }); 234 varNames.push(elm.name); 235 } 236 }); 237 }); 238 var selectables = $('input[type=radio]:checked, input[type=checkbox]', parents); 239 $.each(selectables, function (id, elm) { 240 if ($(elm).prop('disabled')) { 241 return true; 242 } 243 var value = elm.value; 244 if ($(elm).is('input[type=checkbox]:checked')) { 245 if (!$(elm).hasClass('cm-no-change')) { 246 value = $(elm).val(); 247 } 248 } else if ($(elm).is('input[type=checkbox]')) { 249 if ($.inArray(elm.name, varNames) !== -1) { 250 return true; 251 } 252 if (!$(elm).hasClass('cm-no-change')) { 253 value = 'unchecked'; 254 } else { 255 value = ''; 256 } 257 } 258 formData.push({ 259 name: elm.name, 260 value: value 261 }); 262 }); 263 $.ceEvent('trigger', 'ce.product_option_changed_post', [prefix, varId, optId, [], formData, {}, {}, self]); 264}
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.