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

עוד ניסוי
מ 54 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-Dwim.js יובאו
 
(43 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 1: שורה 1:
$(function() {
if ( mw.user.options.get( 'skin' ) === 'vector' ) {
setTimeout(function() {
 
function hebeng(str) {
// Load the search suggestion logic when focus the search box.
var
function dwimEventListener( e ) {
res = '',
if (
hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ";
e.target.id === 'searchInput' ||
str = str.toLowerCase();
/(^|\s)mw-searchInput($|\s)/.test( e.target.className )
for (var i = 0; i < str.length; i++) {
) {
var ic = hes.indexOf(str.charAt(i));
enableDwim();
res += ic + 1 ? hes.charAt((ic + 29) % 58) : str.charAt(i);
document.removeEventListener( 'focusin', dwimEventListener );
}
return res;
}
}
}
$('#searchInput, #searchInput2, #powerSearchText, #searchText')
document.addEventListener( 'focusin', dwimEventListener );
.suggestions({
 
fetch: function(query) {
// Load the search suggestion logic when the search box is already focused
var $this = $(this);
// because the user started typing before the JavaScript is loaded.
if (query.length !== 0) {
if (
$.ajaxSetup({url: mw.util.wikiScript('api'), dataType: 'json'});
document.activeElement && (
var params = {action: 'opensearch', search: query, limit: 10, suggest: ''};
document.activeElement.id === 'searchInput' ||
var request = $.ajax({
/(^|\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,
data: params,
success: function(data) {
url: apiUrl,
if ($.isArray(data) && 1 in data) {
dataType: 'json',
                                var orig = data[1];
success: function( data ) {
$this.suggestions('suggestions', orig);
if ( $.isArray( data ) && 1 in data ) {
if (data[1].length < 10) {
var orig = data[1];
params.search = hebeng(query);
 
params,limit = 10 - data[1].length;
$this.suggestions( 'suggestions', orig );
$.ajax({
 
if ( data[1].length < 10 ) {
params.search = hebeng( query );
if ( params.search === query ) {
return;
}
 
params.limit = 10 - data[1].length;
 
$.ajax( {
data: params,
data: params,
success: function(data) {
url: apiUrl,
if ($.isArray(data) && 1 in data)  
dataType: 'json',
$this.suggestions('suggestions', orig.concat(data[1]));
success: function( data ) {
if ( $.isArray( data ) && 1 in data ) {
$this.suggestions(
'suggestions',
orig.concat( data[1] )
);
}
}
}
});
} );
}
}
}
}
}
}
});
} );
$this.data('request', request);
}
},
cancel: function() {
var request = $(this).data('request');
// If the delay setting has caused the fetch to have not even happend yet, the request object will
// have never been set
if (request && $.isFunction(request.abort)) {
request.abort();
$(this).removeData('request');
}
},
result: {
select: function($input) {
$input.closest('form').submit();
}
},
delay: 120,
positionFromLeft: $('body').hasClass('rtl'),
highlightInput: true
})
.bind('paste cut drop', function(e) {
// make sure paste and cut events from the mouse and drag&drop events
// trigger the keypress handler and cause the suggestions to update
$(this).trigger('keypress');
});
// Special suggestions functionality for skin-provided search box
$('#searchInput').suggestions({
result: {
select: function($input) {
$input.closest('form').submit();
}
},
special: {
render: function(query) {
if ($(this).children().length === 0) {
$(this).show();
var $label = $('<div></div>', {
'class': 'special-label',
text: mw.msg('vector-simplesearch-containing')
})
.appendTo($(this));
var $query = $('<div></div>', {
'class': 'special-query',
text: query
})
.appendTo($(this));
$query.autoEllipsis();
} else {
$(this).find('.special-query')
.empty()
.text(query)
.autoEllipsis();
}
}
},
select: function($input) {
$input.closest('form').append(
$('<input>', {
type: 'hidden',
name: 'fulltext',
val: '1'
})
);
$input.closest('form').submit();
}
}
},
} );
$region: $('#simpleSearch')
}, 1200 ); // setTimeout
});
}
}, 777); // setTimeout.   
 
}); // document.ready
} // skin === vector