Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показано 215 промежуточных версий 2 участников)
Строка 1: Строка 1:
(function () {
(function() {  
     if (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit') return;
     if (typeof mw === 'undefined' || !window.document) return;
 
   
    var previewButton = document.createElement('button');
    function initCollapse() {
    previewButton.textContent = 'Предварительный просмотр';
        var headings = document.querySelectorAll('.chem-heading');  
    previewButton.style.margin = '10px 0';
        var hi = 0;
 
        var len = headings.length;
    var previewContainer = document.createElement('div');
        for (; hi < len; hi++) {
    previewContainer.id = 'live-preview-container';
            (function(node) {
    previewContainer.style.marginTop = '20px';
                if (node.getAttribute('data-chem-attached')) return;  
    previewContainer.style.border = '1px solid #ccc';
                node.setAttribute('data-chem-attached', '1');  
    previewContainer.style.padding = '10px';
                node.style.cursor = 'pointer';  
    previewContainer.style.backgroundColor = '#f9f9f9';
                node.addEventListener('click', function() {
    previewContainer.style.display = 'none';
                    var kind = node.getAttribute('data-kind') || '';
 
                    var wrapper = findWrapper(node, kind);
    var editForm = document.getElementById('editform');
                    if (!wrapper) return;  
    if (editForm) {
                    var btn = node.querySelector('.collapse-btn');  
        editForm.parentNode.insertBefore(previewButton, editForm);
                   
        editForm.parentNode.insertBefore(previewContainer, editForm.nextSibling);
                    if (wrapper.classList.contains('collapsed')) {
    }
                        wrapper.classList.remove('collapsed');  
 
                        wrapper.classList.add('expanded');  
    previewButton.addEventListener('click', function () {
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
        var editText = document.getElementById('wpTextbox1').value;
                        if (btn) btn.textContent = 'свернуть';  
var api = new mw.Api({
                        var cleanup = function() {  
    ajax: {
                            wrapper.style.maxHeight = '';  
        url: 'https://spacestories.club/api.php?action=webapp-manifest'
                            wrapper.removeEventListener('transitionend', cleanup);  
    }
                        };
});
                        wrapper.addEventListener('transitionend', cleanup);
        api.post({
                    } else {  
            action: 'parse',
                        var currentHeight = wrapper.scrollHeight;
            text: editText,
                        wrapper.style.maxHeight = currentHeight + 'px';
            contentmodel: 'wikitext',
                        wrapper.offsetHeight;  
            format: 'json'
                        wrapper.classList.remove('expanded');  
        }).done(function (data) {
                        wrapper.classList.add('collapsed');
            previewContainer.style.display = 'block';
                        wrapper.style.maxHeight = '0px';
            previewContainer.innerHTML = data.parse.text['*'];
                        if (btn) btn.textContent = 'развернуть';
         }).fail(function () {
                    }
             previewContainer.style.display = 'block';
                });
             previewContainer.textContent = 'Ошибка загрузки предварительного просмотра.';
            })(headings[hi]);
         });
        }
     });
    }
   
    function findWrapper(node, kind) {  
        var parent = node.parentNode;
        if (!parent) return null;
        var wrappers = parent.querySelectorAll('.collapsible');
        var wi = 0;  
        var wlen = wrappers.length;  
         for (; wi < wlen; wi++) {  
             if (wrappers[wi].getAttribute('data-kind') === kind) {
                return wrappers[wi];  
             }
        }
        return null;
    }
   
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
         initCollapse();  
     } else {
        document.addEventListener('DOMContentLoaded', initCollapse);  
    }
})();
})();

Текущая версия от 13:10, 4 апреля 2026

(function() { 
    if (typeof mw === 'undefined' || !window.document) return; 
    
    function initCollapse() { 
        var headings = document.querySelectorAll('.chem-heading'); 
        var hi = 0; 
        var len = headings.length; 
        for (; hi < len; hi++) { 
            (function(node) { 
                if (node.getAttribute('data-chem-attached')) return; 
                node.setAttribute('data-chem-attached', '1'); 
                node.style.cursor = 'pointer'; 
                node.addEventListener('click', function() { 
                    var kind = node.getAttribute('data-kind') || ''; 
                    var wrapper = findWrapper(node, kind); 
                    if (!wrapper) return; 
                    var btn = node.querySelector('.collapse-btn'); 
                    
                    if (wrapper.classList.contains('collapsed')) { 
                        wrapper.classList.remove('collapsed'); 
                        wrapper.classList.add('expanded'); 
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px'; 
                        if (btn) btn.textContent = 'свернуть'; 
                        var cleanup = function() { 
                            wrapper.style.maxHeight = ''; 
                            wrapper.removeEventListener('transitionend', cleanup); 
                        }; 
                        wrapper.addEventListener('transitionend', cleanup); 
                    } else { 
                        var currentHeight = wrapper.scrollHeight; 
                        wrapper.style.maxHeight = currentHeight + 'px'; 
                        wrapper.offsetHeight; 
                        wrapper.classList.remove('expanded'); 
                        wrapper.classList.add('collapsed'); 
                        wrapper.style.maxHeight = '0px'; 
                        if (btn) btn.textContent = 'развернуть'; 
                    } 
                }); 
            })(headings[hi]); 
        } 
    } 
    
    function findWrapper(node, kind) { 
        var parent = node.parentNode; 
        if (!parent) return null; 
        var wrappers = parent.querySelectorAll('.collapsible'); 
        var wi = 0; 
        var wlen = wrappers.length; 
        for (; wi < wlen; wi++) { 
            if (wrappers[wi].getAttribute('data-kind') === kind) { 
                return wrappers[wi]; 
            } 
        } 
        return null; 
    } 
    
    if (document.readyState === 'complete' || document.readyState === 'interactive') { 
        initCollapse(); 
    } else { 
        document.addEventListener('DOMContentLoaded', initCollapse); 
    } 
})();