Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // <2012-02-07><LLEE><Inventory check><search for maxQuantity below>
- function InitAkin( select ){
- var dimension1, dimension2, dimension3, size, color, style, sizeID;
- $('.add-to-cart > label').removeClass('hidden');
- $.ajaxSetup({ cache:false });
- if ( select ) {
- sizeID = $(select).find("option:selected").attr('data-productid');
- } else {
- sizeID = $('#size option:selected').attr('data-productid');
- }
- if ( select ) {
- size = $(select).val();
- } else {
- size = $('#size').val();
- }
- color = $('#color').val();
- style = $('#style').val();
- if(size != undefined && color != undefined && style != undefined) {
- dimension1 = size;
- dimension2 = color;
- dimension3 = style;
- } else if(size == undefined){
- if(style == undefined){
- dimension1 = color;
- } else if(color == undefined){
- dimension1 = style;
- } else {
- dimension1 = color;
- dimension2 = style;
- }
- } else if(color == undefined){
- if(size == undefined){
- dimension1 = style;
- } else if(style == undefined){
- dimension1 = size;
- } else {
- dimension1 = size;
- dimension2 = style;
- }
- } else if(style== undefined){
- if(size == undefined){
- dimension1 = color;
- } else if(color == undefined){
- dimension1 = size;
- } else {
- dimension1 = size;
- dimension2 = color;
- }
- }
- // Hide option if only one value
- if ( $("select#color:eq(0)").find("option").size() < 2 ) {
- $("select#color").hide();
- }
- if ( $("select#size(0)").find("option").size() < 2 ) {
- $("select#size").hide();
- }
- if ( $("select#style:eq(0)").find("option").size() < 2 ) {
- $("select#style").hide();
- }
- var akinCount = $("#hidden-akin-count").val();
- var displayFlag = false;
- if(akinCount == 1 && (dimension1 != undefined || dimension2 != undefined || dimension3 != undefined))
- displayFlag = true;
- else if(akinCount == 2 && dimension1 != undefined && dimension2 != undefined)
- displayFlag = true;
- else if(akinCount == 3 && dimension1 != undefined && dimension2 != undefined && dimension3 != undefined)
- displayFlag = true;
- $.getJSON('fetch.aspx?CN=90C4D5C13CDA&DIMENSIONELEMENTID1=' + dimension1 + '&DIMENSIONELEMENTID2=' + dimension2 + '&DIMENSIONELEMENTID3=' + dimension3 + '&PRODUCTAKINID=' + $('#tbCN').val(), function(data){
- if(displayFlag == true)
- {
- var imgPathSect = "";
- var newImageSource = "";
- var price = 0;
- if (data.PRICEAMOUNT === "")
- {
- $('.price').text("");
- }
- else
- {
- price = data.PRICEAMOUNT;
- if ( price.indexOf(".") != -1 ) {
- price = price.split(".");
- }
- $(".add-to-cart .dollar-value").text(price[0]);
- $(".add-to-cart .cent-value").text(price[1]);
- if(ExecuteCufon()) {
- Cufon.replace("#prod-price");
- Cufon.replace(".dollar-value");
- Cufon.replace(".cent-value");
- }
- //$('.price').text(Globalize.format(parseFloat(data.PRICEAMOUNT), "c"));
- }
- $('.btn-add-to-cart').data('sizeid', data.ITEMID );
- $('.btn-add-to-cart,#button-add-to-wishlist').data('dimension', data.DIMENSIONID );
- // MM Disable buttons if no item for selected combination
- if( data.DISABLECLASS === "disabled") {
- $('.btn-add-to-cart, #button-add-to-wishlist').attr("disabled", true).css({ cursor: "default" });
- } else {
- $('.btn-add-to-cart, #button-add-to-wishlist').removeAttr("disabled").css({ cursor: "pointer" });
- }
- // Image source replace
- /*
- if ($('#akin-image').is('.hide-image') == false)
- {
- $('#akin-image').removeClass('hidden');
- imgPathSect = data.MEDIA2.split('\\');
- newImageSource = $('#image-path').val() + imgPathSect[imgPathSect.length - 1];
- $('#akin-image').addClass('loading');
- $('#akin-image img').attr( 'src', unescape(newImageSource) );
- }
- */
- $('#button-add-to-cart').data("image", newImageSource);
- $("#tbTRACKMAXQUANTITY").val(data.TRACKMAXQUANTITY);
- $("#tbQTYAVAILABLE").val(data.QTYAVAILABLE);
- var stockIndicator = data.STOCKINDICATOR || null;
- if ($("#tbTRACKMAXQUANTITY").val() === true || $("#tbTRACKMAXQUANTITY").val() === "true" || $("#tbTRACKMAXQUANTITY").val() === "TRUE")
- {
- $("#stockMsg").removeClass("in-stock").removeClass("no-stock");
- if (parseFloat($("#tbQTYAVAILABLE").val()) > 0.00 && stockIndicator != "O" )
- {
- $("#stockMsg").removeClass("hidden").addClass("in-stock");
- $(".btn-add-to-cart").removeClass('no-stock');
- }
- else
- {
- $("#stockMsg").removeClass("hidden").addClass("no-stock");
- $("#aNotify").unbind("click").bind("click", function () {
- notify(data.ITEMID, data.DIMENSIONID);
- });
- $(".btn-add-to-cart").attr("disabled", "disabled").addClass('no-stock');
- }
- $("#stockMsg").show();
- }
- if ( $('#addToCart2').find('select:visible').length == 0 )
- {
- $('#addToCart2').addClass('no-dimensions');
- }
- $("button[data-method='AddToCart']").show();
- }
- });
- }
- function notify() {
- var contentid, dimensionid, url;
- var contentid = arguments[0];
- if (arguments.length == 2)
- {
- dimensionid = arguments[1];
- url = "Ajax.aspx?CN=A7ACDF319D66&CONTENTID=" + contentid + "&DIMENSIONID=" + dimensionid;
- }
- else
- {
- url = "Ajax.aspx?CN=A7ACDF319D66&CONTENTID=" + contentid;
- }
- var dialog = $("#notify");
- dialog.load(url, function() {
- var notifyButton = {
- text: $('#notifyform').attr('data-button'),
- click: function () {
- $('#notifyform').validation({
- form: 'notifyform',
- success: function() {
- $("#notifyform").AjaxCall({
- url: "Ajax.aspx?CN=A7ACDF319D66",
- type: "POST",
- complete: function(data){
- $('#notify').html('');
- $('#notify').append($(data).find('#notify-message'));
- $('#notify-message').show();
- $("#notify").dialog("option", {
- buttons: {},
- height: 140
- });
- }
- });
- }
- });
- }
- };
- $("#notify").dialog( "option", "buttons", [ notifyButton ] );
- dialog.dialog("open");
- });
- }
- function invite(contentid) {
- var contentid, url;
- url = "Ajax.aspx?CN=5C02F3C0F570&CONTENTID=" + contentid;
- var dialog = $("#invite");
- dialog.load(url, function() {
- dialog.dialog("open");
- });
- }
- var categoryNameMap = {
- "rooibos" : "red",
- "black" : "black",
- "green" : "green",
- "herbal" : "yellow",
- "white" : "white",
- "mate" : "purple",
- "pu'erh" : "brown",
- "oolong" : "blue"
- };
- function selectNavigation( category ) {
- //category = categoryNameMap[category];
- if (!category) { return; }
- var $selected, $parent, className;
- $selected = $("#dt-banner").find('li[data-name="' + category + '"]');
- $parent = $selected.closest("li.level1");
- $selected.find("a").addClass("select");
- $selected.addClass("select");
- $parent.addClass("open");
- }
- $(function() {
- if($("#hidden-akin-count").val() == "")
- {
- $("button[data-method='AddToCart']").show();
- if($("#hidden-quantity-avail").val() == "0")
- $("button[data-method='AddToCart']").attr("disabled","disabled");
- }
- $("#addToCart2 #size").die().live("change", function(){
- $("#addToCart1 #size").val( $(this).val() );
- $("#addToCart1 #size").change();
- });
- $('.add-to-cart #thumbnail').on('click', function(){
- var $img = $(this);
- var defaultBanner = $img.attr("data-defaultBanner");
- var defaultThumb = $img.attr("data-defaultThumb");
- var altBanner = $img.attr("data-altBanner");
- var altThumb = $img.attr("data-altThumb");
- if( $img.hasClass("altview") ) {
- var newLargeImg = 'http://images.davidstea.com/products/' + $('#current-language').val() + '/' + defaultBanner;
- var imgNewSmall = 'http://images.davidstea.com/products/' + $('#current-language').val() + '/' + defaultThumb;
- } else {
- var newLargeImg  = 'http://images.davidstea.com/products/' + $('#current-language').val() + '/' + altBanner ;
- var imgNewSmall  = 'http://images.davidstea.com/products/' + $('#current-language').val() + '/' + altThumb ;
- }
- //swap image
- $(this).attr('src', imgNewSmall);
- $('#main-banner').attr('src', newLargeImg);
- // Toggle altview class to know what image we are showing
- $img.toggleClass("altview");
- });
- // Remove Broken images
- var brokenImageCount = 0;
- $("img.featured-ingredients").on("error", function() {
- $(this).parent().andSelf().remove();
- brokenImageCount += 1;
- // Hide Featured-ingredients-box if images are not available
- if ( brokenImageCount == 2 && $("#featured-ingredients-box").find("div").size() < 1 ) {
- $("#featured-ingredients-box").remove();
- }
- });
- if ($("#contactid").val() !== "ANONYMOUS") {
- $("#button-add-to-wishlist").show();
- } else {
- $("#button-add-to-wishlist").parent().remove();
- }
- if ($('#pname').val() == '') {
- $("#product-flow").hide();
- } else {
- setTimeout(function() {
- selectNavigation( $("#pname").val() );
- }, 300);
- $("#product-flow").show();
- }
- if ($("#tbTRACKMAXQUANTITY").val() === true || $("#tbTRACKMAXQUANTITY").val() === "true" || $("#tbTRACKMAXQUANTITY").val() === "TRUE")
- {
- if (parseFloat($("#tbQTYAVAILABLE").val()) > 0.00)
- {
- $("#stockMsg").removeClass("hidden").addClass("in-stock");
- }
- else
- {
- $("#stockMsg").removeClass("hidden").addClass("no-stock");
- $("#aNotify").bind("click", function () {
- notify($("#content-id").val());
- });
- $(".btn-add-to-cart").attr("disabled", "disabled");
- $("#button-add-to-wishlist").attr("disabled", "disabled");
- }
- }
- $('.more-images a').lightBox({
- imageLoading: 'assets/theme/davidstea/js/lightbox/images/lightbox-ico-loading.gif',
- imageBtnPrev: 'assets/theme/davidstea/js/lightbox/images/lightbox-btn-prev.gif',
- imageBtnNext: 'assets/theme/davidstea/js/lightbox/images/lightbox-btn-next.gif',
- imageBtnClose: 'assets/theme/davidstea/js/lightbox/images/lightbox-btn-close.gif',
- imageBlank: 'assets/theme/davidstea/js/lightbox/images/lightbox-blank.gif'
- });
- //$('#akin-image img').load( function () { $('#akin-image').removeClass('loading') } );
- $('.add-to-cart').on('change', "select", function() {
- InitAkin();
- });
- $('.add-to-cart select:first-child').trigger('change');
- if($('li.prev').attr('data-value') == ""){
- $('li.prev').find('a').remove();
- }
- if($('li.next').attr('data-value') == ""){
- $('li.next').find('a').remove();
- }
- if($('.column-two').children().length == 0){
- $('.column-two').html('Â ');
- }
- $("[data-type=CustomerList]").click(function(){
- $("#dialog-window").AjaxCall({
- url: $(this).attr("data-url") +
- "&CONTENTID="+ $("#content-id").val() +
- "&DIMENSIONID=" + $(this).data('dimension')
- });
- });
- $("#notify").dialog({
- title: $('#notify').attr('data-name'),
- width: 400,
- height: 265,
- draggable: false,
- close: true,
- autoOpen: false
- });
- $("#button-invite-a-friend").bind("click", function () {
- invite($("#content-id").val());
- });
- $("#invite").dialog({
- title: $('#invite').attr('data-name'),
- width: 480,
- height: "auto",
- draggable: false,
- autoOpen: false,
- buttons: [
- {
- text: ($('#current-language').val() == 'EN' ? 'Submit' : 'Soumettre'),
- click: function() {
- $('#inviteform').validation({
- form: 'inviteform',
- success: function() {
- var formData = $("#inviteform").find("input, select, textarea").serialize();
- $.ajax({
- url: "Ajax.aspx?CN=5C02F3C0F570",
- data: formData,
- type: "POST",
- complete: function(resultData){
- $('#invite').html($(resultData.responseText).find('#invite-message'));
- $('#invite-message').show();
- $("#invite").dialog("option", {
- buttons: {},
- height: 115
- });
- }
- });
- }
- });
- }
- }
- ]
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement