Jump to content

MediaWiki:Common.js: Difference between revisions

From International Treaty Law Wiki
No edit summary
No edit summary
Line 86: Line 86:
             + '.search-collapse-content { padding: 15px; display: block; }'
             + '.search-collapse-content { padding: 15px; display: block; }'
             + '.search-collapse-content.collapsed { display: none; }'
             + '.search-collapse-content.collapsed { display: none; }'
             + '.gcse-searchresults-only { min-height: 200px; }';
             + '.gcse-searchresults-only { min-height: 200px; }'
            + '#pse-results-iframe { width: 100%; min-height: 600px; border: none; }';


         var collapseStyle = document.createElement('style');
         var collapseStyle = document.createElement('style');
Line 100: Line 101:
             container.id = 'extra-search-results';
             container.id = 'extra-search-results';


             // Programmable Search Engine (PSE)
             // Programmable Search Engine (PSE) - mit iframe
             var pseSection = document.createElement('div');
             var pseSection = document.createElement('div');
             pseSection.className = 'search-collapse-section';
             pseSection.className = 'search-collapse-section';
           
            // Erstelle eine URL für die PSE-Suche
            var pseUrl = 'https://cse.google.com/cse?cx=86021a982e3a14848&q=' + encodeURIComponent(query);
           
             pseSection.innerHTML =
             pseSection.innerHTML =
                 '<div class="search-collapse-header" data-target="pse-content">Programmable Search Engine</div>' +
                 '<div class="search-collapse-header" data-target="pse-content">Programmable Search Engine</div>' +
                 '<div class="search-collapse-content" id="pse-content">' +
                 '<div class="search-collapse-content" id="pse-content">' +
                 '<div class="gcse-searchresults-only"></div>' +
                 '<iframe id="pse-results-iframe" src="' + pseUrl + '" title="Google Programmable Search Results"></iframe>' +
                 '</div>';
                 '</div>';


Line 139: Line 144:
                 content.toggleClass('collapsed');
                 content.toggleClass('collapsed');
             });
             });
            // Google CSE Script einmalig laden
            if (!document.getElementById('gcse-script')) {
                var s = document.createElement('script');
                s.id = 'gcse-script';
                s.async = true;
                s.src = 'https://cse.google.com/cse.js?cx=86021a982e3a14848';
                document.head.appendChild(s);
            }
         }
         }
     });
     });


}); // Ende $(function(){})
}); // Ende $(function(){})

Revision as of 01:31, 21 January 2026

/* Any JavaScript here will be loaded for all users on every page load. */
/* Clean Print mode + PDF & Share buttons for Vector-2022 */

$(function () {

    // --- 1. Inject Clean Print CSS (full-width A4, desktop + mobile) ---
    var printCss = ''
        + '@media print {'
        + '    /* Hide all non-content elements */'
        + '    #mw-page-base,'
        + '    #mw-head-base,'
        + '    #mw-navigation,'
        + '    #mw-panel,'
        + '    #footer,'
        + '    .vector-header,'
        + '    .vector-page-toolbar,'
        + '    .vector-toc,'
        + '    .vector-sticky-header,'
        + '    .vector-page-tools,'
        + '    .vector-menu,'
        + '    .mw-indicators,'
        + '    .vector-user-links,'
        + '    .vector-search-box,'
        + '    .vector-pinned-container {'
        + '        display: none !important;'
        + '    }'
        + '    #content,'
        + '    .mw-body,'
        + '    .mw-content-container,'
        + '    .mw-body-content {'
        + '        margin: 0 !important;'
        + '        padding: 0 !important;'
        + '        width: 100% !important;'
        + '        max-width: none !important;'
        + '    }'
        + '    body,'
        + '    #content {'
        + '        background: white !important;'
        + '    }'
        + '    .mw-body-content {'
        + '        font-size: 14pt !important;'
        + '        line-height: 1.5 !important;'
        + '    }'
        + '}';

    var styleEl = document.createElement('style');
    styleEl.type = 'text/css';
    styleEl.appendChild(document.createTextNode(printCss));
    document.head.appendChild(styleEl);

    // --- 2. Add PDF + Share buttons to Vector-2022 action bar ---
    if (mw.config.get('wgNamespaceNumber') === 0) {
        var $actions = $('.vector-page-toolbar .vector-page-tools .vector-menu-content-list');
        if ($actions.length) {
            $actions.find('li').filter(function () {
                var t = $(this).text() || '';
                return t.toLowerCase().indexOf('pdf') !== -1;
            }).remove();

            $actions.prepend(
                '<li class="vector-menu-content-list-item"><a href="javascript:window.print()" title="Download clean PDF">PDF</a></li>'
            );

            $actions.prepend(
                '<li class="vector-menu-content-list-item"><a href="javascript:(function(){if(navigator.share){navigator.share({title:document.title,url:location.href});}else{prompt(\'Copy link:\',location.href);}})()" title="Share this page">Share</a></li>'
            );
        }
    }

    // --- 3. Google Search Results under MediaWiki Search ---
    mw.loader.using('mediawiki.util', function () {

        if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;

        var query = mw.util.getParamValue('search');
        if (!query) return;

        // CSS für collapsable Menüs
        var collapseCss = ''
            + '#extra-search-results { margin-top: 2em; border-top: 1px solid #ddd; padding-top: 1em; }'
            + '.search-collapse-section { margin-bottom: 1.5em; border: 1px solid #e0e0e0; border-radius: 4px; }'
            + '.search-collapse-header { background: #f8f9fa; padding: 12px 15px; cursor: pointer; font-weight: bold; border-radius: 4px 4px 0 0; }'
            + '.search-collapse-header:hover { background: #e8e9ea; }'
            + '.search-collapse-header::before { content: "▼ "; display: inline-block; transition: transform 0.2s; }'
            + '.search-collapse-header.collapsed::before { transform: rotate(-90deg); }'
            + '.search-collapse-content { padding: 15px; display: block; }'
            + '.search-collapse-content.collapsed { display: none; }'
            + '.gcse-searchresults-only { min-height: 200px; }'
            + '#pse-results-iframe { width: 100%; min-height: 600px; border: none; }';

        var collapseStyle = document.createElement('style');
        collapseStyle.appendChild(document.createTextNode(collapseCss));
        document.head.appendChild(collapseStyle);

        // Finde die Paginierung (Ergebnisse 1-20, 20-40, etc.)
        var pagination = $('.mw-search-pager-bottom, .results-info').last();
        var insertPoint = pagination.length ? pagination : $('#mw-search-results');

        if (insertPoint.length) {
            var container = document.createElement('div');
            container.id = 'extra-search-results';

            // Programmable Search Engine (PSE) - mit iframe
            var pseSection = document.createElement('div');
            pseSection.className = 'search-collapse-section';
            
            // Erstelle eine URL für die PSE-Suche
            var pseUrl = 'https://cse.google.com/cse?cx=86021a982e3a14848&q=' + encodeURIComponent(query);
            
            pseSection.innerHTML =
                '<div class="search-collapse-header" data-target="pse-content">Programmable Search Engine</div>' +
                '<div class="search-collapse-content" id="pse-content">' +
                '<iframe id="pse-results-iframe" src="' + pseUrl + '" title="Google Programmable Search Results"></iframe>' +
                '</div>';

            // Google Websuche
            var googleSection = document.createElement('div');
            googleSection.className = 'search-collapse-section';
            googleSection.innerHTML =
                '<div class="search-collapse-header" data-target="google-content">Google Websuche</div>' +
                '<div class="search-collapse-content" id="google-content">' +
                '<p style="margin: 0;"><a href="https://www.google.com/search?q=' +
                encodeURIComponent(query) +
                '" target="_blank" rel="noopener noreferrer" style="font-size: 16px;">' +
                '» Suchergebnisse in Google für „' + mw.html.escape(query) + '"</a></p>' +
                '</div>';

            container.appendChild(pseSection);
            container.appendChild(googleSection);

            // Einfügen nach Paginierung
            if (pagination.length) {
                pagination.after(container);
            } else {
                insertPoint.after(container);
            }

            // Toggle-Funktionalität für collapsable Menüs
            $('.search-collapse-header').on('click', function () {
                var targetId = $(this).data('target');
                var content = $('#' + targetId);
                
                $(this).toggleClass('collapsed');
                content.toggleClass('collapsed');
            });
        }
    });

}); // Ende $(function(){})