-
Notifications
You must be signed in to change notification settings - Fork 18
/
admin.js
69 lines (50 loc) · 1.97 KB
/
admin.js
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
68
69
jQuery( document ).ready( function() {
/**
* Hide or show an element depending on which input is checked.
*
* @param fieldOne jQuery object for the first element
* @param fieldOne jQuery object for the second element
* @param fieldOne jQuery object for the input relating to the first element. Note the input for the second must be a sibling. Note that this function only supports 2 fields.
* @return null
*/
var minqueueToggle = function( fieldOne, fieldTwo, fieldOneInput ) {
var toggler = function () {
if ( fieldOneInput.is( ':checked' ) ) {
fieldOne.slideDown( 100 );
fieldTwo.slideUp( 100 );
} else {
fieldOne.slideUp( 100 );
fieldTwo.slideDown( 100 );
}
};
toggler();
fieldOneInput.siblings( 'input[type=radio]' ).andSelf().change( toggler );
};
minqueueToggle( jQuery('#field_manual_scripts'), jQuery('#field_disabled_scripts'), jQuery( '#minqueue_options_scripts_method_manual' ) );
minqueueToggle( jQuery('#field_manual_styles'), jQuery('#field_disabled_styles'), jQuery( '#minqueue_options_styles_method_manual' ) );
/**
* Clone input.
*
* Clones a hidden input (must have class input-template), and appends it.
* Updates numbers in the ID to reflect the current number of inputs.
*
* @param container element
* @return null
*/
var minqueueFieldCloner = function( container ) {
var template = container.find( '.input-template' );
var buttonAddNew = jQuery( '<button class="button">Add New Queue</button>' );
buttonAddNew.appendTo( container );
buttonAddNew.click( function(e){
e.preventDefault();
// Clone the hidden input.
var newInput = template.clone();
// Update the ID
newInput.attr('ID', newInput.attr( 'ID' ).replace('_hidden', '_' + ( container.find( 'textarea' ).length - 1 ) ) );
// Insert & Show
buttonAddNew.before( newInput.show() );
} );
};
minqueueFieldCloner( jQuery( '#field_manual_scripts' ) );
minqueueFieldCloner( jQuery( '#field_manual_styles' ) );
} );