Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Tell me if I understand this correctly...

Here's the HTML that sets everything in motion:

 <li role="presentation"><a href="#summary" aria-controls="summary" role="tab" data-toggle="tab">Health Summary</a></li>

"#summary" - triggers this function:

    $('a[href="#summary"]').on('click', function(){
        setTimeout(function(){
            HealthSummary.init();
        }, 250);
    });

HealthSummary.init - not sure what that means other than, "initialize." There's another script has this:

var HealthSummary = {
    
    initialized: false,
    
    init: function(){
        var self = this;
        
        if (self.initialized) {
            return true;
        }
        
        $('.health-summary[data-id]').each(function(i){
            
            var $this = $(this),
                id = $this.attr('data-id');
            
            if (id === '') {
                $this.html('<h3 class="text-center">Invalid health summary reference</h3>');
                return true;
            }
            
            $this.html('<h3 class="text-center"><i class="fa fa-refresh fa-spin"></i> &nbsp;Loading Health Summary...<br /><small>(This should only take a few seconds.)</small></h3>');
            
            $.get('/health-summary/' + id, function(resp){
                if (resp.error) {
                    $this.html('<div class="alert alert-danger">' + resp.msg + '</div>');
                    return false;
                }
                
                $this.html(resp.data.html);
            }, 'json').fail(function(){
                $this.html('<div class="alert alert-danger">Unfortunately, something appears to have gone wrong. Please refresh the page to try again.</div>');
            });
            
        });
        
        self.initialized = true;
    }
    
};

Open in new window


What's happening, here?

I'm thinking that on line 24, you're getting a page and, according to the routing (this is a Laravel app), you're getting this:

   "health_summary": {
        "url": "/health-summary/{id}",
        "handler": "HealthSummary.php",
        "action": "_default",
        "method": ["get"],
        "security": ["user"]
    },

...health-summary/{id} That's the URL and the "HealthSummary.php" is the systemic scaffolding behind that page.

Correct?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

HealthSummary is a JavaScript object.

init() is a method (aka "function") of the object.

I'm not exactly sure about the relationship between the Laravel route for /health-summary/ and the script HealthSummary.php.  It looks and feels right, based on my experience with Laravel, but it might be worth looking at the routing in Laravel to be sure.
Avatar of Bruce Gust

ASKER

So, I am barking up the right tree, yes...

 $('a[href="#summary"]').on('click', function(){
        setTimeout(function(){
            HealthSummary.init();
        }, 250);
    });

This is instantiating the "HealthSummary" object which is "var HealthSummary=" and all the functionality that follows, yes?

I'm pretty sure about the Laravel routing - one of the advantages of working with a page that works. But I wanted to get someone else's eyes on my logic in terms of the "flowchart" with the link -> $('a[href="#summary"]').on('click', function(){ -> HealthSummary object.

That's the right flow, yes?
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, gentlemen!

I've got another question at https://www.experts-exchange.com/questions/29025252/How-do-I-pass-another-variable-into-this-function.html. If you've got the time, I would welcome the input.

Thanks, again!
You are welcome.