| 1 |
<?php |
| 2 |
|
| 3 |
if( ! class_exists( 'wp_mapit_scripts' ) ) { |
| 4 |
|
| 5 |
/** |
| 6 |
* Class to manage the scripts and styles for WP MAPIT |
| 7 |
*/ |
| 8 |
class wp_mapit_scripts |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Add hooks and filters to enqueue scripts and styles needed for WP MAPIT |
| 12 |
* |
| 13 |
* @since 1.0 |
| 14 |
* @static |
| 15 |
* @access public |
| 16 |
*/ |
| 17 |
public static function init() { |
| 18 |
add_action( 'wp_enqueue_scripts', __CLASS__ . '::wp_enqueue_scripts' ); |
| 19 |
add_action( 'admin_enqueue_scripts', __CLASS__ . '::admin_enqueue_scripts' ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Hook to add scripts and styles for WP MAPIT frontend |
| 24 |
* |
| 25 |
* @since 1.0 |
| 26 |
* @static |
| 27 |
* @access public |
| 28 |
*/ |
| 29 |
public static function wp_enqueue_scripts() { |
| 30 |
wp_enqueue_style( 'wp-mapit-leaflet-css', WP_MAPIT_URL . 'css/leaflet.css' ); |
| 31 |
wp_enqueue_style( 'wp-mapit-leaflet-responsive-popup-css', WP_MAPIT_URL . 'css/leaflet.responsive.popup.css' ); |
| 32 |
wp_enqueue_style( 'wp-mapit-leaflet-gesture-handling-css', WP_MAPIT_URL . 'css/leaflet-gesture-handling.css' ); |
| 33 |
|
| 34 |
if( is_rtl() ) { |
| 35 |
wp_enqueue_style( 'wp-mapit-leaflet-responsive-popup-rtl-css', WP_MAPIT_URL . 'css/leaflet.responsive.popup.rtl.css' ); |
| 36 |
} |
| 37 |
|
| 38 |
wp_enqueue_script( 'wp-mapit-leaflet-js', WP_MAPIT_URL . 'js/leaflet.js', array( 'jquery' ) ); |
| 39 |
wp_enqueue_script( 'wp-mapit-leaflet-responsive-popup-js', WP_MAPIT_URL . 'js/leaflet.responsive.popup.js', array( 'jquery' ) ); |
| 40 |
wp_enqueue_script( 'wp-mapit-leaflet-gray-js', WP_MAPIT_URL . 'js/TileLayer.Grayscale.js', array( 'jquery' ) ); |
| 41 |
wp_enqueue_script( 'wp-mapit-leaflet-gesture-handling-js', WP_MAPIT_URL . 'js/leaflet-gesture-handling.js', array( 'jquery' ) ); |
| 42 |
|
| 43 |
wp_enqueue_script( 'wp-mapit-js', WP_MAPIT_URL . 'js/wp_mapit.js', array( 'jquery' ) ); |
| 44 |
|
| 45 |
wp_localize_script( 'wp-mapit-js', 'wp_mapit', array( |
| 46 |
'plugin_attribution' => '<strong>Developed by <a href="http://wp-mapit.chandnipatel.in">WP MAPIT</a></strong> | ' |
| 47 |
) ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Hook to add scripts and styles for WP MAPIT admin |
| 52 |
* |
| 53 |
* @since 1.0 |
| 54 |
* @static |
| 55 |
* @access public |
| 56 |
*/ |
| 57 |
public static function admin_enqueue_scripts() { |
| 58 |
wp_enqueue_media(); |
| 59 |
|
| 60 |
wp_enqueue_style( 'wp-mapit-leaflet-css', WP_MAPIT_URL . 'css/leaflet.css' ); |
| 61 |
wp_enqueue_style( 'wp-mapit-css', WP_MAPIT_URL . 'css/wp_mapit_admin.css' ); |
| 62 |
wp_enqueue_style( 'wp-mapit-leaflet-responsive-popup-css', WP_MAPIT_URL . 'css/leaflet.responsive.popup.css' ); |
| 63 |
wp_enqueue_style( 'wp-mapit-leaflet-gesture-handling-css', WP_MAPIT_URL . 'css/leaflet-gesture-handling.css' ); |
| 64 |
|
| 65 |
if( is_rtl() ) { |
| 66 |
wp_enqueue_style( 'wp-mapit-leaflet-responsive-popup-rtl-css', WP_MAPIT_URL . 'css/leaflet.responsive.popup.rtl.css' ); |
| 67 |
} |
| 68 |
|
| 69 |
wp_enqueue_script( 'wp-mapit-leaflet-js', WP_MAPIT_URL . 'js/leaflet.js', array( 'jquery' ) ); |
| 70 |
wp_enqueue_script( 'wp-mapit-leaflet-gray-js', WP_MAPIT_URL . 'js/TileLayer.Grayscale.js', array( 'jquery' ) ); |
| 71 |
wp_enqueue_script( 'wp-mapit-leaflet-responsive-popup-js', WP_MAPIT_URL . 'js/leaflet.responsive.popup.js', array( 'jquery' ) ); |
| 72 |
wp_enqueue_script( 'wp-mapit-leaflet-gesture-handling-js', WP_MAPIT_URL . 'js/leaflet-gesture-handling.js', array( 'jquery' ) ); |
| 73 |
|
| 74 |
wp_enqueue_script( 'wp-mapit-admin-js', WP_MAPIT_URL . 'js/wp_mapit_admin.js', array( 'jquery' ) ); |
| 75 |
|
| 76 |
wp_localize_script( 'wp-mapit-admin-js', 'wp_mapit', array( |
| 77 |
'choose_image_text' => __( 'Choose Image', WP_MAPIT_TEXTDOMAIN ), |
| 78 |
'ajax_error_message' => __( 'Oops! Something went wrong. Please try again.', WP_MAPIT_TEXTDOMAIN ), |
| 79 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 80 |
'please_wait_text' => __( 'Please wait', WP_MAPIT_TEXTDOMAIN ), |
| 81 |
'search_text' => __( 'Search', WP_MAPIT_TEXTDOMAIN ), |
| 82 |
'plugin_attribution' => '<strong>Developed by <a href="http://wp-mapit.chandnipatel.in">WP MAPIT</a></strong> | ' |
| 83 |
) ); |
| 84 |
|
| 85 |
if( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp_mapit' ) { |
| 86 |
wp_enqueue_script( 'wp-mapit-admin-settings-js', WP_MAPIT_URL . 'js/wp_mapit_admin_settings.js', array( 'jquery' ) ); |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Calling init function to activate hooks and filters. |
| 93 |
*/ |
| 94 |
wp_mapit_scripts::init(); |
| 95 |
} |