MediaWiki:Common.js: различия между версиями

New Help Overlay
(Sandbox code replaced by extension SandboxLink)
(New Help Overlay)
Строка 1: Строка 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 */
        window.utag_data={
window.utag_data={
            'site_id': 'FamilySearch',
    'site_id': 'FamilySearch',
'page_channel': 'Wiki',
    'page_channel': 'Wiki',
            'page_detail': document.location.pathname, //'Home' for the homepage or a unique page title for other pages
    'page_detail': document.location.pathname, //'Home' for the homepage or a unique page title for other pages
};
};


        (function(a,b,c,d){
(function(a,b,c,d){
            a='//tags.tiqcdn.com/utag/lds/familysearch/prod/utag.js';
    a='//tags.tiqcdn.com/utag/lds/familysearch/prod/utag.js';
            b=document;c='script';d=b.createElement(c);d.src=a;d.type='text/java'+c;d.async=true;
    b=document;c='script';d=b.createElement(c);d.src=a;d.type='text/java'+c;d.async=true;
            a=b.getElementsByTagName(c)[0];a.parentNode.insertBefore(d,a);
    a=b.getElementsByTagName(c)[0];a.parentNode.insertBefore(d,a);
        })();
})();
 
/* --- WalkMe Snippet 11/16/2017---*/
(function() {var walkme = document.createElement('script'); walkme.type = 'text/javascript'; walkme.async = true; walkme.src = 'https://cdn.walkme.com/users/70d691a8f9e74afca1b8d8b935598004/walkme_70d691a8f9e74afca1b8d8b935598004_https.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(walkme, s); window._walkmeConfig = {smartLoad:true}; })();
/* --- WalkMe Snippet ---*/


function getCookie(name) {
function getCookie(name) {
Строка 252: Строка 253:


mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );


/* Added for Accordion button */
/* Added for Accordion button */
Строка 291: Строка 291:
         var locationMap = document.createElement('link');
         var locationMap = document.createElement('link');
         locationMap.rel = 'import';
         locationMap.rel = 'import';
/* CHANGE NEEDED: replace URL below every time the location-map.html is changed */
/* CHANGE NEEDED: update URL below every time the location-map.html is changed */
         locationMap.href = 'https://gist.githubusercontent.com/ahancey/a86414a07c7c1466cc36ffb790a0817d/raw/578be7c96148d1148f6aaf211c3599c25b86a60f/location-map.html';
         locationMap.href = 'https://gist.githubusercontent.com/ahancey/a86414a07c7c1466cc36ffb790a0817d/raw/748a662f88adf92729d925ebf5fb1ce26ec0bb38/location-map.html';
        var s = document.getElementsByTagName('script')[0];
      var s = document.getElementsByTagName('script')[0];
         s.parentNode.insertBefore(locationMap, s);
         s.parentNode.insertBefore(locationMap, s);


Строка 299: Строка 299:
     }
     }
})();
})();
/* code for new landing page */
// test if we're on the home page
if ( /Main_Page/.test(document.location.href) ) {
    $("#firstHeading").css("border", "0", "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');
    /**
    * Attach a click handler to our buttons to show the "countries" menus
    */
    $('[id$=_button]').click(function () {
        // show the menu in case it's hidden
        $("#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);
        }
    });
    /**
    * Attach a click handler to "links" (spans with class .menulink) in the menus.
    * Because the menus are dynamic, we use a "delegated" event handler
    * with jQuery's .on()
    * https://api.jquery.com/on/
    */
    $("#menu").on("click", ".menulink", function () {
        // console.log( $( this ).text() );
        // find out what menu to show
        var menu = $(this).text().toLowerCase();
        // replace all the blanks
        menu = menu.replace(/ /g, "_");
        menu = menu + "_states";
        // console.log("showing menu for " + menu);
        showList(menu);
    });
    /**
    * Add an event listener to state and country menus
    * so that clicking the red [x] will close the menu.
    */
    $("#menu").on("click", ".exit", function () {
        var menu = $(".exit").parent().attr("parent");
        if (menu) {
            showList(menu);
        } else {
        //showAllCountries();
            $("#menu").hide();
        }
    });
}
/* end code for landing page*/
/** 2020/08/31 Add code for new Help Menu Overlay */
// URL for bringing in the bundle to the wiki
const url = '/wiki/public_html/helptray.js';
// the selector for the Help button in the header
const button = document.querySelector('#helpLink');
button.addEventListener('click', function () {
  // If the script that brings in the Help Overlay isn't on the page yet, we know
  // we need to load it in
  if ( typeof window.renderHelpTray === "undefined" ) {
    const script = document.createElement('script');
    script.setAttribute('src', url);
    // Once the script loads, we need to do a little more set up and then actually
    // open the Help Overlay
    script.onload = function () {
      // This event is fired when the Help Overlay is rendered for the first time
      // Setting { once: true } as an option avoids the potential for multiple
      // times getting called. Once this event fires, we just fire the event to
      // let the Help Overlay it needs to open
      document.addEventListener('helpTrayReady', function () {
        document.dispatchEvent(new CustomEvent('openHelpTray'));
      }, { once: true });
      // Here we create an element to render the Help Overlay on. Just a generic div works
      const renderDiv = document.createElement('div');
      // We add an ID in case we need to easily reference it elsewhere
      renderDiv.id = 'helpOverlayRoot';
      // If you go the route of creating the element programatically, be sure to add it
      // to the body somewhere. Here we just put at the end of the <body>
      document.body.appendChild(renderDiv);
      // This is a consistent way to get info about the size and position of the button
      // We can use this to determine where to set the initial position (the x being pulled
      // out here will be the left of the button, which is the correct x value to start the
      // help tray at. The y is the top of the button, which we can add the button's height
      // to in order to get the correct y value to start the help tray at)
      const rect = button.getBoundingClientRect();
      const x = rect.left;
      const y = rect.top;
      const height = rect.height;
      // Finally, call the renderHelpTray function with the element (required) and the
      // initial position (optional but highly recommended)
      window.renderHelpTray(renderDiv, [x, y + height]);
    };
    document.head.insertBefore(script, document.head.firstChild);
  } else {
    // If we get to this else, the script is already on the page, so we just need
    // to dispatch the appropriate event. At a minimum, this can just fire the
    // openHelpTray event, but the ideal scenario is that the button click acts as
    // a toggle. This example shows how to check if the Help Overlay is already open
    // on the page, and fires the appropriate event based on that
    const eventName = document.querySelector('[data-test=helpOverlayCloseButton]') ? 'closeHelpTray' : 'openHelpTray';
    document.dispatchEvent(new CustomEvent(eventName));
  }
});