function smDebounce( func, wait, immediate ) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; function smUpdateValues( parent ) { var values = parent.find( '.values' ); values.empty(); parent.find( '[data-select="dst"] option' ).each( function() { values.append( $('', { type: 'hidden', name: values.data( 'name' ), value: $(this).val() }) ); }); } $(document).ready( function() { $('.select_many.input select').on( 'dblclick', function( event ) { if( event.target.tagName.toLowerCase() == 'option' ) { var parent = $(this).closest( '.select_many' ); var opt = $(event.target); var dst = parent.find( $(this).data( 'select' ) == 'src' ? '[data-select="dst"]' : '[data-select="src"]' ); dst.append( $('