Diferencia entre revisiones de «MediaWiki:Gadget-edit-templates.js»

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (nawww)
Etiqueta: Deshacer
m (tweaks)
 
Línea 10: Línea 10:
 
el.className = 'mw-editsection'
 
el.className = 'mw-editsection'
 
el.style.float = 'right'
 
el.style.float = 'right'
  +
el.title = 'edit this template'
 
// push [] around the A element into the span
 
// push [] around the A element into the span
 
el.append( '[', link, ']')
 
el.append( '[', link, ']')
Línea 17: Línea 18:
 
function add_editsection_link(box) {
 
function add_editsection_link(box) {
 
if (!box.id) return;
 
if (!box.id) return;
  +
// turn dot-encoded id numbers into %-encoded as per url-encoding
// FIXME: what does this do?
 
 
const id = box.id.replace(/\.(\d+)/, '%$1')
 
const id = box.id.replace(/\.(\d+)/, '%$1')
 
// generate an edit link
 
// generate an edit link

Revisión actual del 20:07 31 ene 2021


/// create a link that looks like .editsection
function make_editsection_link(url) {
 // generate an edit link
 const link = document.createElement('a')
 link.setAttribute('href', url)
 link.textContent = 'edit'
 // wrap the link in an '.editsection' link floated right
 const el = document.createElement('span')
 el.className = 'mw-editsection'
 el.style.float = 'right'
 el.title = 'edit this template'
 // push [] around the A element into the span
 el.append( '[', link, ']')
 return el
}
/// add the link to the given box
function add_editsection_link(box) {
 if (!box.id) return;
 // turn dot-encoded id numbers into %-encoded as per url-encoding
 const id = box.id.replace(/\.(\d+)/, '%$1')
 // generate an edit link
 const el = make_editsection_link('/edit/Template:'+ id)
 // get the title element
 const title = box.querySelector('.title')
 title.appendChild(el)
}

mw.hook('wikipage.content').add(function edit_templates(content) {
 const templates = Array.from(jQuery('.infobox,.navbar', content))
 if (!templates.length) return
 templates.forEach(add_editsection_link)
 console.debug('gadget:', 'edit-templates')
})