Skip to content

Instantly share code, notes, and snippets.

@addisonhall
Last active December 21, 2015 13:29
Show Gist options
  • Save addisonhall/6312476 to your computer and use it in GitHub Desktop.
Save addisonhall/6312476 to your computer and use it in GitHub Desktop.
Customizing Business Catalyst default javascript alerts with jGrowl
// Default BC alert messages
/*
var Oshoplang = {
RemoveError: 'ERROR: To remove or update quantities select the View Cart link.',
Added: ' item(s) added to your cart.',
OutOfStock: 'Either product is out of stock or choose a smaller quantity',
PreOrder: ' item(s) pre-ordered and added to your cart.',
MinLimit: 'ERROR: Quantity entered is too small, please enter a larger quantity.',
MaxLimit: 'ERROR: Quantity entered is too large, please enter a smaller quantity.',
InvalidQuantity: 'ERROR: Quantity entered is not valid.',
CartEmpty: 'Your Shopping cart is empty.',
CartUpdateSuccess: 'Shopping cart updated successfully.',
InvalidShip: 'ERROR: Please choose a valid shipping option.',
ChooseState: 'ERROR: Please choose a destination state to calculate state tax.',
EnterZip: 'ERROR: Please enter in your Zip/Postcode to calculate shipping costs for your order.',
ChooseShip: 'ERROR: Please select a shipping charge for your order.',
IncorrectGForm: 'ERROR: Your gift voucher form is not setup correctly. Please reset to original to restore.',
EnterGName: 'ERROR: Please enter a name for the recipient of your gift voucher.',
InvalidGEmail: 'ERROR: Please enter a valid email address for the recipient of your gift voucher.',
EnterGMessage: 'ERROR: Please enter a personal message for the recipient of your gift voucher.',
ChooseAttribute: 'ERROR: Please choose relevant options before adding to cart.'
};
*/
// Customize BC alerts with jGrowl
// Also requires nl2br function below
// https://github.com/stanlemon/jGrowl
window.alert = function(msg) {
switch(msg) {
case 'ERROR: Please choose relevant options before adding to cart.':
var newMsg = '<b>Hang on!</b> Please select at least one flavor...';
$.jGrowl(nl2br(newMsg));
break;
case 'ERROR: Please choose a valid shipping option.':
var newMsg = '<b>Wait!</b> How do you want this shipped?';
$.jGrowl(nl2br(newMsg));
break;
default:
$.jGrowl(nl2br(msg));
}
}
// Convert line breaks for jGrowl display, or other stuff
// Reference: http://stackoverflow.com/questions/2919337/jquery-convert-line-breaks-to-br-nl2br-equivalent
function nl2br(str, is_xhtml) {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment