Advertisement
ForbodingAngel

Untitled

May 15th, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: jQuery Responsive Select Menu
  4. * Plugin URI: http://mightyminnow.com
  5. * Description: The jQuery Responisve Select Menu plugin replaces the default WordPress navigation menu(s) with a dropdown &lt;select&gt; on mobile devices.
  6. * Version: 9001
  7. * Author: MIGHTYminnow
  8. * Author URI: http://mightyminnow.com
  9. * License: GPLv2+
  10. */
  11.  
  12. // Definitions
  13. define( 'PLUGIN_NAME', 'jQuery Responsive Select Menu' );
  14.  
  15. // Includes
  16. require_once dirname( __FILE__ ) . '/admin.php';
  17.  
  18. /**
  19. * Loads text domain for internationalization
  20. *
  21. * @package jQuery Responsive Select Menu
  22. * @since 1.0
  23. */
  24. function jrsm_init() {
  25.  
  26. // Load plugin text domain
  27. load_plugin_textdomain( 'jrsm', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  28. }
  29. add_action( 'plugins_init', 'jrsm_init' );
  30.  
  31. /**
  32. * Enqueues required scripts & styles, and passes PHP variables to jQuery file
  33. *
  34. * @package jQuery Responsive Select Menu
  35. * @since 1.0
  36. */
  37. function jrsm_scripts() {
  38.  
  39. // Make sure jQuery is included
  40. wp_enqueue_script('jquery');
  41.  
  42. // Include JRSM jQuery
  43. wp_enqueue_script( 'jrsm-jquery', plugins_url( '/jrsm-jquery.js', __FILE__ ), array( 'jquery' ), '1.0', false );
  44.  
  45. // Add PHP plugin variables to the $params[] array to pass to jQuery
  46. $params = array (
  47. 'containers' => get_option( 'jrsm-containers' ),
  48. 'width' => get_option( 'jrsm-width' ),
  49. 'firstItem' => get_option( 'jrsm-first-term' ),
  50. 'indent' => get_option( 'jrsm-sub-item-spacer' ),
  51. 'showCurrentPage' => get_option( 'jrsm-show-current-page' ),
  52. );
  53.  
  54. // Pass PHP variables to jQuery script
  55. wp_localize_script( 'jrsm-jquery', 'php_params', $params );
  56.  
  57. // Load custom CSS file
  58. wp_enqueue_style( 'jrsm-css', plugin_dir_url( __FILE__ ) . 'jrsm.css' );
  59.  
  60. // Append custom CSS based on plugin settings
  61. $containers = str_replace(', ', ',', get_option( 'jrsm-containers' ) );
  62. if ( !empty( $containers ) ) {
  63. // Get menu <ul>'s inside container(s)
  64. $containers = explode( ',', $containers );
  65. foreach( $containers as &$container ) {
  66. $container = '.jquery ' . $container . ' ul';
  67. }
  68. $containers = implode( ', ', $containers );
  69. $width = get_option( 'jrsm-width' );
  70.  
  71. $css = "
  72. @media (max-width: {$width}px) {
  73.  
  74. {$containers} {
  75. display: none !important;
  76. }
  77.  
  78. .jquery-responsive-select-menu {
  79. display: inline-block;
  80. }
  81.  
  82. }";
  83.  
  84. wp_add_inline_style( 'jrsm-css', $css );
  85. }
  86.  
  87. }
  88. add_action( 'wp_enqueue_scripts', 'jrsm_scripts', 0 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement