מדיה ויקי:Gadget-HotCat.js: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
Also enable HotCat when there are no categories yet. Code from User:TheDJ, adapted by User:Lupo |
||
| שורה 84: | שורה 84: | ||
var form = document.getElementById ('upload'); | var form = document.getElementById ('upload'); | ||
hotcat_old_onsubmit = form.onsubmit; | hotcat_old_onsubmit = form.onsubmit; | ||
form.onsubmit =hotcat_on_upload | form.onsubmit = hotcat_on_upload; | ||
} | } | ||
| שורה 116: | שורה 113: | ||
} | } | ||
return true; | return true; | ||
} | } | ||
| שורה 130: | שורה 121: | ||
hotcat_check_upload () ; | hotcat_check_upload () ; | ||
if( document.getElementById('ca-viewsource' ) != null // User has no permission to edit | |||
|| wgAction != 'view' // User is editing or previewing or... | |||
|| wgNamespaceNumber == -1 && !hotcat_upload) // Special page other than Special:Upload | |||
return; | |||
// | var visible_cats = | ||
document.getElementById ('mw-normal-catlinks') || // MW 1.13alpha | |||
getElementsByClassName ( document , "p" , "catlinks" ) [0]; // MW < 1.13 && Special:Upload | |||
var hidden_cats = | |||
document.getElementById ('mw-hidden-catlinks'); | |||
if (visible_cats == null) { | |||
// Insert an empty category line | |||
var footer = null; | |||
if (hidden_cats == null) { | |||
footer = getElementsByClassName (document , "div" , "printfooter")[0]; | |||
if (!footer) return; // Don't know where to insert the category line | |||
} | |||
visible_cats = document.createElement ('div'); | |||
visible_cats.setAttribute ('id', 'mw-normal-catlinks'); | |||
var label = document.createElement ('a'); | |||
label.setAttribute ('href', wgArticlePath.replace (/\$1/, 'Special:Categories')); | |||
label.setAttribute ('title', 'Special:Categories'); | |||
label.appendChild (document.createTextNode ('Category')); | |||
visible_cats.appendChild (label); | |||
visible_cats.appendChild (document.createTextNode (':')); | |||
if (hidden_cats == null) { | |||
var container = document.createElement ('div'); | |||
container.setAttribute ('id', 'catlinks'); | |||
var tmp = document.createElement ('div'); | |||
tmp.className = 'catlinks'; | |||
tmp.appendChild (visible_cats); | |||
container.appendChild (tmp); | |||
footer.parentNode.insertBefore (container, footer.nextSibling); | |||
} else { | |||
hidden_cats.parentNode.insertBefore (visible_cats, hidden_cats); | |||
} | |||
} // end if no categories | |||
hotcat_modify_existing ( | hotcat_modify_existing ( visible_cats ) ; | ||
hotcat_append_add_span ( | hotcat_append_add_span ( visible_cats ) ; | ||
// Check for state restoration (Lupo, 2008-02-06) | // Check for state restoration (Lupo, 2008-02-06) | ||
| שורה 154: | שורה 172: | ||
function hotcat_append_add_span ( catline ) { | function hotcat_append_add_span ( catline ) { | ||
var span_add = document.createElement ( "span" ) ; | var span_add = document.createElement ( "span" ) ; | ||
if ( catline.getElementsByTagName('span')[0] ) | |||
if ( catline.firstChild ) catline.appendChild ( | catline.appendChild (document.createTextNode (" | ")); | ||
catline.appendChild ( span_add ) ; | else if (catline.firstChild) | ||
hotcat_create_span ( span_add ) ; | catline.appendChild (document.createTextNode (' ')); | ||
catline.appendChild ( span_add ); | |||
hotcat_create_span ( span_add ); | |||
} | } | ||