PageSourceSearch

https://pasma-shop.ru/wa-data/public/shop/plugins/pnotice/js/pnotice.js?v1.5.0-6689671026

js pasma-shop.ru collected 2026-09-24 12:06:37 UTC 14,692 bytes, 282 lines download raw bytes

1(function($) {
2    'use sctrict'
3    $.pnotice = {
4        mask:'',
5        url:'',
6        yandex:'',
7        policyCheckbox:'',
8        stocks:'',
9        templates:'',
10        skus:'',
11        skuFeature:'',
12
13        init: function(options, templates) {
14            this.mask = options.mask || false;
15            this.url = options.url || '/';
16            this.yandex = options.yandex || '';
17            this.policyCheckbox = options.policyCheckbox || false;
18            this.stocks = options.stocks || false;
19            this.templates = templates;
20
21            this.initSkuFeature();
22            this.initView();
23            this.initSubmitProduct('pnoticeForm');
24            this.initSubmitProduct('pnotice');
25            this.initClose();
26
27            if(this.mask) this.initMask();
28
29        },
30        getSku: function(skusSELECT) {
31            var key = '';
32            var sku = '';
33            var skus = this.skus;
34            var skuFeature = this.skuFeature;
35
36            if(skusSELECT != null && Object.keys(skusSELECT).length == 1) {
37                var first;
38                for (var i in skusSELECT) {
39                    first = skusSELECT[i];
40                    break;
41                }
42                sku = first;
43            } else if(skusSELECT != null) {
44                if(skuFeature.length) {
45                    skuFeature.each(function() {
46                        key += $(this).data('feature-id') + ':' + $(this).val() + ';';
47                    });
48                    sku = skusSELECT[key];
49                } else if(skus.length) {
50                    key = skus.filter(':checked').val();
51                    sku = skusSELECT[key];
52                }
53            }
54            return sku;
55        },
56        initSkuFeature: function() {
57            var that = this;
58
59            var pnoticeForm = $('.pnoticeForm');
60            var buttonView = $('.pnotice__buttonView');
61
62            if (pnoticeForm.length || buttonView.length) {
63                that.skus = $('input[name="sku_id"]');
64                that.skuFeature = $("[name^='features[']");
65
66                var product = buttonView.data('product') || pnoticeForm.find('.pnoticeForm__button').data('product');
67                var skusSELECT = product.skusSELECT;
68                function skuFeatureHide() {
69                    var sku = that.getSku(skusSELECT);
70                    var stock = that.stocksCheck(sku, pnoticeForm, 'pnoticeForm');
71
72                    if (sku && (!sku.available || stock)) {
73                        buttonView.show();
74                        pnoticeForm.show();
75                        pnoticeForm.find('.pnoticeForm__sku').val(sku.id);
76                    } else {
77                        buttonView.hide();
78                        pnoticeForm.hide();
79                    }
80                }
81
82                if (that.skus.length) {
83                    that.skus.change(function () {
84                        skuFeatureHide();
85                    });
86                    skuFeatureHide();
87                }
88
89                if (that.skuFeature.length) {
90                    that.skuFeature.change(function () {
91                        skuFeatureHide();
92                    });
93                    skuFeatureHide();
94                }
95            }
96        },
97        initView: function() {
98            var that = this;
99
100            $('body').on('click', '.pnotice__buttonView', function() {
101                var product = $(this).data('product');
102                var skuName = '';
103                var sku = that.getSku(product.skusSELECT);
104
105                $('body').append(that.templates);
106                var pnotice = $('.pnotice');
107                var stock = that.stocksCheck(sku, pnotice, 'pnotice');
108
109                console.log(product);
110
111                pnotice.find('.pnotice__img').html('<img src="'+product.image+'" alt="" />');
112                pnotice.find('.pnotice__sku').val(product.sku_id);
113                pnotice.find('.pnotice__id').val(product.id);
114                pnotice.find('.pnotice__n').text(product.name);
115
116                if(product.frontend_url) {
117                    var url = location.protocol+'//'+location.hostname+product.frontend_url;
118                    pnotice.find('.pnotice__button').after('<input class="pnotice__url" type="hidden" name="pnotice__url" value="'+url+'">');
119                }
120
121
122                if (sku) {
123                    if (!sku.available || stock) {
124                        skuName = sku.name;
125                        $('.pnotice__sku').val(sku.id);
126                    } else {
127                        $('.pnotice__error').show();
128                        $('.pnotice__bid').hide();
129                    }
130
131                    if(skuName != '')
132                        pnotice.find('.pnotice__variants').text(skuName);
133                }
134
135                that.yandexTarget('click');
136
137                setTimeout(function() {
138                    if(that.mask)
139                        pnotice.find('.pnotice__input_phone').mask(that.mask);
140
141                    pnotice.addClass('pnotice_active');
142                    $('.pnoticeW').addClass('pnoticeW_active');
143                    $('body').addClass('pnoticeOver');
144                }, 100);
145
146                return false;
147            });
148        },
149        stocksCheck: function(sku, ob, cl) {
150            var that = this;
151            var count = 0;
152
153            ob.find('.'+cl+'__select_stocks').remove();
154
155            if(sku!=undefined && sku.stocks!=undefined && that.stocks) {
156                var selectStocks = '<select class="'+cl+'__select '+cl+'__select_stocks" name="pnotice__stocks">';
157                for(var key in sku.stocks) {
158                    if(sku.stocks[key] == 0 && that.stocks[key]) {
159                        count++;
160                        selectStocks += '<option value="' + key + '">' + that.stocks[key].name + '</option>';
161                    }
162                }
163                selectStocks += '</select>';
164
165                if(count>0)
166                    ob.find('.' + cl + '__button').before(selectStocks);
167            }
168
169            return count>0 || false;
170        },
171        initSubmitProduct: function(cl) {
172            var that = this;
173
174            $('body').on('focusin', '.'+cl+'__input', function() {
175                $(this).removeClass(cl+'__input_error');
176            });
177
178            if(that.policyCheckbox) {
179                $('body').on('change', '.'+cl+'__policyCheckbox', function(event) {
180                    $(this).parent().removeClass(cl+'__politika_error');
181                });
182            }
183
184            $('body').on('submit', '.'+cl+' form', function(event) {
185                var f = $(this);
186                var error = false;
187
188                $('.'+cl+'__input').each(function(index, el) {
189                    if($(this).val().trim() == '') {
190                        error = true;
191                        $(this).addClass(cl+'__input_error');
192                    }
193                });
194
195                var email = f.find('input[name="pnotice__email"]');
196                if(email.length && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.val())) {
197                    error = true;
198                    email.addClass(cl+'__input_error');
199                }
200
201                var policyCheckbox;
202                if(that.policyCheckbox && !f.find('.'+cl+'__policyCheckbox').is(':checked')) {
203                    error = true;
204                    f.find('.'+cl+'__politika').addClass(cl+'__politika_error');
205                }
206
207                if(!error)
208                    that.addRequest(f, cl);
209
210                return false;
211            });
212        },
213        addRequest: function(f, cl, error) {
214            var that = this;
215            var btn = f.find('.'+cl+'__button');
216            var serialize = f.serialize();
217
218            var url = f.find('.pnotice__url').val();
219            if(!url) serialize += '&pnotice__url=' + location.href;
220
221            serialize += '&pnotice__antispam=' + $('.'+cl+'__antispam').text();
222
223            btn.addClass('pnotice__button_loading').attr('disabled','disabled');
224            $.ajax({
225                url: that.url + 'pnotice/add/',
226                data: serialize,
227                dataType: "json",
228                type: "post",
229                success: function (response) {
230                    if (response.status == 'ok' && response.data) {
231                        if (response.data.status && response.data.message) {
232                            $('.'+cl+'__bid').hide();
233                            $('.'+cl+'__thankText').html(response.data.message).show().parent().show();
234                            that.yandexTarget('send');
235                        } else if (response.data.message) {
236                            alert(response.data.message);
237                            that.yandexTarget('fail');
238                        }
239                    }
240                    btn.removeClass('pnotice__button_loading').removeAttr('disabled');
241                },
242                error: function () {
243                    btn.removeClass('pnotice__button_loading').removeAttr('disabled');
244                    that.yandexTarget('fail');
245                }
246            });
247        },
248        initClose: function() {
249            $('body').on('click', '.pnotice__close,.pnoticeW,.pnotice__buttonClose', function(event) {
250                $('.pnotice').removeClass('pnotice_active');
251                $('.pnoticeW').removeClass('pnotice_active');
252                $('body').removeClass('pnoticeOver');
253
254                setTimeout(function() {
255                    $('.pnotice,.pnoticeW').remove();
256                }, 300);
257            });
258        },
259        initMask: function() {
260            $('.pnoticeForm__input_tel').mask(this.mask);
261        },
262        yandexTarget: function(target) {
263            var yaCounter = this.yandex.counter;
264            var target = this.yandex[target];
265
266            if(yaCounter && target)
267            {
268                var yaCounter = window['yaCounter' + yaCounter];
269                yaCounter.reachGoal(target);
270            }
271        }
272    }
273})(jQuery);
274
275
276/*
277    jQuery Masked Input Plugin
278    Copyright (c) 2007 - 2015 Josh Bush (digitalbush.com)
279    Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license)
280    Version: 1.4.1
281*/
282!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b,c=navigator.userAgent,d=/iphone/i.test(c),e=/chrome/i.test(c),f=/android/i.test(c);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(c,g){var h,i,j,k,l,m,n,o;if(!c&&this.length>0){h=a(this[0]);var p=h.data(a.mask.dataName);return p?p():void 0}return g=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},g),i=a.mask.definitions,j=[],k=n=c.length,l=null,a.each(c.split(""),function(a,b){"?"==b?(n--,k=a):i[b]?(j.push(new RegExp(i[b])),null===l&&(l=j.length-1),k>a&&(m=j.length-1)):j.push(null)}),this.trigger("unmask").each(function(){function h(){if(g.completed){for(var a=l;m>=a;a++)if(j[a]&&C[a]===p(a))return;g.completed.call(B)}}function p(a){return g.placeholder.charAt(a<g.placeholder.length?a:0)}function q(a){for(;++a<n&&!j[a];);return a}function r(a){for(;--a>=0&&!j[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);n>c;c++)if(j[c]){if(!(n>d&&j[c].test(C[d])))break;C[c]=C[d],C[d]=p(d),d=q(d)}z(),B.caret(Math.max(l,a))}}function t(a){var b,c,d,e;for(b=a,c=p(a);n>b;b++)if(j[b]){if(d=q(b),e=C[b],C[b]=c,!(n>d&&j[d].test(e)))break;c=e}}function u(){var a=B.val(),b=B.caret();if(o&&o.length&&o.length>a.length){for(A(!0);b.begin>0&&!j[b.begin-1];)b.begin--;if(0===b.begin)for(;b.begin<l&&!j[b.begin];)b.begin++;B.caret(b.begin,b.begin)}else{for(A(!0);b.begin<n&&!j[b.begin];)b.begin++;B.caret(b.begin,b.begin)}h()}function v(){A(),B.val()!=E&&B.change()}function w(a){if(!B.prop("readonly")){var b,c,e,f=a.which||a.keyCode;o=B.val(),8===f||46===f||d&&127===f?(b=B.caret(),c=b.begin,e=b.end,e-c===0&&(c=46!==f?r(c):e=q(c-1),e=46===f?q(e):e),y(c,e),s(c,e-1),a.preventDefault()):13===f?v.call(this,a):27===f&&(B.val(E),B.caret(0,A()),a.preventDefault())}}function x(b){if(!B.prop("readonly")){var c,d,e,g=b.which||b.keyCode,i=B.caret();if(!(b.ctrlKey||b.altKey||b.metaKey||32>g)&&g&&13!==g){if(i.end-i.begin!==0&&(y(i.begin,i.end),s(i.begin,i.end-1)),c=q(i.begin-1),n>c&&(d=String.fromCharCode(g),j[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),f){var k=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(k,0)}else B.caret(e);i.begin<=m&&h()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&n>c;c++)j[c]&&(C[c]=p(c))}function z(){B.val(C.join(""))}function A(a){var b,c,d,e=B.val(),f=-1;for(b=0,d=0;n>b;b++)if(j[b]){for(C[b]=p(b);d++<e.length;)if(c=e.charAt(d-1),j[b].test(c)){C[b]=c,f=b;break}if(d>e.length){y(b+1,n);break}}else C[b]===e.charAt(d)&&d++,k>b&&(f=b);return a?z():k>f+1?g.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,n)):z():(z(),B.val(B.val().substring(0,f+1))),k?b:l}var B=a(this),C=a.map(c.split(""),function(a,b){return"?"!=a?i[a]?p(b):a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return j[b]&&a!=p(b)?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(b);var a;E=B.val(),a=A(),b=setTimeout(function(){B.get(0)===document.activeElement&&(z(),a==c.replace("?","").length?B.caret(0,a):B.caret(a))},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on("input.mask paste.mask",function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),h()},0)}),e&&f&&B.off("input.mask").on("input.mask",u),A()})}})});

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.