Viper007Bond

Untitled

Sep 4th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     jQuery(document).ready(function($) {
  2.         // ID tracker field
  3.         var IDtracker = $('<input>').attr({
  4.             type: 'hidden',
  5.             id: 'acami-idtracker',
  6.             name: 'acami-idtracker',
  7.             value: ''
  8.         }).prependTo('#update-nav-menu');
  9.  
  10.         function acami_add_checkbox( item ) {
  11.             // Skip items that are known not to be hierarchical post types or that we already modified
  12.             if ( $(item).is('.acami-checked, .menu-item-custom, .menu-item-category, .menu-item-post_tag') ) {
  13.                 return;
  14.             }
  15.  
  16.             // Don't check this item again
  17.             $(item).addClass('acami-checked');
  18.  
  19.             var itemID = parseInt( $(item).attr('id').replace('menu-item-', ''), 10 );
  20.  
  21.             // Gotta figure it out in PHP, so use an AJAX call
  22.             jQuery.post(
  23.                 ajaxurl,
  24.                 {
  25.                     action: 'acami_get_menu_status',
  26.                     id: itemID
  27.                 },
  28.                 function( response ){
  29.                     if ( response && response.add ) {
  30.                         // Track IDs to check the POST for
  31.                         IDtracker.val( IDtracker.val() + ',' + itemID );
  32.  
  33.                         // Add the checkbox
  34.                         var checkboxid = 'acami-child-checkbox-' + itemID;
  35.                         $(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>');
  36.  
  37.                         if ( response.checked ) {
  38.                             $('#' + checkboxid).prop('checked', true);
  39.                         }
  40.                     }
  41.                 },
  42.                 'json'
  43.             );
  44.         }
  45.  
  46.         // Try adding checkboxes to all existing menu items
  47.         $('.menu-item').each(function(){
  48.             acami_add_checkbox( this );
  49.         });
  50.  
  51.         // When hovering over a menu item added using Javascript, try adding a checkbox to it (props DD32 for mouseover hack)
  52.         $('.menu-item.pending').live('mouseover', function(){
  53.             acami_add_checkbox( this );
  54.         });
  55.     });
Advertisement
Add Comment
Please, Sign In to add comment