[support] I have a shopping cart block within the main pages that I want to refresh by calling the div called "panel-pane pane-block pane-uc-cart-0" every 2.5 seconds.

Carl Wiedemann carl.wiedemann at gmail.com
Thu Jan 27 18:13:00 UTC 2011


Questions that deal with code are generally better suited for the
development list; nevertheless, here are some tips to get you started. :)

You first need a query that returns the block's markup independent of
anything else. In your own custom module, you would probably have to write
your own AJAX menu callback in hook_menu() which *prints* (or uses
drupal_json) of the hook_block() markup from uc_cart.module.

In your module's hook_init() you use drupal_add_js() to load a JS file that
would implement the setInterval when the document is loaded. The best
practice for this is in JS is to leverage Drupal.behaviors, e.g.,

Drupal.behaviors.foo = function() {
// setInterval stuff goes here to call AJAX menu callback specified in
hook_menu().
}

Drupal.behaviors calls the specified function when the DOM is completely
loaded (i.e. whenever Drupal.attachBehaviors is called). Check
out Drupal.behaviors.password in modules/user/user.js for one such example.

Make sure you use proper access control in the hook_menu() callback. Also
consider how this solution will scale.

On Thu, Jan 27, 2011 at 7:21 AM, John Mitchell <mitchelljj98 at gmail.com>wrote:

> I have a shopping cart block within the main pages that I want to refresh
> by calling the div called "panel-pane pane-block pane-uc-cart-0" every 2.5
> seconds.
> What is the most efficient way to implement this?
>
> I believe the way to call the javascript within drupal is by using the
> drupal_add_js() command but where do I put these commands so that the timer
> is run to refresh this shopping cart block every 2.5 seconds?  I have seen
> some documentation that recommends using hook_init for javascript that is
> needed for all pages.
>
> I believe that the timer is setup by running the command:
>         *setInterval(shoppingCartInfo, 2500);*
> With shoppingCartInfo being a command that does a call to refresh the
> shopping cart block which could be a set of ajax calls or maybe command like
> *window.panel-pane pane-block pane-uc-cart-0.refresh().
> *
> Thanks,
>
> John
>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110127/6026887a/attachment.html 


More information about the support mailing list