PageSourceSearch

https://spirit.watch/wa-apps/shop/plugins/contacts/js/contacts.js?v=8888

js spirit.watch collected 2026-10-08 13:57:54 UTC 12,795 bytes, 349 lines download raw bytes

1/**
2 * Created by Echo-company
3 */
4function ContactsEchoCompany() {
5    var that = this;
6
7    that.isInit = false;
8
9    that.scroll = 0;
10    that.template = null;
11
12    that.auto_mask = 1;
13
14    var placement = 'top';
15
16    that.is_touch_device = function () {
17        return 'ontouchstart' in window;
18    };
19
20    that.checkHeight = function (m_popup, offset) {
21
22        var $wrapper = $('.b-contacts__wrapper');
23        var offset_top = $wrapper.data('top-offset') || 0;
24        var bottom = m_popup.position().top + offset_top + m_popup.outerHeight(true);
25
26        if (bottom > $(window).height()) {
27            var m_content = m_popup.find('.webui-popover-content');
28            m_content.outerHeight($(window).height() - m_content.position().top - m_popup.position().top - offset - offset_top);
29        }
30
31    };
32
33    that.checkRight = function (m_popup) {
34        var right = m_popup.position().left + m_popup.outerWidth(true);
35        if (right > $(window).width()) {
36            var need_change = right - $(window).width();
37
38            if (need_change > m_popup.position().left) {
39                need_change = m_popup.position().left;
40            }
41            m_popup.css("left", m_popup.position().left - need_change);
42
43            if ((placement == 'top') || (placement == 'bottom')) {
44                m_popup.find('.webui-arrow').css("left", m_popup.find('.webui-arrow').position().left + need_change);
45            }
46        }
47    };
48
49    that.checkLeft = function (m_popup) {
50        var left = m_popup.position().left;
51        if (left < 0) {
52            var need_change = -left;
53
54            m_popup.css("left", 0);
55
56            if ((placement == 'top') || (placement == 'bottom')) {
57                m_popup.find('.webui-arrow').css("left", m_popup.find('.webui-arrow').position().left - need_change);
58            }
59        }
60
61    };
62
63    that.globalCheck = function (m_popup) {
64        if ((placement == 'left') || (placement == 'right')) {
65
66            var $wrapper = $('.b-contacts__wrapper');
67
68            var offset_top = $wrapper.data('top-offset') || 0;
69            var original_position = m_popup.position();
70
71            if (original_position.top < -offset_top) {
72                m_popup.css("top", -offset_top);
73
74                var change = - offset_top - original_position.top;
75                m_popup.find('.webui-arrow').css("top", m_popup.find('.webui-arrow').position().top - change);
76            }
77
78            var bottom = m_popup.position().top + offset_top + m_popup.outerHeight(true);
79            if (bottom > $(window).height()) {
80
81                if (-m_popup.position().top < offset_top) {
82                    var may_change = offset_top + m_popup.position().top;
83                    var need_change = bottom - $(window).height();
84
85                    if (need_change > may_change) {
86                        need_change = may_change;
87                    }
88
89                    m_popup.css("top", m_popup.position().top - need_change);
90                    m_popup.find('.webui-arrow').css("top", m_popup.find('.webui-arrow').position().top + need_change);
91                }
92            }
93
94            that.checkHeight(m_popup, 5);
95
96            //check left
97            if (placement == 'right') {
98                that.checkRight(m_popup);
99            }
100            if (placement == 'left') {
101
102                var left = -m_popup.position().left + that.template.outerWidth(true);
103
104                if (left > $(window).width()) {
105                    var need_change = left - $(window).width() + 10;
106
107                    if (need_change > that.template.outerWidth(true)) {
108                        need_change = that.template.outerWidth(true);
109                    }
110                    m_popup.css("left", m_popup.position().left + need_change);
111
112                }
113            }
114
115        }
116        if ((placement == 'top') || (placement == 'bottom')) {
117            that.checkRight(m_popup);
118            that.checkLeft(m_popup);
119
120            var m_offset = 15;
121
122            if (placement == 'top') {
123                var top = $(that.template).outerHeight() - m_popup.position().top;
124                if (top > $(window).height()) {
125                    var need_change = top - $(window).height() + 10;
126                    m_popup.css("top", m_popup.position().top + need_change);
127
128                    var m_content = m_popup.find('.webui-popover-content');
129                    m_content.outerHeight(m_content.outerHeight() - need_change);
130                }
131            } else {
132                that.checkHeight(m_popup, m_offset);
133            }
134        }
135    };
136
137    that.initContacts = function () {
138
139
140        that.template = $($('#shopcontacts__template').html());
141
142
143        $('body').append(that.template);
144
145        var need_middle = false;
146
147        that.auto_mask = that.template.data('auto_mask');
148
149        if (that.template.hasClass('b-contacts__wrapper--left')) {
150            placement = 'right';
151            need_middle = true;
152        }
153
154        if (that.template.hasClass('b-contacts__wrapper--right')) {
155            placement = 'left';
156            need_middle = true;
157        }
158
159        if (that.template.hasClass('b-contacts__wrapper--top')) {
160            placement = 'bottom';
161        }
162
163        if (that.template.hasClass('b-contacts__wrapper--scroll')) {
164            that.scroll = that.template.data('scroll');
165            $(window).scroll(that.calcScroll);
166            that.calcScroll();
167        }
168
169        if (need_middle) {
170            $(window).resize(that.calcMiddle);
171            //  $(document).scroll(that.calcMiddle);
172            that.calcMiddle();
173        }
174
175
176        if ((!that.template.data('mobile')) && (!that.is_touch_device()
176)) {
177            that.template.find('.b-contacts__has_title').webuiPopover({
178                placement: placement,
179                container: that.template,
180                trigger: 'hover'
181            });
182        }
183
184        var call_block = that.template.find('.b-contacts__call_block');
185        if (call_block.length > 0) {
186            call_block.find('>a').webuiPopover({
187                placement: placement,
188                container: that.template,
189                trigger: 'click',
190                closeable: true,
191                width: 300,
192                dismissible: false
193            });
194
195            if (that.auto_mask) {
196                $('#shop_contacts__call_input').inputmask("phone",
197                    {
198                        "oncomplete": function () {
199                            $('#shop_contacts__call_input').addClass("b-contacts__call_complete").removeClass('b-contacts__call_incomplete');
200                        },
201                        "onincomplete": function () {
202                            $('#shop_contacts__call_input').removeClass("b-contacts__call_complete");
203                        }
204                    }
205                );
206            } else {
207                $('#shop_contacts__call_input').addClass('b-contacts__call_complete');
208            }
209
210            $('.b-contacts__call_form').submit(function (e) {
211                that.template.find('.b-contacts__error').html('');
212                if ($(this).find('.b-contacts__call_complete').length == 0) {
213                    $('#shop_contacts__call_input').addClass('b-contacts__call_incomplete').focus();
214                } else if ($(this).find('#shop_contacts__call_input.wa-error').length != 0) {
215                    //Работа сторонних плагинов
216                } else {
217                    //Send
218                    var url = that.template.data('base_url') + "shop_contacts_call_request/";
219                    that.template.find('.b-contacts__loader').show();
220                    that.template.find('.b-contacts__call_input').attr('disabled', 'disabled');
221                    $.post(url, {
222                        tel: $('#shop_contacts__call_input').val(),
223                        subject: $('#shop_contacts__call_subject').val(),
224                        r: Math.random()
225                    }).done(function (response) {
226
227                        if (response.status && response.status == 'ok') {
228                            WebuiPopovers.updateContent(call_block.find('a'), response.data);
229                        } else {
230                            try {
231                                that.template.find('.b-contacts__error').html('' + response.errors);
232                            } catch (e) {
233                            }
234                        }
235                        that.template.find('.b-contacts__loader').hide();
236                        that.template.find('.b-contacts__call_input').removeAttr('disabled');
237                    }).fail(function () {
238                        that.template.find('.b-contacts__loader').hide();
239                        that.template.find('.b-contacts__call_input').removeAttr('disabled');
240                    })
241                }
242                e.preventDefault();
243            })
244        }
245
246
247        var form_block = that.template.find('.b-contacts__form_block');
248        if (form_block.length > 0) {
249            form_block.find('>a').webuiPopover({
250                placement: placement,
251                container: that.template,
252                trigger: 'click',
253                closeable: true,
254                width: 300,
255                dismissible: false
256            });
257            if (that.auto_mask) {
258                form_block.find('.b-contacts__form--tel').inputmask("phone");
259            }
260
261            $(document).on('submit', '.b-contacts__form_form', function (e) {
262                var url = that.template.data('base_url') + "shop_contacts_form_request/";
263                that.template.find('.b-contacts__loader').show();
264                that.template.find('.b-contacts__form_input').attr('disabled', 'disabled');
265
266                var data = $(this).serializeArray();
267
268                $.post(url, data).done(function (response) {
269
270                    if (response.status && response.status == 'ok') {
271
272                        //Update the Popover content
273                        WebuiPopovers.updateContent(form_block.find('a'), response.data);
274
275                        //that.template.find('.b-contacts__form_popup').html(response.data);
276                        if (that.template.find('.b-contacts__form--tel').length > 0) {
277                            if (that.auto_mask) {
278                                that.template.find('.b-contacts__form--tel').inputmask("phone");
279                            }
280                        }
281
282                    } else {
283                        try {
284                            that.template.find('.b-contacts__form_form .b-contacts__error').html('' + response.errors);
285                        } catch (e) {
286                        }
287                    }
288                    that.template.find('.b-contacts__loader').hide();
289                    that.template.find('.b-contacts__form_input').removeAttr('disabled');
290                }).fail(function () {
291                    that.template.find('.b-contacts__loader').hide();
292                    that.template.find('.b-contacts__form_input').removeAttr('disabled');
293                });
294                e.preventDefault();
295            });
296        }
297
298        $(document).on('shown.webui.popover', function (e, e1) {
299            var m_popup = $(e1);
300            that.globalCheck(m_popup);
301        });
302
303        $(document).on('hide.webui.popover', function (e, e1) {
304            $(e1).find('.webui-popover-content').height('auto');
305        });
306
307        $(window).resize(function () {
308            var m_popup = $('.webui-popover.in');
309            if (m_popup.length > 0) {
310                that.globalCheck(m_popup);
311            }
312        });
313
314    };
315
316    that.calcMiddle = function () {
317        var block = $('.b-contacts__wrapper');
318        var middle = ($(window).height() - block.height()) / 2;
319        middle = middle >= 0 ? middle : 0;
320        block.data('top-offset', middle);
321        block.css("top", middle.toString() + 'px');
322    };
323
324    that.calcScroll = function () {
325        var winscroll = $(window).scrollTop();
326
327        if (winscroll >
327 that.scroll) {
328            that.template.fadeIn();
329        } else {
330            that.template.fadeOut();
331        }
332    };
333
334
335    that.forceInit = function () {
336        if (!that.isInit) {
337
338            that.initContacts();
339
340            that.isInit = true;
341        }
342    };
343
344    $(document).ready(function () {
345        that.forceInit();
346    });
347
348
349}

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.