diff --git a/css/uc_ajax_cart.css b/css/uc_ajax_cart.css index afa82be..3b2b924 100644 --- a/css/uc_ajax_cart.css +++ b/css/uc_ajax_cart.css @@ -3,3 +3,14 @@ color : black ; } +.uc-ajax-cart-blockui { + padding: 10px; +} + +.uc-ajax-cart-blockui .uc-ajax-cart-throbber { + padding-left: 17px; + background-image: url(../throbber.gif); + background-repeat: no-repeat; + background-position: left -17px; +} + diff --git a/images/throbber.gif b/images/throbber.gif new file mode 100644 index 0000000000000000000000000000000000000000..4352e64e859bb5e4d2e438f00d9d34c1d27462d1 GIT binary patch literal 1336 zcmZ?wbhEHbQ4?wxw{`P%dE_uhYh4g^5*`~UYq@csXH5cvQ7KL`K~ zSNzZI=Nc01>=@u`q-Vg)2on0q!pa7ub%2-wGjt;xM?96htN#UJ%?T-6rgZtrY<|Ka1OPl_mB6Jg*5LIzfMpw})>Vz{+posxMR zi-3r`qS(tB$*%Owi{%D!oL792{%`J$H8TJ!WCqrdP3uc@?o?A_*6SBIA!xCfoBN~lRKL}M9M}TG4QR6P1VqX}3Jj+37jp#`NeKl+ z>&)2Oz@T087*cX=&L8M`3NOk?4psB${7@Fdqq+!*ZTY z`Gde>Nly`jfCh%+>s)6fl&%oVSz>6|tzodh26yaXCJl3e3{HlJ4mJh>J;4c@TugrF zoRVf0bY%3*eemdGkJ{S6#H*_hFti2t8t>X5u' + Drupal.settings.uc_ajax_cart.ADD_MESSAGE + ''); + Drupal.theme('ajaxCartMessage', '' + Drupal.settings.uc_ajax_cart.ADD_MESSAGE + ''); jQuery.get(Drupal.settings.uc_ajax_cart.CART_LINK_CALLBACK, - { href: this.href }, + {href: this.href}, ajaxCartFormSubmitted); return false; }) @@ -79,11 +78,11 @@ Drupal.behaviors.ucAjaxCart = function (context) { form.ajaxSubmit({ url : Drupal.settings.uc_ajax_cart.CALLBACK, beforeSubmit : function () { - ajaxCartBlockUI(Drupal.settings.uc_ajax_cart.ADD_TITLE, - '
' + Drupal.settings.uc_ajax_cart.ADD_MESSAGE + '
')}, + Drupal.theme('ajaxCartMessage', '' + Drupal.settings.uc_ajax_cart.ADD_MESSAGE + ''); + }, success : ajaxCartFormSubmitted, type : 'post', - data: { 'op': $elem.val() } + data: {'op': $elem.val()} }); return false; }); @@ -105,7 +104,6 @@ Drupal.behaviors.ucAjaxCart = function (context) { // Call behaviors over cart page. ajaxCartCartPageBehaviors(context); - } @@ -118,9 +116,9 @@ function ajaxCartSubmit() { success: ajaxCartFormSubmitted, beforeSubmit: function () { jQuery('#uc-cart-view-form input').attr('disabled', 'disabled'); - ajaxCartBlockUI(Drupal.settings.uc_ajax_cart.ADD_TITLE, '
' + Drupal.settings.uc_ajax_cart.UPDATE_MESSAGE + '
'); + Drupal.theme('ajaxCartMessage', '' + Drupal.settings.uc_ajax_cart.UPDATE_MESSAGE + ''); }, - data: { 'op': button.val() } + data: {'op': button.val()} }); return false; } @@ -197,7 +195,7 @@ function ajaxCartOpenCart(instantly) { Drupal.uc_ajax_cart.cart_wrapper.addClass('cart-open'); if (Drupal.settings.uc_ajax_cart.TRACK_CLOSED_STATE) { - jQuery.cookie('ajax-cart-visible', '1', { path: '/'}); + jQuery.cookie('ajax-cart-visible', '1', {path: '/'}); } } } @@ -217,7 +215,7 @@ function ajaxCartCloseCart(instantly) { Drupal.uc_ajax_cart.cart_wrapper.removeClass('cart-open'); if (Drupal.settings.uc_ajax_cart.TRACK_CLOSED_STATE && (jQuery.cookie('ajax-cart-visible') != '0')) { - jQuery.cookie('ajax-cart-visible', '0', { path: '/'}); + jQuery.cookie('ajax-cart-visible', '0', {path: '/'}); } } } @@ -268,64 +266,6 @@ function ajaxCartCheckCookieCartState() { } } - -// Show message using BlockUI anc configured layout. -function ajaxCartShowMessageProxy(title, message) { - - if (Drupal.settings.uc_ajax_cart.HIDE_CART_OPERATIONS) { - return; - } - - // Check if UI is blocked. Blocked UI implies no fader in to avoid flickering. - var fadein = 0; - if (!Drupal.uc_ajax_cart.blockUI_blocked) { - fadein = 500; - } - - Drupal.uc_ajax_cart.blockUI_blocked += 1; - if (Drupal.settings.uc_ajax_cart.BLOCK_UI == 1) { - jQuery.blockUI({ message : '

' + title + '

' + message, fadeIn: fadein }); - } - else { - var $m = $('
'); - if (title) { - $m.append('

' + title + '

'); - } - - if (message) { - $m.append('

' + message + '

