MediaWiki:Common.js: различия между версиями

Нет описания правки
Метка: отменено
Нет описания правки
Метка: ручная отмена
 
(не показана 1 промежуточная версия этого же участника)
Строка 29: Строка 29:
             dropdown.addClass('active');
             dropdown.addClass('active');
             content.css('max-height', content[0].scrollHeight + 'px'); // Автоматическая высота
             content.css('max-height', content[0].scrollHeight + 'px'); // Автоматическая высота
        }
    });
});
function getPageImage(title, size = 200) {
    return fetch(
        mw.util.wikiScript('api') +
        `?action=query&titles=${encodeURIComponent(title)}&prop=pageimages&piprop=thumbnail&pithumbsize=${size}&format=json`
    )
    .then(res => res.json())
    .then(data => {
        const pages = data.query.pages;
        const page = Object.values(pages)[0];
        return page.thumbnail ? page.thumbnail.source : null;
    });
}
mw.hook('ext.popups.render').add(function(popup, data) {
    const title = data.title;
    getPageImage(title, 200).then(imgUrl => {
        if (imgUrl) {
            const imgElem = document.createElement('img');
            imgElem.className = 'pageimage';
            imgElem.src = imgUrl;
            popup.querySelector('.mwe-popups-container').prepend(imgElem);
         }
         }
     });
     });
});
});