Diferencia entre revisiones de «MediaWiki:Gadget-artist-portal.js»

De La Coppermind
Ir a la navegación Ir a la búsqueda
m (tweak)
m (pass in content to jQuery things)
Línea 3: Línea 3:
 
console.debug('artist-portal:', content)
 
console.debug('artist-portal:', content)
   
document.querySelectorAll('a[title^="Coppermind:Artists/"]').forEach(function each_artist(el) {
+
Array.from(jQuery('a[title^="Coppermind:Artists/"]',content)).forEach(function each_artist(el) {
 
// replace text with artist name
 
// replace text with artist name
 
el.innerText = el.innerText.replace('Coppermind:Artists/','')
 
el.innerText = el.innerText.replace('Coppermind:Artists/','')
 
})
 
})
   
Array.from(jQuery('a[title^="Coppermind:Artists/"]').closest('ul')).forEach(function sort_list(ul) {
+
Array.from(jQuery('a[title^="Coppermind:Artists/"]',content).closest('ul')).forEach(function sort_list(ul) {
 
const kids = Array.from(ul.children)
 
const kids = Array.from(ul.children)
 
console.debug('sorting:', kids.length, 'elements from', ul)
 
console.debug('sorting:', kids.length, 'elements from', ul)

Revisión del 21:24 21 abr 2020

mw.hook('Coppermind:Artists').add(function artist_portal(content) {

console.debug('artist-portal:', content)

Array.from(jQuery('a[title^="Coppermind:Artists/"]',content)).forEach(function each_artist(el) {
 // replace text with artist name
 el.innerText = el.innerText.replace('Coppermind:Artists/','')
})

Array.from(jQuery('a[title^="Coppermind:Artists/"]',content).closest('ul')).forEach(function sort_list(ul) {
 const kids = Array.from(ul.children)
 console.debug('sorting:', kids.length, 'elements from', ul)
 kids.sort(function sort_kids(a,b) { return a.innerText < b.innerText ? -1 : +1 })
 kids.forEach(function reinsert(li) { ul.append(li) })
})

// END
})