enqueues.php
1 year ago
health-check.php
1 year ago
helpers.php
1 year ago
scripts.php
1 year ago
styles.php
1 year ago
scripts.php
72 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Javascripts enqueueing functions. |
| 4 | * |
| 5 | * @package alphalisting |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace eslin87\AlphaListing; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Enqueue Tabs script on pages where the shortcode is active |
| 18 | * |
| 19 | * @since 2.0.0 |
| 20 | * @param bool $force Set this to true if you want the script to always be enqueued. |
| 21 | * @return void |
| 22 | */ |
| 23 | function alphalisting_enqueue_tabs( bool $force = false ) { |
| 24 | global $post; |
| 25 | if ( $force || ( is_singular() && has_shortcode( $post->post_content, 'alphalisting' ) ) ) { |
| 26 | wp_enqueue_script( 'alphalisting-tabs' ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Forcibly enqueue Tabs script. This is a helper function which can be hooked in-place of the default hook added in `alphalisting_add_styling` |
| 32 | * |
| 33 | * @since 2.0.0 |
| 34 | * @return void |
| 35 | */ |
| 36 | function alphalisting_force_enqueue_tabs() { |
| 37 | alphalisting_enqueue_tabs( true ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Replace the default Tabs script enqueue function with `alphalisting_force_enqueue_tabs` to always add the Tabs script to pages |
| 42 | * |
| 43 | * @since 2.0.0 |
| 44 | * @return void |
| 45 | */ |
| 46 | function alphalisting_force_enable_tabs() { |
| 47 | if ( false !== has_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\alphalisting_enqueue_tabs' ) ) { |
| 48 | remove_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\alphalisting_enqueue_tabs' ); |
| 49 | } |
| 50 | add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\alphalisting_force_enqueue_tabs' ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Enqueue the widget configuration support script |
| 55 | * |
| 56 | * @since 2.1.0 |
| 57 | * @return void |
| 58 | */ |
| 59 | function alphalisting_enqueue_widget_admin_script() { |
| 60 | wp_enqueue_script( 'alphalisting-widget-admin' ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Enqueue Scrollfix script |
| 65 | * |
| 66 | * @since 4.0.0 |
| 67 | * @return void |
| 68 | */ |
| 69 | function alphalisting_enqueue_scroll_fix() { |
| 70 | wp_enqueue_script( 'alphalisting-scroll-fix' ); |
| 71 | } |
| 72 |