PageSourceSearch

https://upackmax.ru/assets/components/mssaleprice/js/web/default.js?v=2d36f3d176

js upackmax.ru collected 2026-10-10 02:33:02 UTC 9,381 bytes, 272 lines download raw bytes

1(function (window, document, $, msSalePriceConfig) {
2	var msSalePrice = msSalePrice || {};
3	
4	msSalePriceConfig.callbacksTemplate = function () {
5        return {
6            before: [],
7            response: {
8                success: [],
9                error: []
10            }
11        }
12    };
13	
14    msSalePrice.setup = function () {
15		this.form = '.mssaleprice_form';
16		this.actionName = 'mssp_action';
17        this.sendData = {
18            $form: null,
19            action: null,
20            formData: null
21        };
22    };
23	
24	msSalePrice.send = function (data, callbacks) {
25		
26        var runCallback = function (callback, bind) {
27            if (typeof callback == 'function') {
28                return callback.apply(bind, Array.prototype.slice.call(arguments, 2));
29            }
30            else if (typeof callback == 'object') {
31                for (var i in callback) {
32                    if (callback.hasOwnProperty(i)) {
33                        var response = callback[i].apply(bind, Array.prototype.slice.call(arguments, 2));
34                        if (response === false) {
35                            return false;
36                        }
37                    }
38                }
39            }
40            return true;
41        };
42        // set context
43        if ($.isArray(data)) {
44            data.push({
45                name: 'ctx',
46                value: msSalePriceConfig.ctx
47            });
48        }
49        else if ($.isPlainObject(data)) {
50            data.ctx = msSalePriceConfig.ctx;
51        }
52        else if (typeof data == 'string') {
53            data += '&ctx=' + msSalePriceConfig.ctx;
54        }
55
56        // set action url
57        var formActionUrl = (msSalePrice.sendData.$form)
58            ? msSalePrice.sendData.$form.attr('action')
59            : false;
60        var url = (formActionUrl)
61            ? formActionUrl
62            : (msSalePriceConfig.actionUrl)
63                      ? msSalePriceConfig.actionUrl
64                      : document.location.href;
65        // set request method
66        var formMethod = (msSalePrice.sendData.$form)
67            ? msSalePrice.sendData.$form.attr('method')
68            : false;
69        var method = (formMethod)
70            ? formMethod
71            : 'post';
72
73        // callback before
74        if (runCallback(callbacks.before) === false) {
75            return;
76        }
77		$.ajax({
78			type: method,
79			url: url,
80			dataType: 'json',
81			data: data,
82			async: true,
83			cache: false,
84			success: function(response){
85				if(response.success){
86                    if (response.message) {
87                        miniShop2.Message.success(response.message);
88                    }
89                    runCallback(callbacks.response.success, msSalePrice, response);
90				}
91				else{
92					miniShop2.Message.error(response.message);
93                    runCallback(callbacks.response.error, msSalePrice, response);
94				}
95			}
96		});
97    };
98	
99	msSalePrice.initialize = function() {
100		msSalePrice.setup();
101        msSalePrice.Product.initialize();
102	}
103	
104    msSalePrice.controller = function () {
105        var self = this;
106        switch (self.sendData.action) {
107            case 'product/getprice':
108                msSalePrice.Product.getprice();
109                break;
110            default:
111                return;
112        }
113    };
114	
115	msSalePrice.Product = {
116		callbacks: {
117            getprice: msSalePriceConfig.callbacksTemplate(),
118            getincart: msSalePriceConfig.callbacksTemplate()
119        },
120        setup: function () {
121			msSalePrice.Product.form = '.ms2_form.mssaleprice_form';
122			msSalePrice.Product.price = '.mssaleprice-cost';
123			msSalePrice.Product.old_price = '.mssaleprice-old-cost';
124			msSalePrice.Product.count = '.mssaleprice-count';
125			msSalePrice.Product.count_popup = '.mssaleprice-count-popup';
126        },
127        initialize: function () {
128            msSalePrice.Product.setup();
129			
130			$(document).on('change', msSalePrice.Product.form, function (e) {
131				e.preventDefault();
132				var $form = $(this);
133				var action = 'product/getprice';
134				
135				var formData = $form.serializeArray();
136				formData.push({
137					name: msSalePrice.actionName,
138					value: action
139				});
140				msSalePrice.sendData = {
141					$form: $form,
142					action: action,
143					formData: formData
144				};
145				msSalePrice.controller();
146			});
147			
148			if ($(msSalePrice.Product.count).length){
149				
150				$(document).on('focus', msSalePrice.Product.count +' [name="count"]', function (e) {
151					$p = $(this).parents( msSalePrice.Product.count ).find(msSalePrice.Product.count_popup);
152					if( $p ){
153						$p.fadeIn();
154					}
155					e.preventDefault();
156					return false;
157				});
158
159				$(document).on('blur', msSalePrice.Product.count +' [name="count"]', function (e) {
160					$p = $(this).parents( msSalePrice.Product.count ).find(msSalePrice.Product.count_popup);
161					if( $p ){
162						$p.fadeOut();
163					}
164					e.preventDefault();
165					return false;
166				});
167				
168				$(document).on('click', msSalePrice.Product.count +' [data-count]', function (e) {
169					$count = $(this).data('count') || 1;
170					$(this).parents( msSalePrice.Product.count ).find('[name="count"]').val( $count ).trigger('change');
171					e.preventDefault();
172					return false;
173				});
174			}
175			
176			miniShop2.Callbacks.add('Cart.change.response.success', 'mssaleprice', msSalePrice.Product.status);
177        },
178        getprice: function () {
179			console.log('dfdfbdfb');
180            var callbacks = msSalePrice.Product.callbacks;
181            callbacks.getprice.response.success = function (response) {
182				
183				$(msSalePrice.sendData.$form).find(msSalePrice.Product.price + ' span').text( miniShop2.Utils.formatPrice( response.data.price ) );
184				$(msSalePrice.Product.price + '-' + response.data.rid + ' span').each(function(i,e){
185					$(e).text( miniShop2.Utils.formatPrice( response.data.price ) );
186				});
187				
188				if (!miniShop2.Utils.empty(response.data.old_price)){
189					$(msSalePrice.sendData.$form).find( msSalePrice.Product.old_price + ' span' ).text( miniShop2.Utils.formatPrice(response.data.old_price) );
190					$(msSalePrice.sendData.$form).find( msSalePrice.Product.old_price).show();
191					
192					$(msSalePrice.Product.old_price + '-' + response.data.rid).show();
193					$(msSalePrice.Product.old_price + '-' + response.data.rid ).each(function(i,e){
194						$(e).find('span').text( miniShop2.Utils.formatPrice( response.data.old_price ) );
195					});
196				}
197				else{
198					$(msSalePrice.sendData.$form).find( msSalePrice.Product.old_price + ' span' ).text( '' );
199					$(msSalePrice.sendData.$form).find( msSalePrice.Product.old_price).hide();
200					$(msSalePrice.Product.old_price + '-' + response.data.rid).hide();
201				}
202
203				$(msSalePrice.sendData.$form).find(msSalePrice.Product.count_popup).html($(response.data.table).find(msSalePrice.Product.count_popup).html());
204				
205				$(document).trigger('mssp_callback', ['getprice', response]);
206            };
207			
208            msSalePrice.send(msSalePrice.sendData.formData, msSalePrice.Product.callbacks.getprice);
209        },
210        status: function(response){
211        	if (response.data.mssp){
212        		$.each(response.data.mssp, function(key, values){
213					
214        			$( '#' + key + ' ' + msSalePrice.Product.price + ' span', miniShop2.Cart.cart ).text( miniShop2.Utils.formatPrice( values.price ) );
215					
216					if (!miniShop2.Utils.empty(values.old_price)){
217						$( '#' + key + ' ' + msSalePrice.Product.old_price + ' span', miniShop2.Cart.cart ).text( miniShop2.Utils.formatPrice(values.old_price) );
218						$( '#' + key + ' ' + msSalePrice.Product.old_price, miniShop2.Cart.cart).show();
219					}
220					else{
221						$( '#' + key + ' ' + msSalePrice.Product.old_price + ' span', miniShop2.Cart.cart ).text( '' );
222						$( '#' + key + ' ' + msSalePrice.Product.old_price, miniShop2.Cart.cart).hide();
223					}
224        		});
225        	}
226        },
227        /*
228		getincart: function(msresponse){
229			var key = msresponse.data.key;
230			
231			var callbacks = msSalePrice.Product.callbacks;
232            callbacks.getincart.response.success = function (response) {
233				
234				$( '#' + key + ' ' + msSalePrice.Product.price + ' span', miniShop2.Cart.cart ).text( miniShop2.Utils.formatPrice( response.data.price ) );
235				
236				if (!miniShop2.Utils.empty(response.data.old_price)){
237					$( '#' + key + ' ' + msSalePrice.Product.old_price + ' span', miniShop2.Cart.cart ).text( miniShop2.Utils.formatPrice(response.data.old_price) );
238					$( '#' + key + ' ' + msSalePrice.Product.old_price, miniShop2.Cart.cart).show();
239				}
240				else{
241					$( '#' + key + ' ' + msSalePrice.Product.old_price + ' span', miniShop2.Cart.cart ).text( '' );
242					$( '#' + key + ' ' + msSalePrice.Product.old_price, miniShop2.Cart.cart).hide();
243				}
244				$(document).trigger('mssp_callback', ['getincart', response]);
245				
246				miniShop2.Order.getcost();
247            };
248            var data = {};
249            data[msSalePrice.actionName] = 'product/getincart';
250            data['key'] = key;
251            msSalePrice.send(data, msSalePrice.Product.callbacks.getincart);
252		}*/
253	}
254	
255    $(document).ready(function ($) {
256        msSalePrice.initialize();
257    });
258
259    window.msSalePrice = msSalePrice;
260})(window, document, jQuery, msSalePriceConfig);
261
262/* event example */
263$(document).on('mssp_callback', function (e, action, response) {
264	/*
265	console.log(action, response);
266	switch (action){
267		case 'getprice':
268			break;
269		case 'getincart':
270			break;
271	}*/
272});

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.