| @@ -1,10 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | +namespace WPDeveloper\BetterDocs\Core; | |
| 2 | 3 | |
| 3 | -namespace WPDeveloper\BetterDocs\Core; | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 4 | 7 | |
| 8 | + | |
| 5 | 9 | use WPDeveloper\BetterDocs\Utils\Base; |
| 6 | 10 | use WPDeveloper\BetterDocs\Utils\Helper; |
| 11 | +use WPDeveloper\BetterDocs\FrontEnd\PrintTemplate; | |
| 7 | 12 | |
| 8 | 13 | class Scripts extends Base { |
| 9 | 14 | protected $settings; |
| 10 | 15 | |
| @@ -72,8 +77,25 @@ | ||
| 72 | 77 | $assets->register( 'betterdocs-reactions', 'shortcodes/js/reactions.js', [ 'jquery' ] ); |
| 73 | 78 | $assets->register( 'betterdocs-search', 'shortcodes/js/search.js', [ 'jquery' ] ); |
| 74 | 79 | $assets->register( 'betterdocs-search-modal', 'shortcodes/js/search-modal.js', [ 'jquery' ] ); |
| 75 | 80 | |
| 81 | + /** | |
| 82 | + * Print template config for the single-doc Print / Save-as-PDF button. | |
| 83 | + * | |
| 84 | + * These values feed the print *popup* opened by the BetterDocs print | |
| 85 | + * icon. The browser's own Ctrl/Cmd+P route is handled separately by | |
| 86 | + * {@see PrintTemplate}, which resolves the same two values — see that | |
| 87 | + * class for why the two routes use different layout mechanisms. | |
| 88 | + * | |
| 89 | + * Both toggles live in `betterdocs_settings` (BetterDocs → Settings → | |
| 90 | + * Layout → Single Doc → General) rather than theme mods, so they stay | |
| 91 | + * reachable on block/FSE themes, which have no Customizer. Both default | |
| 92 | + * to OFF; while a toggle is off the value resolves empty and the print | |
| 93 | + * script renders nothing for it. | |
| 94 | + */ | |
| 95 | + $print_logo = PrintTemplate::get_logo(); | |
| 96 | + $print_footer = PrintTemplate::get_footer(); | |
| 97 | + | |
| 76 | 98 | $assets->localize( |
| 77 | 99 | 'betterdocs', |
| 78 | 100 | 'betterdocsConfig', |
| 79 | 101 | [ |
| @@ -80,9 +102,13 @@ | ||
| 80 | 102 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 81 | 103 | 'copy_text' => __( 'Copied', 'betterdocs' ), |
| 82 | 104 | 'sticky_toc_offset' => $this->settings->get( 'sticky_toc_offset' ), |
| 83 | 105 | 'summary_nonce' => wp_create_nonce( 'betterdocs_article_summary_nonce' ), |
| 84 | - 'summary_error' => __( 'Failed to generate doc summary. Please try again.', 'betterdocs' ) | |
| 106 | + 'summary_error' => __( 'Failed to generate doc summary. Please try again.', 'betterdocs' ), | |
| 107 | + 'print' => [ | |
| 108 | + 'logo' => $print_logo ? esc_url( $print_logo ) : '', | |
| 109 | + 'footer' => $print_footer ? wp_kses_post( $print_footer ) : '' | |
| 110 | + ] | |
| 85 | 111 | ] |
| 86 | 112 | ); |
| 87 | 113 | |
| 88 | 114 | $assets->localize( |
| @@ -117,9 +143,11 @@ | ||
| 117 | 143 | betterdocs()->assets->localize( |
| 118 | 144 | 'betterdocs-category-grid', |
| 119 | 145 | 'betterdocsCategoryGridConfig', |
| 120 | 146 | [ |
| 121 | - 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false | |
| 147 | + 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false, | |
| 148 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 149 | + 'lazy_load_action' => 'betterdocs_lazy_category_body' | |
| 122 | 150 | ] |
| 123 | 151 | ); |
| 124 | 152 | |
| 125 | 153 | $this->blocks( $assets ); |