JavaScript
<script>
/* -------------------------------
カレント表示(リンクテキスト) v1.0.0
------------------------------- */
'use strict';
document.addEventListener('DOMContentLoaded', function () {
const curretList = document.querySelectorAll('.js-current_list a'); /* カレント表示対象とするaタグ一覧を取得 */
curretList.forEach(function (link) {
/* aタグのパスと現在のページのパスが一致したらクラスを付与 */
if (link.pathname === location.pathname) {
link.classList.add('current');
}
/* TOPページかどうかを判定してカレント表示用クラスを付与 */
if (window.location.pathname === "/" && link.pathname === "/index") {
link.classList.add('current');
}
});
});
/* -------------------------------
カレント表示(リンクテキスト) END
------------------------------- */
</script>
CSS内にデフォルトで用意されている、「JSパーツ集記述場所」の中に追加してください。
※アップセル等で見つからない場合は、LP記述欄の下などに入れてください。
/*----- カレント表示(リンクテキスト) v1.0.0-----*/
.theme-fo-base {
:is(
.main-visual,
.wrapper .contents,
.wrapper .side,
.foot
) {
// サイドバー等でも使えるようにネスト略
.component:not(:root:root) {
&:is(
.richtext,/*使用しないパーツは削除*/
.list/*使用しないパーツは削除*/
) {
&.current_list {
ul {
list-style-type: none;
margin: 0;
li {
a {
display: block;
text-decoration: none;
padding: 5px 30px;
&:hover {
background-color: #ffc72e;
color: #fff;
opacity: 1;
}
// 該当ページリンクにつくアクセント
&.current {
background-color: #ffad2f;
color: #fff;
}
}
ul {
li {
a {
padding-left: 50px;
}
}
}
}
}
}
}
}
}
}
/*----- カレント表示(リンクテキスト) END -----*/
編集画面CSS内にデフォルトで用意されている、「//JSパーツの記述はここにお願いします」の中に追加してください。
※アップセル等で見つからない場合は、@include edit-page {}内に必ず入れてください。
/*----- カレント表示(リンクテキスト)編集画面用 v1.0.0-----*/
:is(
.main-visual,
.wrapper .contents,
.wrapper .side,
.foot
) {
.component {
&.richtext/*リッチテキスト使用の場合、操作性が悪くなるので対策*/{
&.current_list {
ul {
list-style-type: disc;
margin-left: 40px;
li {
a {
display: initial;
text-decoration: underline;
padding: 0;
&:hover {
background-color: initial;
color: initial;
opacity: initial;
}
}
ul {
li {
a {
padding-left: 0;
}
}
}
}
}
}
}
}
}
/*----- カレント表示(リンクテキスト)編集画面用 END -----*/