Passed
Push — 247-fix/delete-term-meta ( 0c7c80...e69629 )
by Rajan
07:33
created

$(document).ready   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 32
rs 9.112
c 1
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 13 2
A 0 7 1
1
/**
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
			ajax: {
10
				url: ajaxurl,
11
				dataType: 'json',
12
				delay: 250,
13
				data: function ( params ) {
14
					return {
15
						q: params.term,
16
						taxonomy: jQuery('input[name=smbd_meta_term_taxonomy]:checked').val(),
17
						action: 'bd_load_taxonomy_term'
18
					};
19
				},
20
				processResults: function ( data ) {
21
					var options = [];
22
23
					if ( data ) {
24
						jQuery.each( data, function ( index, dataPair ) {
25
							options.push( { id: dataPair[ 0 ], text: dataPair[ 1 ] } );
26
						} );
27
					}
28
29
					return {
30
						results: options
31
					};
32
				},
33
				cache: true
34
			},
35
			minimumInputLength: 2, // the minimum of symbols to input before perform a search
36
			width: '300px'
37
		} );
38
	});
39
40
	jQuery( '.select2-terms' ).change(function(){
41
		jQuery( '.select2-term-meta' ).select2( {
42
			ajax: {
43
				url: ajaxurl,
44
				dataType: 'json',
45
				delay: 250,
46
				data: function () {
47
					return {
48
						term_id: jQuery('.select2-terms').val(),
49
						action: 'bd_load_taxonomy_term_meta'
50
					};
51
				},
52
				processResults: function ( data ) {
53
					var options = [];
54
55
					if ( data ) {
56
						jQuery.each( data, function ( index, dataPair ) {
57
							options.push( { id: dataPair[ 0 ], text: dataPair[ 0 ] } );
58
						} );
59
					}
60
61
					return {
62
						results: options
63
					};
64
				},
65
				cache: true
66
			},
67
			minimumInputLength: 2, // the minimum of symbols to input before perform a search
68
			width: '300px'
69
		} );
70
	});
71
	
72
} );