Skip to content

Commit

Permalink
wp_add_inline_script() で追加する JS は minify_js() を使用しない
Browse files Browse the repository at this point in the history
  • Loading branch information
yhira committed Nov 12, 2023
1 parent 54f4aa9 commit b3914ef
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/html-forms.php
Expand Up @@ -458,7 +458,7 @@ function generate_color_picker_tag($name, $value, $label){
<p><label for="<?php echo $name; ?>"><?php echo $label; ?></label></p>
<p><input type="text" name="<?php echo $name; ?>" value="<?php echo esc_html($value); ?>" ></p>
<?php wp_enqueue_script( 'wp-color-picker' );
$data = minify_js('(function( $ ) {
$data = '(function( $ ) {
var options = {
defaultColor: false,
change: function(event, ui){},
Expand All @@ -467,7 +467,7 @@ function generate_color_picker_tag($name, $value, $label){
palettes: true
};
$("input:text[name=\''.$name.'\']").wpColorPicker(options);
})( jQuery );');
})( jQuery );';
wp_add_inline_script( 'wp-color-picker', $data, 'after' ) ;

$res = ob_get_clean();
Expand Down
43 changes: 20 additions & 23 deletions lib/utils.php
Expand Up @@ -542,19 +542,16 @@ function wp_enqueue_script_hatebu_share_button_js(){
function wp_enqueue_script_clipboard_js(){
if ( is_singular() && (is_top_copy_share_button_visible() || is_bottom_copy_share_button_visible()) ){
wp_enqueue_script( 'clipboard-js', get_template_directory_uri().'/plugins/clipboard.js-master/dist/clipboard.min.js', array( 'jquery' ), false, true );
$data = ("
$data = "
(function($){
var clipboard = new Clipboard('.copy-button');//clipboardで使う要素を指定
clipboard.on('success', function(e) {
// console.info('Action:', e.action);
// console.info('Text:', e.text);
// console.info('Trigger:', e.trigger);
$('.copy-info').fadeIn(500).delay(1000).fadeOut(500);
e.clearSelection();
});
})(jQuery);
");
";
wp_add_inline_script( 'clipboard-js', $data, 'after' ) ;
}
}
Expand Down Expand Up @@ -582,13 +579,13 @@ function wp_enqueue_highlight_js(){
$selector = get_code_highlight_css_selector();
}

$data = minify_js('
$data = '
(function($){
$("'.$selector.'").each(function(i, block) {
hljs.highlightBlock(block);
});
})(jQuery);
');
';
wp_add_inline_script( 'code-highlight-js', $data, 'after' ) ;
}
}
Expand Down Expand Up @@ -630,11 +627,11 @@ function wp_enqueue_baguettebox(){
//baguetteboxスクリプトの呼び出し
wp_enqueue_script( 'baguettebox-js', get_template_directory_uri() . '/plugins/baguettebox/dist/baguetteBox.min.js', array( 'jquery' ), false, true );
$selector = '.entry-content';
$data = minify_js('
$data = '
(function($){
baguetteBox.run("'.$selector.'");
})(jQuery);
');
';
wp_add_inline_script( 'baguettebox-js', $data, 'after' ) ;
}
}
Expand Down Expand Up @@ -677,7 +674,7 @@ function wp_enqueue_clingify(){
},
';
}
$data = minify_js('
$data = '
(function($){
function adjustHeader(){
$(".js-clingify-placeholder").height($("#header-container").height());
Expand All @@ -690,7 +687,7 @@ function adjustHeader(){
'.$options.'
});
})(jQuery);
');
';
wp_add_inline_script( 'clingify-js', $data, 'after' );
}
}
Expand All @@ -709,7 +706,7 @@ function wp_enqueue_slick(){
if (is_carousel_autoplay_enable()) {
$autoplay = 'autoplay: true,';
}
$data = minify_js('
$data = '
(function($){
$(".carousel-content").slick({
dots: true,'.
Expand Down Expand Up @@ -751,7 +748,7 @@ function wp_enqueue_slick(){
});
})(jQuery);
');
';
wp_add_inline_script( 'slick-js', $data, 'after' ) ;
}

Expand All @@ -772,15 +769,15 @@ function wp_enqueue_slicknav(){
//wp_enqueue_style( 'slicknav-style', get_template_directory_uri() . '/plugins/slicknav/slicknav.css' );
//SlickNavスクリプトの呼び出し
wp_enqueue_script( 'slicknav-js', get_template_directory_uri() . '/plugins/slicknav/jquery.slicknav.min.js', array( 'jquery' ), false, true );
$data = minify_js('
$data = '
(function($){
$(".menu-header").slicknav({
label: "'.apply_filters('wp_enqueue_slicknav_label', 'MENU').'",
parentTag: "div",
allowParentLinks: true,
});
})(jQuery);
');
';
wp_add_inline_script( 'slicknav-js', $data, 'after' ) ;

}
Expand All @@ -796,7 +793,7 @@ function wp_enqueue_scrollhint(){
wp_enqueue_style( 'scrollhint-style', get_template_directory_uri() . '/plugins/scroll-hint-master/css/scroll-hint.css' );
//ScrollHintスクリプトの呼び出し
wp_enqueue_script( 'scrollhint-js', get_template_directory_uri() . '/plugins/scroll-hint-master/js/scroll-hint.min.js', array( 'jquery' ), false, true );
$data = minify_js('
$data = '
(function($){
new ScrollHint(".scrollable-table", {
suggestiveShadow: true,
Expand All @@ -805,7 +802,7 @@ function wp_enqueue_scrollhint(){
}
});
})(jQuery);
');
';
wp_add_inline_script( 'scrollhint-js', $data, 'after' ) ;

}
Expand All @@ -825,22 +822,22 @@ function wp_enqueue_stickyfill(){

//position: sticky;に対応していないブラウザの場合はstickyfillを実行
if (is_scrollable_sidebar_enable() && ($is_ie || $is_edge_version_under_16)) {
$data = minify_js('
$data = '
(function($){
var elements = $(".sidebar-scroll");
Stickyfill.add(elements);
})(jQuery);
');
';
wp_add_inline_script( 'stickyfill-js', $data, 'after' );
}

if (is_scrollable_main_enable() && ($is_ie || $is_edge_version_under_16)) {
$data = minify_js('
$data = '
(function($){
var elements = $(".main-scroll");
Stickyfill.add(elements);
})(jQuery);
');
';
wp_add_inline_script( 'stickyfill-js', $data, 'after' );
}

Expand Down Expand Up @@ -873,12 +870,12 @@ function wp_enqueue_jquery_masonry(){
';
}
//実行コードの記入
$code = minify_js('
$code = '
(function($){'.
$common_code.
$admin_code
.'})(jQuery);
');
';
wp_add_inline_script( 'jquery-masonry', $code, 'after' );
}

Expand Down
16 changes: 8 additions & 8 deletions skins/skin-grayish-topfull/functions.php
Expand Up @@ -6,7 +6,7 @@
// -----------------------------------------------------------------------------
// site_font_size

// font_awesome_5 default
// font_awesome_5 default
if (!function_exists('get_site_icon_font')) :
function get_site_icon_font()
{
Expand Down Expand Up @@ -939,7 +939,7 @@ function skin_grayish_top_header_navibg()
} else {
$style_opacity = '0.5';
}
// hex to dec
// hex to dec
$style_rgba = '';
$style_rgba = color_code($hex_navi_bgcolor, $style_opacity);

Expand Down Expand Up @@ -1313,7 +1313,7 @@ function customize_more_button_caption()
}
endif;

// フロントページ・インデックスページのNextボタン
// フロントページ・インデックスページのNextボタン
add_filter('pagination_next_link_caption', 'skin_grayish_nextbutton_text');
if (!function_exists('skin_grayish_nextbutton_text')) :
function skin_grayish_nextbutton_text()
Expand Down Expand Up @@ -1470,7 +1470,7 @@ function skin_grayish_ohter_headerbg()
} else {
$style_opacity = '0.5';
}
// hex to dec
// hex to dec
$style_rgba = '';
$style_rgba = color_code($hex_navi_bgcolor, $style_opacity);

Expand Down Expand Up @@ -1843,7 +1843,7 @@ function skin_grayish_mobile_headerbg()
$style_opacity = '0.5';
}

// hex to dec
// hex to dec
$style_rgba = '';
$style_rgba = color_code($hex_navi_bgcolor, $style_opacity);

Expand Down Expand Up @@ -1958,7 +1958,7 @@ function skin_grayish_mobile_footerbg()
} else {
$style_opacity = '0.5';
}
// hex to dec
// hex to dec
$style_rgba = '';
$style_rgba = color_code($hex_navi_bgcolor, $style_opacity);

Expand Down Expand Up @@ -2073,7 +2073,7 @@ function wp_enqueue_scrollhint_skinadd()
//ScrollHintスクリプトの呼び出し
wp_enqueue_script('scrollhint-js', get_template_directory_uri() . '/plugins/scroll-hint-master/js/scroll-hint.min.js', array('jquery'), false, true);
}
$data = minify_js('
$data = '
(function($){
new ScrollHint(".skin-grayish .under-entry-content .related-list", {
suggestiveShadow: false,
Expand All @@ -2082,7 +2082,7 @@ function wp_enqueue_scrollhint_skinadd()
}
});
})(jQuery);
');
';
wp_add_inline_script('scrollhint-js', $data, 'after');
}
}
Expand Down

0 comments on commit b3914ef

Please sign in to comment.