PageSourceSearch

https://www.sarahlovellart.co.uk/modules/product/js/product.js?v=4

js sarahlovellart.co.uk collected 2026-09-26 20:37:05 UTC 12,290 bytes, 376 lines download raw bytes

1$(function(){
2	$('body').on( "click",".link-add-favourites", function(e) {
3		is_favourite = true;
4		$(this).closest('form').submit()
5		e.preventDefault();
6
7	})
8	// price break
9	$('.product-list').find('.action-block').hover(function(){
10		product_page_idx = $(this).closest('.product').data('idx');
11		if ($('#price-break-' + product_page_idx + ' .price-break').length > 0) $('#price-break-' + product_page_idx).show();
12	}, function(){
13		$('.price-break-block').hide();
14	})
15	// change variant select
16	$('#main-content-box').delegate(".attribute-select", "change", function(){
17		$this = $(this)
18		check_switch_gallery_variant_image($this)
19		count = 0
20		att_ids = $(this).closest('.cv-list').find('.attribute-select').map(function(index) {			
21			count++; 
22			$this = $(this)
23			if ($this.is(':radio')){
24				if (!$this.is(':checked')) return;
25				$this.next().qtip('hide') 
26			}
27			return 'a' + $this.data('rank') + '=' + this.value;
28		}).get().join("&")
29		ajaxLoadE = $(this).closest('.cv-list')
30		ajaxLoadE.data('url', ajaxLoadE.data('url').substring(0, ajaxLoadE.data('url').indexOf('?')) + '?'+att_ids )
31		ajaxLoad(ajaxLoadE)		
32	})
33	
34	$('#main-content-box').delegate(".product-action-form select.is-variant", "change", function(){	
35		$this = $(this)
36		switch_variant($this,true)
37		check_switch_gallery_variant_image($this)
38	})
39	$('#main-content-box').delegate(".product-action-form input:radio.is-variant", "change", function(){	
40		$this = $(this)
41		switch_variant($this,true)
42		check_switch_gallery_variant_image($this)
43	})
44
45	$('#main-content-box').on({
46		keyup: function(){
47			$this = $(this)
48			delay(function(){
49			  switch_variant($this)
50			}, 500 );
51		}
52	}, ".product-action-form .calc.text");
53	
54	$('#main-content-box').on({
55		change: function(){
56			switch_variant($(this))
57		},
58		"focus click": function(){
59			/* make sure variants are selected before focusing on calc fields */
60			$(this).closest('.product-action-form').find('.variant-list select').each(function() {
61				if ($(this).val() == ''){
62					$(this).focus().valid()
63				}
64			})
65		}
66	}, ".product-action-form .calc");
67		 
68	/* qtip customisation */
69	$('.product-action-form').on({
70		'mouseover': function() {
71			$(this).qtip({
72				overwrite: false,
73				position: {
74					at: 'bottom center', 
75					my: 'top center'		
76				},
77				style: {
78					classes: 'qtip-tipsy qtip-shadow qtip-microblog qtip-centre'
79				},
80				show: { ready: true }
81			})
82		},   
83		'touchstart': function() {
84				$(this).click()
85		}
86	} ,'.qtip-simple')
87	
88	folder_tile_match_height();
89})
90
91// match col height
92function folder_tile_match_height(){
93    if (!window.matchHeight) return;
94    window.matchHeight('.folder-product.folder-tile .column-image');
95    window.matchHeight('.folder-product.folder-tile .item-info');
96}
97
98$(window).on('load', function(){
99	 if ($('.product-item .variant-block').length){
100		setTimeout('switch_variant($(".product-action-form select.is-variant"))', 300);	 
101	 }
102})
103
104/*---------------- add_to_basket (external interface) --------------------- */
105function add_to_basket(product_action_form){
106	$form 				= $(product_action_form)
107	$item_product    	= $form.closest('.item-product')
108	product_page_idx 	= $item_product.data('idx');
109	qty 				= $form.find('#qty-' + product_page_idx).val();
110	product_idx			= $form.find('#product-' + product_page_idx).val();
111	type				= '';
112	if (typeof is_favourite == 'boolean'){
113		delete window.is_favourite;
114		type = 'favourite';
115	}
116	if (typeof is_subscribensave == 'boolean'){
117		delete window.is_subscribensave;
118		type = 'subscribensave';
119		window.location = "/subscribensave-"+encodeURIComponent(product_idx)+"/secure/myaccount/item_subscribe.htm"
120		return
121	}
122	if (typeof before_add_to_basket === 'function'){
123		before_add_to_basket(function(){ ajax_cart_action( '',product_page_idx,product_idx,qty,'add',type,product_action_form )})
124	 	return false;
125	}
126	ajax_cart_action( '',product_page_idx,product_idx,qty,'add',type,product_action_form )
127}
128
129/*---------------- ajax_cart_action --------------------- */
130
131function ajax_cart_action(serial_key, product_page_idx, product_idx, qty, method, type, product_action_form){
132	var fn = window['submit_callback'+product_page_idx];
133    if (typeof fn === 'function'){
134    	fn( product_page_idx, product_idx, qty, method, type, product_action_form );
135    } else {
136    	$.ajax({
137			async: false,
138			url: '/product/ajax/cart_action.php',
139			data:{
140				serial_key:serial_key,
141				idx:product_page_idx,
142				product_idx:product_idx,
143				qty:qty,
144				method:method,
145				type:type
146			},
147			type: "POST",
148			dataType: "json",
149			success: function(data) {
150				console.log(type)					
151				if (type=='subscribensave') {				
152				console.log(data.html)					
153					$('#modal-dlg').html(data.html)
154				}			
155				if (data.notify) {				
156					notify(data.notify);
157				}			
158				if (typeof ajax_cart_action_callback === 'function'){
159					ajax_cart_action_callback(data.trolley_type);
160				}
161				
162				if (data.cart_updated) {
163					/* basket-count */
164					if (data.trolley_item_qty) {
165						$('#basket-count-' + product_page_idx ).show().html(data.trolley_item_qty)
166					} else {
167						$('#basket-count-' + product_page_idx ).hide()
168					}
169					slideDisplayCart()
170				}
171				if (data.trolley_script){
172					 eval(data.trolley_script);
173				}
174				
175			}
176		})	
177    }    
178	if (typeof fbq == 'function') fbq('track', 'AddToCart');
179}
180
181/*---------------- check_switch_gallery_variant_image --------------------- */
182function check_switch_gallery_variant_image(el){
183	if(typeof gallery_variant_images != 'function') return false
184	if (el.hasClass('variant-image-select')){
185		im_array = []		
186		if (el.is('select')){
187			data = el.find(':selected').data()
188		} else {
189			data = el.data()
190		}
191		if (data.v){
192			im_array = String(data.v).split(',');
193		}
194		gallery_variant_images(im_array)
195	}	
196}
197
198/*---------------- switch_variant --------------------- */
199function switch_variant($this, variant_changed){
200
201	$paform = $this.closest('.product-action-form');
202	list_view = ($this.closest('.folder-product').length);
203
204	a1 = a2 = a3 = a4 = 0;
205	$paform.find('select').each(function(){			
206		window['a' + $(this).data('rank')] = $(this).val()
207	})
208	product_page_idx 	= $this.closest('.item-product').data('idx')
209	
210	/* radio swatches */
211	if ( tmp_a1 = $("input[name=a1_" + product_page_idx + "]:checked").val()) a1 = tmp_a1
212	if ( tmp_a2 = $("input[name=a2_" + product_page_idx + "]:checked").val()) a2 = tmp_a2
213	if ( tmp_a3 = $("input[name=a3_" + product_page_idx + "]:checked").val()) a3 = tmp_a3
214	if ( tmp_a4 = $("input[name=a4_" + product_page_idx + "]:checked").val()) a4 = tmp_a4
215	
216	// pre ajax callback
217	if (variant_changed && typeof before_variant_change === 'function'){
218		before_variant_change($paform)
219	}
220
221	$.ajax({
222		async: false,
223		url: '/product/ajax/variant_change.php',
224		data: {
225			idx:product_page_idx,
226			a1:a1,
227			a2:a2,
228			a3:a3,
229			a4:a4,
230			list_view:list_view,
231			'calc_fields': $paform.find('.calc:visible').serialize()
232		},
233		type: "POST", 
234		dataType: "json",
235		success: function(data) {
236			$('#product-' + product_page_idx, $paform ).val(data.id)
237			$('#price-break-' + product_page_idx, $paform ).html('')
238			if (data.price_break?.length) {
239				$('#price-break-' + product_page_idx, $paform ).html(data.price_break)
240			}
241			if (data.image_id && data.image_id !== '0' && typeof goToGalleryImage === "function") {
242				goToGalleryImage(data.image_id)
243			}
244			$this.closest('.item-idx-' + product_page_idx).find('.append-title').remove()
245			if (data.append_title) {
246				$this.closest('.item-idx-' + product_page_idx)
247					.find('.pg-title-list').append(' <span class="append-title">'+ data.append_title +'</span>').end()
248					.find('.pg-title').append(' <span class="append-title">'+ data.append_title +'</span>')
249			}
250			$('#variant-extra-info-' + product_page_idx ).html('')
251			if (data.extra_info) {
252				$('#variant-extra-info-' + product_page_idx ).html(data.extra_info)
253			}
254			if (data.is_hidden_shop == 1) {
255				$this.closest('.item-idx-' + product_page_idx).addClass('hide-shop')
256			} else {
257				$this.closest('.item-idx-' + product_page_idx).removeClass('hide-shop')
258			}
259			if (data.code) {
260				$this.closest('.item-idx-' + product_page_idx).find('.code').html(data.code)
261			}
262			if (data.pack_size) {
263				$this.closest('.item-idx-' + product_page_idx).find('.pack-size').html(data.pack_size)
264			}
265			if (data.pack_type) {
266				$this.closest('.item-idx-' + product_page_idx).find('.pack-type').html(data.pack_type)
267			}
268			if (data.vat_status) {
269				$this.closest('.item-idx-' + product_page_idx).find('.vat-status').html(data.vat_status)
270			}			
271			$('.price-amount', $paform ).html(data.price )			
272			if (data.price_orig){
273				$this.closest('.item-idx-' + product_page_idx).addClass('on-offer').find('.price-orig .amount').html(data.price_orig)
274			} else {
275				$this.closest('.item-idx-' + product_page_idx).removeClass('on-offer').find('.price-orig').html('')
276			}
277			
278			/* new stock */
279			$('.item-idx-'+ product_page_idx).removeClass('stock-controlled stock-in stock-low stock-out stock-orderout stock-over');
280			if (data.stock_class) {
281				$('.item-idx-'+ product_page_idx).addClass(data.stock_class);
282			}
283			
284			/* multibuy class */
285			$('.item-idx-'+ product_page_idx).removeClass(function (index, className) {
286   				return (className.match (/multibuy-[0-9a-fx]+/gi) || []).join(' ') + ' is-multibuy';
287			});
288
289			if (data.multibuy_idx) {
290				$('.item-idx-'+ product_page_idx).addClass('is-multibuy');
291				$('.item-idx-'+ product_page_idx).addClass('multibuy-' + data.multibuy_idx);
292			}
293			
294			/* basket-count */
295			if (data.qty) {
296				$('#basket-count-' + product_page_idx ).show().html(data.qty)
297			} else {
298				$('#basket-count-' + product_page_idx ).hide()
299			}
300			
301			/* variant_class */
302			$('.item-idx-'+ product_page_idx).removeClass($('.item-idx-'+ product_page_idx).data('variant_class'))
303			if (data.variant_class) {
304				$('.item-idx-'+ product_page_idx).addClass(data.variant_class)
305				$('.item-idx-'+ product_page_idx).data('variant_class',data.variant_class)
306			}
307			
308			/* swap image */
309			if(data.stock_img){
310				$('.item-idx-'+ product_page_idx).find('.stock-img').replaceWith(data.stock_img)
311			} else {
312				$('.item-idx-'+ product_page_idx).find('.stock-img').html('')
313			}
314			if(data.stock_msg){
315				$('.item-idx-'+ product_page_idx).find('.stock-msg').replaceWith(data.stock_msg)
316			} else {
317				$('.item-idx-'+ product_page_idx).find('.stock-msg').html('')
318			}		
319			
320			if (typeof variant_change_callback == 'function'){
321				variant_change_callback()
322			}
323			if (data.notify) {
324				console.log(data.notify)
325				notify(data.notify);
326			}			
327			
328			// match col height in case title gets appended
329			folder_tile_match_height();
330									
331		}
332	})
333}
334
335
336/* ---------------------- trolley ----------------------------------------------------*/
337confighoverTrolley = { over: basketDisplay, timeout: 300, out: basketHide };
338
339/*---------------- basketDisplay --------------------- */
340function basketDisplay(){		
341	$('.error').qtip('hide');
342	if ($('#pane-trolley-wrap .item').not('.trolley-hidden').length > 0){
343		$('#pane-trolley-slidecontent').show()
344	}
345	if (typeof t !== 'undefined') clearTimeout(t)
346}
347	
348/*---------------- basketHide --------------------- */
349function basketHide(){
350	$('#pane-trolley-slidecontent').hide()
351	$('#mobile-trolley-notification').hide()
352}
353	
354
355/*---------------- slideDisplayCart --------------------- */
356
357function slideDisplayCart(){	
358
359	if (typeof t !== 'undefined') clearTimeout(t)
360	$.ajax ({ type: 'post', dataType:'json', url: '/product/ajax/pane_trolley.php', data: { ajax_add_item: 1},
361		success: function(data) {						
362			if(!$('#header-mob').is(":visible")) {
363				$('html, body').animate({scrollTop:0}, 'slow');
364			}
365			$('.items').html(data.items).animate({top:0}, 'slow').closest('#pane-trolley-slidecontent').show().find('.total-price').html(data.total)
366			$('.trolley-price').html(data.trolley_price)
367			.siblings('.trolley-items').html(data.trolley_items)
368			.siblings('.trolley-items-label').html(data.trolley_items_label)
369			$('#pane-trolley-wrap').removeClass('trolley-empty')
370			$('#mobile-trolley-items').html(data.trolley_count_items)
371			$('#mobile-trolley-notification').html(data.trolley_item_latest).fadeIn()
372			$('.new').animate({backgroundColor: '#fff'}, 1500);
373			t=setTimeout("basketHide()", 2500 )
374		}
375	})		
376}

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.