(function(w){ var jQ = w.jQuery; if(typeof jQ !== 'function' && typeof jQ.getJSON !== 'function') { return; } // Logic to decode qs var re = /([^&=]+)=?([^&]*)/g; var decodeRE = /\+/g; // Regex for replacing addition symbol with a space var decode = function (str) {return decodeURIComponent( str.replace(decodeRE, " ") );}; function parseQs(query) { var params = {}, e; while ( e = re.exec(query) ) { var k = decode( e[1] ), v = decode( e[2] ); if (k.substring(k.length - 2) === '[]') { k = k.substring(0, k.length - 2); (params[k] || (params[k] = [])).push(v); } else params[k] = v; } return params; } function sortData(arr,type) { if (type === 'numeric') { return arr.sort(function(a, b) { return (a-b); }) } else { return arr.sort(); } } var qs = parseQs(w.location.search.replace('?','')); // Get list of dynamic inputs var loadResource = []; var parentCategory = ''; if(window.parentCategory) { parentCategory = window.parentCategory; } jQ('[data-search]').each(function(i,v){ if(jQ(v).attr('data-search')) { loadResource.push(jQ(v).attr('data-search')); } }); if(loadResource.length) { var url = '/catalog/item/customfield-options?cf='+loadResource.join('|'); if(parentCategory) { url += '&parentCategoryId='+parentCategory; } jQ.getJSON(url, function( data ) { jQ.each( data, function( key, arr ) { var ele = '[data-search="'+key+'"]'; // If element exists then append options in it if (jQ(ele).length > 0) { jQ(ele).each(function(i,v){ if(jQ(v).attr('data-sort')) { arr = sortData(arr,jQ(v).attr('data-sort')); } var name = jQ(v).attr('name'); jQ.each( arr, function( val, txt ) { var selected = ""; jQ(v).append(jQ('