'); - } - - jQuery.blockUI({ - message: $m, - fadeIn: fadein, - fadeOut: 700, - showOverlay: false, - centerY: false, - css: { - width: '350px', - top: '10px', - left: '', - right: '10px', - border: 'none', - padding: '5px', - backgroundColor: '#000', - '-webkit-border-radius': '10px', - '-moz-border-radius': '10px', - 'border-radius': '10px', - color: '#fff', - opacity: 1 - } - }); - } -} - - -function ajaxCartShowMessageProxyClose() { - jQuery.unblockUI(); -} - - // Toggle cart block. function ajaxCartToggleView() { Drupal.uc_ajax_cart.cart_open_state ? ajaxCartCloseCart() : ajaxCartOpenCart(); @@ -341,19 +281,20 @@ function ajaxCartFormSubmitted(e) { ajaxCartUpdateBlockCart(); - ajaxCartBlockUI(Drupal.settings.uc_ajax_cart.CART_OPERATION, e); + Drupal.theme('ajaxCartMessage', e); ajaxCartReloadCartView(); } - -function ajaxCartBlockUI(title, message) { - ajaxCartShowMessageProxy(title, message); -} - - +/* + * This function is used in uc_ajax_cart.theme.inc on an onclick= statement. + * @TODO: Remove it from there and add it here. The main problem with it is + * that when the products are added, we need to reattach Drupal behaviors + * to the added elements. This has proven not to be that easy, we might a bit + * of a rework and cleaning to do that. + */ function ajaxCartBlockUIRemove(url) { jQuery('#uc-cart-view-form input').attr('disabled', 'disabled'); - ajaxCartShowMessageProxy(Drupal.settings.uc_ajax_cart.REMOVE_TITLE, Drupal.settings.uc_ajax_cart.REMOVE_MESSAGE); + Drupal.theme('ajaxCartMessage', '' + Drupal.settings.uc_ajax_cart.REMOVE_MESSAGE + ''); jQuery.post(url, ajaxCartFormSubmitted); return false; } @@ -379,15 +320,6 @@ function ajaxCartUpdateCartViewUpdated(e) { ajaxCartInitCartView(); } - -function ajaxCartShowMessages(e) { - if (e != "") { - clearTimeout(); - ajaxCartShowMessageProxy('Message', e); - } -} - - /** * Checks if a add to cart input submit button element must be ajaxified. */ @@ -400,3 +332,43 @@ function _checkAjaxify($elem) { return rc; } +Drupal.theme.prototype.ajaxCartMessage = function (message) { + if (Drupal.settings.uc_ajax_cart.HIDE_CART_OPERATIONS) { + return; + } + + // Check if UI is blocked. Blocked UI implies no fader in to avoid flickering. + var fadein = 0; + if (!Drupal.uc_ajax_cart.blockUI_blocked) { + fadein = 500; + } + + Drupal.uc_ajax_cart.blockUI_blocked += 1; + if (Drupal.settings.uc_ajax_cart.BLOCK_UI == 1) { + jQuery.blockUI({message : '
' + message + '
', fadeIn: fadein}); + } + else { + jQuery.blockUI({ + message: '
'+ message + '', + fadeIn: fadein, + fadeOut: 700, + showOverlay: false, + centerY: false, + css: { + width: '350px', + top: '10px', + left: '', + right: '10px', + border: 'none', + padding: '10px', + backgroundColor: '#000', + '-webkit-border-radius': '10px', + '-moz-border-radius': '10px', + 'border-radius': '10px', + color: '#fff', + opacity: 1 + } + }); + } +} + diff --git a/uc_ajax_cart.module b/uc_ajax_cart.module index e1b3af6..1f644ac 100644 --- a/uc_ajax_cart.module +++ b/uc_ajax_cart.module @@ -289,15 +289,13 @@ function _uc_ajax_cart_load_res() { $settings = array( 'CALLBACK' => url(UC_AJAX_CART_ADD_CALLBACK), 'SHOW_CALLBACK' => url(UC_AJAX_CART_SHOW_CALLBACK) , - 'ADD_TITLE' => t('Please wait'), // Message's title displayed when a product is being added to cart. - 'ADD_MESSAGE' => t('Add product to cart'), // Message displayed when a product is being added to cart. - 'REMOVE_TITLE' => t('Please wait'), // Message's title displayed when a product is being removed to cart. - 'REMOVE_MESSAGE' => t('Remove product from cart'), // Message displayed when a product is being removed from cart. + 'ADD_MESSAGE' => t('Adding product to the cart...'), // Message displayed when a product is being added to cart. + 'REMOVE_MESSAGE' => t('Removing product from the cart...'), // Message displayed when a product is being removed from cart. 'CART_LINK_CALLBACK' => url(UC_AJAX_CART_LINK_CALLBACK), 'BLOCK_UI' => (int) variable_get('ajax_cart_message_effect' , UC_AJAX_CART_DEFAULT_EFFECT), 'TIMEOUT' => (int) variable_get('ajax_cart_message_timeout', UC_AJAX_CART_DEFAULT_TIMEOUT), 'UPDATE_CALLBACK' => url(UC_AJAX_CART_UPDATE_CALLBACK), - 'UPDATE_MESSAGE' => t('Update cart'), // Message displayed when a product is being updated in cart. + 'UPDATE_MESSAGE' => t('Updating cart...'), // Message displayed when a product is being updated in cart. 'SESSION' => session_id(), 'UPDATE' => variable_get('uc_ajax_cart_closed_update',0), 'CART_OPERATION' => t('Cart'), // Message's title displayed when a product is being added to cart. @@ -407,3 +405,4 @@ function uc_ajax_cart_theme_registry_alter(&$theme_registry) { function uc_ajax_uc_empty_cart() { return '

'. t('There are no products in your shopping cart.') .'

'; } +