diff --git a/uc_option_image.js b/uc_option_image.js index 654d03b..a7a6bdb 100644 --- a/uc_option_image.js +++ b/uc_option_image.js @@ -1,9 +1,15 @@ var UCOI = UCOI || {}; +/** + * Attached behaviors. + */ +Drupal.behaviors.UCOI = function(context) { + UCOI.init(context) +} /** * Initialize. */ -UCOI.init = function() { +UCOI.init = function(context) { var size = Drupal.settings.UCOI.size; this.images = Drupal.settings.UCOI.images; this.effect = Drupal.settings.UCOI.effect; @@ -13,14 +19,14 @@ UCOI.init = function() { this.nodeid = Drupal.settings.UCOI.nodeid; // Selects - $('.add-to-cart select.form-select').change(function(){ + $('.attributes select.form-select', context).change(function(){ if (aid = UCOI.getAID(this)){ UCOI.switchImage(aid, this, size); } }); // Radios - $('.add-to-cart .form-radios input').click(function(){ + $('.attributes .form-radios input', context).click(function(){ if (aid = UCOI.getAID(this)){ UCOI.switchImage(aid, this, size); } @@ -82,9 +88,3 @@ UCOI.getAID = function(input) { var name = $(input).attr('name'); return name.match(/attributes\[([0-9]+)\]/)[1]; }; - -if (Drupal.jsEnabled) { - $(function(){ - UCOI.init(); - }); -}