מדיה ויקי:Gadget-HotCat.js: הבדלים בין גרסאות בדף
מ typo |
Several fixes to make this work also on IE6 and even if the user denies ActiveX execution (in degraded mode: no suggestions) |
||
| שורה 9: | שורה 9: | ||
var hotcat_no_autocommit = 1; | var hotcat_no_autocommit = 1; | ||
var hotcat_old_onsubmit = null; | var hotcat_old_onsubmit = null; | ||
var hotcat_nosuggestions = false; | |||
// hotcat_nosuggestions is set to true if we don't have XMLHttp! (On IE6, XMLHttp uses | |||
// ActiveX, and the user may deny execution.) If true, no suggestions will ever be | |||
// displayed, and there won't be any checking whether the category exists. | |||
// Lupo, 2008-01-20 | |||
var hotcat_xmlhttp = null; | |||
var hotcat_modify_blacklist = new Array ( | var hotcat_modify_blacklist = new Array ( | ||
| שורה 282: | שורה 288: | ||
form.style.display = "inline" ; | form.style.display = "inline" ; | ||
var list = document.createElement ( "select" ) ; | var list = null; | ||
if (!hotcat_nosuggestions) { | |||
// Only do this if we may actually use XMLHttp... | |||
list = document.createElement ( "select" ) ; | |||
list.id = "hotcat_list" ; | |||
list.onclick = function () | |||
{ | |||
var l = document.getElementById("hotcat_list"); | |||
if (l != null) | |||
document.getElementById("hotcat_text").value = l.options[l.selectedIndex].text; | |||
hotcat_text_changed(); | |||
}; | |||
list.ondblclick = function () | |||
{ | |||
var l = document.getElementById("hotcat_list"); | |||
if (l != null) | |||
document.getElementById("hotcat_text").value = l.options[l.selectedIndex].text; | |||
// Don't call text_changed here if on upload form: hotcat_ok will remove the list | |||
// anyway, so we must not ask for new suggestions since show_suggestions might | |||
// raise an exception if it tried to show a no longer existing list. | |||
// Lupo, 2008-01-20 | |||
if (!hotcat_upload) hotcat_text_changed(); | |||
hotcat_ok(); | |||
}; | |||
list.style.display = "none" ; | |||
} | |||
var text = document.createElement ( "input" ) ; | var text = document.createElement ( "input" ) ; | ||
text.size = 40 ; | text.size = 40 ; | ||
| שורה 295: | שורה 323: | ||
text.onkeyup = function () { window.setTimeout("hotcat_text_changed();", JSconfig.keys['HotCatDelay'] ); } ; | text.onkeyup = function () { window.setTimeout("hotcat_text_changed();", JSconfig.keys['HotCatDelay'] ); } ; | ||
var exists = document.createElement ( "img" ) ; | var exists = null; | ||
if (!hotcat_nosuggestions) { | |||
exists = document.createElement ( "img" ) ; | |||
exists.id = "hotcat_exists" ; | |||
exists.src = hotcat_exists_no ; | |||
} | |||
var OK = document.createElement ( "input" ) ; | var OK = document.createElement ( "input" ) ; | ||
| שורה 309: | שורה 340: | ||
cancel.onclick = hotcat_cancel ; | cancel.onclick = hotcat_cancel ; | ||
form.appendChild ( list ) ; | if (list != null) form.appendChild ( list ) ; | ||
form.appendChild ( text ) ; | form.appendChild ( text ) ; | ||
form.appendChild ( exists ) ; | if (exists != null) form.appendChild ( exists ) ; | ||
form.appendChild ( OK ) ; | form.appendChild ( OK ) ; | ||
form.appendChild ( cancel ) ; | form.appendChild ( cancel ) ; | ||
| שורה 390: | שורה 421: | ||
if ( hotcat_last_v == v ) return ; // Nothing's changed... | if ( hotcat_last_v == v ) return ; // Nothing's changed... | ||
if (hotcat_nosuggestions) { | |||
// On IE, XMLHttp uses ActiveX, and the user may deny execution... just make sure | |||
// the list is not displayed. | |||
var list = document.getElementById ('hotcat_list'); | |||
if (list != null) list.style.display = "none" ; | |||
var exists = document.getElementById ('hotcat_exists'); | |||
if (exists != null) exists.style.display = "none" ; | |||
return; | |||
} | |||
hotcat_running = 1 ; | hotcat_running = 1 ; | ||
hotcat_last_v = v ; | hotcat_last_v = v ; | ||
| שורה 395: | שורה 436: | ||
if ( v != "" ) { | if ( v != "" ) { | ||
var url = wgServer + "/" + wgScriptPath + "/api.php?format=xml&action=query&list=allpages&apnamespace=14&apfrom=" + encodeURIComponent( v ) ; | var url = wgServer + "/" + wgScriptPath + "/api.php?format=xml&action=query&list=allpages&apnamespace=14&apfrom=" + encodeURIComponent( v ) ; | ||
if | if (hotcat_xmlhttp != null) { | ||
hotcat_xmlhttp = | hotcat_xmlhttp.abort() ; // Just to make sure... | ||
delete hotcat_xmlhttp; | |||
} | |||
hotcat_xmlhttp = sajax_init_object() ; | |||
if (hotcat_xmlhttp == null) { | |||
//Oops! We don't have XMLHttp... | |||
hotcat_nosuggestions = true; | |||
var list = document.getElementById ('hotcat_list'); | |||
if (list != null) list.style.display = "none" ; | |||
var exists = document.getElementById ('hotcat_exists'); | |||
if (exists != null) exists.style.display = "none" ; | |||
hotcat_running = 0; | |||
return; | |||
} | |||
hotcat_xmlhttp.open('GET', url, true); | hotcat_xmlhttp.open('GET', url, true); | ||
hotcat_xmlhttp.onreadystatechange = function () { | hotcat_xmlhttp.onreadystatechange = function () { | ||
| שורה 411: | שורה 465: | ||
} | } | ||
hotcat_show_suggestions ( titles ) ; | hotcat_show_suggestions ( titles ) ; | ||
hotcat_running = 0 ; | |||
} | } | ||
}; | }; | ||
| שורה 417: | שורה 472: | ||
var titles = new Array () ; | var titles = new Array () ; | ||
hotcat_show_suggestions ( titles ) ; | hotcat_show_suggestions ( titles ) ; | ||
hotcat_running = 0 ; | |||
} | } | ||
} | } | ||
| שורה 425: | שורה 480: | ||
var list = document.getElementById ( "hotcat_list" ) ; | var list = document.getElementById ( "hotcat_list" ) ; | ||
var icon = document.getElementById ( "hotcat_exists" ) ; | var icon = document.getElementById ( "hotcat_exists" ) ; | ||
// Somehow, after a double click on the selection list, we still get here in IE, but | |||
// the list may no longer exist... Lupo, 2008-01-20 | |||
if (list == null) return; | |||
if (hotcat_nosuggestions) { | |||
list.style.display = "none" ; | |||
if (icon != null) icon.style.display = "none"; | |||
return; | |||
} | |||
if ( titles.length == 0 ) { | if ( titles.length == 0 ) { | ||
list.style.display = "none" ; | list.style.display = "none" ; | ||
| שורה 431: | שורה 494: | ||
} | } | ||
// Set list size to minimum of 5 and actual number of titles. Formerly was just 5. | |||
// Lupo, 2008-01-20 | |||
list.size = (titles.length > 5 ? 5 : titles.length) ; | |||
list.size = 5 ; | |||
list.style.align = "left" ; | list.style.align = "left" ; | ||
list.style.zIndex = 5 ; | list.style.zIndex = 5 ; | ||
list.style.position = "absolute" ; | list.style.position = "absolute" ; | ||
// Was listh = titles.length * 20: that makes no sense if titles.length > list.size | |||
// Lupo, 2008-01-20 | |||
var listh = list.size * 20; | |||
var nl = parseInt (text.parentNode.offsetLeft) - 1 ; | |||
var nt = parseInt (text.offsetTop) - listh ; | |||
list.style.top = nt + "px" ; | list.style.top = nt + "px" ; | ||
list.style.width = text.offsetWidth + "px" ; | list.style.width = text.offsetWidth + "px" ; | ||
| שורה 458: | שורה 526: | ||
if ( first_title == hotcat_last_v ) return ; | if ( first_title == hotcat_last_v ) return ; | ||
var nosel = hotcat_last_v.length ; | // Put the first entry of the title list into the text field, and select the | ||
// new suffix such that it'll be overwritten if the user keeps typing. | |||
// ONLY do this if we have a way to select parts of the content of a text | |||
// field, otherwise, this is very annoying for the user. Note: IE does it | |||
// again differently from the two versions previously implemented. | |||
// Lupo, 2008-01-20 | |||
if (text.setSelectionRange || | |||
text.createTextRange || | |||
typeof (text.selectionStart) != 'undefined' && | |||
typeof (text.selectionEnd) != 'undefined') | |||
{ | |||
var nosel = hotcat_last_v.length ; | |||
text.value = first_title ; | |||
if (text.setSelectionRange) // e.g. khtml | |||
text.setSelectionRange (nosel, first_title.length); | |||
else if (text.createTextRange) { // IE | |||
var new_selection = text.createTextRange(); | |||
new_selection.move ("character", nosel); | |||
new_selection.moveEnd ("character", first_title.length - nosel); | |||
new_selection.select(); | |||
} else { | |||
text.selectionStart = nosel; | |||
text.selectionEnd = first_title.length; | |||
} | |||
} | } | ||
} | } | ||
//</pre></nowiki> | //</pre></nowiki> | ||