2

I'll be very specific here. If you go to UtahRealEstate.com and do a search and look at the results in the map view, there are plots all over the map and listings off to the right. If you click a pin on the map you get a pop-up, then click the MLS # and you get another popup with the property description. You can also click the MLS number on a listing on the right and open a property description popup.

I want to add a button in the html of that popup. I can insert the html fine, but the challenge is, how do I determine when that property description has loaded so I can then read the html inside it and add my button?

Screenshots:

enter image description here

enter image description here

enter image description here

Mike Grace
  • 16,636
  • 8
  • 59
  • 79
Dustin
  • 3,965
  • 5
  • 27
  • 33
  • It's a bit trickier than at first glance. There are a couple of aspects that make what you are trying to do a bit tricky so I am working on an answer right now. – Mike Grace Feb 03 '11 at 21:28
  • There are different map views. How did you get to the map view that you want to work on first? Could you post a screen shot of the specific map view you are talking about? – Mike Grace Feb 03 '11 at 21:35
  • The screenshots are exactly what I'm referring to. Thanks for posting them. I'm not sure of different map views. I'm just doing a search for say "Alpine, UT", the looking at the results in the map view. If you do the list view and click the View Property, It loads a page for that property and I have a button being inserted there. It's just thick box view that I'm not sure how to know when it is loaded completely to trigger the js function. – Dustin Feb 03 '11 at 23:35

2 Answers2

1

Short answer (I'll edit later):

Use the action Watch to watch a selector.

Then, use the select when click.

Jessie A. Morris
  • 2,267
  • 21
  • 23
1

I used the trick where you don't look for elements until you have to based on user clicks. The real tricky part was that the MLS number link that shows up in the card on the map was halting the propagation of the click event to the window so I couldn't use the live click binding.

I'm really sick so I can't stay up much longer but the code is fairly well commented so you should be able to read your way through my madness. ; )

ruleset a60x561 {
  meta {
    name "utahrealestate"
    description <<
      utahrealestate
    >>
    author "Mike Grace"
    logging off
  }

  dispatch {
    domain "utahrealestate.com"
  }

  rule search_for_realestate {
    select when web pageview "\/search\/"
    pre {

    }
    {
      notify("title","content") with sticky = true;
      emit <|
        // sidebar click watching easy
        // click event isn't being blocked so we can use .live and not 
        // worry about HTML being present at time of event listener binding
        $K(".full_line a").live("click", function() {
          console.log("sidebar mls clicked");
          // get the report!!!
          KOBJ.a60x561.getReport();
        });

        // pin on map mls number is a bit harder because click event is 
        // being blocked from propegating to the window
        // to get around this we can
        // 1) watch for click on pin
        // 2) wait for mls element to load
        // 3) attatch our own element level event listener
        $K("#mapdiv_OpenLayers_Container image").click(function() {
          console.log("pin on map clicked");
          // attatch click event listener on mls element once it loads
          setTimeout(function() {
            KOBJ.a60x561.grabMls();
          }, 500);
        });  

        // ATATCH LISTENER TO MLS NUM ON MAP
        KOBJ.a60x561.grabMls = function() {
          console.log("looking for mls in hovercard");

          // grab jQuery reference to element we are looking for
          var $cardMls = $K("#property-overview a:first");

          // only go on if it's on the page and visible
          if ( ($cardMls.length > 0) && ($cardMls.is(":visible")) ) {

            console.log("foud mls on hevercard");

            // watch for click on mls num on card
            $cardMls.click(function() {
              console.log("mls clicked on hovercard above map pin");
              // get the report!!!
              KOBJ.a60x561.getReport();
            });
          } else {
            setTimeout(function() {
              KOBJ.a60x561.grabMls();
            }, 500);
          };
        };

        // GRAB REALESTATE LISTING DETAILS ONCE IT LOADS IN THICK BOX
        KOBJ.a60x561.getReport = function() {
          if ($K("#public-report-wrap").length > 0) {
            console.log("Listing details found!");
          } else {
            setTimeout(function() {
              KOBJ.a60x561.getReport();
            }, 500);
          };
        };
      |>;
    }
  }
}

Screenshot of firebug console as I test the app

enter image description here

Dustin
  • 3,965
  • 5
  • 27
  • 33
Mike Grace
  • 16,636
  • 8
  • 59
  • 79
  • This worked great. There was an issue when you clicked a pin while one hovercard was already open, so I made a minor modification. Other than that, perfect! – Dustin Feb 04 '11 at 20:38
  • SWEET! Yeah, I forgot to test that use case. Glad I could help out. – Mike Grace Feb 04 '11 at 23:43