Widget:Autorenbox: Unterschied zwischen den Versionen
Aus ZUM-Unterrichten
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
KKeine Bearbeitungszusammenfassung Markierung: 2017-Quelltext-Bearbeitung |
||
Zeile 18: | Zeile 18: | ||
).getPrefixedText() | ).getPrefixedText() | ||
; | ; | ||
const userlistEl = $(element). | const userlistEl = $(element).find('[data-zum-hook="userlist"]'); | ||
const lastModifiedEl = $(element). | const lastModifiedEl = $(element).find('[data-zum-hook="last-modified"]'); | ||
const api = new mw.Api(); | const api = new mw.Api(); | ||
const response = api.get({ | const response = api.get({ | ||
Zeile 41: | Zeile 41: | ||
let userChanges = pageData | let userChanges = pageData | ||
.contributors | .contributors | ||
.reduce((acc, c)=> {acc[c.name] = {count:0, last:0}; return acc;}, {}); | .reduce((acc, c)=> {acc[c.name] = {count:0, last:0, id:c.id}; return acc;}, {}); | ||
userChanges = pageData.revisions.reduce((acc, r) => { | userChanges = pageData.revisions.reduce((acc, r) => { | ||
acc[r.user] = acc[r.user] || {count:0, last:0}; | acc[r.user] = acc[r.user] || {count:0, last:0}; | ||
Zeile 48: | Zeile 48: | ||
return acc; | return acc; | ||
}, userChanges); | }, userChanges); | ||
Object.keys(userChanges).sort((a,b) => { | const usernames = Object.keys(userChanges).sort((a,b) => { | ||
let diff = userChanges[b].count - userChanges[a].count; | let diff = userChanges[b].count - userChanges[a].count; | ||
if(diff !== 0){ | if(diff !== 0){ | ||
Zeile 54: | Zeile 54: | ||
} | } | ||
return userChanges[b].last - userChanges[a].last; | return userChanges[b].last - userChanges[a].last; | ||
}).forEach((user) => { | }) | ||
const userdatas = usernames.map((user) => api | |||
.parse(`{{#:avatar|${user}|l}}`) | |||
.then((imgTag) => $(imgTag)) | |||
.then((img$) => img$.find('img').andSelf().filter('img').attr('src')) | |||
.then((imgSrc) => {user, imgSrc}) | |||
.fail((ignored)=> null)) | |||
); | |||
$.when(...userdatas) | |||
.then((...userdatas) => userdatas.filter((ud) => ud !== null)) | |||
.then((userdatas) => { | |||
userdatas.forEach(({user, imgSrc}) => { | |||
$('<img>') | |||
.attr('src', imgSrc) | |||
.wrap('<a>').attr('href', mw.Title.makeTitle(mw.config.get('wgNamespaceIds')['benutzer'], user).getUrl()) | |||
.wrap('<div class="uk-border-circle uk-text-center" style="overflow:hidden;width:60%;margin:auto;">') | |||
.wrap('<div class="uk-panel uk-panel-border uk-text-small" style="max-width:12h">') | |||
.appendTo($(userlistEl)); | |||
}); | |||
}) | |||
.then((ignored) => $(element).removeClass('uk-hidden')); | |||
});//end response.then | });//end response.then | ||
});//end loader.enqueue | });//end loader.enqueue |