1saffire.angular.app.directive('sfCartItemAdded', ['saffire.angular.cart.cartItemService', '$window', function (cartItemService, $window) { 2 3 function link(scope, element, attrs) { 4 5 scope.$watch('cartItem', function (newVal, oldVal) { 6 7 if (scope.cartItem) { 8 9 var checkoutBtn = element.find('.addtocartmodal-bottom a:last-child'); 10 11 checkoutBtn.focus(); 12 13 // trap tab focus in lightbox 14 var firstFocusableEl = element.find('.cartmodalclose'); 15 var lastFocusableEl = element.find('a.button'); 16 17 lastFocusableEl.keydown(function (e) { 18 if (e.shiftKey && e.which == 9) { 19 $('.addtocartmodal__continue').focus(); 20 } else if (e.which == 9) { 21 e.preventDefault(); 22 firstFocusableEl.focus(); 23 } 24 }); 25 26 firstFocusableEl.keydown(function (e) { 27 if (e.shiftKey && e.which == 9) {
28 lastFocusableEl.focus(); 29 } 30 if (e.key === 'Enter') { 31 e.preventDefault(); 32 scope.closeModal(); 33 scope.$apply(); 34 } 35 }); 36 37 // handle escape key and clicking out of modal content 38 $(document).on('keyup', function (e) { 39 if (e.which === 27) { 40 scope.closeModal(); 41 scope.$apply(); 42 } 43 }); 44 45 element.click(function (e) { 46 if (e.target === $(this)[0]) { 47 scope.closeModal(); 48 scope.$apply(); 49 } 50 }); 51 } 52 53 }, true) 54 55 //Cart Upsell "Add To Cart" function 56 scope.addCartItem = function (element, postData) { 57 58 59 if (FB_CONFIG) { 60 postData.fbEventID = guid(); 61 } 62 63 postData.inCheckout = scope.cartItem.incheckout; 64 65 cartItemService.addCartItem(postData).then(function (response) { 66 if (!response.ExceptionType) { 67 if (response.IsSuccess) { 68 if (scope.cartItem.incheckout && cartItemService.onCheckoutAddCartItemSuccess !== undefined) { 69 cartItemService.onCheckoutAddCartItemSuccess(element, response, postData, true); 70 } 71 72 if (FB_CONFIG && typeof fbq === 'function') { 73 fbq('track', 'AddToCart', null, { eventID: postData.fbEventID }); 74 } 75 76 ShowAddToCartSavedModal(element, postData.options.addToCartMessage, response, postData.inCheckout); 77 UpdateCartIndicator(); 78 } 79 else { 80 scope.showMessage({ 81 message: response.Message, 82 buttons: [{ 83 text: 'OK', 84 onClick: function () { 85 scope.closeMessage(); 86 } 87 }], 88 }); 89 } 90 } 91 else { 92 scope.showMessage({ 93 message: 'An error occurred while saving: <br/>' + response.ExceptionMessage, 94 buttons: [{ 95 text: 'OK', 96 onClick: function () { 97 scope.closeMessage(); 98 } 99 }], 100 }); 101 } 102 }); 103 } 104 105 scope.checkoutNow = function () { 106 if (scope.cartItem.incheckout) { 107 scope.closeModal(); 108 } else { 109 $window.top.location = SITEBASEURL + "cart.aspx"; 110 } 111 } 112 }; 113 114 return { 115 scope: { 116 cartItem: '=', 117 isRendered: '=', 118 addToCartMessage: '=', 119 cartUpsellSwiperOptions: '=', 120 closeModal: '&' 121 }, 122 templateUrl: SITEBASEURL + 'core/content/angular/cart/cartItem/cartItemAdded.html?sv=' + SITEVERSION, 123 link: link 124 } 125}]); 126 127 128 129
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.