Khác biệt giữa bản sửa đổi của “Thành viên:Cumeo89/monobook.js”

Nội dung được xóa Nội dung được thêm vào
Cumeo89 (thảo luận | đóng góp)
Không có tóm lược sửa đổi
Cumeo89 (thảo luận | đóng góp)
Không có tóm lược sửa đổi
Dòng 1:
 
 
function wiktauto_init() {
var data = {
values: [
// languages
"Brai", "Cham", "Hani", "Hans",
 
"Hang", "Hant", "Hira", "Grek", "Cyrl", "Latn", "Jpan", "vie-n",
 
"Runr", "Xsux", "Teng", "Thai", "epo", "afr", "sqi", "amu", "eng",
 
"ang", "ara", "pol", "isl", "eus", "fas", "bos", "ina", "por",
 
"cat", "gan", "hrv", "heb", "dan", "dng", "deu", "est", "fao",
 
"fry", "glg", "grn", "nld", "haw", "hin", "hun", "czh", "ell",
 
"ido", "ind", "gle", "hak", "kur", "lat", "jbo", "msa", "mlt",
 
"mnp", "nan", "czo", "cdo", "mar", "nap", "nor", "nob", "nno",
 
"nep", "rus", "wuu", "jpn", "oci", "fin", "fra", "cpx", "yue",
 
"cmn", "qya", "ron", "ces", "sna", "slk", "sux", "swa", "cjy",
 
"tat", "spa", "tha", "tur", "swe", "tpi", "kor", "zho", "hsn",
 
"tpn", "vie", "ita",
// parts of speech
"cmavo", "noun", "pr-noun",
 
"coll-noun", "pronoun", "dem-pronoun", "per-pronoun",
 
"ref-pronoun", "rel-pronoun", "place", "part-adj", "verb",
 
"imp-verb", "ref-verb", "coverb", "prep", "suffix", "copula",
 
"conj", "co-conj", "sub-conj", "article", "indef-article",
 
"part-article", "def-article", "tr-verb", "intr-verb", "adv",
 
"circumfix", "num", "interj", "prefix", "adj", "indef-adj",
 
"dem-adj", "pr-adj", "pos-adj", "part", "aux-verb", "infix", "dem",
 
"clitic", "enclitic", "mesoclitic", "proclitic", "det", "interrog",
 
"contr", "abbr", "abr", "adpos", "circumpos", "postpos",
// others
"nôm", "homo", "paro",
 
"hanviet", "syn", "redup", "compound", "drv", "ant", "rel", "trans"],
suggestions : [
// languages
"Chữ Braille", "Chữ Chăm",
 
"Chữ Hán", "Chữ Hán giản thể", "Chữ Hangul", "Chữ Hán phồn thể",
 
"Chữ Hiragana", "Chữ Hy Lạp", "Chữ Kirin", "Chữ Latinh",
 
"Chữ Nhật hỗn hợp", "Chữ Nôm", "Chữ Rune", "Chữ Sumer",
 
"Chữ Tengwar", "Chữ Thái", "Quốc tế ngữ", "Tiếng Afrikaans",
 
"Tiếng Albani", "Tiếng Amuzgo", "Tiếng Anh", "Tiếng Anh cổ",
 
"Tiếng Ả Rập", "Tiếng Ba Lan", "Tiếng Băng Đảo", "Tiếng Basque",
 
"Tiếng Ba Tư", "Tiếng Bosnia", "Tiếng Bổ trợ Quốc tế",
 
"Tiếng Bồ Đào Nha", "Tiếng Catalan", "Tiếng Cống", "Tiếng Croat",
 
"Tiếng Do Thái", "Tiếng Đan Mạch", "Tiếng Đông Can", "Tiếng Đức",
 
"Tiếng Estonia", "Tiếng Faroe", "Tiếng Frysk", "Tiếng Galicia",
 
"Tiếng Guaraní", "Tiếng Hà Lan", "Tiếng Hawaii", "Tiếng Hindi",
 
"Tiếng Hung", "Tiếng Huy", "Tiếng Hy Lạp", "Tiếng Ido",
 
"Tiếng Indonesia", "Tiếng Ireland", "Tiếng Khách Gia",
 
"Tiếng Kurd", "Tiếng Latinh", "Tiếng Lojban", "Tiếng Mã Lai",
 
"Tiếng Malta", "Tiếng Mân Bắc", "Tiếng Mân Nam", "Tiếng Mân Trung",
 
"Tiếng Mân Đông", "Tiếng Marathi", "Tiếng Napoli", "Tiếng Na Uy",
 
"Tiếng Na Uy (Bokmål)", "Tiếng Na Uy (Nynorsk)", "Tiếng Nepal",
 
"Tiếng Nga", "Tiếng Ngô", "Tiếng Nhật", "Tiếng Oc",
 
"Tiếng Phần Lan", "Tiếng Pháp", "Tiếng Phổ Hiền",
 
"Tiếng Quảng Đông", "Tiếng Quan Thoại", "Tiếng Quenya",
 
"Tiếng Rumani", "Tiếng Séc", "Tiếng Shona", "Tiếng Slovak",
 
"Tiếng Sumer", "Tiếng Swahili", "Tiếng Tấn", "Tiếng Tatar",
 
"Tiếng Tây Ban Nha", "Tiếng Thái", "Tiếng Thổ Nhĩ Kỳ",
 
"Tiếng Thụy Điển", "Tiếng Tok Pisin", "Tiếng Triều Tiên",
 
"Tiếng Trung Quốc", "Tiếng Tương", "Tiếng Tupi", "Tiếng Việt",
 
"Tiếng Ý",
// parts of speech
"cmavo", "Danh từ", "Danh từ riêng",
 
"Danh từ tập họp", "Đại từ", "Đại từ chỉ định", "Đại từ nhân xưng",
 
"Đại từ phản thân", "Đại từ quan hệ", "Địa danh", "Động tính từ",
 
"Động từ", "Động từ không ngôi", "Động từ phản thân",
 
"Đồng động từ", "Giới từ", "Hậu tố", "Hệ từ", "Liên từ",
 
"Liên từ kết hợp", "Liên từ phụ thuộc", "Mạo từ",
 
"Mạo từ bất định", "Mạo từ bộ phận", "Mạo từ hạn định",
 
"Ngoại động từ", "Nội động từ", "Phó từ", "Phụ tố chu vi", "Số từ",
 
"Thán từ", "Tiền tố", "Tính từ", "Tính từ bất định",
 
"Tính từ chỉ định", "Tính từ riêng", "Tính từ sở hữu", "Trợ từ",
 
"Trợ động từ", "Trung tố", "Từ chỉ định", "Từ ghép", "Từ ghép sau",
 
"Từ ghép trung", "Từ ghép trước", "Từ hạn định", "Từ nghi vấn",
 
"Từ rút gọn", "Từ viết tắt", "Từ viết tắt", "Yếu tố",
 
"Yếu tố quanh", "Yếu tố sau",
// others
"Chữ Nôm", "Từ đồng âm",
 
"Từ viết tương tự", "Phiên thiết Hán-Việt", "Đồng nghĩa", "Từ láy",
 
"Từ ghép", "Từ dẫn xuất", "Trái nghĩa", "Từ liên hệ", "Dịch"]
};
for (i in data.values) {
data.suggestions[i] = data.values[i] + ' - ' + data.suggestions[i];
data.values[i] = '{{-' + data.values[i] + '-}}';
}
}
 
