ميدياويكي:Gadget-Dwim.js
ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.
//[[:ar:user:קיפודנחש/dwim.js]]
if ( mw.user.options.get( 'skin' ) === 'vector' )
$(function() {
setTimeout( function() {
'use strict';
var $searchBoxes = $( '#searchInput, #searchInput2, #powerSearchText, #searchText' );
function hebeng( str ) {
var res = '',
hes = "qwertyuiop{}asdfghjkl:\"zxcvbn<>?\u0636\u0636\u0635\u062B\u0642\u0641\u063A\u0639\u0647\u062E\u062D\u062C\u062F\u0634\u0633\u064A\u0628\u0644\u0627\u062A\u0646\u0645\u0643\u0637\u0626\u0621\u0624\u0631\uFEFB\u0649\u0629\u0648\u0632\u0638";//hack for keyboard layout [[:File:KB United States-NoAltGr.svg]] vs [[:File:KB Arabic.svg]]
str = str.toLowerCase();
for (var i = 0; i < str.length; i++) {
var ic = hes.indexOf( str.charAt( i ) );
res += ic + 1 ? hes.charAt( ( ic + 29 ) % 58 ) : str.charAt( i );
}
return res;
}
$searchBoxes.suggestions( {
fetch: function( query ) {
var $this = $( this );
if ( query.length !== 0 ) {
var params = {
action: 'opensearch',
search: query,
limit: 10,
suggest: ''
};
$.ajax( {
data: params,
url: mw.util.wikiScript('api'),
dataType: 'json',
success: function( data ) {
if ($.isArray( data ) && 1 in data) {
var orig = data[1];
$this.suggestions( 'suggestions', orig );
if ( data[1].length < 10 ) {
params.search = hebeng( query );
if ( params.search === query )
return;
params.limit = 10 - data[1].length;
$.ajax({
data: params,
url: mw.util.wikiScript('api'),
dataType: 'json',
success: function( data ) {
if ( $.isArray( data ) && 1 in data )
$this.suggestions( 'suggestions', orig.concat( data[1] ) );
}
});
}
}
}
} );
}
}
});
}, 1200); // setTimeout
}); // document.ready