-
Notifications
You must be signed in to change notification settings - Fork 44
/
footer-javascript.php
254 lines (211 loc) · 8.31 KB
/
footer-javascript.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php //AMPページでは呼び出さない(通常ページのみで呼び出す)
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
if (!is_amp()): ?>
<?php //AdSense非同期スクリプトを出力
//広告の存在を確認するグローバル変数
global $_IS_ADSENSE_EXIST;
//アドセンス共通スクリプトコード
define('ADSENSE_SCRIPT_CODE', '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client='.get_adsense_data_ad_client().'" crossorigin="anonymous"></script>');
//if ($_IS_ADSENSE_EXIST && !is_customize_preview() && !is_cocoon_settings_preview()) {
if (is_ads_visible() && $_IS_ADSENSE_EXIST && !is_customize_preview()) {
echo ADSENSE_SCRIPT_CODE;
} //AdSense非同期スクリプトを出力
?>
<?php //Pinterestシェア用のスクリプト
if (is_singular() && is_pinterest_share_pin_visible()): ?>
<script async defer data-pin-height="28" data-pin-hover="true" src="//assets.pinterest.com/js/pinit.js"></script>
<?php endif //Pinterestシェア用のスクリプト ?>
<?php //Pinterestシェアボタン用のスクリプト
if (is_singular() && (is_top_pinterest_share_button_visible() || is_bottom_pinterest_share_button_visible())): ?>
<script>!function(d,i){if(!d.getElementById(i)){var j=d.createElement("script");j.id=i;j.src="//assets.pinterest.com/js/pinit_main.js";var w=d.getElementById(i);d.body.appendChild(j);}}(document,"pinterest-btn-js");</script>
<?php endif //Pinterestシェアボタン用のスクリプト ?>
<?php //コピーシェアボタン用のスクリプト
global $_MOBILE_COPY_BUTTON;
if ((is_top_copy_share_button_visible() || is_bottom_copy_share_button_visible()) && $_MOBILE_COPY_BUTTON): ?>
<div class="copy-info"><?php _e('タイトルとURLをコピーしました', THEME_NAME); ?></div>
<script src="//cdn.jsdelivr.net/clipboard.js/1.5.13/clipboard.min.js"></script>
<script>
(function($){
selector = '.copy-button';//clipboardで使う要素を指定
$(selector).click(function(event){
//クリック動作をキャンセル
event.preventDefault();
});
//クリップボード動作
var clipboard = new Clipboard(selector);
clipboard.on('success', function(e) {
$('.copy-info').fadeIn(500).delay(1000).fadeOut(500);
e.clearSelection();
});
})(jQuery);
</script>
<?php endif //コピーシェアボタン用のスクリプト ?>
<?php //カルーセルが表示されている時
if (false && is_carousel_visible() && get_carousel_category_ids()): ?>
<script>
(function($){
//カルーセルの表示
$('.carousel').fadeIn();
})(jQuery);
</script>
<?php endif //カルーセルが表示されている時?>
<?php //本文中のJavaScriptをまとめて出力
global $_THE_CONTENT_SCRIPTS;
if ($_THE_CONTENT_SCRIPTS): ?>
<script><?php echo $_THE_CONTENT_SCRIPTS; ?></script>
<?php endif //本文中のJavaScriptをまとめて出力 ?>
<?php /*固定ヘッダー*/
if (is_header_fixed()): ?>
<script>
(function($) {
/*固定ヘッダー化*/
function stickyHeader() {
if (!$("#header-container").hasClass("fixed-header")) {
/* 余白調整用の空クラスを追加する */
$('#header-container').after('<div id="header-fixed"></div>');
/* ヘッダーの高さの変化分、paddingで調整しスクロール位置を止まらせる */
$("#header-fixed").css({
'padding-top': `${threashold}px`,
});
/* トップメニュータイプに変更する */
$("#header-container-in").removeClass('hlt-center-logo hlt-center-logo-top-menu').addClass("hlt-top-menu wrap");
$("#header-container").addClass("fixed-header");
$("#header-container").css({
'position': 'fixed',
'top': '-100px',
'left': '0',
'width': '100%',
});
const wpadminbar = document.getElementById('wpadminbar');
const headerContainerTop = wpadminbar ? wpadminbar.clientHeight : 0;
$('#header-container').animate(
{
top: headerContainerTop,
},
500
);
}
}
/*固定ヘッダーの解除*/
function staticHeader() {
if ($("#header-container").hasClass("fixed-header")) {
/*センターロゴタイプに戻す*/
$("#header-container-in").removeClass("hlt-top-menu hlt-tm-right hlt-tm-small hlt-tm-small wrap").addClass("<?php echo get_additional_header_container_classes(); ?>");
$("#header-container").removeClass("fixed-header");
$("#header-container").css({
'position': 'static',
'top': 'auto',
'left': 'auto',
'width': 'auto',
});
/* ヘッダーの高さの戻る分、padding削除しスクロール位置を止まらせる */
$("#header-fixed").css({
'padding-top': '0',
});
$("#header-fixed").remove();
}
}
/* 境界値をヘッダーコンテナに設定 */
var threashold = $('#header-container').height();
var prevScrollTop = -1;
var $window = $(window);
var mobileWidth = 1023;
$window.scroll(function() {
var scrollTop = $window.scrollTop();
var s1 = (prevScrollTop > threashold);
var s2 = (scrollTop > threashold);
var w = $window.width();
/*スクロールエリアの位置調整*/
function adjustScrollArea(selector) {
if ($(selector) && $(selector).offset()) {
offset = $(selector).offset().top;
h = $("#header-container").height();
pt = $(selector).css('padding-top');
if (pt) {
pt = pt.replace('px', '');
} else {
pt = 0;
}
if ((scrollTop >= offset - h) && (w > mobileWidth)) {
if ((pt <= 1) && $("#header-container").hasClass('fixed-header')) {
$(selector).css({
'padding-top': h + 'px',
});
}
} else {
if (pt > 0) {
$(selector).css({
'padding-top': 0,
});
}
}
}
}
/*スクロール追従エリアの調整*/
function adjustScrollAreas() {
adjustScrollArea('#sidebar-scroll');
adjustScrollArea('#main-scroll');
}
/*固定ヘッダーのスタイル決め*/
function adjustFixedHeaderStyle(s1, s2, w, scrollTop, mobileWidth) {
if (s1 ^ s2) {
if (s2 && (w > mobileWidth)) {
stickyHeader();
}
}
/* 境界値に達したら固定化 */
if (scrollTop <= threashold || w <= mobileWidth) {
staticHeader();
}
}
adjustFixedHeaderStyle(s1, s2, w, scrollTop, mobileWidth);
adjustScrollAreas();
prevScrollTop = scrollTop;
});
/*ウインドウがリサイズされたら発動*/
$window.resize(function () {
/*ウインドウの幅を変数に格納*/
var w = $window.width();
if (w <= mobileWidth) { /*モバイル端末の場合*/
staticHeader();
} else { /*パソコン端末の場合*/
var scrollTop = $window.scrollTop();
if (scrollTop >= 50) {
stickyHeader();
}
}
});
})(jQuery);
</script>
<?php endif //固定ヘッダー ?>
<?php //Swiper
global $_IS_SWIPER_ENABLE;
if ($_IS_SWIPER_ENABLE): ?>
<link rel='stylesheet' id='swiper-style-css' href='https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.css' />
<script src="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.js"></script>
<script>
const mySwiper = new Swiper('.is-list-horizontal.swiper', {
// Optional parameters
slidesPerView: 'auto',
spaceBetween: 4,
navigation: {
prevEl: '.is-list-horizontal .swiper-button-prev',
nextEl: '.is-list-horizontal .swiper-button-next',
},
});
</script>
<?php endif; //Swiper ?>
<?php //数式表示
if (is_formula_enable() && is_math_shortcode_exist()): ?>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
MathJax.Hub.Config({
});
</script>
<?php endif; //数式表示 ?>
<?php endif //!is_amp() ?>