מדיה ויקי:Gadget-Dwim.js: הבדלים בין גרסאות בדף

איך?
מ 54 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-Dwim.js יובאו
 
(51 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 1: שורה 1:
// סקריפט להפיכת "טמקא" ל-"ynet" וכד' בתיבת החיפוש. נכתב על ידי [[משתמש:קיפודנחש|קיפודנחש]]
if ( mw.user.options.get( 'skin' ) === 'vector' ) {
$(document).ready(function() {mediaWiki.loader.using('jquery.suggestions', function () {
 
$('#searchInput, #searchInput2, #powerSearchText, #searchText').suggestions({
// Load the search suggestion logic when focus the search box.
fetch:function(query) {
function dwimEventListener( e ) {
var $this=$(this);
if (
var request = $.ajax({url:wgScriptPath+'/api.php',
e.target.id === 'searchInput' ||
data:{'action':'opensearch', 'search': query, 'namespace':0, 'suggest':''},
/(^|\s)mw-searchInput($|\s)/.test( e.target.className )
dataType:'json',
) {
success: function(data){
enableDwim();
if (data && 1 in data) {
document.removeEventListener( 'focusin', dwimEventListener );
$this.suggestions('suggestions',data[1]);
}
if (data[1].length < 8) {
}
var orig = data[1], alt = '', lq = query.toLowerCase(), hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ";
document.addEventListener( 'focusin', dwimEventListener );
for (var i = 0; i < query.length; i++) {
 
var ic = hes.indexOf(lq.charAt(i));
// Load the search suggestion logic when the search box is already focused
alt += ic + 1 ? hes.charAt((ic + 29) % 58) : l.charAt(i);
// because the user started typing before the JavaScript is loaded.
if (
document.activeElement && (
document.activeElement.id === 'searchInput' ||
/(^|\s)mw-searchInput($|\s)/.test( document.activeElement.className )
)
) {
enableDwim();
}
 
function enableDwimModernVector() {
// @todo
}
 
function enableDwim() {
'use strict';
if(mw.loader.getState('mediawiki.searchSuggest') === 'registered') {
// Vector is using the new version of search. Exit early to avoid running incompatible code.
enableDwimModernVector();
return;
}
 
setTimeout( function() {
var hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ",
hebeng = function ( str ) {
return ( str || '' ).replace( /./g, function( c ) {
var ic = hes.indexOf( c.toLowerCase() );
 
return ic + 1 ? hes.charAt( ( ic + 29 ) % 58 ) : c;
} );
};
var $searchBoxes = $(
'#searchInput, #searchInput2, #powerSearchText, #searchText'
);
 
$searchBoxes.suggestions( {
fetch: function( query ) {
var $this = $( this ),
apiUrl = mw.util.wikiScript( 'api' );
 
if ( query.length !== 0 ) {
var params = {
action: 'opensearch',
search: query,
redirects: 'return',
suggest: true
};
 
$.ajax( {
data: params,
url: apiUrl,
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: apiUrl,
dataType: 'json',
success: function( data ) {
if ( $.isArray( data ) && 1 in data ) {
$this.suggestions(
'suggestions',
orig.concat( data[1] )
);
}
}
} );
}
}
}
$.ajax({url:wgScriptPath+'/api.php',
data:{'action':'opensearch','search': alt, limit: 12 - orig.length, 'namespace': 0, 'suggest': ''},
dataType:'json',
success: function(data){
if (data && 1 in data)
$this.suggestions('suggestions', orig.concat(data[1]));
}
});
}
}
}
} );
}
}
});
$(this).data('request',request);
},
cancel: function() {
var request=$(this).data('request');
if (request && typeof request.abort=='function') {
request.abort();
$(this).removeData('request');
}
}
},
} );
result: {select: function ($input) {$input.closest('form').submit();}},
}, 1200 ); // setTimeout
delay: 120,
}
positionFromLeft: $('body').is('.rtl'),
 
highlightInput:true
} // skin === vector
}).bind('paste cut drop input', function(e) {$(this).trigger('keypress');});
});});