summaryrefslogtreecommitdiff
path: root/views/mods/mod_productvariants/frontend.js
blob: 2d4957ac19ef0ffac9d844c32875d5d2ae931584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
    function wpsg_mod_productvariants_reload(event)
    {
        
        var template_index = jQuery(event.target).closest('.wpsg_mod_productvariants_product_wrap').attr('wpsg-productindex');

        // Nach dem Nachladen steht der Fokus wieder auf der Auswahl, nicht auf body (Tastatur, W4)
        var focus_id = event.target.id || '';
        var focus_image = jQuery(event.target).closest('.wpsg_vp_update_image').data('wpsg-id');
 
        wpsg_blockProductTemplate(template_index);
  
		jQuery.ajax( {
			'url': wpsg_ajax.ajaxurl,
			'method': 'get',
			'data': {
				'action': 'wpsg_productvariants_switch',
				'wpsg_post_id': jQuery('#wpsg_produktform_' + template_index + ' input[name="wpsg_post_id"]').val(),
				'form_data': jQuery('#wpsg_produktform_' + template_index).serialize(),				
				'product_index': template_index
			},
			'success': function(data) {
		 
				jQuery('#wpsg_produktform_' + template_index).replaceWith(data);
				if (typeof refreshFsLightbox === 'function') refreshFsLightbox();

				var form = document.getElementById('wpsg_produktform_' + template_index);
				var focus = ((focus_id !== '')?document.getElementById(focus_id):null);
				if (!focus && form && typeof focus_image !== 'undefined') focus = form.querySelector('.wpsg_vp_update_image[data-wpsg-id="' + focus_image + '"]');
				if (!focus && form) focus = form.querySelector('.wpsg_vp_update, .wpsg_vp_update_image');
				if (focus) focus.focus();
				
			}
		} );
        
    } // function wpsg_mod_productvariants_reload(event)