「MediaWiki:Common.js」の版間の差分
t |
細 t |
||
| 69行目: | 69行目: | ||
/* beta2 ここまで */ | /* beta2 ここまで */ | ||
/* スマホめにゅー */ | /* スマホめにゅー */ | ||
(function() { | (function() { | ||
function initCustomMenu() { | |||
// Minervaのメニュー(三本線クリックで出る中身)を探す | |||
// いろいろなパターンに対応 | |||
var $ | var $target = $('.menu ul:first, .navigation-drawer ul:first, #mw-mf-page-left ul:first'); | ||
if ($ | if ($target.length && !$('#p-custom-accordion').length) { | ||
console.log("Target found! Injecting menu..."); | |||
var html = | |||
'<ul class="level1" id="p-custom-accordion" style="list-style:none !important; margin:0 !important; padding:0 !important;">' + | |||
'<li class="menu__item" style="cursor:pointer; padding: 10px 16px; border-top: 1px solid #eaecf0;">' + | |||
'<span class="mw-ui-icon mw-ui-icon-before mw-ui-icon-mf-expand"></span>' + | |||
'<span style="font-weight:bold;">カスタムメニュー</span>' + | |||
'</li>' + | |||
'<div class="level2-container" style="display:none; background: #f8f9fa;">' + | |||
'<li class="menu__item"><a href="/wiki/Wiki:方針" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-notice"><span>方針</span></a></li>' + | |||
'<li class="menu__item"><a href="/wiki/特別:特別ページ一覧" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-star"><span>特別ページ一覧</span></a></li>' + | |||
'<li class="menu__item"><a href="/wiki/特別:ページ一覧" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-listBullet"><span>全てのページ</span></a></li>' + | |||
'<li class="menu__item"><a href="/wiki/特別:最近の更新" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-recentChanges"><span>最近の更新</span></a></li>' + | |||
'</div>' + | |||
'</ul>'; | |||
$ | $target.before(html); // prepend(一番上)ではなくbefore(直前)で試す | ||
$( | $('#p-custom-accordion .level1, #p-custom-accordion li:first').on('click', function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
$( | $('.level2-container').slideToggle(200); | ||
}); | }); | ||
} | } | ||
} | |||
// 1. ページ読み込み時に実行 | |||
if ( | $(document).ready(initCustomMenu); | ||
}, | // 2. それでもダメなら0.5秒おきに監視(5秒間) | ||
var retry = 0; | |||
var timer = setInterval(function() { | |||
initCustomMenu(); | |||
if (++retry > 10) clearInterval(timer); | |||
}, 500); | |||
})(); | })(); | ||
console.log("OK Common.js") | console.log("OK Common.js") | ||