var textbox = document.getElementById('wpTextbox1');
var inputBox = document.createElement('input');
inputBox.style.display = 'none';
inputBox.type = 'text';
inputBox.style.position = 'absolute';
var pos = wiktauto_findPos(textbox);
inputBox.style.left = pos.left;
inputBox.style.top = pos.top + textbox.offsetHeight - 25;
inputBox.style.zIndex = 1;
document.body.appendChild(inputBox);
 
var autoSuggestDivtextbox = document.createElementgetElementById('divwpTextbox1');
var inputBox = document.createElement('input');
autoSuggestDiv.id = 'autosuggest';
inputBox.type = 'text';
autoSuggestDiv.appendChild(document.createElement('ul'));
var pos = wiktauto_findPos(textbox);
document.body.appendChild(autoSuggestDiv);
inputBox.style.left = pos.left + "px";
autoSuggest = new AutoSuggest(inputBox, data);
inputBox.style.top = (pos.top + textbox.offsetHeight - 25) + "px";
document.body.appendChild(inputBox);
 
var autoSuggestDiv = document.createElement('div');
autoSuggest.suggestionUsed = function() {
autoSuggestDiv.id = 'wiktauto-autosuggest';
if ( document.selection && document.selection.createRange ) { // IE/Opera
autoSuggestDiv.appendChild(document.createElement('ul'));
document.body.appendChild(autoSuggestDiv);
autoSuggest = new AutoSuggest(inputBox, data);
autoSuggest.suggestionUsed = function() {
if ( document.selection && document.selection.createRange ) { // IE/Opera
// save window scroll position
if ( document.documentElement && document.documentElement.scrollTop ) {
Hàng 132 ⟶ 189:
textbox.scrollTop = textScroll;
}
inputBox.style.display = 'none';
autoSuggest.hideDiv();
textbox.focus();
};
wiktauto_addKeydownHandler(inputBox, function(ev) {
var key = wiktauto_getKeyCode(ev), ESC = 27;
if (key == ESC) {
inputBox.style.display = 'none';
autoSuggest.hideDiv();
textbox.focus();
}
}
});
textbox.onkeydown = function(ev) {
var key = wiktauto_getKeyCode(ev), SPACE = 32;
if (key == SPACE && ev.ctrlKey) {
selText = '';
if ( document.selection && document.selection.createRange ) { // IE/Opera
// get current selection
var range = document.selection.createRange();
Hàng 159 ⟶ 216:
}
selText = selText.replace(/^[ {-]*((?:\w+\s*)+)[ -}]*$/, '$1');
inputBox.value = selText;
 
inputBox.style.display = 'block';
inputBox.select();
inputBox.focus();
}
}
}
}
textbox.onfocus = function(ev) {
inputBox.style.display = 'none';
autoSuggest.hideDiv();
}
}
}
 
