מדיה ויקי:Gadget-Dwim.js: הבדלים בין גרסאות בדף
מראה
←using [[mw:CodeEditor|CodeEditor]]: איך, איך? |
לא ברור למה, אבל 1.19 שבר את הגאדג'ט הזה. |
||
| שורה 1: | שורה 1: | ||
$(function() { | |||
$ | mw.loader.using('jquery.suggestions', function() { | ||
$('#searchInput, #searchInput2, #powerSearchText, #searchText').suggestions({ | function hebeng(str) { | ||
var | |||
res = '', | |||
hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ"; | |||
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; | |||
} | |||
$('#searchInput, #searchInput2, #powerSearchText, #searchText') | |||
.suggestions({ | |||
fetch: function(query) { | |||
var $this = $(this); | |||
if (query.length !== 0) { | |||
$.ajaxSetup({url: mw.util.wikiScript('api'), dataType: 'json'}); | |||
var params = {action: 'opensearch', search: query, limit: 10, suggest: ''}; | |||
var request = $.ajax({ | |||
data: params, | |||
success: function(data) { | |||
if ($.isArray(data) && 1 in data) { | |||
$this.suggestions('suggestions', data[1]); | |||
if (data[1].length < 10) { | |||
params.search = hebeng(query); | |||
params,limit = 10 - data[1].length; | |||
$.ajax({ | |||
data: params, | |||
success: function(data) { | |||
if ($.isArray(data) && 1 in data) | |||
$this.suggestions('suggestions', 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(); | |||
} | } | ||
}) | }, | ||
$(this). | 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') | |||
}); | |||
}); | |||
}); | |||
} | |||
גרסה מ־07:38, 1 במרץ 2012
$(function() {
mw.loader.using('jquery.suggestions', function() {
function hebeng(str) {
var
res = '',
hes = "qwertyuiopasdfghjkl;zxcvbnm,./'קראטוןםפשדגכעיחלךףזסבהנמצתץ";
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;
}
$('#searchInput, #searchInput2, #powerSearchText, #searchText')
.suggestions({
fetch: function(query) {
var $this = $(this);
if (query.length !== 0) {
$.ajaxSetup({url: mw.util.wikiScript('api'), dataType: 'json'});
var params = {action: 'opensearch', search: query, limit: 10, suggest: ''};
var request = $.ajax({
data: params,
success: function(data) {
if ($.isArray(data) && 1 in data) {
$this.suggestions('suggestions', data[1]);
if (data[1].length < 10) {
params.search = hebeng(query);
params,limit = 10 - data[1].length;
$.ajax({
data: params,
success: function(data) {
if ($.isArray(data) && 1 in data)
$this.suggestions('suggestions', 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')
});
});
});