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

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (try this)
m (nawww)
Etiqueta: Deshacer
Línea 27: Línea 27:
   
 
mw.hook('wikipage.content').add(function edit_templates(content) {
 
mw.hook('wikipage.content').add(function edit_templates(content) {
 
const templates = Array.from(jQuery('.infobox,.navbar', content))
console.log(content, typeof content, content instanceof HTMLElement)
 
const templates = Array.from(content.querySelectorAll('.infobox,.navbar', content))
 
 
if (!templates.length) return
 
if (!templates.length) return
 
templates.forEach(add_editsection_link)
 
templates.forEach(add_editsection_link)

Revisión del 20:03 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'
 // 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;
 // FIXME: what does this do?
 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')
})