Hàng 175 ⟶ 232:
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
}
return { "left": curleft, "top": curtop };
}
Hàng 194 ⟶ 251:
this.elem = elem;
 
this.values = data.values;
this.suggestions = data.suggestions;
 
Hàng 207 ⟶ 264:
 
//A div to use to create the dropdown.
this.div = document.getElementById("wiktauto-autosuggest");
 
 
Hàng 218 ⟶ 275:
 
//The browsers' own autocomplete feature can be problematic, since it will
//be making suggestions from the users' past input.
//Setting this attribute should turn it off.
Hàng 226 ⟶ 283:
if(!elem.id)
{
var id = "wiktauto-autosuggest" + idCounter;
idCounter++;
 
Hàng 274 ⟶ 331:
/********************************************************
onkeyup handler for the elem
If the text is of sufficient length, and has been changed,
then display a list of eligible suggestions.
********************************************************/
elem.onkeyup = function(ev)
{
var key = wiktauto_getKeyCode(ev);
Hàng 308 ⟶ 365:
 
/********************************************************
Insert the highlighted suggestion into the input box, and
remove the suggestion dropdown.
********************************************************/
Hàng 317 ⟶ 374:
this.elem.value = this.eligible[this.highlighted].value;
this.hideDiv();
//It's impossible to cancel the Tab key's default behavior.
//So this undoes it by moving the focus back to our field right after
//the event completes.
Hàng 463 ⟶ 520:
};
this.div.className="wiktauto-suggestion_list";
this.div.style.position = 'absolute';
 
Hàng 479 ⟶ 536:
this.eligible = new Array();
for (i in this.suggestions)
{
var suggestion = this.suggestions[i];
Hàng 496 ⟶ 553:
// tinh diem
score += index;
for (k in indices) {
score += (indices[k] - index);
}
}
for (k = index-1; k >= 0 && temp.charAt(k) != ' '; k--) {
score += 5;
}
}
for (k = index+parts[j].length; k < temp.length
&& temp.charAt(k) != ' '; k++) {
score += 5;
}
}
// thay bang ki tu dac biet de tranh danh dau 2 lan
indices[indices.length] = index;
lengths[lengths.length] = parts[j].length;
temp = temp.substr(0, index)
+ wiktauto_times('\u0001', parts[j].length)
+ temp.substr(index + parts[j].length);
Hàng 529 ⟶ 586:
}
}
for (j in indices) { + "px"
suggestion = suggestion.substr(0, indices[j])
+ '<strong>' + suggestion.substr(indices[j], lengths[j]) + '</strong>'
+ suggestion.substr(indices[j] + lengths[j]);
Hàng 556 ⟶ 613:
 
/********************************************************
Helper function to determine the event source element in a
browser-independent manner.
********************************************************/
Hàng 573 ⟶ 630:
 
/********************************************************
Helper function to cancel an event in a
browser-independent manner.
(Returning false helps too).
Hàng 593 ⟶ 650:
 
/********************************************************
Helper function to determine the keycode pressed in a
browser-independent manner.
********************************************************/
Hàng 609 ⟶ 666:
 
function wiktauto_times(p, n) {
var s = '';
for ( ; n > 0; n--) {
s += p;
}
}
return s;
}
 
function wiktauto_addKeydownHandler(elem, keydownHandler) {
if (elem.onkeydown) {
var originHandler = elem.onkeydown;
elem.onkeydown = function(ev) {
Hàng 624 ⟶ 681:
}
} else {
elem.onkeydown = keydownHandler;
}
}