1
|
|
|
/** |
2
|
|
|
* JavaScript for Bulk move Plugin |
3
|
|
|
* |
4
|
|
|
* http://sudarmuthu.com/wordpress/bulk-move |
5
|
|
|
* |
6
|
|
|
* @author: Sudar <http://sudarmuthu.com> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/*jslint browser: true, devel: true*/ |
10
|
|
|
/*global BULK_MOVE, jQuery, document, postboxes, pagenow, ajaxurl*/ |
11
|
|
|
jQuery(document).ready(function () { |
12
|
|
|
jQuery( 'button[value="move_tags"], button[value="move_cats"], button[value="move_category_by_tag"], button[value="move_custom_taxonomy"]' ).click( function () { |
13
|
|
|
return confirm( BULK_MOVE.msg.move_warning ); |
14
|
|
|
}); |
15
|
|
|
|
16
|
|
|
// Enable toggles for all modules. |
17
|
|
|
postboxes.add_postbox_toggles( pagenow ); |
18
|
|
|
|
19
|
|
|
jQuery( 'tr.taxonomy-select-row, tr.term-select-row, .bm_ct_filters, .bm_ct_submit' ).hide(); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Load Taxonomy on Post Type change. |
23
|
|
|
*/ |
24
|
|
|
jQuery( '#smbm_mbct_post_type' ).change( function () { |
25
|
|
|
var selectedPostType = jQuery( this ).val(), |
26
|
|
|
payload = { |
27
|
|
|
'action' : BULK_MOVE.bulk_move_posts.action_get_taxonomy, |
28
|
|
|
'nonce' : BULK_MOVE.bulk_move_posts.nonce, |
29
|
|
|
'post_type': selectedPostType |
30
|
|
|
}; |
31
|
|
|
|
32
|
|
|
if ( '-1' === selectedPostType ) { |
33
|
|
|
jQuery( 'tr.taxonomy-select-row, tr.term-select-row, .bm_ct_filters, .bm_ct_submit' ).hide(); |
34
|
|
|
|
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
jQuery.ajaxSetup( { async: false } ); |
39
|
|
|
|
40
|
|
|
jQuery.post( ajaxurl, payload, function( response ) { |
41
|
|
|
jQuery( 'tr.taxonomy-select-row' ).hide(); |
42
|
|
|
|
43
|
|
|
if ( ! response.success ) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
var taxonomies = response.data.taxonomies || {}; |
48
|
|
|
|
49
|
|
|
if ( jQuery.isEmptyObject( taxonomies ) ) { |
50
|
|
|
alert( response.data.no_taxonomy_msg ); |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
jQuery( 'tr.taxonomy-select-row' ).show(); |
55
|
|
|
|
56
|
|
|
// Reset options on each AJAX request. |
57
|
|
|
jQuery( '#smbm_mbct_taxonomy' ).children( 'option' ).remove(); |
58
|
|
|
|
59
|
|
|
jQuery( '<option/>', { |
60
|
|
|
'value': '-1', |
61
|
|
|
'text': response.data.select_taxonomy_label |
62
|
|
|
}).appendTo( '#smbm_mbct_taxonomy' ); |
63
|
|
|
|
64
|
|
|
jQuery.each( taxonomies, function( index, taxonomy ) { |
65
|
|
|
jQuery( '<option/>', { |
66
|
|
|
'value': taxonomy, |
67
|
|
|
'text': taxonomy |
68
|
|
|
}).appendTo( '#smbm_mbct_taxonomy' ); |
69
|
|
|
}); |
70
|
|
|
}); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Load Term on Taxonomy change. |
75
|
|
|
*/ |
76
|
|
|
jQuery( '#smbm_mbct_taxonomy' ).change( function () { |
77
|
|
|
|
78
|
|
|
var selectedTaxonomy = jQuery( this ).val(), |
79
|
|
|
payload = { |
80
|
|
|
'action' : BULK_MOVE.bulk_move_posts.action_get_terms, |
81
|
|
|
'nonce' : BULK_MOVE.bulk_move_posts.nonce, |
82
|
|
|
'taxonomy' : selectedTaxonomy |
83
|
|
|
}; |
84
|
|
|
|
85
|
|
|
if ( '-1' === selectedTaxonomy ) { |
86
|
|
|
jQuery( 'tr.term-select-row, .bm_ct_filters, .bm_ct_submit' ).hide(); |
87
|
|
|
|
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
jQuery.ajaxSetup( { async: false } ); |
92
|
|
|
|
93
|
|
|
jQuery.post( ajaxurl, payload, function( response ) { |
94
|
|
|
|
95
|
|
|
if ( ! response.success ) { |
96
|
|
|
return; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
var terms = response.data.terms || {}; |
100
|
|
|
|
101
|
|
|
if ( jQuery.isEmptyObject( terms ) ) { |
102
|
|
|
alert( response.data.no_term_msg ); |
103
|
|
|
|
104
|
|
|
return; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
jQuery( 'tr.term-select-row' ).show(); |
108
|
|
|
|
109
|
|
|
// Reset options on each AJAX request. |
110
|
|
|
jQuery( '#smbm_mbct_selected_term, #smbm_mbct_mapped_term' ).children( 'option' ).remove(); |
111
|
|
|
|
112
|
|
|
jQuery( '<option/>', { |
113
|
|
|
'value': '-1', |
114
|
|
|
'text': response.data.select_term_label |
115
|
|
|
}).appendTo( '#smbm_mbct_selected_term' ); |
116
|
|
|
|
117
|
|
|
jQuery( '<option/>', { |
118
|
|
|
'value': '-1', |
119
|
|
|
'text': response.data.remove_term_label |
120
|
|
|
}).appendTo( '#smbm_mbct_mapped_term' ); |
121
|
|
|
|
122
|
|
|
jQuery.each( terms, function( termId, term ) { |
123
|
|
|
jQuery( '<option/>', { |
124
|
|
|
'value': termId, |
125
|
|
|
'text': term['term_name'] |
126
|
|
|
}).appendTo( '#smbm_mbct_selected_term' ); |
127
|
|
|
|
128
|
|
|
jQuery( '<option/>', { |
129
|
|
|
'value': termId, |
130
|
|
|
'text': term['term_name'] |
131
|
|
|
}).appendTo( '#smbm_mbct_mapped_term' ); |
132
|
|
|
}); |
133
|
|
|
}); |
134
|
|
|
}); |
135
|
|
|
|
136
|
|
|
jQuery( '#smbm_mbct_selected_term, #smbm_mbct_mapped_term' ).change( function() { |
137
|
|
|
jQuery( '.bm_ct_filters, .bm_ct_submit' ).show(); |
138
|
|
|
}); |
139
|
|
|
}); |
140
|
|
|
|