jQuery.noConflict(); jQuery(document).on('submit', 'form[name=availableAttributesSearch]', function() { var selected_attributes = getSelectedAttributes(true); var selected_attributes_split = getSelectedAttributes(false, true); jQuery('input[name=attSearchList]').val(selected_attributes.attributevalues); jQuery('input[name=attributes]').val(selected_attributes_split.attributes); jQuery('input[name=attributeValues]').val(selected_attributes_split.attributevalues); }); function attributeSearch_initTabs() { /* Initialize Tabs */ var attributeTabs=new ddtabcontent("attributeTabs"); attributeTabs.setselectedClassTarget("link"); attributeTabs.init(); jQuery('.select-availattributes').children('option:selected').attr('selected', false); setURLSpecifiedSearchAttributes(); } jQuery(document).on('click', '.attsearch-more-link', function() { var clicked_link = jQuery(this); var invisible_elements = clicked_link.parent().siblings(); jQuery.each(invisible_elements, function(key, link) { jQuery(link).show(); }); clicked_link.hide(); }); jQuery(document).on('change', '.select-availattributes', function() { markSelection(jQuery(this)); refreshSelectionOptions(); }); jQuery(document).on('click', '.attribute-search-selection-clear', function() { clearSelection(jQuery(this)); refreshSelectionOptions(); }); // Client Side Caching var queryCache = {}; function getCachedResponse(parameters) { var serialized = JSON.stringify(parameters); if ( typeof(queryCache[serialized]) != 'undefined' ) { return queryCache[serialized]; } else { return false; } } function cacheResponse(parameters, result) { var serialized = JSON.stringify(parameters); queryCache[serialized] = result; } function setURLSpecifiedSearchAttributes() { jQuery('.select-availattributes').each( function(key, select_option) { var select_id = jQuery(select_option).attr('data-id'); var querystring_value = 0; if(querystring(select_id).length > 0) { querystring_value = decodeURIComponent(querystring(select_id)[0]).replace('+', '\ '); } if (querystring_value.length > 0 && querystring_value != '0') { jQuery(select_option).children('option[value="' + querystring_value + '"]').attr('selected', true); jQuery(select_option).change(); } }); } function refreshSelectionOptions() { var selectedAttributes = getSelectedAttributes(); var target = jQuery(this); var cacheResult = getCachedResponse(selectedAttributes); if (cacheResult != false) { showAvailableAttributes( target, cacheResult); } else { jQuery.ajax( { url: "/index.cfm?fuseaction=catalog.attributeOptionsSearch", data: selectedAttributes, dataType: 'json', type: 'GET', success: function(data) { cacheResponse(selectedAttributes, data.DATA); showAvailableAttributes( target, data.DATA ); } } ); } } function markSelection(select_obj) { var selected_val = select_obj.children('option:selected').val(); if (selected_val != 0) { // Create selection filler text with remove option var filler_text_wrapper = jQuery('
'); var filler_text_text_wrapper = jQuery('
'); filler_text_text_wrapper.appendTo(filler_text_wrapper); filler_text_text_wrapper.addClass('attribute-search-selection-text'); filler_text_text_wrapper.html(selected_val.split("~")[1]); var filler_text_clear_button = jQuery('
'); filler_text_clear_button.appendTo(filler_text_wrapper); filler_text_clear_button.addClass('attribute-search-selection-clear'); filler_text_clear_button.html('[Remove]'); filler_text_wrapper.appendTo( select_obj.parent().children('.attsearch-filler') ); select_obj.hide(); } } function clearSelection(select_filler_clear_obj) { var select_wrapper = select_filler_clear_obj.parents('.attsearch-wrapper').first(); var selection_filler_wrapper = select_filler_clear_obj.parents('.attsearch-filler').first(); select_wrapper.children('select').show(); select_wrapper.children('select').children('option[value=0]').attr('selected', true); selection_filler_wrapper.html(''); } function getSelectedAttributes(nosplit, leavezero) { var nosplit = nosplit || false; var leavezero = leavezero || false; var selectedAttributes = {}; selectedAttributes.catId = "40916"; selectedAttributes.attributes = ""; selectedAttributes.attributevalues = ""; jQuery.each(jQuery('.select-availattributes'), function(key, selection) { var id = jQuery(selection).attr('data-id'); var value = jQuery(selection).children('option:selected').val(); if (!nosplit) { value = value.split("~"); try { value = value[1]; } catch(e) { value = ""; } } if (value != "" && typeof(value) != 'undefined' && value != 0) { selectedAttributes.attributes += "," + id; selectedAttributes.attributevalues += "," + value; } else { if (leavezero) { selectedAttributes.attributes += "," + id; selectedAttributes.attributevalues += "," + 0; } } }); return selectedAttributes; } function showAvailableAttributes(target, data) { var target = target; jQuery(target).attr('data-selected', 'true'); jQuery.each( jQuery('.select-availattributes[value=0]'), function(key, target) { jQuery(target).children('option').remove(); jQuery(target).append(''); }); jQuery.each(data, function(key, val) { var group_id = val[1]; var option_value = val[3]; var option_count = val[4]; var new_option = jQuery('