Jump to content

Topic on Talk:ResourceLoader/Core modules

mw.hook("wikipage.content")

3
Ponor (talkcontribs)

I have a piece of code that's supposed to run every time Wikipedia Recent Changes is (semi)automatically refreshed (live feed / button press on new changes):

$(document).ready(function() {

if (mw.config.get("wgCanonicalSpecialPageName") === "Recentchanges") {

       mw.hook("wikipage.content").add(function (){

            /*...code to move some divs around...*/

            console.log("fired!")

       })

   }

}

This always seems to fire twice. My question is whether "wikipage.content change" applies only to content provided by the server, or does my div-moving-around also count as content change, triggering the hook for the second time. How can one prevent this from happening? Thnx.

Nirmos (talkcontribs)
Ponor (talkcontribs)

Thank you very much, @Nirmos! For reference, this is what needs to be done (from example #4):

a) define a function that needs to be run when the page is loaded and when the mw-changeslist <div> (Recent Changes page) is refreshed:

function fireIt() {
 /*...code to move some divs around...*/
 console.log("fired!")
 }

b) run the function within $(document).ready()

c) set up a mw.hook within $(document).ready() like this

mw.hook("wikipage.content").add( function (element) {
   if ( element.hasClass( 'mw-changeslist' ) ) {
           fireIt();
           }
   });
Reply to "mw.hook("wikipage.content")"