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

放肆的年华 提交于 2019-12-07 19:34:38

问题


Could we add our menu items in Starter kit Gitkit NavBar ?
There are two list items in the drop down : Manage Account and Sign Out.
Is it possible to add a third option with a URL link ( say like Update Profile ) ?

The html for the #navbar gets loaded through Javascript code of Gitkit.

I use GAE Python.

Possible solutions which I could think of are :
After my webpage loads completely, I could add my own <li> items to the list of dropdown menu provided by #navbar.
Or
Write a custom "Sign In cum User Info " ( #navbar ) widget.

Is there a better and simpler approach ?

MY REQUEST TO GITKIT TEAM FOR ENHANCEMENT
It would be great if we could provide our custom menu items along with their URL links as options to below JS code which loads #navbar :

<script type=text/javascript>
  window.google.identitytoolkit.signInButton(
    '#navbar', // accepts any CSS selector
    {
      widgetUrl: "http://www.mywebsite.com/oauth2callback",
      signOutUrl: "/", 

      // Example of possible solution ( my suggestion ): 
      custom_menu_item__1__name : "item_1", // My Custom Menu Item 1 
      custom_menu_item__1__link : "http://site/link_url_1", 
      :: 
      custom_menu_item__n__name : "item_1", // My Custom Menu Item n 
      custom_menu_item__n__link : "http://site/link_url_1", 
    }
  );
</script>

UPDATE
Temporary Fix = I have added the needed menu options using jquery temporarily. Code snippet provided below to help anyone with similar needs till official solution arrives :

On page load,

custom_menu_add_job_id = setInterval(function(){ 
        add_custom_menu(); 
    }, 5000); 

function add_custom_menu(){ 
    if ($("#navbar").find(".gitkit-user-card-menu").length){ 
        $(".gitkit-user-card-menu").append($("<li class='gitkit-user-card-menuitem' id='smh_user_profile' tabindex='0'> <img src='/images/person_32x32.png' class='user_profile_menu_icon' > Profile </li>")
            .click(function(){ 
                window.location.href = window.location.protocol + "//" + window.location.host + "/user/"; 
            }) 
        ); 
        clearInterval(custom_menu_add_job_id); 
    } 
}

If you want, you could check it live at ShowMyHall.


回答1:


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();}
        },
      ]
  };



回答2:


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.




回答3:


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');
}


来源:https://stackoverflow.com/questions/31540583/could-we-add-our-menu-items-in-gitkit-starter-kit-sign-in-cum-user-info-na

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!