| @@ 5-46 (lines=42) @@ | ||
| 2 | * Add select2 functionality.. |
|
| 3 | */ |
|
| 4 | /*global ajaxurl*/ |
|
| 5 | jQuery( document ).ready( function () { |
|
| 6 | /** |
|
| 7 | * Normal select2. |
|
| 8 | */ |
|
| 9 | jQuery( '.select2-taxonomy' ).select2( { |
|
| 10 | width: '300px' |
|
| 11 | } ); |
|
| 12 | ||
| 13 | /** |
|
| 14 | * Enable AJAX for Taxonomy Select2. |
|
| 15 | */ |
|
| 16 | jQuery( '.select2-taxonomy-ajax' ).select2( { |
|
| 17 | ajax: { |
|
| 18 | url: ajaxurl, |
|
| 19 | dataType: 'json', |
|
| 20 | delay: 250, |
|
| 21 | data: function ( params ) { |
|
| 22 | return { |
|
| 23 | q: params.term, |
|
| 24 | taxonomy: jQuery( this ).attr( 'data-taxonomy' ), |
|
| 25 | action: 'bd_load_taxonomy_term' |
|
| 26 | }; |
|
| 27 | }, |
|
| 28 | processResults: function ( data ) { |
|
| 29 | var options = []; |
|
| 30 | ||
| 31 | if ( data ) { |
|
| 32 | jQuery.each( data, function ( index, dataPair ) { |
|
| 33 | options.push( { id: dataPair[ 0 ], text: dataPair[ 1 ] } ); |
|
| 34 | } ); |
|
| 35 | } |
|
| 36 | ||
| 37 | return { |
|
| 38 | results: options |
|
| 39 | }; |
|
| 40 | }, |
|
| 41 | cache: true |
|
| 42 | }, |
|
| 43 | minimumInputLength: 2, // the minimum of symbols to input before perform a search |
|
| 44 | width: '300px' |
|
| 45 | } ); |
|
| 46 | } ); |
|
| 47 | ||
| @@ 5-45 (lines=41) @@ | ||
| 2 | * Add select2 functionality.. |
|
| 3 | */ |
|
| 4 | /*global ajaxurl*/ |
|
| 5 | jQuery( document ).ready( function () { |
|
| 6 | ||
| 7 | jQuery( 'input[name=smbd_meta_term_taxonomy]' ).change(function(){ |
|
| 8 | jQuery( '.select2-terms' ).select2( { |
|
| 9 | data: function(){ |
|
| 10 | return []; |
|
| 11 | }, |
|
| 12 | } ); |
|
| 13 | jQuery( '.select2-terms' ).select2( { |
|
| 14 | ajax: { |
|
| 15 | url: ajaxurl, |
|
| 16 | dataType: 'json', |
|
| 17 | delay: 250, |
|
| 18 | data: function ( params ) { |
|
| 19 | return { |
|
| 20 | q: params.term, |
|
| 21 | taxonomy: jQuery('input[name=smbd_meta_term_taxonomy]:checked').val(), |
|
| 22 | action: 'bd_load_taxonomy_term' |
|
| 23 | }; |
|
| 24 | }, |
|
| 25 | processResults: function ( data ) { |
|
| 26 | var options = []; |
|
| 27 | ||
| 28 | if ( data ) { |
|
| 29 | jQuery.each( data, function ( index, dataPair ) { |
|
| 30 | options.push( { id: dataPair[ 0 ], text: dataPair[ 1 ] } ); |
|
| 31 | } ); |
|
| 32 | } |
|
| 33 | ||
| 34 | return { |
|
| 35 | results: options |
|
| 36 | }; |
|
| 37 | }, |
|
| 38 | cache: true |
|
| 39 | }, |
|
| 40 | minimumInputLength: 2, // the minimum of symbols to input before perform a search |
|
| 41 | width: '300px' |
|
| 42 | } ); |
|
| 43 | }); |
|
| 44 | ||
| 45 | } ); |
|