settings.js
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* JavaScript for the settings interface.
*
* @since 1.0.0
*
* @package Media_Library_Organizer
* @author Media Library Organizer
*/
jQuery( document ).ready(
function( $ ) {
/**
* Initialize Selectize Instances
*/
if ( typeof mediaLibraryOrganizerSelectizeInit !== 'undefined' ) {
mediaLibraryOrganizerSelectizeInit();
}
/**
* Save Settings via AJAX
*/
$( 'form#media-library-organizer' ).on(
'submit',
function( e ) {
// Don't submit form.
e.preventDefault();
// Show modal and overlay.
wpzinc_modal_open( media_library_organizer_settings.save_settings_modal.title, '' );
// Send via AJAX.
$.ajax(
{
url: ajaxurl,
type: 'POST',
async: true,
data: {
action: media_library_organizer_settings.save_settings_action,
nonce: media_library_organizer_settings.save_settings_nonce,
settings: JSON.stringify( $( this ).serializeArray() )
},
error: function( a, b, c ) {
// Close modal and overlay.
wpzinc_modal_close();
},
success: function( result ) {
if ( ! result.success ) {
wpzinc_modal_show_error_message_and_exit( result.data );
}
// Show success message and close.
wpzinc_modal_show_success_and_exit( media_library_organizer_settings.save_settings_modal.title_success );
}
}
);
}
);
}
);