MediaWiki:Common.js

From OHO - search engine for sustainable open hardware projects
Revision as of 23:08, 26 October 2020 by Javierf (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Das folgende JavaScript wird für alle Benutzer geladen. */
jQuery(document).ready(function($) {
    $(".wait_screen_box").hide();

    mw.loader.using('jquery.ui.autocomplete', function() {
        (function (mw, $) {
            $(function () {
                $('.searchInputProjectKWAC').autocomplete( {
                    source: function(request, response) {
                        var api = new mw.Api();
                        api.get({action:'pfautocomplete', limit:10, substr:request.term, property:'KeywordsEN'}).done(
                        function (dataEN) {
                            api.get({action:'pfautocomplete', limit:10, substr:request.term, property:'KeywordsES'}).done(
                            function (dataES) {
                                api.get({action:'pfautocomplete', limit:10, substr:request.term, property:'KeywordsDE'}).done(
                                function (dataDE) {
                                    var dataf = [];
                                    dataf = processListAC(request.term, dataEN, dataf);
                                    dataf = processListAC(request.term, dataDE, dataf);
                                    dataf = processListAC(request.term, dataES, dataf);
                                    dataf = dataf.sort().slice(0, 10);
                                    response(dataf);
                                });
                            });
                        });
                    }
                });
            });
        }(mediaWiki, jQuery));
    });
});

function processListAC(search, data, dataf) {
    for(var dlist in data) {
        for(var drow in data[dlist]) {
            var listW = data[dlist][drow].title.split(",");
            for(var w in listW) {
                wt = listW[w].trim();
                if (wt.length>0) {
                    wt = wt.charAt(0).toUpperCase() + wt.substr(1).toLowerCase();
                    if (wt.toLowerCase().indexOf(search.toLowerCase())===0 && $.inArray(wt, dataf)===-1) {
                        dataf[dataf.length] = wt;
                    }
                }
            }
        }
    }
    return dataf;
}
OPEN HARDWARE OBSERVATORY 2020
| |
|||