Skip to content

Commit 2f7e32e

Browse files
committed
Better JS for loading the CSS stylesheets. Fixes #77. Thanks @georgik.
1 parent c092d8a commit 2f7e32e

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

syntaxhighlighter.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ function __construct() {
5555
add_filter( 'bp_get_the_topic_post_edit_text', array( $this, 'decode_shortcode_contents' ), 1 ); // BuddyPress
5656

5757
// Outputting SyntaxHighlighter's JS and CSS
58-
add_action( 'wp_head', array( $this, 'output_header_placeholder' ), 15 );
5958
add_action( 'admin_head', array( $this, 'output_header_placeholder' ), 15 ); // For comments
6059
add_action( 'wp_footer', array( $this, 'maybe_output_scripts' ), 15 );
6160
add_action( 'admin_footer', array( $this, 'maybe_output_scripts' ), 15 ); // For comments
@@ -323,7 +322,7 @@ function enqueue_block_editor_assets() {
323322
'syntaxhighlighter-blocks',
324323
plugins_url( 'dist/blocks.build.js', __FILE__ ),
325324
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ),
326-
( defined( 'WP_DEBUG' ) && WP_DEBUG )
325+
( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) )
327326
? filemtime( plugin_dir_path( __FILE__ ) . 'dist/blocks.build.js' )
328327
: $this->pluginver
329328
);
@@ -889,13 +888,6 @@ function js_escape_singlequotes( $string ) {
889888
}
890889

891890

892-
// Output an anchor in the header for the Javascript to use.
893-
// In the <head>, we don't know if we'll need this plugin's CSS and JavaScript yet but we will in the footer.
894-
function output_header_placeholder() {
895-
echo '<style type="text/css" id="syntaxhighlighteranchor"></style>' . "\n";
896-
}
897-
898-
899891
// Output any needed scripts. This is meant for the footer.
900892
function maybe_output_scripts() {
901893
global $wp_styles;
@@ -956,7 +948,7 @@ function maybe_output_scripts() {
956948
corecss.rel = "stylesheet";
957949
corecss.href = corecssurl;
958950
}
959-
document.getElementsByTagName("head")[0].insertBefore( corecss, document.getElementById("syntaxhighlighteranchor") );
951+
document.head.appendChild( corecss );
960952
<?php
961953
endif; // Endif $needcore
962954

@@ -970,8 +962,7 @@ function maybe_output_scripts() {
970962
themecss.rel = "stylesheet";
971963
themecss.href = themecssurl;
972964
}
973-
//document.getElementById("syntaxhighlighteranchor").appendChild(themecss);
974-
document.getElementsByTagName("head")[0].insertBefore( themecss, document.getElementById("syntaxhighlighteranchor") );
965+
document.head.appendChild( themecss );
975966
<?php
976967
endif; // Endif none != theme
977968

@@ -1588,4 +1579,4 @@ function validate_settings( $settings ) {
15881579
function SyntaxHighlighter() {
15891580
global $SyntaxHighlighter;
15901581
$SyntaxHighlighter = new SyntaxHighlighter();
1591-
}
1582+
}

0 commit comments

Comments
 (0)