מדיה ויקי:Gadget-HotCat.js: הבדלים בין גרסאות בדף
Fix another obscure failure |
Add support for state restoration from new UploadForm |
||
| שורה 138: | שורה 138: | ||
hotcat_modify_existing ( catline ) ; | hotcat_modify_existing ( catline ) ; | ||
hotcat_append_add_span ( catline ) ; | hotcat_append_add_span ( catline ) ; | ||
// Check for state restoration (Lupo, 2008-02-06) | |||
if ( hotcat_upload | |||
&& typeof (UploadForm) != 'undefined' | |||
&& typeof (UploadForm.previous_hotcat_state) != 'undefined' | |||
&& UploadForm.previous_hotcat_state != null) | |||
UploadForm.previous_hotcat_state = hotcat_set_state (UploadForm.previous_hotcat_state); | |||
} | } | ||
| שורה 577: | שורה 584: | ||
} | } | ||
} | } | ||
function hotcat_get_state () | |||
{ | |||
var cats = document.getElementById ('catlinks'); | |||
if (cats == null) return ""; | |||
var result = null; | |||
cats = cats.getElementsByTagName ('span') ; | |||
for (var i = 0; i < cats.length; i++ ) { | |||
var text = cats[i].getElementsByTagName('a')[0].innerHTML; | |||
if (text.length > 0 && text != '(+)') { | |||
if (result == null) | |||
result = text; | |||
else | |||
result = result + '\n' + text; | |||
} | |||
} | |||
return result; | |||
} | |||
function hotcat_set_state (state) | |||
{ | |||
var cats = state.split ('\n'); | |||
if (cats.length == 0) return null; | |||
var parent = document.getElementById ('catlinks'); | |||
if (parent == null) return state; | |||
// HotCat uses a 'p' element inside the 'div' to wrap its spans... | |||
parent = parent.firstChild; | |||
if (parent == null || parent.getAttribute ('class') != 'catlinks') return state; | |||
var n = (parent.childNodes ? parent.childNodes.length - 1 : 0); | |||
if (n < 0) n = 0; | |||
var before = parent.lastChild; | |||
for (var i = 0; i < cats.length; i++) { | |||
if (cats[i].length > 0) { | |||
var lk = document.createElement ('a'); | |||
lk.href = wgArticlePath.split ('$1').join ('Category:' + encodeURIComponent (cats[i])); | |||
lk.appendChild (document.createTextNode (cats[i])); | |||
lk.setAttribute ('title', cats[i]); | |||
var span = document.createElement ('span'); | |||
span.appendChild (lk); | |||
parent.insertBefore (span, before); | |||
if (before != null) parent.insertBefore (document.createTextNode (' | '), before); | |||
hotcat_modify_span (span, n++); | |||
} | |||
} | |||
return null; | |||
} | |||
//</pre></nowiki> | //</pre></nowiki> | ||