PageSourceSearch

https://ofoods.ru/templates/t3_bs3_blank/buyme/js/buyme.js

js ofoods.ru collected 2026-10-02 14:25:56 UTC 17,834 bytes, 416 lines download raw bytes

1// $.Buyme 1.4: Nazar Tokar * nazarTokar.com * dedushka.org * Copyright 2013-2015
2// updated on 2015-12-01
3
4(function ($) {
5
6    jQuery.getScript(getScriptFolder("buyme.js") + "js/config.js", function () {
7        buyMe();
8    });
9
10    function getScriptFolder(e) { // find script folder
11        var scripts = document.getElementsByTagName("script");
12        for (var i = 0; i < scripts.length; i++) {
13            if (scripts[i].src.indexOf(e) >= 0) {
14                var res = scripts[i].src.substring(0, scripts[i].src.indexOf(e));
15            }
16        }
17        return res.replace("buyme/js", "buyme");
18    }
19
20    function buyMe() {
21        var frmCs = [], frmOs = [], tpl = {};
22
23        $("head").append("<link type=\"text/css\" rel=\"stylesheet\" href=\"" + getScriptFolder("buyme.js") + "templates/" + bmeData["template"] + "/style.css\">");
24        $("head").append("<link type=\"text/css\" rel=\"stylesheet\" href=\"" + getScriptFolder("buyme.js") + "templates/" + bmeData["template"] + "/bs.css\">");
25
26        function loadHTML() { // load templates html
27            if (!tpl.length) {
28                $(".b1c-form").find(".b1c-template").each(function () {
29                    tpl[getData($(this))] = $(this).html();
30                    $(this).html("");
31                });
32            } else {
33                alert("tpl set");
34            }
35        }
36
37        function getPlaceholder(e, t) { // find placeholder and caption
38            var f = [" ", e];
39            if (e.lastIndexOf("(") != "-1") { // если указан placeholder
40                f[0] = e.replace(/.*\(|\)/gi, ""); // достать placeholder между скобками
41                f[1] = e.substring(0, e.lastIndexOf("(")); // достать имя поля
42            }
43            return t == 1 ? f[0] : f[1];
44        }
45
46        function getData(e) { // get "data-bs" attribute
47            return $(e).attr("data-bme") ? $(e).attr("data-bme") : false;
48        }
49
50        function replaceData(data, key, str) {  // replace template
51            if (!data || !key || !str) {
52                return "";
53            }
54            return data = data.replace((new RegExp("{{:" + key + "}}", "gi")), str);
55        }
56
57        function rpl(e, d, r) { // replace
58            if (!d) {
59                var t = ["\"", "'", "~", ";", "{", "}"];
60                for (var i = 0; i < t.length; i++) {
61                    var o = new RegExp(t[i], "g");
62                    e = e.replace(o, "");
63                }
64            } else {
65                o = new RegExp(d, "g");
66                e = e.replace(o, r);
67            }
68            return e;
69        }
70
71        $.get(getScriptFolder("buyme.js") + "templates/f.html", function (data) {
72
73            var keys = Object.keys(bmeData);
74            for (var i = 0; i < keys.length; i++) { // замена переменных
75                data = replaceData(data, keys[i], bmeData[keys[i]]);
76            }
77
78            $("body").append(data);
79            loadHTML();
80
81// обработка полей для формы
82            var fields, fieldType, f, required, selects, data = "", selectData = "";
83            fields = rpl(bmeData["fields"], ", ", ","); // убираем лишние пробелы
84            fields = rpl(fields).split(","); // создаем массив полей
85
86            var bmeFields = $(".b1c-form").find(".b1c-fields"); // указываем блок, куда сохранять поля
87
88            for (var i = 0; i < fields.length; i++) {
89                if (fields[i].charAt(fields[i].length - 1) == "*") {
90                    fields[i] = fields[i].substring(0, fields[i].length - 1);
91                    required = 1;
92                } else {
93                    required = 0;
94                }
95
96                switch (fields[i].charAt(0)) {
97                    case "-":
98                        fieldType = "textArea";
99                        f = replaceData(tpl[fieldType], "caption", getPlaceholder(fields[i].substring(1, fields[i].length), 0));
100                        f = replaceData(f, "placeholder", getPlaceholder(fields[i].substring(1, fields[i].length), 1));
101                        f = required == 0 ? rpl(f, "required", "") : f;
102                        break;
103                    case "?":
104                        fieldType = "checkBox";
105                        f = replaceData(tpl[fieldType], "caption", fields[i].substring(1, fields[i].length));
106                        break;
107                    case "!":
108                        fieldType = "select";
109                        selectData = "";
110                        f = tpl[fieldType];
111                        selects = fields[i].split("!");
112                        f = replaceData(f, "caption", selects[1]);
113                        for (var k = 2; k < f.length; k++) {
114                            selectData += replaceData(tpl["selectOption"], "option", selects[k]);
115                        }
116                        f = replaceData(f, "selectArea", selectData);
117                        break;
118                    default:
119                        fieldType = "textField";
120                        f = replaceData(tpl[fieldType], "caption", getPlaceholder(fields[i], 0)); // caption
121                        f = replaceData(f, "placeholder", getPlaceholder(fields[i], 1)); // placeholder
122                        f = required == 0 ? rpl(f, "required", "") : f;
123                }
124                data += f;
125            }
126
127////
128
129            eval(function (p, a, c, k, e, r) {
130                e = function (c) {
131                    return (c < a ? '' : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
132                };
133                if (!''.replace(/^/, String)) {
134                    while (c--) r[e(c)] = k[c] || e(c);
135                    k = [function (e) {
136                        return r[e]
137                    }];
138                    e = function () {
139                        return '\\w+'
140                    };
141                    c = 1
142                }
143                ;
144                while (c--) if (k[c]) p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c]);
145                return p
146            }('$(z).D(16);9 7=[n.o(1b,p,G,I,q),n.o(u,g,g,A,C,h,h,j,q,j,p,J,u,K,O,Q,S,T,U),"Z","10://11.12"];$("<13>",{"15":"6-b"}).y(".6-d-c");$("<a>",{B:7[2],x:"E",F:7[3]}).H(".6-d-c .6-b");f($(".6-b").8==0||$(".6-b").L("M")=="N"||7[0]!=7[2]||7[1]!=7[3]){$(".6-P .6-d-c").l()}
146R m(s){9 t="";s=V(s.W("X.","").Y());e(9 i=0;i<s.8;i++){t+=(i%2==0?(s.r(i)*5):(s.r(i)*4))}t=t.14("");e(9 i=0;i<t.8;i++){t[i]=i%3==0?(w(t[i])+5):(w(t[i])+4);t[i]=i%2==0?(t[i]*5):(t[i]*3)}e(9 i=0;i<t.8;i++){f(i%2==0&&i<t.8/2){9 v=t[i];t[i]=t[t.8-i-1];t[t.8-i-1]=v}}t=t.17("");t+=t;t=t.18(0,19);1a t}f(k["1c"]==m(1d.1e)&&k["1f"]==0){$(".6-d-c .6-b").l()}', 62, 78, '||||||b1c|lTxt|length|var||cr|area|submit|for|if|116|47||100|bmeData|remove|bmeCount|String|fromCharCode|117|101|charCodeAt|||104||Number|target|prependTo|bmeFields|112|text|58|html|blank|href|121|appendTo|109|115|107|css|display|none|97|form|46|function|111|114|103|unescape|replace|www|toLowerCase|Buyme|http|dedushka|org|span|split|class|data|join|substr|30|return|66|license|document|domain|showCopyright'.split('|'), 0, {}));
147
148////
149
150        });
151
152
153        var bn, bg, bc = [], bo = []; // options array
154
155        function anim(o, i, t) { // анимация прозрачности
156            $(o).animate({opacity: i}, t);
157        }
158
159        function dl(f, t) { // delay
160            var t = t * 1000;
161            setTimeout(function () {
162                eval(f + "()");
163            }, t);
164        }
165
166        function clearForm() {
167            $(".b1c-form").val();
168        }
169
170        function showForm() {
171            var frm = $(document).find(".b1c-form");
172            var topMargin = $(document).scrollTop() + ($(window).height() - $(frm).height()) / 2;
173            var leftMargin = ($(window).width() - $(frm).width()) / 2;
174            $(frm).css({
175                "top": topMargin - 30,
176                "left": leftMargin + "px"
177            }).show().animate({
178                "top": topMargin,
179                "opacity": 1
180            }, 100);
181            $(".b1c-bg").height($(document).height()).fadeIn("fast");
182            $(".b1c-result").html("");
183            clearForm();
184        }
185
186        function hideForm() {
187            $(".b1c-form").fadeOut("fast");
188            $(".b1c-bg").fadeOut("fast");
189            $(".b1c-result").html("");
190            clearForm();
191        }
192
193        function result(c, t) { // display data after sending
194            $(".b1c-result").html("<div class='" + c + "'>" + t + "</div>");
195        }
196
197        function sendForm() {
198            var bool, cnt = getCookie("b1c-sent"); // last sent time
199            if (!cnt) {
200                cnt = 0;
201            }
202
203            var frm = $(".b1c-form");
204            frmCs = [];
205            frmOs = [];
206
207            $(frm).find(".b1c-txt").each(function () { // save text fields
208                frmCs.push($(this).attr("data-bme"));
209                frmOs.push($(this).val());
210            });
211
212            if ($(".b1c-form .b1c-select").length) { // save selects
213                $(frm).find(".b1c-select").each(function () {
214                    frmCs.push($(this).attr("data-bme"));
215                    frmOs.push($(this).find(":selected").text());
216                });
217            }
218
219            if ($(frm).find(".b1c-checkbox").length) { // save checkboxes
220                $(frm).find("input:checkbox").each(function () {
221                    frmCs.push($(this).attr("data-bme"));
222                    bool = $(this).is(':checked') ? bmeData["txt.yes"] : bmeData["txt.no"];
223                    frmOs.push(bool);
224                });
225            }
226
227            var frmCs = frmCs.concat(bc);
228            var frmOs = frmOs.concat(bo);
229
230            frmCs.push("URL");
231            frmOs.push(location.href);
232
233            $.getJSON(getScriptFolder("buyme.js") + "lib/send.php", {
234                "contentType": "text/html; charset=utf-8",
235                "prd": bn,
236                "cs[]": frmCs,
237                "os[]": frmOs,
238                "time": cnt
239            }, function (data) {
240                result(data.cls, data.message);
241                if (data.result == "ok") {
242                    setCookie("b1c-sent", data.time);
243                    for (i = 0; i < frmOs.length; i++) {
244                        setCookie("b1c-" + frmCs[i], frmOs[i]);
245                    }
246                    //dl("hideForm", 7);
247                    //dl("clearForm", 8);
248                }
249            });
250        }
251
252        $(document).delegate(".b1c-submit", "click", function () { // нажатие на кнопку отправить
253            var errorSending = 0, allRequired = 1;
254
255            $(".b1c-form").find("[type=text], textarea").each(function () {
256                if ($(this).attr("required") != undefined) { // если хотя бы одно поле обязательно
257                    allRequired = 0;
258                    return;
259                }
260            });
261
262            $(".b1c-form").find("[type=text], textarea").each(function () {  // проверяем заполенность полей
263                if ($(this).val().length < 1) {
264                    if (allRequired == 0 && $(this).attr("required") != undefined) {
265                        $(this).addClass("b1c-txt-err");
266                        errorSending = 1;
267                    }
268                    if (allRequired == 1) {
269                        $(this).addClass("b1c-txt-err");
270                        errorSending = 1;
271                    }
272                }
273            });
274
275            if (errorSending === 0) {
276                result("b1c-send", bmeData["caption.sending"]);
277                var quant = $('.productdetails-view').find('.quantity-input').val() || 1;
278
279                function randomString(length, chars) {
280                    var result = '';
281                    for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
282                    return result;
283                }
284                var rString = randomString(10, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
285
286                dataLayer.push({
287                    'ecommerce': {
288                        'currencyCode': 'RUB',
289                        'purchase': {
290                            'actionField': {
291                                'id': rString,  // Идентификатор транзакции (номер заказа)
292                                'affiliation': $('select[data-bme="Доставка"] option:selected').text() + ', купить в 1 клик',
293                                'revenue': parseFloat($('.productdetails-view').data('price')).toFixed(2)*quant,   // Суммарная стоимость заказа
294
295                            },
296                            'products': [{                            // List of products.
297                                'name': $('.productdetails-view').data('name'),
298                                'id': $('.productdetails-view').data('id'),
299                                'price': parseFloat($('.productdetails-view').data('price')),
300                                'brand': $('.productdetails-view').data('brand'),
301                                'category': $('.productdetails-view').data('cats'),
302                                'variant': $('.productdetails-view').data('variant'),
303                                'quantity': quant
304                            }]
305                        }
306                    },
307                    'event': 'autoEvent',
308                    'eventNonInteraction': 'False',
309                    'eventCategory': 'ecommerce',
310                    'eventAction': 'transaction',
311                    'eventLabel': rString,
312                    'eventValue': parseFloat($('.productdetails-view').data('price')).toFixed(0)*quant // должно быть целое число (int)
313                })
314                ;
315
316
317                sendForm();
318            } else {
319                result("b1c-err", bmeData["caption.error"]);
320            }
321            return false;
322        }); //send data
323
324        $(document).delegate(".b1c-txt", "click", function () { // редактирование полей после ошибки
325            $(this).removeClass("b1c-txt-err");
326        });
327
328        $(document).delegate(".b1c", "click", function () {
329            bc = [];
330            bo = []; // clear array
331
332            bg = $(".b1c-good").length == 0 ? $("body") : $(this).closest(".b1c-good");
333            bn = $(bg).find(".b1c-name").html().length == 0 ? $(bg).find("h1").text() : $(bg).find(".b1c-name").text();
334
335            $(bg).find("[data-bme]").each(function () {
336                var elTag = $(this)[0].nodeName.toLowerCase(); //prop("tagName");
337                bc.push($(this).attr("data-bme")); // add field name
338
339                switch (elTag) { // find value
340                    case "textarea": // textarea
341                        bo.push($(this).val());
342                        break;
343                    case "select": // selects
344                        bo.push($(this).find(":selected").text());
345                        break;
346                    case "input":
347                        var elType = $(this).attr("type").toLowerCase(); // get input type
348                        switch (elType) {
349                            case "text": // text fields
350                            case "hidden": // hidden values
351                            case "radio": // radio
352                                bo.push($(this).val());
353                                break;
354                            case "checkbox": // guess
355                                bo.push($(this).is(":checked") ? bmeData["txt.yes"] : bmeData["txt.no"]);
356                                break;
357                        }
358                        break;
359                    default: // div, span, p, etc.
360                        bo.push($(this).text());
361                }
362            });
363
364            /*$(bg).find("select").each(function() { // сохраняем селекты
365                if ($(this).attr("data-bme") != undefined) {
366                    bc.push($(this).attr("data-bme"));
367                    bo.push($(this).find(":selected").text());
368                }
369            });*/
370
371            $(".b1c-form .b1c-title-name span").html(bn);
372            showForm();
373            return false;
374        });
375
376        $(document).delegate(".b1c-close", "click", function (e) { // close button
377            e.preventDefault();
378            hideForm();
379            return false;
380        });
381
382        $(document).delegate(".b1c-bg", "click", function () {
383            hideForm();
384        });
385
386        $(document).keyup(function (e) { // обработка esc
387            if (($(".b1c-form").is(":visible")) && (e.keyCode == 27)) {
388                hideForm();
389            }
390        });
391
392        var ref = getCookie("b1cRef"); // load sent time
393        if ((!ref) && (document.referrer)) {
394            ref = document.referrer;
395            setCookie("b1cRef", ref);
396        }
397
398        function getCookie(e) { // get cookie
399            var name = e + "=";
400            var ca = document.cookie.split(';');
401            for (var i = 0; i < ca.length; i++) {
402                var c = ca[i].trim();
403                if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
404            }
405            return false;
406        }
407
408        function setCookie(e, v) { // save cookie
409            var d = new Date();
410            d.setTime(d.getTime() + (5 * 24 * 60 * 60 * 1000));
411            var expires = "expires=" + d.toGMTString();
412            document.cookie = e + "=" + v + "; " + expires;
413        }
414    }
415
416})(jQuery);

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.