Could we add our menu items in Gitkit Starter kit “Sign In cum User Info ” ( #navbar )?

冷暖自知 提交于 2019-12-06 13:28:09

Customized menu items are now supported in Google Identity Toolkit javascript widget. Examples:

window.google.identitytoolkit.signInButton(
  '#navbar', // accepts any CSS selector
  {
    widgetUrl: "...",
    dropDownMenu: [
        {
          'label': 'Check Configuration',
          'url': '/config'
        },
        {
          'label': 'Sign out',
          'handler': function() {google.identitytoolkit.signOut();}
        },
        {
          'label': 'Manage Account',
          'handler': function() {google.identitytoolkit.manageAccount();}
        },
      ]
  };

Until this feature arrives, I also implemented a similar temporary fix that you outlined at the end of your question. I got around using a timer as follows (note that my gitkit is using the div login):

    $(window).load(function() {
        $("#login").hover(function() {
            add_custom_menu_items();
        })
    });

    function add_custom_menu_items(){
        if ($("#login").find(".gitkit-user-card-menu").length == 1){
            if ($("#my_data_link").length == 0) {
                $(".gitkit-user-card-menu li:eq(0)").after($('<li class="gitkit-user-card-menuitem" id="my_data_link" tabindex="0"><a href="/my_data/">My data</a></li>'));
            }
        }
    }

Basically when you hover over the div it adds the menu item, but only if it hasn't already been added.

The navbar drop down menu does not support images but if you really need that, here's a hacky way to do it in jquery:

var config = {...}; // your config which includes the custom drop down menu.
// Render button on load. (now supported)
window.onload = function() {
  window.google.identitytoolkit.signInButton(
    '#navbar', // accepts any CSS selector
    config);
  // This will modify the html content of the first option in drop down menu.
  // Make menu dom changes.
  jQuery('#navbar li:first-child').html('<img src="img.png">My Label');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!