cmoreira

tshowcase - Convert 4th Taxonomy Dropdown to Inputs

Dec 1st, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery('#tshowcase-dtaxonomy').each(function(i, select){
  2.    
  3.     var $select = jQuery(select);
  4.  
  5.     $select.wrap( "<div class='tshowcase_inline_filter'></div>" );
  6.     $select.find('option').each(function(j, option){
  7.         var $option = jQuery(option);
  8.         // Create a radio:
  9.         var $radio = jQuery('<input type="radio" />');
  10.         // Set name and value:
  11.         var thisval = $option.val();
  12.         var thisfor = 'dtaxonomy-'+$option.val();
  13.         if(thisval == '') { thisval = 0; thisfor = 'dtaxonomy-all' }
  14.  
  15.         $radio.attr('name', $select.attr('name')).attr('value', thisval).attr('id', thisfor);
  16.         // Set checked if the option was selected
  17.         if ($option.attr('selected')) $radio.prop('checked', true);
  18.         // Insert radio before select box:
  19.         $select.before($radio);
  20.  
  21.         // Insert a label:
  22.         $select.before(
  23.  
  24.           jQuery("<label />")
  25.             .attr('for', thisfor)
  26.             .text($option.text())
  27.             );
  28.     });
  29.  
  30.        
  31.     $select.remove();
  32. });
Advertisement
Add Comment
Please, Sign In to add comment