jquery question

Events happening in the community are now at Drupal community events on www.drupal.org.
royerd's picture

Hi Jon:

Perhaps you can give guidance to me on this matter. And if you don't have time, I understand of course.

A programmer on a site I work with was having trouble with a collapsed field group not opening and says that there is a bug in the views_slideshow.js I wondered if you could look at this patch and tell me if this is something I should pass on to the folks that maintain that module or if, instead, this is not needed or even a symptom that he's done something wrong in the module he built.

Here's the patch:

Index: views_slideshow.js
===================================================================
--- views_slideshow.js    (revision 9255)
+++ views_slideshow.js    (working copy)
@@ -157,7 +157,11 @@
        }
      }

-    $(settings.targetId).cycle(settings.opts);
+    try {
+        $(settings.targetId).cycle(settings.opts);
+   } catch (err) {
+    return ;
+   } ;

      // Start Paused
      if (settings.start_paused) {

And his initial note to me about this was here--then the patch above followed. Is he correct in finding a bug here?

Here's the exchange (in reverse order with the initial note to me at the very bottom):

Never said there were broken slide shows. I said that views_slideshow.js (javascript) is, somehow broken and is breaking other pieces of the UI in the main web site, in particular the collapsible fieldset on the Your Asset Module page. Visible by firing up You Asset Module. Bring up firebug. Reload the page (note that the Import Asset fieldset isn't enabled). You'll see the error in the firebug console. Because of this error no other js executes and the UI is incompletely instantiated. Thus a bug in views_slideshow.js.

Best,

On 4/14/11 12:40 PM, Daniel Royer wrote:
I'm not seeing any broken slideshows. The three used on the front page seem to be working fine.

Which one is broken? I'm sorry. . . . guess I don't understand.

Dan

On 4/14/2011 at 12:36 PM, in message 4DA7229D.3080700@csworks.com, Dick M. wrote:

and is causing problems with [at least] the asset tool's user interface, i.e.,the collapsible fieldset doesn't get enabled because the js error happens before it gets a chance to run.

The error is:

$(settings.targetId).cycle is not a function
$(settings.targetId).cycle(settings.opts); Line 160 of views_slideshow.js

According to the javascript console in firefox.

I suspect that unless you actually HAVE a slideshow active (which the Your Asset Module page definitely doesn't, at least I didn't put it there) then you shouldn't be including views_slideshow.js. Of course, there may be a views slideshow here somewhere, but I don't know how to figure that out.

Anyway, looks like a bug in view and/or the views supporting code, so... to you.

Best,

Comments

Well, the try/catch proposed

jonbob's picture

Well, the try/catch proposed in the patch would solve the symptom being reported (that other things on the page are breaking), but doesn't really address the root issue, so it isn't appropriate for a patch to the module. A real solution would prevent the JS error in the first place, not just handle the error.

I'm not familiar with this module, so I'm not sure how it is supposed to work, but I see from the error that it is trying to use jQuery's Cycle plugin to do its job. That error message ($(settings.targetId).cycle is not a function) could be thrown for two reasons. First, it would be reported if Cycle were not loaded. I don't know whether that happens automatically by the module, or if something else needs to load that. I suspect, since slideshows on the site are working, that this is not the issue. The other possibility is that settings.targetId is not pointing to a DOM element. That sounds consistent with the theory here. However, I don't know how that is getting populated.

So I guess in summary: this is probably a bug in that module, and you can use the patch on your site to solve some of your problems, but the patch isn't one that should be put on the module and distributed.

Jon, you are a treasure.

royerd's picture

Jon, you are a treasure. Thanks so much for this response. Very helpful.

Yes, that module is a custom module, not a contributed module.

Dan

Grand Rapids, MI

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: