Skip to content

Instantly share code, notes, and snippets.

@buntine
Created May 15, 2012 02:27
Show Gist options
  • Save buntine/2698635 to your computer and use it in GitHub Desktop.
Save buntine/2698635 to your computer and use it in GitHub Desktop.
//Selecting Item Colours
$(".dress-container .select-colour a").click(function(){
//find the colour range
var colourRange = $(this).parent().next(".colours");
//find the links in the colour range
var colourRangeLink = $(colourRange).find("a");
//showing colour range
$(colourRange).show();
//choose colour and make default colour the selected colour
$(colourRangeLink).click(function(){
//getting the choosen colour and replace default colour
var colour = $(this).attr("href").substr(1);
$(this).parents(".dress-container").find(".selected-colour").html(colour);
//hide range
$(".colours").hide();
return false;
});
return false;
});
//Adding selected item on mannequin and adding item to cart list.
$(".dress-container a.add").on("click", function() {
//get item id, type (for layering), price and name
var id = $(this).attr('href').substr(1);
var type = $(this).siblings('img').attr('class');
var itemPrice = $(this).siblings(".itemprice").html();
var itemName = $(this).siblings(".itemname").html();
//add respective item image to mannequin
var itemImage = '<img src="site_media/img/dress/full/'+ id +'.png" title="" alt="" class="'+ type +'" witdh="400" height="600" />';
alert(defaultColour);
// if ( colour == null) {
// colour = $(this).siblings(".selected-colour").html();
// }
var chosenItem = '<li>' + itemName + ' - ' + colour + '<br />' + itemPrice + '</li>';
$("#dressing-room").last().append(itemImage);
$("#dressing-cart").append(chosenItem);
$(this).hide();
return false;
});
but i'm not putting it in a function
$(".dress-container a.add").on("click", function() {
var li = $(this).closest("li");
choose_item(li);
return false;
});
function choose_item(li) {
//getting the default colour
var defaultColour = li.find(".selected-colour").html();
alert(defaultColour);
/* //Adding selected item on mannequin and adding item to cart list.
//get item id, type (for layering), price and name
var id = $(this).attr('href').substr(1);
var type = $(this).siblings('img').attr('class');
var itemPrice = $(this).siblings(".itemprice").html();
var itemName = $(this).siblings(".itemname").html();
//add respective item image to mannequin
var itemImage = '<img src="site_media/img/dress/full/'+ id +'.png" title="" alt="" class="'+ type +'" witdh="400" height="600" />';
// if ( colour == null) {
// colour = $(this).siblings(".selected-colour").html();
// }
var chosenItem = '<li>' + itemName + ' - ' + colour + '<br />' + itemPrice + '</li>';
$("#dressing-room").last().append(itemImage);
$("#dressing-cart").append(chosenItem);
$(this).hide();
return false;
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment