Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($) {
- // ID tracker field
- var IDtracker = $('<input>').attr({
- type: 'hidden',
- id: 'acami-idtracker',
- name: 'acami-idtracker',
- value: ''
- }).prependTo('#update-nav-menu');
- function acami_add_checkbox( item ) {
- // Skip items that are known not to be hierarchical post types or that we already modified
- if ( $(item).is('.acami-checked, .menu-item-custom, .menu-item-category, .menu-item-post_tag') ) {
- return;
- }
- // Don't check this item again
- $(item).addClass('acami-checked');
- var itemID = parseInt( $(item).attr('id').replace('menu-item-', ''), 10 );
- // Gotta figure it out in PHP, so use an AJAX call
- jQuery.post(
- ajaxurl,
- {
- action: 'acami_get_menu_status',
- id: itemID
- },
- function( response ){
- if ( response && response.add ) {
- // Track IDs to check the POST for
- IDtracker.val( IDtracker.val() + ',' + itemID );
- // Add the checkbox
- var checkboxid = 'acami-child-checkbox-' + itemID;
- $(item).find('.menu-item-actions .link-to-original').after('<p><label><input type="checkbox" id="' + checkboxid + '" name="' + checkboxid + '" value="1" /> Automatically add all descendants as submenu items</label></p>');
- if ( response.checked ) {
- $('#' + checkboxid).prop('checked', true);
- }
- }
- },
- 'json'
- );
- }
- // Try adding checkboxes to all existing menu items
- $('.menu-item').each(function(){
- acami_add_checkbox( this );
- });
- // When hovering over a menu item added using Javascript, try adding a checkbox to it (props DD32 for mouseover hack)
- $('.menu-item.pending').live('mouseover', function(){
- acami_add_checkbox( this );
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment