MediaWiki:Common.js: различия между версиями
Shihov (обсуждение | вклад) Нет описания правки |
Shihov (обсуждение | вклад) Нет описания правки |
||
| Строка 63: | Строка 63: | ||
} | } | ||
function expandAndFindCategory($parent) { | function expandAndFindCategory($parent, callback) { | ||
var $toggleButton = $parent.find('.CategoryTreeToggle').first(); | |||
if ($toggleButton.length && !$parent.hasClass('expanded')) { | |||
$toggleButton.click(); | |||
setTimeout(function() { | |||
if (scrollToCategory(mw.config.get('wgTitle'))) { | |||
}, 1000); | callback(true); | ||
} else { | |||
callback(false); | |||
} | |||
} | }, 1000); | ||
} else { | |||
callback(false); | |||
} | |||
} | } | ||
function recursiveSearchForCategory() { | |||
console.log("Очищаем localStorage перед поиском..."); | console.log("Очищаем localStorage перед поиском..."); | ||
localStorage.removeItem('lastOpenedPageTitle'); | localStorage.removeItem('lastOpenedPageTitle'); | ||
| Строка 96: | Строка 98: | ||
var $categoryItems = $('#p-categorytree-portlet .CategoryTreeItem'); | var $categoryItems = $('#p-categorytree-portlet .CategoryTreeItem'); | ||
var index = 0; | |||
function processNext() { | |||
if (index >= $categoryItems.length) { | |||
console.log("Категория для текущей страницы не найдена."); | |||
return; | return; | ||
} | } | ||
var $item = $($categoryItems[index]); | |||
expandAndFindCategory($item, function(found) { | |||
if (!found) { | |||
index++; | |||
processNext(); | |||
} | |||
}); | |||
} | } | ||
processNext(); | |||
} | } | ||
setTimeout(() | setTimeout(function() { | ||
recursiveSearchForCategory(); | recursiveSearchForCategory(); | ||
}, 500); | }, 500); | ||