jQuery and Weblocks

66 views
Skip to first unread message

elz...@gmail.com

unread,
Apr 23, 2012, 5:49:00 AM4/23/12
to webl...@googlegroups.com
Disclaimer: I am very new to actually producing Weblocks applications.

I was wrapping a bit of jQuery code (Galleria) in a widget and found out that just including jQuery in my dependencies breaks the auto-update of widgets.  I wanted to see if this is just the expected behavior and it is some kind of jQuery/Prototype conflict, or something else .  This might very well be a some other kind of error.  Here is my test case:

http://paste.lisp.org/display/129114

Without jQuery, you can increase and decrease the number-box widgets.  With jQuery loaded, the links make no immediate changes, but after a page refresh, the changes show up.

Also, any thoughts on a cleaner way to do this kind of demo program (although I am happy with everything except the inline style, but that is just for convenience during development).  I am trying to write a tutorial reflecting the current recommendations on how to use Weblocks while I am learning (i.e. focus on widgets and dispatch facilities, leave out views, downplay continuations).

Zach KS

Zach Kost-Smith

unread,
Apr 24, 2012, 12:02:57 PM4/24/12
to webl...@googlegroups.com
Figured it out.  It is pretty common for jQuery to conflict with Prototype, it seems.  See http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Just insert a script a jQuery.noConflict() call on every page that loads jQuery.  Then, wrap your jQuery code in an environment like:

     // Put all your code in your document ready area
     jQuery(document).ready(function($){
       // Do jQuery stuff using $
       $("div").hide();
     });

Or like this in parenscript:

(ps:ps
  (ps:chain (j-query document)
            (ready (lambda ($)
                     "simple"))))

I suppose the best idea is to define a script that just executes the noConflict function (which you include in your dependencies) and a macro environment for re-enabling jQuery's $ syntax.  Hope this helps others.

Zach KS
Reply all
Reply to author
Forward
0 new messages