1mcWeb.productlistfavorites = new (function ($) { 2 'use strict'; 3 4 var obj = this; 5 obj.productlist; 6 7 obj.events = { 8 onDoAddProductToFavourites: "mcWeb.productlistfavorites.onDoAddProductToFavourites" 9 } 10 11 obj.addToFav = function(webcartid) { 12 PubSub.publish(mcWeb.productlistfavorites.events.onDoAddProductToFavourites, webcartid); 13 }; 14 15 this.vm = function (product) { 16 obj.productlist = product; 17 18 var self = this; 19 self.service = obj.productlist.service; 20 self.orderbookManagerService = new WebApiService("OrderbookManagement"); 21 self.multipleActiveCarts = false; 22 self.favSubAdded = false; 23 setTimeout(function() { 24 self.orderbookManagerService.GetAction("GetFavouriteSettings").then( function(result) { 25 if (result && result.UseMultipleCartCheck) { 26 self.service.GetAction("HasMultipleFavouriteCarts").then(function(result) { 27 self.multipleActiveCarts = !!result; 28 }); 29 } 30 }); 31 },50); 32 33 34 self.useMultipleCartCheck = false;//todo: get setting info about whether or not we need to check for multiple favourite carts 35 36 self.addUsingPopup = function(sender,plid, quantity,isCheckout,hidePopup, doRemove) { 37 self.lastPlid = plid; 38 self.lastIsCheckout = isCheckout; 39 self.lastHidePopup = hidePopup; 40 self.doRemove = doRemove; 41 var $sender = jQuery(sender); 42 if (self.multipleActiveCarts) { 43 var inlineId = "favPopup"; 44 if (jQuery('#' + inlineId).length > 0) { 45 jQuery('#' + inlineId).remove();//remove the old popup that might exist somewhere else in the document 46 } 47 48 49 var offset = jQuery(sender).offset(); 50 var offsetParent = jQuery(sender).parent().offset(); 51 var myZIndex = $sender.css("z-index"); 52 if (jQuery.isNumeric(myZIndex)) { 53 myZIndex = myZIndex + 1; 54 } 55 56 //var top = offset.top - window.pageYOffset; 57 //var left = offset.left - window.pageXOffset; 58 59 var top = offset.top - offsetParent.top;// - window.pageYOffset; 60 var left = offset.left - offsetParent.left;// - window.pageXOffset; 61 62 var documentWidth = jQuery(document).width(); 63 var spaceToRhs = documentWidth - offset.left; 64 65 if(spaceToRhs < 160){ 66 left = left - 160; 67 } 68 69 70 var mystyle = "top:" + top + "px; left:" + left + "px;z-index:"+myZIndex; 71 72 var $div = jQuery("<div>", { id: inlineId, "class": "dropdown-placeholder", "style": mystyle }); 73 $sender.closest('div.WebPubElement').addClass('show-overflow'); 74 // var $div = jQuery("<div>", { id: inlineId, "class": "dropdown-placeholder"}); 75 var buttonContainer = $sender.parent(); 76 if (buttonContainer.length > 0) { 77 jQuery(buttonContainer).append($div); 78 } 79 80 var dropdownType = "add"; 81 if (doRemove) 82 dropdownType = "remove"; 83 84 getLibrary("web-orderbook-4").then(() => { 85 mcWeb.orderbookManager.showOrderbookControlInline('favourite-dropdown-' + dropdownType, null, "#" + inlineId); 86 }); 87 if (!self.favSubAdded) { 88 PubSub.subscribe(mcWeb.productlistfavorites.events.onDoAddProductToFavourites, 89 function(data, favCartId) { 90 91 $sender.find('.heart-empty').hide(); 92 $sender.find('.heart-full').show(); 93 if (self.lastPlid >= 0) { 94 self.add(sender, 95 self.lastPlid, 96 quantity, 97 self.lastIsCheckout, 98 self.lastHidePopup, 99 favCartId); 100 } else { 101 //no plid set, use any selected products, as selected by checkboxes 102 self.addAll(sender, self.lastIsCheckout, self.lastHidePopup, favCartId,self.doRemove); 103 } 104 }); 105 self.favSubAdded = true; 106 } 107 } else { 108 $sender.find('.heart-empty').hide(); 109 $sender.find('.heart-full').show(); 110 self.add(sender, plid, quantity, false, false,0); 111 } 112 }; 113 114 self.addAll = function(sender, isCheckout, hidePopup, favCartId, doRemove) { 115 try { 116 isCheckout = (isCheckout === undefined) ? false : isCheckout; 117 var quantity =1; 118 var plids = []; 119 jQuery(".product-select[data-plid]").each(function(index,item) { 120 if(item.checked) 121 plids.push(jQuery(item).data("plid")); 122 }); 123 124 var data = { 125 Plids: plids, 126 Sender: 'productlist-favorites4.js', 127 FavCartId: favCartId, 128 DoRemove: doRemove 129 }; 130 131 if (hidePopup != true) { 132 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCart : mcWeb.cartsmall.events.onShowNewItemInCart); 133 } 134 135 self.service.PostAction("AddAllToFavourites", data).then(function (result) { 136 if (result != null && result.Success == true) { 137 138 if (hidePopup != true) { 139 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCartText : mcWeb.cartsmall.events.onShowNewItemInCartText, { status: true, msg: result.PopupText, popupTime: result.PopupTime, favouriteCart: true });
140 } 141 if (!isCheckout) { 142 PubSub.publish(mcWeb.cartsmall.events.onUpdateCart, null); 143 } 144 145 146 } else { 147 if (hidePopup != true) { 148 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCartText : mcWeb.cartsmall.events.onShowNewItemInCartText, { status: false, msg: ((result == null) ? '' : result.PopupText),popupTime: result.PopupTime,favouriteCart: true }); 149 } 150 151 } 152 }); 153 } catch (e) { 154 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCartText : mcWeb.cartsmall.events.onShowNewItemInCartText, { status: false, msg: 'Error: ' + e,popupTime: result.PopupTime,favouriteCart: true }); 155 alert("Exception: " + e); 156 } 157 }; 158 159 160 161 self.add = function (sender, plid, quantity, isCheckout, hidePopup, favCartId) { 162 163 try { 164 isCheckout = (isCheckout === undefined) ? false : isCheckout; 165 quantity = (quantity == null) ? 1 : parseFloat(quantity); 166 quantity = (isNaN(quantity) || quantity < 0) ? 1 : quantity; 167 168 if (plid < 0) { 169 self.addAll(sender, isCheckout, hidePopup, favCartId, quantity <=0); 170 171 return; 172 } 173 if(favCartId === undefined) 174 favCartId = -1; 175 176 var data = { 177 plid: plid, 178 isConfig: false, 179 quantity: quantity, 180 sender: 'productlist-favorites2016.js', 181 favCartId: favCartId 182 }; 183 184 if (hidePopup != true) { 185 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCart : mcWeb.cartsmall.events.onShowNewItemInCart); 186 } 187 188 self.service.GetAction("AddToFavoriteCart", data).then(function (result) { 189 if (result != null && result.Success == true) { 190 191 if (quantity == 0 && sender != null) { 192 $(sender).closest(".WebPubElement").remove(); 193 } 194 195 if (hidePopup != true) { 196 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCartText : mcWeb.cartsmall.events.onShowNewItemInCartText, { status: true, msg: result.PopupText, favouriteCart: true }); 197 } 198 if (!isCheckout) { 199 PubSub.publish(mcWeb.cartsmall.events.onUpdateCart, null); 200 PubSub.publish("mcWeb.favhead.onFavCountChanged",null); 201 } 202 203 204 } else { 205 if (hidePopup != true) { 206 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCartText : mcWeb.cartsmall.events.onShowNewItemInCartText, { status: false, msg: ((result == null) ? '' : result.PopupText), favouriteCart: true }); 207 } 208 209 } 210 PubSub.publish("AjaxRenderingEngine.onReloadFieldByListingType", 38); //reload fields using Favourite listing rule 211 }); 212 } catch (e) { 213 PubSub.publish((isCheckout) ? mcWeb.cart.events.onShowNewItemInCartText : mcWeb.cartsmall.events.onShowNewItemInCartText, { status: false, msg: 'Error: ' + e, favouriteCart: true }); 214 alert("Exception: " + e); 215 } 216 }; 217 218 self.remove = function (sender, plid, isCheckout, hidePopup) { 219 self.add(sender, plid, 0, isCheckout, hidePopup && plid >= 0,-1); 220 }; 221 }; 222})(jQuery);
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.