Jump to content

MediaWiki:Common.js: Difference between revisions

m
Updated to latest version of common.js with new landing page changes in place.
(remove conditional load of Adobe A/B testing code to prevent load errors and delays on the Main Page)
m (Updated to latest version of common.js with new landing page changes in place.)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
// test if we're on the home page
if (/Main_Page/.test(document.location.href)) {
    $("#firstHeading").css("textAlign", "center","border", "0");
}


/* Adobe Analytics added 2019-05-16 */
/* Adobe Analytics added 2019-05-16 */
Line 296: Line 301:


/* code for new landing page */
/* code for new landing page */
if (/Main_Page/.test(document.location.href)) {
// test if we're on the home page
     var el = document.querySelector('#firstHeading');
if ( /Main_Page/.test(document.location.href) ) {
    el.style.border = "0";
     $("#firstHeading").css("border", "0", "textAlign", "center");
    el.style.textAlign = "center";
}


/**
* Conditional include of Map Menus data structure
* and all the Map Menus functionality
* - only for pages with 'Main Page' in the title
*/
// test if we're on the home page & on beta
if ( /Main_Page/.test(document.location.href) ) {
    // console.log('loading menus data');
    mw.loader.load('/wiki/en/index.php?title=MediaWiki:MapMenu.js&action=raw&ctype=text/javascript');


     // By wrapping the code block in $() we get the same behavior as using
     /**
    // document).ready(function () { }
    * Attach a click handler to our buttons to show the "countries" menus
    $(function () {
    */
         // start off with hiding Countries and States
    $('[id$=_button]').click(function () {
         hideCountries();
        // show the menu in case it's hidden
         hideStates();
        $("#menu").show();
        var position = this.id.indexOf('_button');
        var name = this.id.substring(0, position);
        name += "_countries";
         // console.log ("showing list for " + name);
         if (name == 'all_countries_countries') {
            showAllCountries();
         } else {
            showList(name);
        }
    });


        // https://api.jquery.com/category/selectors/
    /**
        // attach to elements ending with _list
    * Attach a click handler to "links" (spans with class .menulink) in the menus.
        $('[id$=_list]').click(function () {
    * Because the menus are dynamic, we use a "delegated" event handler
            hideCountries();
    * with jQuery's .on()
            $("#countries_list").hide();
    * https://api.jquery.com/on/
            hideStates();
    */
            // show the corresponding country
    $("#menu").on("click", ".menulink", function () {
            var position = this.id.indexOf('_list');
        // console.log( $( this ).text() );
            var target = this.id.substring(0, position);
        // find out what menu to show
            var myId = '#' + target + '_countries';
        var menu = $(this).text().toLowerCase();
            $(myId).show(200);
        // replace all the blanks
            var thisExitMenu = "#exit_menu_" + target + '_countries';
        menu = menu.replace(/ /g, "_");
            //console.log("showing exit menu " + thisExitMenu);
        menu = menu + "_states";
            $(thisExitMenu).show();
        // console.log("showing menu for " + menu);
        });
        showList(menu);
    });


        // attach to elements ending with _list2
    /**
        $('[id$=_list2]').click(function (e) {
    * Add an event listener to state and country menus
            // show the corresponding states
    * so that clicking the red [x] will close the menu.
            var position = this.id.indexOf('_list2');
    */
            var target = this.id.substring(0, position);
    $("#menu").on("click", ".exit", function () {
            var myId = '#' + target + '_states';
        var menu = $(".exit").parent().attr("parent");
            //console.log("You clicked a list2; showing " + myId)
         if (menu) {
            $(myId).show(200);
             showList(menu);
            // stop the bubble which would hide all states
        } else {
            e.stopPropagation();
        //showAllCountries();
            // since we stop the bubble, make sure countries_list is hidden
             $("#menu").hide();
            $("#countries_list").hide();
         }
        });
 
        // clicking any class="exit_menu" hides all states
        $('.exit_menu').click(function () {
            hideStates();
            // let stateList = this.parentNode.parentNode.id;
            // console.log ('You clicked in ' + stateList);
            $("#all_countries_countries").hide();
        });
          
        // attach to any id with exit_menu at the start
        $('[id^=exit_menu]').click(function () {
             // hide the corresponding _countries
            var target = this.id.substring(10);
            var myId = '#' + target;
            //console.log("You clicked an exit_menu for " + this.id);
            //console.log("Hiding " + myId + " and showing the countries_list");
            $(myId).hide();
            // show the countries_list
             $("#countries_list").show(200);
         });
     });
     });
}
function hideCountries() {
    $('[id$=_countries]').hide();
}
function hideStates() {
    $('[id$=_states]').hide();
}
}
/* end code for landing page*/
/* end code for landing page*/
2,664

edits