Calling gwd functions from a separate js file

631 views
Skip to first unread message

Matt Phillips

unread,
Jun 2, 2015, 12:30:39 PM6/2/15
to gwd...@googlegroups.com
Hello,

Seeing an issue here with an expandable ad. Instead of using the click component, I'm calling gwd.handleExpand_buttonAction(); from within my custom js file to expand the ad. The reason for this is that the ad loads dynamic results for real estate search depending on what is returned, and updates the p tags with jQuery .text(). However, if the event handler for the expand occurs after my populateResults function is called, the fields don't get updated (or, I suppose, are getting overwritten with the default values). Anytime I try and call gwd.handleExpand_buttonAction(); within my file, it always loads after my results function. If I call the expand within GWD its ok, however, I need to call it within my file so that it only expands conditionally on any results being returned (don't want it to expand and show blank data if no listings are present). I'd rather not use a javascript setTimeout as that could be unreliable. Any suggestions?

   -Matt-

Kishore Subramanian

unread,
Jun 3, 2015, 1:54:51 PM6/3/15
to gwd...@googlegroups.com
Is it possible for you to provide the code snippet of both the generated gwd.handleExpand_buttonAction and your custom code?

Matt Phillips

unread,
Jun 3, 2015, 2:17:37 PM6/3/15
to gwd...@googlegroups.com
Hi Kishore,

Here's a zip with all raw and published assets. "christies_expand.js" is my custom file. Function window.searchResults gets all the data and pushes it into an array. window.popResults then navigates to the next page and loads the data. Ideally I'd call "gwd.actions.gwdDoubleclick.goToPage('gwd-ad', 'expanded-page');" at the top of the popResults function (you'll see it commented out) rather than from the GWD event "gwd.searchResults" the way it is now, but from within my js is where I've been having load priority issues

   -Matt-
christies_expand.zip

Matt Phillips

unread,
Jun 16, 2015, 1:38:38 PM6/16/15
to gwd...@googlegroups.com
Any update on this issue? I often need to implement this in the ads we do, so any help would be great

   -Matt-

Jaz

unread,
Jun 22, 2015, 1:28:12 PM6/22/15
to gwd...@googlegroups.com
Hi Matt,

Just a quick note, we'll take a look at this and get back to you asap.

thx
jaz
Program Manager, GWD

Kishore Subramanian

unread,
Jun 22, 2015, 1:41:44 PM6/22/15
to gwd...@googlegroups.com
Hi Matt,

Can you try by replacing the jquery $(#id) calls with gwd.actions.events.getElementById(id) ?
For example, in christies_expand.js, replace:
$('#address').text($(results_xml[result_index]).find('Address').text());
with
$(gwd.actions.events.getElementById('address')).text($(results_xml[result_index]).find('Address').text());

and so on for all the $(id) values. 

The reason: GWD runtime only keeps the current page (GWD page) in the DOM. So if the user is in the invitation state, the expanded page is not in the DOM. Since, popResults is invoked when the user is in the invitation state, the expanded page elements are not in the DOM and hence jQuery('#address') etc will return an empty jquery object. However, gwd.actions.events.getElementById will do the right thing and return the Element. jquery(element) will create a jquery object for the element.

Let us know if this works.

Matt Phillips

unread,
Jun 22, 2015, 1:49:17 PM6/22/15
to gwd...@googlegroups.com
Hey Kishore,

Thanks for getting back to me. I just tried this and it worked perfectly. I was wondering if this was a DOM issue since the functions appeared to be firing when intended, so that makes total sense. I know jQuery can be a bit heavy but it works really well for the dynamic nature of our ads. I'll use gwd.actions.events.getElementById going forward to make sure elements are always present in the DOM. Thanks again!

   -Matt-
Reply all
Reply to author
Forward
0 new messages