| 1 |
jQuery( document ).ready(function( $ ) { |
| 2 |
$( '#update-nav-menu' ).bind( 'click', function( e ) { |
| 3 |
if ( e.target && e.target.className && -1 != e.target.className.indexOf( 'item-edit' ) ) { |
| 4 |
$( "input[value='#pll_switcher'][type=text]" ).parent().parent().parent().each(function(){ |
| 5 |
var item = $( this ).attr( 'id' ).substring( 19 ); |
| 6 |
$( this ).children( 'p:not( .field-move )' ).remove(); // remove default fields we don't need |
| 7 |
|
| 8 |
h = $( '<input>' ).attr({ |
| 9 |
type: 'hidden', |
| 10 |
id: 'edit-menu-item-title-' + item, |
| 11 |
name: 'menu-item-title[' + item + ']', |
| 12 |
value: pll_data.title |
| 13 |
}); |
| 14 |
$( this ).append( h ); |
| 15 |
|
| 16 |
h = $( '<input>' ).attr({ |
| 17 |
type: 'hidden', |
| 18 |
id: 'edit-menu-item-url-' + item, |
| 19 |
name: 'menu-item-url[' + item + ']', |
| 20 |
value: '#pll_switcher' |
| 21 |
}); |
| 22 |
$( this ).append( h ); |
| 23 |
|
| 24 |
// a hidden field which exits only if our jQuery code has been executed |
| 25 |
h = $( '<input>' ).attr({ |
| 26 |
type: 'hidden', |
| 27 |
id: 'edit-menu-item-pll-detect-' + item, |
| 28 |
name: 'menu-item-pll-detect[' + item + ']', |
| 29 |
value: 1 |
| 30 |
}); |
| 31 |
$( this ).append( h ); |
| 32 |
|
| 33 |
ids = Array( 'hide_if_no_translation', 'hide_current', 'force_home', 'show_flags', 'show_names', 'dropdown' ); // reverse order |
| 34 |
|
| 35 |
// add the fields |
| 36 |
for ( var i = 0; i < ids.length; i++ ) { |
| 37 |
p = $( '<p>' ).attr( 'class', 'description' ); |
| 38 |
$( this ).prepend( p ); |
| 39 |
label = $( '<label>' ).attr( 'for', 'edit-menu-item-' + ids[ i ] + '-' + item ).text( ' ' + pll_data.strings[ ids[ i ] ] ); |
| 40 |
p.append( label ); |
| 41 |
cb = $( '<input>' ).attr({ |
| 42 |
type: 'checkbox', |
| 43 |
id: 'edit-menu-item-' + ids[ i ] + '-' + item, |
| 44 |
name: 'menu-item-' + ids[ i ] + '[' + item + ']', |
| 45 |
value: 1 |
| 46 |
}); |
| 47 |
if ( ( typeof( pll_data.val[ item ] ) != 'undefined' && pll_data.val[ item ][ ids[ i ] ] == 1 ) || ( typeof( pll_data.val[ item ] ) == 'undefined' && ids[ i ] == 'show_names' ) ) { // show_names as default value |
| 48 |
cb.prop( 'checked', true ); |
| 49 |
} |
| 50 |
label.prepend( cb ); |
| 51 |
} |
| 52 |
}); |
| 53 |
|
| 54 |
// disallow unchecking both show names and show flags |
| 55 |
$( '.menu-item-data-object-id' ).each(function() { |
| 56 |
var id = $( this ).val(); |
| 57 |
var options = ['names-', 'flags-']; |
| 58 |
$.each( options, function( i, v ) { |
| 59 |
$( '#edit-menu-item-show_' + v + id ).change(function() { |
| 60 |
if ( 'checked' != $( this ).attr( 'checked' ) ) { |
| 61 |
$( '#edit-menu-item-show_' + options[ 1 - i ] + id ).prop( 'checked', true ); |
| 62 |
} |
| 63 |
}); |
| 64 |
}); |
| 65 |
}); |
| 66 |
} |
| 67 |
}); |
| 68 |
}); |
| 69 |
|