Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:13:15+00:00 2026-05-29T11:13:15+00:00

I am using events to manage the ui after users log in and out

  • 0

I am using events to manage the ui after users log in and out of a website, when a login occurs a login event is published and when a user logs out a logout event is published.

With this system in place I am trying the idea of small inline bits of javascript to deal with the ui elements which subscribe to the events.

At the top of the page is a login/logout link so I am using the following code for changing the login status

<div id="account_panel" class="signed_out">
    <div class="in">
        <a href="/account" class="name"></a> | <a href="/account/signout">Sign-out</a>
    </div>
    <div class="out">
        <a href="/account/signin" class="signin">Sign-in</a> | <a href="/account/register" class="register">Register</a>
    </div>
</div>
<script>
    if (window.jQuery) {
        $('body').on('login.account.website', function(event, data){
            $('#account_panel').removeClass('signed_out').addClass('signed_in');
            if (data)
                jQuery('#account_panel .name').text(data.first_name+' '+data.last_name);
        });
    }
</script>

I have several pieces of code like this, the idea is they are all self contained and do not affect or directly depend on other things, the javascript only relates to the code next to it so it seems sensible to put them together.

The initial state of the html is generated server side to allow the site to function without javascript, a code snipit like this is also contained in its own template file.

I want to carry on using this method for various elements on the site but I am interested to find out if there is a better maintainable method I should be using.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:13:16+00:00Added an answer on May 29, 2026 at 11:13 am

    I’d argue this method is difficult to maintain, having to track snippets of code scattered over multiple html documents. Why not keep the code in one place and bind to your events only when certain DOM elements are present:

    if (window.jQuery) {
      function whenSignedOut(){
        $('body').on('login.account.website', function(event, data){
           $('#account_panel').removeClass('signed_out').addClass('signed_in');
           if (data)
               jQuery('#account_panel .name').text(data.first_name+' '+data.last_name);
        });
      }
    
      function whenSignedIn(){  
      }
    }
    
    if (window.jQuery) {
      $(document).ready(function(){
        if($('div#account_panel.signed_out').length > 0)) {
          whenSignedOut();
        }
    
        if($('div#account_panel.signed_in').length > 0)) {
          whenSignedIn();
        }
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was using Events in my class and added an event reference to the
I'm using events as part of a game model, and for extensibility and code
I want to read and write from serial using events/interrupts. Currently, I have it
When delegating events using .on how do I target child elements: I have tried:
I'm trying to intercept events using Gdk.Window.AddFilter(Gdk.FilterFunc) in Mono. So far, I have been
I'm having trouble understanding using D3 events and dispatch functions. I have a chart
How to detect click (including browser's back button) events using javascript?
Basically what I'm trying to do is have a picture rotate using mouse events.
I'm using a google events tracker like this: _gaq.push(['_setAccount', 'UA-1422398-23']); _gaq.push(['_trackEvent', 'BookingRequest', 'Parent Name',
I am developing an events page using jquery mobile. I have a stylish way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.