summaryrefslogtreecommitdiff
blob: d7291e96e3d6e6599e825813dbac529148cce8b7 (plain)
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
/* jshint onevar: false, smarttabs: true */
/* global _novaDragDrop */

( function( $ ) {
	var list;

	function init() {
		list = $( '#the-list' );
		dragMenus();
		addNonce();
		addSubmitButton();
		changeToPost();
	}

	function dragMenus() {
		list.sortable( {
			cancel: '.no-items',
			stop: function( event, ui ) {
				if ( ui.item.is( ':first-child' ) ) {
					return list.sortable( 'cancel' );
				}
				//
				reOrder();
			},
		} );
	}

	function reOrder() {
		list.find( '.menu-label-row' ).each( function() {
			var term_id = $( this ).data( 'term_id' );
			$( this )
				.nextUntil( '.menu-label-row' )
				.each( function( i ) {
					var row = $( this );
					row.find( '.menu-order-value' ).val( i );
					row.find( '.nova-menu-term' ).val( term_id );
				} );
		} );
	}

	function addSubmitButton() {
		$( '.tablenav' ).prepend(
			'<input type="submit" class="button-primary button-reorder alignright" value="' +
				_novaDragDrop.reorder +
				'" name="' +
				_novaDragDrop.reorderName +
				'" />'
		);
	}

	function addNonce() {
		$( '#posts-filter' ).append(
			'<input type="hidden" name="' +
				_novaDragDrop.nonceName +
				'" value="' +
				_novaDragDrop.nonce +
				'" />'
		);
	}

	function changeToPost() {
		$( '#posts-filter' ).attr( 'method', 'post' );
	}

	// do it
	$( document ).ready( init );
} )( jQuery );