Re: JQuery HELP!

Posts: 67
Joined: 08/08/2007
Early adopter... addicted to alphas.Getting busy with the Ubercode.

Ok, so I'll go through my steps, at least so far. I copied the node.tpl file into one called node-personalised_cards.tpl.php because my class for my product was personalised_cards. Then at the top of that I've added these lines:

<?php drupal_add_js(path_to_theme()."/personalised.js"); ?>
<?php
drupal_add_js
("if (Drupal.jsEnabled) {  $(document).ready(function(){font_set_onchange('".base_path()."','".path_to_theme()."')}); }",'inline');
?>

Basically that adds my javascript file and then adds my function call to when the page loads. Then I have the attached javascript file. I'm not pasting it in because part of it is long. In that I have both the image change, and the price change when the quantity changes. The quantity one is the longest, so I'll just copy and paste there the parts that is just for the image change for the font:

function font_set_onchange(base_path, path_to_theme){
$("#edit-attributes-3").change(function(){font_image(base_path, path_to_theme)});
font_image(base_path, path_to_theme);
quantity_set_onkeyup();  // not needed for just the font change
colour_set_onchange();   // not needed for just the font change
}

function font_image(base_path, path_to_theme){
var font_value = $("#edit-attributes-3 option:selected").val();
$('#fontimage').remove();
var path = base_path+path_to_theme+'/images/font_images/'+font_value+'.gif'
$("#edit-attributes-3").after("&nbsp;&nbsp;&nbsp;<img src=\"" + path + "\" id=\"fontimage\"/>");
$("#edit-attributes-3").parent().attr("width","250px");  // this is because of a strange behavior where the div doesn't seem to adjust to the size with the image and moves the next line down a little way for a long image
}

Anyway, have a look through that, and if there are any questions, let me know. The quantity stuff is pretty neat, because I had to put it on a timeout so that if someone is entering in several keystrokes, it only picks up once they pause. I also plan to put in that once it gets above a certain amount, they can't add it to the cart. For this site, once they want above 5000 cards, it is a special order, so they'll have to call up. We don't expect it to happen that often...haha.

Cheers,
Steph

AttachmentSize
personalised.js_.txt2.74 KB
JQuery HELP! By: ssherriff (11 replies) Wed, 08/08/2007 - 09:45