Thanks Thadeus, I'll take a look at your patches and try to
incorporate them shortly.
On the stars issue, once the elements are replaced, the events are
destroyed in jQuery. I think the best solution here is to not replace
the elements but to return a script that alters the src attributes of
the existing images to reflect the choice. Something like this maybe:
jQuery.each(jQuery("#sdiv").children(), function(){...test and alter
src..});
On Sep 20, 10:33 pm, Thadeus Burgess <[email protected]>
wrote:
> I am trying to implement a stars rating function using clienttools (which is
> awesome)
>
> When it returns new DOM, the stars are replaced correctly, however the
> jquery stops working on the new stars, even though the ID's are the same,
> How would you do this so that the stars get replaced, and jquery still work
> on them?
>
> def teststars():
> stars = []
>
> txt = ""
> for i in range(0,5):
> star = IMG(_src=S("images/star_void.gif"), _id="star%d" %(i))
> event.listen("click", star, handle_it, success="#sdiv",
> handler_args=[i])
> stars.append(star)
> txt += "%s" % star
>
> sdiv = DIV(XML(txt), _id="sdiv")
>
> return dict(d=sdiv)
>
> def handle_it():
> value = int(request.args(0))
> stars = []
> txt = ""
>
> for i in range(0, 5):
> if i <= value:
> img = "images/star_full.gif"
> if i > value:
> img = "images/star_void.gif"
>
> star = IMG(_src=S(img), _id="star%d"%(i))
>
> stars.append(star)
> txt += "%s" % star
>
> return txt
>
> -Thadeus
>
> On Sun, Sep 20, 2009 at 10:00 PM, Thadeus Burgess <[email protected]
>
> > wrote:
> > Also, to allow passing a custom CSS selector to the success, for when you
> > don't want to create the representation in controller
>
> > 132 if hasattr(success,'xml'):
> > 133 if success['_id']:
> > 134 success = 'jQuery("#%s").html(msg);' % success['_id']
> > 135 else:
> > 136 raise ValueError('Invalid success component for event.
> > No ID attribute found.')
> > 137+ else:
> > 138+ success = 'jQuery("%s").html(msg);' % success
>
> > -Thadeus
>
> > On Sun, Sep 20, 2009 at 9:40 PM, Thadeus Burgess <
> > [email protected]> wrote:
>
> >> Thats cool!
>
> >> Here is a patch to allow for passing args to the handler URL.
>
> >> 115- def listen(self, event, helper, handler, success="eval(msg);",
> >> data='form:first'):
> >> 115+ def listen(self, event, helper, handler, success="eval(msg);",
> >> data='form:first', handler_args=''):
>
> >> 137- url = URL(r=self.environment.request,f=handler.__name__)
> >> 137+ url =
> >> URL(r=self.environment.request,f=handler.__name__,args=handler_args)
>
> >> -Thadeus
>
> >> On Sun, Sep 20, 2009 at 9:19 AM, mr.freeze <[email protected]> wrote:
>
> >>> Thanks Iceberg. I'll try to post more examples that show the
> >>> difference. Also, if you think of anything it could be doing better,
> >>> let me know.
>
> >>> On Sep 20, 6:57 am, Iceberg <[email protected]> wrote:
> >>> > On Sep20, 2:14am, "mr.freeze" <[email protected]> wrote:
>
> >>> > > Hi folks,
>
> >>> > > I just wanted to share a module that I'm working on for a
> >>> > > project. It contains tools for managing client events and resources
> >>> > > from the server. Here are the main features:
>
> >>> > > 1) Dynamic inclusion and downloading of resources (scripts/css).
> >>> > > 2) Server side event handling for client side events.
> >>> > > 3) Dynamic execution of script from the controller. (through
> >>> > > document.ready injection)
> >>> > > 4) Helpers for google hosted ajax APIs.
>
> >>> > > You can see instructions and examples here:
>
> >>> > >http://www.web2pyslices.com/main/slices/take_slice/8
>
> >>> > > It's definitely a work in progress, but let me know what you think.
>
> >>> > > -Nathan
>
> >>> > After trying to implement your 4 examples in a "normal" way, which
> >>> > turns out to be tricky or even difficult (especially in the last two
> >>> > cases), I am convinced that this client tools have its great value!
> >>> > Well done, Nathan!
>
> >>> > This stuff looks cool. Would you please give some more example (in
> >>> > your slice site) to demonstrate what mission this tool performs easier
> >>> > than otherwise?
>
> >>> > I don't mean this stuff is not good. I just have poor imagination and
> >>> > sorry for that. :-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---