PageSourceSearch

https://virtualofficesingapore.sg/wp-content/plugins/added-to-cart…/assets/js/xoo-cp-js.js?ver=1.7

js virtualofficesingapore.sg collected 2026-10-05 03:26:29 UTC 7,484 bytes, 289 lines download raw bytes

1jQuery(document).ready(function($){
2
3	var focus_qty;
4
5	//Open cart pop up
6	function open_popup(){
7		$('.xoo-cp-opac').show();
8    	$('.xoo-cp-modal').addClass('xoo-cp-active');
9	}
10
11	//On add to cart
12	$(document.body).on('added_to_cart',function(){
13		open_popup();
14	});
15
16
17	//CLose Popup
18	function close_popup(e){
19		$.each(e.target.classList,function(key,value){
20			if(value == 'xoo-cp-close' || value == 'xoo-cp-modal'){
21				$('.xoo-cp-opac').hide();
22				$('.xoo-cp-modal').removeClass('xoo-cp-active');
23				$('.xoo-cp-atcn , .xoo-cp-content').html('');
24			}
25		})
26	}
27
28	$(document).on('click','.xoo-cp-close , .xoo-cp-modal',close_popup);
29
30	//Block popup
31	function block_popup(){
32		$('.xoo-cp-outer').show();
33	}
34
35	//Unblock popup
36	function unblock_popup(){
37		$('.xoo-cp-outer').hide();
38	}
39
40	//Reset cart button/form
41	function reset_cart(atc_btn){
42		$('.xoo-cp-added',atc_btn).remove();
43		var qty_elem = atc_btn.parents('form.cart').find('.qty');
44		if(qty_elem.length > 0) qty_elem.val(qty_elem.attr('min') || 1);
45		$('.added_to_cart').remove();
46	}
47
48	//Notice Function
49	function show_notice(notice_type,notice){
50	 	$('.xoo-cp-notice').html(notice).attr('class','xoo-cp-notice').addClass('xoo-cp-nt-'+notice_type);
51	 	$('.xoo-cp-notice-box').fadeIn('fast');
52	 	clearTimeout(fadenotice);
53	 	var fadenotice = setTimeout(function(){
54	 		$('.xoo-cp-notice-box').fadeOut('slow');
55	 	},3000);
56	};
57
58	//Add to cart function
59	function add_to_cart(atc_btn,form_data){
60
61		// Trigger event.
62		$( document.body ).trigger( 'adding_to_cart', [ atc_btn, form_data ] );
63
64		$.ajax({
65			url: xoo_cp_localize.wc_ajax_url.toString().replace( '%%endpoint%%', 'xoo_cp_add_to_cart' ),
66			type: 'POST',
67			data: $.param(form_data),
68		    success: function(response){
69		    	
70		    	$('.xoo-cp-adding',atc_btn).remove();
71
72				if(response.fragments){
73					// Trigger event so themes can refresh other areas.
74					$( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, atc_btn ] );
75					atc_btn.append('<span class="xoo-cp-icon-check xoo-cp-added"></span>');
76				}
77				else if(response.error){
78					show_notice('error',response.error)
79				}
80				else{
81					console.log(response);
82				}
83
84				//Reset to default
85				if(xoo_cp_localize.reset_cart) reset_cart(atc_btn);
86		
87		    }
88		})
89	}
90
91
92	//Add to cart on single page
93	$(document).on('submit','form.cart',function(e){
94		var form = $(this);
95		var atc_btn  = form.find( 'button[type="submit"]');
96
97		var form_data = form.serializeArray();
98
99		// if button as name add-to-cart get it and add to form
100        if( atc_btn.attr('name') && atc_btn.attr('name') == 'add-to-cart' && atc_btn.attr('value') ){
101            form_data.push({ name: 'add-to-cart', value: atc_btn.attr('value') });
102        }
103
104        var is_valid = false;
105
106        $.each( form_data, function( index, data ){
107        	if( data.name === "add-to-cart" ){
108        		is_valid = true;
109        		return false;
110        	}
111        } )
112
113        if( is_valid ){
114        	e.preventDefault();
115        }
116        else{
117        	return;
118        }
119
120        $('.xoo-cp-added',atc_btn).remove();
121		atc_btn.append('<span class="xoo-cp-icon-spinner xoo-cp-adding" aria-hidden="true"></span>');
122
123        form_data.push({name: 'action', value: 'xoo_cp_add_to_cart'});
124
125		add_to_cart(atc_btn,form_data);//Ajax add to cart
126	})
127
128
129	//Ajax function to update cart (In a popup)
130	function xoo_cp_update_ajax(cart_key,new_qty,pid){
131		return $.ajax({
132				url: xoo_cp_localize.adminurl,
133				type: 'POST',
134				data: {action: 'xoo_cp_change_ajax',
135					   cart_key: cart_key, 
136					   new_qty: new_qty,
137					   pid: pid
138					}
139			})
140	}
141
142	//Update cart
143	function update_cart(cart_key,new_qty){
144		block_popup();
145		$.ajax({
146			url: xoo_cp_localize.wc_ajax_url.toString().replace( '%%endpoint%%', 'xoo_cp_update_cart' ),
147			type: 'POST',
148			data: {
149				cart_key: cart_key,
150				new_qty: new_qty
151			},
152			success: function(response){
153				if(response.fragments){
154					var fragments = response.fragments,
155						cart_hash =  response.cart_hash;
156
157					//Set fragments
158			   		$.each( response.fragments, function( key, value ) {
159						$( key ).replaceWith( value );
160						$( key ).stop( true ).css( 'opacity', '1' ).unblock();
161					});
162
163			   		if(wc_cart_fragments_params){
164				   		var cart_hash_key = wc_cart_fragments_params.ajax_url.toString() + '-wc_cart_hash';
165						//Set cart hash
166						sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( fragments ) );
167						localStorage.setItem( cart_hash_key, cart_hash );
168						sessionStorage.setItem( cart_hash_key, cart_hash );
169					}
170
171					$(document.body).trigger('wc_fragments_loaded');
172				}
173				else{
174					//Print error
175					//show_notice('error',response.error);
176					console.log(response);
177				}
178
179				unblock_popup();
180			}
181
182		})
183	}
184
185
186	//Save Quantity on focus
187	$(document).on('focusin','.xoo-cp-qty',function(){
188		focus_qty = $(this).val();
189	})
190
191
192	//Qty input on change
193	$(document).on('change','.xoo-cp-qty',function(e){
194		var _this = $(this);
195		var new_qty = parseFloat($(this).val());
196		var step = parseFloat($(this).attr('step'));
197		var min_value = parseFloat($(this).attr('min'));
198		var max_value = parseFloat($(this).attr('max'));
199		var invalid  = false;
200
201	
202		if(new_qty === 0){
203			_this.parents('.xoo-cp-pdetails').find('.xoo-cp-remove-pd').trigger('click');
204			return;
205		}
206		//Check If valid number
207		else if(isNaN(new_qty)  || new_qty < 0){
208			invalid = true;
209		}
210
211		//Check maximum quantity
212		else if(new_qty > max_value && max_value > 0){
213			alert('Maximum Quantity: '+max_value);
214			invalid = true;
215		}
216
217		//Check Minimum Quantity
218		else if(new_qty < min_value){
219			invalid = true;
220		}
221
222		//Check Step
223		else if((new_qty % step) !== 0){
224			alert('Quantity can only be purchased in multiple of '+step);
225			invalid = true;
226		}
227
228		//Update if everything is fine.
229		else{
230			var cart_key = $(this).parents('tr').data('xoo_cp_key');
231			update_cart(cart_key,new_qty);
232		}
233
234		if(invalid === true){
235			$(this).val(focus_qty);
236		}
237		
238	})
239
240	//Plus minus buttons
241	$(document).on('click', '.xcp-chng' ,function(){
242		var _this = $(this);
243		var qty_element = _this.siblings('.xoo-cp-qty');
244		qty_element.trigger('focusin');
245		var input_qty = parseFloat(qty_element.val());
246
247		var step = parseFloat(qty_element.attr('step'));
248		var min_value = parseFloat(qty_element.attr('min'));
249		var max_value = parseFloat(qty_element.attr('max'));
250
251		if(_this.hasClass('xcp-plus')){
252			var new_qty	  = input_qty + step;
253		
254			if(new_qty > max_value && max_value > 0){
255				alert('Maximum Quantity: '+max_value);
256				return;
257			}
258		}
259		else if(_this.hasClass('xcp-minus')){
260			
261			var new_qty = input_qty - step;
262			if(new_qty === 0){
263				_this.parents('.xoo-cp-pdetails').find('.xoo-cp-remove .xcp-icon').trigger('click');
264				return;
265			}
266			else if(new_qty < min_value){
267				return;
268			} 
269			else if(input_qty < 0){
270				alert('Invalid');
271				return;
272			}
273		}
274
275		var cart_key = $(this).parents('tr').data('xoo_cp_key');
276
277		update_cart(cart_key,new_qty);
278	})
279
280
281
282	//Remove item from cart
283	$(document).on('click','.xoo-cp-remove-pd',function(e){
284		e.preventDefault();
285		var cart_key = $(this).parents('tr').data('xoo_cp_key');
286		update_cart(cart_key,0);
287	})
288
289})

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.