AnsPress_Syntax_Highlighter::output_scripts()

Description #

Output required scripts in footer.

Source #

File: addons/free/syntaxhighlighter.php

	public static function output_scripts() {
		if ( ! is_anspress() ) {
			return;
		}

		global $wp_styles;

		$scripts = [];
		foreach ( self::$brushes as $brush => $label ) {
			$scripts[] = 'syntaxhighlighter-brush-' . strtolower( $brush );
		}

		wp_print_scripts( $scripts );

		if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
			$wp_styles = new WP_Styles();
		}

		$sh_css = '';
		$theme_css = '';

		if ( ! empty( $wp_styles ) && ! empty( $wp_styles->registered ) &&
			! empty( $wp_styles->registered['syntaxhighlighter-core'] ) &&
			! empty( $wp_styles->registered['syntaxhighlighter-core']->src ) ) {
				$sh_css = add_query_arg( 'ver', AP_VERSION, $wp_styles->registered['syntaxhighlighter-core']->src );
				$theme_css = add_query_arg( 'ver', AP_VERSION, $wp_styles->registered['syntaxhighlighter-theme-default']->src );
		}
		?>
		<script type='text/javascript'>
			(function($){
				SyntaxHighlighter.defaults.toolbar = false;

				$(document).ready(function(){
					AnsPress.loadCSS('<?php echo esc_url( $sh_css ); ?>');
					AnsPress.loadCSS('<?php echo esc_url( $theme_css ); ?>');

					SyntaxHighlighter.highlight();
				});
			})(jQuery);
		</script>
		<?php
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment