Passed
Push — master ( cf71c4...27b5ca )
by Austin
02:02
created

$(ꞌ#add-repeaterꞌ).click   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 9.4285
1
/**
2
 * Repeaters
3
 */
4
(function( $ ) {
5
	'use strict';
6
7
	/**
8
	 * Clones the hidden field to add another repeater.
9
	 */
10
	$('#add-repeater').on( 'click', function( e ) {
11
12
		e.preventDefault();
13
14
		var clone = $('.repeater.hidden').clone(true);
15
16
		clone.removeClass('hidden');
17
		clone.insertBefore('.repeater.hidden');
18
19
		return false;
20
21
	});
22
23
	/**
24
	 * Removes the selected repeater.
25
	 */
26
	$('.link-remove').on('click', function() {
27
28
		var parents = $(this).parents('.repeater');
29
30
		if ( ! parents.hasClass( 'first' ) ) {
31
32
			parents.remove();
33
34
		}
35
36
		return false;
37
38
	});
39
40
	/**
41
	 * Shows/hides the selected repeater.
42
	 */
43
	$( '.btn-edit' ).on( 'click', function() {
44
45
		var repeater = $(this).parents( '.repeater' );
46
47
		repeater.children( '.repeater-content' ).slideToggle( '150' );
48
		$(this).children( '.toggle-arrow' ).toggleClass( 'closed' );
49
		$(this).parents( '.handle' ).toggleClass( 'closed' );
50
51
	});
52
53
	/**
54
	 * Changes the title of the repeater header as you type
55
	 */
56
	$(function(){
57
58
		$( '.repeater-title' ).on( 'keyup', function(){
59
60
			var repeater = $(this).parents( '.repeater' );
61
			var fieldval = $(this).val();
62
63
			if ( fieldval.length > 0 ) {
64
65
				repeater.find( '.title-repeater' ).text( fieldval );
66
67
			} else {
68
69
				repeater.find( '.title-repeater' ).text( nhdata.repeatertitle );
0 ignored issues
show
Bug introduced by
The variable nhdata seems to be never declared. If this is a global, consider adding a /** global: nhdata */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
70
71
			}
72
73
		});
74
75
	});
76
77
	/**
78
	 * Makes the repeaters sortable.
79
	 */
80
	$(function() {
81
82
		$( '.repeaters' ).sortable({
83
			cursor: 'move',
84
			handle: '.handle',
85
			items: '.repeater',
86
			opacity: 0.6
87
		});
88
	});
89
90
})( jQuery );
91