diff --git a/commerce_ajax_cart.admin.inc b/commerce_ajax_cart.admin.inc index 9568366..0906c5c 100644 --- a/commerce_ajax_cart.admin.inc +++ b/commerce_ajax_cart.admin.inc @@ -99,9 +99,9 @@ function commerce_ajax_cart_settings_form() { // TODO Bad. Better solution? $form['commerce_ajax_cart_fly2cart_parent'] = array( '#type' => 'textfield', - '#title' => t('Image and add to cart container class'), + '#title' => t('Image and add to cart container classes or IDs'), '#default_value' => variable_get('commerce_ajax_cart_fly2cart_parent'), - '#description' => t('CSS class name of closest parent container, that contain image of product and add to cart form. For example, .node or .views-row.
Be sure, that doesn\'t contain other products images and add to cart forms.'), + '#description' => t('Class or ID names of closest parent element, separated by comma, that contain both image of product and "add to cart" form
For example, .node,.views-row.
Be sure, it shouldn\'t contain other products images and add to cart forms.'), '#states' => array( 'invisible' => array( ':input[name="commerce_ajax_cart_fly2cart"]' => array('checked' => FALSE), diff --git a/js/commerce_ajax_cart.js b/js/commerce_ajax_cart.js index c95a6dd..47cc066 100644 --- a/js/commerce_ajax_cart.js +++ b/js/commerce_ajax_cart.js @@ -90,35 +90,40 @@ Drupal.ajax.prototype.commands.commerceAjaxCartFly = function(ajax, response, status) { var link2cart = $('.commerce-ajax-cart-loader'); + // TODO Very bad. Better solution? - var imgtodrag = $('#' + response.data).parents(Drupal.settings.commerce_ajax_cart.fly2cart_parent).find('img').eq(0); - if (imgtodrag.length) { - var imgclone = imgtodrag.clone().offset({ - top: imgtodrag.offset().top, - left: imgtodrag.offset().left - }).css({ - 'opacity': '0.5', - 'position': 'absolute', - 'height': imgtodrag.clientHeight, - 'width': imgtodrag.clientWidth, - 'z-index': '999' - }).appendTo(jQuery('body')).animate({ - 'top': link2cart.offset().top + 10, - 'left': link2cart.offset().left + 10, - 'width': link2cart.clientHeight, - 'height': link2cart.clientHeight - }, 1000); + $.each(Drupal.settings.commerce_ajax_cart.fly2cart_parent, function(index, value) { + var imgtodrag = $('#' + response.data).parents(value).find('img').eq(0); + if (imgtodrag.length) { + var imgclone = imgtodrag.clone().offset({ + top: imgtodrag.offset().top, + left: imgtodrag.offset().left + }).css({ + 'opacity': '0.5', + 'position': 'absolute', + 'height': imgtodrag.clientHeight, + 'width': imgtodrag.clientWidth, + 'z-index': '999' + }).appendTo(jQuery('body')).animate({ + 'top': link2cart.offset().top + 10, + 'left': link2cart.offset().left + 10, + 'width': link2cart.clientHeight, + 'height': link2cart.clientHeight + }, 1000); + + imgclone.animate( + { + 'width': 0, + 'height': 0 + }, + function () { + $(this).detach(); + } + ); + } + }); + - imgclone.animate( - { - 'width': 0, - 'height': 0 - }, - function () { - $(this).detach(); - } - ); - } } })(jQuery);