MediaWiki:CustomSearch.js

Daripada Wiktionary

Catatan: Selepas menyiarkan perubahan, anda mungkin perlu memintas cache pelayar untuk melihatnya.

  • Firefox / Safari: Tahan Shift sambil mengklik Reload, atau tekan sama ada Ctrl-F5 atau Ctrl-R (⌘-R pada Mac)
  • Google Chrome: Tekan Ctrl-Shift-R (⌘-Shift-R pada Mac)
  • Internet Explorer / Edge: Tahan Ctrl sambil mengklik Refresh, atau tekan Ctrl-F5
  • Opera: Tekan Ctrl-F5.
/*<pre> This file should only be included for pages that use it. At the moment that is only [[Help:Customizing_your_monobook]]. If you wish to add pages to use this, edit the relevant section of Common.js
 
FireFox and IE 7 allow sites to customize the integrated search box. Below exposes that through [[WT:CUSTOM]]. */
 
$(function () {
    // Find the container node and bail if it's not there
    var searches = document.getElementById('wtCustomIntegratedSearchProviders');
    if (!searches) return;
 
    // Remove all children from 'searches'
    while (searches.hasChildNodes()) {
        searches.removeChild(searches.firstChild);
    }
 
    // Bail out in unsupported browsers with a message that this doesn't work
    if (!(window.external && ("AddSearchProvider" in window.external))) {
        var span = document.createElement('em');
        span.appendChild(document.createTextNode('Ciri ini tidak disokong oleh pelayar anda. Maaf!'));
        searches.appendChild(span);
        return;
    }
 
    // MediaWiki built-in search
    appendSearchProviderLink(
        'MediaWiki:SearchMsWiktWithMediaWiki.xml',
        'Tambah penyedia carian bersepadu "Wiktionary Bahasa Melayu".'
    );
 
    // English Witionary search with Google
    appendSearchProviderLink(
        'MediaWiki:SearchMsWiktWithGoogle.xml',
        'Tambah penyedia carian bersepadu "Wiktionary Bahasa Melayu melalui Google".'
    );
 
    // All Witionary search with Google
    appendSearchProviderLink(
        'MediaWiki:SearchAllWiktWithGoogle.xml',
        'Tambah penyedia carian bersepadu "Semua Wiktionary melalui Google".'
    );
 
    // English Witionary search with Ninjawords
    appendSearchProviderLink(
        'MediaWiki:SearchWithNinjawords.xml',
        'Tambah penyedia carian bersepadu "Wiktionary Bahasa Melayu melalui Ninjawords”.'
    );
 
    // Anchor creator helper
    function appendSearchProviderLink(providerXml, linkText) {
        var anchor = document.createElement("a");
        anchor.setAttribute('href', '#');
        anchor.appendChild(document.createTextNode(linkText));
 
        var providerXmlUrl =
            'http://ms.wiktionary.org/w/index.php?action=raw&title=' +
            encodeURIComponent(providerXml);
 
        anchor.onclick = function () {
            window.external.AddSearchProvider(providerXmlUrl);
            return false;
        };
 
        if (searches.hasChildNodes()) {
            searches.appendChild(document.createElement("br"));
        }
 
        searches.appendChild(anchor);
    }
});