Advertisement
brasofilo

Admin-Page-Class : Adding hashes to the URL

Dec 11th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.01 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Modified function in class - START->END HASH
  4.  * admin-page-class.php#L448
  5.  */
  6. public function panel_script() {
  7.     /* ... */
  8.     echo '
  9.          //bind click on menu action to show the right tab.
  10.          jQuery(".panel_menu li").bind("click", function(event){
  11.            event.preventDefault()
  12.            if (!jQuery(this).hasClass("active_tab")){
  13.         //hide all
  14.         jQuery(".setingstab").hide("slow");
  15.         jQuery(".panel_menu li").removeClass("active_tab");
  16.         tab  = jQuery(this).find("a").attr("href");
  17.         jQuery(this).addClass("active_tab");
  18.         jQuery(tab).show("fast");
  19.  
  20.         /* START HASH */
  21.         hash = tab.replace( "#", "" );
  22.         location.hash = "btn_"+hash;
  23.         /* END HASH */
  24.            }
  25.          });'
  26.     /* ... */
  27. }
  28.  
  29. /**
  30.  * Manipulate first active tab according to URL hash
  31.  * my-plugin.php
  32.  */
  33. add_action( 'admin_init', 'mtt_temp_plugin_init' );
  34.  
  35. function mtt_temp_plugin_init()
  36. {
  37.     global $mtt_class_admin_instance;
  38.     $page = $mtt_class_admin_instance->options_class->_Slug;
  39.     add_action('load-'.$page, 'print_header_footer_scripts' );
  40. }
  41.  
  42. function print_header_footer_scripts()
  43. {
  44.     global $mtt_class_admin_instance;
  45.     $page = $mtt_class_admin_instance->options_class->_Slug;
  46.     add_action('admin_head-'.$page, 'my_custom_css');
  47.     add_action('admin_footer-'.$page, 'manipulate_options_hashes', 15 );
  48. }
  49.  
  50. function my_custom_css() {}
  51.  
  52. function manipulate_options_hashes()
  53. {
  54.     ?>
  55.     <script type="text/javascript">
  56.         jQuery(document).ready( function($)
  57.         {
  58.             if( location.hash )
  59.             {
  60.                 // get our hash
  61.                 hash = location.hash.substring(1);
  62.                 hash = hash.replace( "btn_", "" );
  63.  
  64.                 // prevent modifications on first page
  65.                 if( "login_logout" != hash )
  66.                 {
  67.                     // toggle active menu items
  68.                     $('.panel_menu li:first').removeClass('active_tab');
  69.                     $(".panel_menu li."+hash).addClass('active_tab');
  70.  
  71.                     // show content
  72.                     $(".setingstab").hide("slow");
  73.                     var tab  = $(".panel_menu li."+hash+" a").attr("href");
  74.                     $(tab).show();
  75.                 }
  76.             }
  77.         });
  78.     </script>
  79.     <?php  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement