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

asked on

How do I keep these two scripts from stepping on one another?

Head out to http://www.brucegust.com/portfolio/verizon/index_static.php#

There are two ways that you can hide and show the different events on the calendar. One is by using the little keyboard on the left, the other is the list of states that show up when you click on the number to the right of each month.

The problem is this: While for the most part, everything works well, on occasion, you'll click on a "calendar" (which is a series of regions that potentially include a number of states) and when you go to click on a state, because of the "queue" that I've got set up, the resulting collection of layers doesn't make sense.

So what I need to do is figure out how to ensure that every time my user clicks on a region on the keyboard, whatever "queue" has been cached has been reset so it's as if the page has been reloaded.

In other words, these functions:

function SCTL()
{
      queue.SCTL=true;
      queue.SCTL_long=true;
      
      $("Arkansas,.Florida,.Georgia,.Kentucky,.Louisiana,.Mississippi,.North Carolina,.Oklahoma,.South Carolina,.Tennessee,.Texas").show();
      $(".CATN,.FL,.CTX,.HGC,.GAAL,.AREA,.ALU,.ERC,.DEVICE, .CATN_long,.FL_long,.CTX_long,.HGC_long,.GAAL_long,.AREA_long,.ALU_long,.ERC_long,.DEVICE_long").hide();

      for( var state in queue)
      {
         $("." + state).show();
      }
      
return true;
}

...will sometimes prove problematic if the user has been hiding and showing various regions using the keyboard. I believe it's because the "queue" is storing certain "show" values and I need to make sure that doesn't happen.

You'll see how I solved my "calendar" problem by including "$(".CATN,.FL,.CTX,.HGC,.GAAL,.SCTL,.ALU,.ERC,.DEVICE, .CATN_long,.FL_long,.CTX_long,.HGC_long,.GAAL_long,.SCTL_long,.ALU_long,.ERCLong,.DEVICE_long").hide();" in every state function. This guarantees a clean starting point, as far as the various regions' visibility.

But I can't figure out how to ensure the same kind of clean slate when my user is working with the regions and as a result, sometimes certain states aren't showing up when their corresponding region has been clicked.

What do you think?
SOLUTION
Avatar of Rob
Rob
Flag of Australia 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
SOLUTION
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
Avatar of Bruce Gust

ASKER

Gentlemen!

Thanks for the feedback! I've come up with a plan after having read your comments and spending some time with my code this am.

I incorporated some "alerts" into my script so I could better see what was going on. The good news is that everything is working exactly as it should. The challenge is accommodate the "queue" variables, especially when going back and forth between the two different options (calendar and states).

What I've decided to do is check to see what's in either "queue" or "the_queue." "the_queue" is the variable in my calendars code, "queue" is what I'm using with my states. The question that I need answered is this:

When I do: alert(JSON.stringify(queue), I get either "{}" or "Alabama=true" etc. I want to simply see if there's anything in the array. I've tried this:

if (queue === 'undefined') {
            alert("nothing");
      }

...and nothing happens. Even when I know there's nothing in "queue," nothing fires.

Even when I try something like:

if(queue.length>0) - nothing happens.

How can I check to see if there are any values in my queue array? If I can get that piece figured out, I believe we'll be poised on the threshold of great things.

Thanks!
ASKER CERTIFIED SOLUTION
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
SOLUTION
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