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