| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php /** |
| 2 | 2 | * @version 1.0 |
| 3 | 3 | * @description AJX_Bookings |
| 4 | 4 | * @category AJX_Bookings Class |
| @@ -35,16 +35,12 @@ | ||
| 35 | 35 | * Define HOOKs for loading CSS and JavaScript files |
| 36 | 36 | */ |
| 37 | 37 | public function init_load_css_js_tpl() { |
| 38 | 38 | |
| 39 | - // Load only at AJX_Bookings Settings Page. | |
| 40 | - if ( 'vm_booking_listing' === wpbc_get_default_saved_view_mode_for_wpbc_page() ) { | |
| 39 | + add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 ); | |
| 40 | + add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 ); | |
| 41 | 41 | |
| 42 | - add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 ); | |
| 43 | - add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 ); | |
| 44 | - | |
| 45 | - add_action( 'wpbc_hook_settings_page_footer', array( $this, 'hook__page_footer_tmpl' ) ); | |
| 46 | - } | |
| 42 | + add_action( 'wpbc_hook_settings_page_footer', array( $this, 'hook__page_footer_tmpl' ) ); | |
| 47 | 43 | } |
| 48 | 44 | |
| 49 | 45 | |
| 50 | 46 | /** |
| @@ -55,17 +51,33 @@ | ||
| 55 | 51 | * @return void |
| 56 | 52 | */ |
| 57 | 53 | public function js_load_files( $where_to_load ) { |
| 58 | 54 | |
| 59 | - $in_footer = true; | |
| 55 | + if ( ! is_admin() || ! wpbc_is_bookings_page() ) { | |
| 56 | + return; | |
| 57 | + } | |
| 60 | 58 | |
| 61 | 59 | if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ), true ) ) ) { |
| 60 | + self::enqueue_js_files_now(); | |
| 61 | + } | |
| 62 | + } | |
| 62 | 63 | |
| 63 | - wp_enqueue_script( 'wpbc-booking_ajx_toolbar_hooks', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__hooks.js', array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 64 | - wp_enqueue_script( 'wpbc-booking_ajx_listing', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__listing.js', array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 65 | - wp_enqueue_script( 'wpbc-booking_ajx_actions', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__actions.js', array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 66 | - wp_enqueue_script( 'wpbc-boo_listing_ajx_actions', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/boo_listing__actions.js', array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 67 | - } | |
| 64 | + /** | |
| 65 | + * Enqueue AJAX booking listing scripts. | |
| 66 | + * | |
| 67 | + * The Booking Listing page prints inline initialization in its content. In Free, the saved default view can differ | |
| 68 | + * from the current tab, so this method is also called directly from the page content as a last-mile guarantee. | |
| 69 | + * | |
| 70 | + * @return void | |
| 71 | + */ | |
| 72 | + public static function enqueue_js_files_now() { | |
| 73 | + | |
| 74 | + $in_footer = true; | |
| 75 | + | |
| 76 | + wp_enqueue_script( 'wpbc-booking_ajx_listing', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__listing.js', array( 'wpbc_all', 'wp-util' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 77 | + wp_enqueue_script( 'wpbc-booking_ajx_toolbar_hooks', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__hooks.js', array( 'wpbc-booking_ajx_listing', 'wpbc-ui-chosen-filter' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 78 | + wp_enqueue_script( 'wpbc-booking_ajx_actions', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__actions.js', array( 'wpbc-booking_ajx_listing' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 79 | + wp_enqueue_script( 'wpbc-boo_listing_ajx_actions', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/boo_listing__actions.js', array( 'wpbc-booking_ajx_listing' ), WP_BK_VERSION_NUM, $in_footer ); | |
| 68 | 80 | } |
| 69 | 81 | |
| 70 | 82 | |
| 71 | 83 | /** |