MediaWiki:Gadget-Gender.js: Difference between revisions

Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
rewrite using $.getJSON
mNo edit summary
(rewrite using $.getJSON)
Line 5: Line 5:
   $(function() {
   $(function() {
     // init AJAX and request the user's gender from the API
     // init AJAX and request the user's gender from the API
     var a = sajax_init_object();
     $.getJSON(
    a.open("GET", wgServer + wgScriptPath +
      mw.util.wikiScript( 'api' ),
                  "/api.php?format=json&action=query&list=users&ususers=" +
      {
                  escape(wgTitle.replace(/ /, "_")) + "&usprop=gender",
        format: 'json',
          true);
        action: 'query',
        list: 'users',
    // when response arrives...
        ususers: escape(wgTitle.replace(/ /, "_")),
    a.onreadystatechange = function() {
        usprop: 'gender'
      if(a.readyState == 4 && a.status == 200) {
      },
        // parse the JSON response
      function( response ) {
         var genderText =  
         var genderText = response.query.users[0].gender;
          eval("(" + a.responseText + ")").query.users[0].gender;
 
         // U+2640 and U+2642 are female and male signs respectively.
         // U+2640 and U+2642 are female and male signs respectively.
         var genderSymbol = "";
         var genderSymbol = "";
Line 25: Line 24:
           genderSymbol = "<span class=\"male-icon\">&#x2642;</span>";
           genderSymbol = "<span class=\"male-icon\">&#x2642;</span>";
         }
         }
 
         // if gender was specified, append the symbol
         // if gender was specified, append the symbol
         if (genderSymbol != "") {
         if (genderSymbol != "") {
Line 33: Line 31:
         }
         }
       }
       }
     };
     );
    // send the API request
    a.send();
   });
   });
}
}

Navigation menu