tags:

views:

166

answers:

2

I'm working on an online ordering system for photography clients: Here. (Forgive the requirement of having to sign in).

After signing in, the user is able to rate pictures using the stars listed below each picture, then subsequently view 3 star pics, or 4 star pics, etc. However, when the user clicks on an image, a lightbox expands (prettyPhoto namely) which contains the picture as well as the stars listed below. I want users to be able to star a picture within the lightbox, but the javascript is not being passed after the prettyPhoto lightbox is initialized. Consequently, they can't rate pictures within the lightbox. I've heard of something similar to this, but have no idea about how to go about tackling the problem. Any help would be appreciated. Thanks!

A: 
could this work for you ?

$.noConflict();
$(function($) {
     //you jquery here
});
Puaka
I'm quite the newbie....how exactly would I implement that? Would I put the script reference in there?
Dustin
before execute your pretty photo script, just put $.noConflict(). something like this : eg.<script src="other script here e.g prototype"></script><script src="jquery"></script><script>$.noConflict();</script>im not sure this will solve your problem, you can try. read more here http://api.jquery.com/jQuery.noConflict/
Puaka
I'm only using jquery on this....thanks though
Dustin
A: 

You labeled this as "ajax", is that because the star rating system is being pulled in via ajax? If so, then the problem would be the (most likely) click event bound to the stars. You would need to use jQuery's "live" or "delegate" functions.

This is also the case if you're using javascript to write the HTML of the star selection piece to the DOM any time after the page is initially loaded (or after the click event is initially bound).

Or the problem could be with the selector markup... if, for example, you're star rating system is something like:

<ul id="star-rating-system">
    <li><img href="star.png" alt="star" /></li>
    <li><img href="star.png" alt="star" /></li>
    <li><img href="star.png" alt="star" /></li>
    <li><img href="star.png" alt="star" /></li>
</ul>

Then there may be an issue with having 2 things on the page with the same ID, which would cause a problem.

Do you think you could provide a bit more information for more clarity? For example, the HTML for the star rating system, and any information about how or if you altered the original prettyPhoto javascript.

RussellUresti
I have a foreach loop in php that queries a db. The image is an href with a link to a unique div. e.g. <a href="#inline_demo<?php echo $i?>" rel='prettyphoto'><img....></a><input name="star<?php echo $k; ?>" id="1" type="radio" class="star"/>....that div is hidden until I click on the image link, then I have the following displayed: <div id="inline_demo<?php echo $k?>" style="display:none; margin: auto;"> ....image here....<input name="star<?php echo $m; ?>" id="1" type="radio" class="star"/></div>
Dustin
And what's the javascript code that controls the star rating?
RussellUresti
$(window).load(function(){ $('.star').click(function() { id = $(this).attr('id'); ids = id.split('//'); rating = ids[0]; image = ids[1]; email = '<?php echo $_SESSION['email'];?>'; if (image != null){ $.post("<?php echo site_url('ordering/rate_pic') ?>", {imagename: image, rating:rating, email: email},function(data) { alert(data); }); } else { url = "<?php echo site_url('ordering/show_only_star'); ?>/" + rating + " #img_pic"; $('#img_pic').load(url, function(data) { $.getScript("<?php echo $url ?>star/jquery.rating.js"); }); } }); });
Dustin
It doesn't seem like it should need it, but have you tried using $('.star').live('click',function(){ ...code here... }); instead of $('.star').click(function() { ...code here... }); It's worth a try, depending on how the modal is behaving. It seems like it may be removing the HTML and then reattaching it to the DOM at the time of execution. You'll need jQuery 1.4 or later, I believe.
RussellUresti
Brilliant! Works like a charm now!...however, the star hovering isn't working. I'm not too picky, but is there any way to get that to work too?
Dustin
Hovering is a bit trickier. You'll need to use the live() function again, but you can only pass it 1 function (instead of passing it 2 like you would a normal hover() function). So, you can use something like $('.star').live('hover',function(){ $(this).toggleClass('hovered');}); or you can specifically set live('mouseover',function()) and live('mouseout',function()) calls. The 2 separate ones will be most easiest.
RussellUresti