PageSourceSearch

https://well-good.ru/catalog/view/theme/royal/js/common.js

js well-good.ru collected 2026-09-29 20:00:34 UTC 22,990 bytes, 800 lines download raw bytes

1function getURLVar(key) {
2	var value = [];
3
4	var query = document.location.search.split('?');
5
6	if (query[1]) {
7		var part = query[1].split('&');
8
9		for (i = 0; i < part.length; i++) {
10			var data = part[i].split('=');
11
12			if (data[0] && data[1]) {
13				value[data[0]] = data[1];
14			}
15		}
16
17		if (value[key]) {
18			return value[key];
19		} else {
20			return '';
21		}
22	}
23}
24
25$(document).ready(function() {
26	// Highlight any found errors
27	$('.text-danger').each(function() {
28		var element = $(this).parent().parent();
29
30		if (element.hasClass('form-group')) {
31			element.addClass('has-error');
32		}
33	});
34
35		// Currency
36	$('#form-currency .currency-select').on('click', function(e) {
37		e.preventDefault();
38
39		$('#form-currency input[name=\'code\']').val($(this).attr('name'));
40
41		$('#form-currency').submit();
42	});
43
44	// Language
45	$('#form-language .language-select').on('click', function(e) {
46		e.preventDefault();
47
48		$('#form-language input[name=\'code\']').val($(this).attr('name'));
49
50		$('#form-language').submit();
51	});
52
53	/* Search */
54	$('#search input[name=\'search\']').parent().find('button').on('click', function() {
55		var url = $('base').attr('href') + 'index.php?route=product/search';
56
57        var value = $('input[name=\'search\']').val();
58		if (value) {
59			url += '&search=' + encodeURIComponent(value);
60		}
61
62		location = url;
63	});
64
65	$('#search input[name=\'search\']').on('keydown', function(e) {
66		if (e.keyCode == 13) {
67			$('input[name=\'search\']').parent().find('button').trigger('click');
68		}
69	});
70
71	// Menu
72	$('#menu .dropdown-menu').each(function() {
73		var menu = $('#menu').offset();
74		var dropdown = $(this).parent().offset();
75
76		var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
77
78		if (i > 0) {
79			$(this).css('margin-left', '-' + (i + 5) + 'px');
80		}
81	});
82
83
84	// Product Grid
85	$('#grid-view').click(function() {
86		$('#content .product-layout > .clearfix').remove();
87
88		// What a shame bootstrap does not take into account dynamically loaded columns
89		cols = $('#column-right, #column-left').length;
90
91		if (cols == 2) {
92			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-4 col-xs-12');
93		} else if (cols == 1) {
94			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-4 col-xs-12');
95		} else {
96			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-4 col-xs-12');
97		}
98
99	});
100
101	if (localStorage.getItem('display') == 'list') {
102		$('#list-view').trigger('click');
103	} else {
104		$('#grid-view').trigger('click');
105	}
106
107
108
109
110	// Checkout
111	$(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) {
112		if (e.keyCode == 13) {
113			$('#collapse-checkout-option #button-login').trigger('click');
114		}
115	});
116
117	// tooltips on hover
118	$('[data-toggle=\'tooltip\']').tooltip({container: 'body',trigger: 'hover'});
119
120	// Makes tooltips work on ajax generated content
121	$(document).ajaxStop(function() {
122		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
123	});
124});
125// Cart add remove functions
126var cart = {
127	'add': function(product_id, quantity) {
128		$.ajax({
129			url: 'index.php?route=checkout/cart/add',
130			type: 'post',
131			data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
132			dataType: 'json',
133			beforeSend: function() {
134				$('#cart > button').button('loading');
135			},
136			complete: function() {
137				$('#cart > button').button('reset');
138			},			
139			success: function(json) {
140				$('.alert, .text-danger').remove();
141
142				if (json['redirect']) {
143					location = json['redirect'];
144				}
145
146				if (json['success']) {
147					   $('#addtocart').find('.modal-body p').html(json['success']);
148		   $("#addtocart").modal('show');
149					
150					// Need to set timeout otherwise it wont update the total
151					setTimeout(function () {
152						$('#cart button .carthead').html('<span id="cart-total"> ' + json['total'] + '</span>');
153					}, 100);
154				
155				$('#cart > ul').load('index.php?route=common/cart/info ul li');
156				}
157		},
158			error: function(xhr, ajaxOptions, thrownError) {
159				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
160			}
161		});
162	},
163	'update': function(key, quantity) {
164		$.ajax({
165			url: 'index.php?route=checkout/cart/edit',
166			type: 'post',
167			data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
168			dataType: 'json',
169			beforeSend: function() {
170				$('#cart > button').button('loading');
171			},
172			complete: function() {
173				$('#cart > button').button('reset');
174			},			
175			success: function(json) {
176				// Need to set timeout otherwise it wont update the total
177				setTimeout(function () {
178//					var count = parseInt(json['total']);
179//					if (count) {count = "<br>"+count+"шт.";} else {count=""}
180					var count = parseInt(json['total']);
181					if (count) {count = "";} else {json['total'] = ""; count=""}
182					$('#cart button .carthead').html('<span id="cart-total">' + count + json['total'] + '</span>');
183				}, 100);
184
185				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
186					location = 'index.php?route=checkout/cart';
187				} else {
188					$('#cart > ul').load('index.php?route=common/cart/info ul li');
189				}
190		  },
191			error: function(xhr, ajaxOptions, thrownError) {
192				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
193			}
194		});
195	},
196	'remove': function(key) {
197		$.ajax({
198			url: 'index.php?route=checkout/cart/remove',
199			type: 'post',
200			data: 'key=' + key,
201			dataType: 'json',
202			beforeSend: function() {
203				$('#cart > button').button('loading');
204			}, 
205			complete: function() {
206				$('#cart > button').button('reset');
207			},
208			success: function(json) {
209				// Need to set timeout otherwise it wont update the total
210				setTimeout(function () {
211//					var count = parseInt(json['total']);
212//					if (count) {count = "<br>"+count+"шт.";} else {count=""}
213
214					$('#cart button .carthead').html('<span id="cart-total">' + json['total'] + '</span>');
215				}, 100);
216				
217				var now_location = String(document.location.pathname);
218
219				if ((now_location == '/cart/') || (now_location == '/checkout/') || (getURLVar('route') == 'checkout/cart') || (getURLVar('route') == 'checkout/checkout')) {
220					location = 'index.php?route=checkout/cart';
221				} else {
222					$('#cart > ul').load('index.php?route=common/cart/info ul li');
223				}
224			},
225			error: function(xhr, ajaxOptions, thrownError) {
226				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
227			}
228		});
229	}
230}
231
232var voucher = {
233	'add': function() {
234
235	},
236	'remove': function(key) {
237		$.ajax({
238			url: 'index.php?route=checkout/cart/remove',
239			type: 'post',
240			data: 'key=' + key,
241			dataType: 'json',
242			beforeSend: function() {
243				$('#cart > button').button('loading');
244			},
245			complete: function() {
246				$('#cart > button').button('reset');
247			},
248			success: function(json) {
249				// Need to set timeout otherwise it wont update the total
250				setTimeout(function () {
251					$('#cart button > span').html('<span id="cart-total"> ' + json['total'] + '</span>');
252				}, 100);
253
254				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
255					location = 'index.php?route=checkout/cart';
256				} else {
257					$('#cart > ul').load('index.php?route=common/cart/info ul li');
258				}
259			},
260			error: function(xhr, ajaxOptions, thrownError) {
261				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
262			}
263		});
264	}
265}
266var wishlist = {
267	'add': function(product_id) {
268		$.ajax({
269			url: 'index.php?route=account/wishlist/add',
270			type: 'post',
271			data: 'product_id=' + product_id,
272			dataType: 'json',
273			success: function(json) {
274				$('.alert').remove();
275            $("#wishlist").modal('show');
276				if (json['success']) {
277			$("#wishlist .modal-body p").html(json['success']);
278				}
279
280				if (json['info']) {
281			$("#wishlist .modal-body p").html(json['info']);
282				}
283
284				$('#wishlist-total span').html(json['total']);
285				$('#wishlist-total').attr('title', json['total']);
286		},
287			error: function(xhr, ajaxOptions, thrownError) {
288				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
289			}
290		});
291	},
292	'remove': function() {
293
294	}
295}
296
297var compare = {
298	'add': function(product_id) {
299		$.ajax({
300			url: 'index.php?route=product/compare/add',
301			type: 'post',
302			data: 'product_id=' + product_id,
303			dataType: 'json',
304			success: function(json) {
305				$('.alert').remove();
306
307				if (json['success']) {
308					$("#compare").modal('show');
309					$("#compare .modal-body p").html(json['success']);
310					$('#compare-total').html(json['total']);
311				}
312		},
313			error: function(xhr, ajaxOptions, thrownError) {
314				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
315			}
316		});
317	},
318	'remove': function() {
319
320	}
321}
322
323/* Agree to Terms */
324$(document).delegate('.agree', 'click', function(e) {
325	e.preventDefault();
326
327	$('#modal-agree').remove();
328
329	var element = this;
330
331	$.ajax({
332		url: $(element).attr('href'),
333		type: 'get',
334		dataType: 'html',
335		success: function(data) {
336			html  = '<div id="modal-agree" class="modal">';
337			html += '  <div class="modal-dialog">';
338			html += '    <div class="modal-content">';
339			html += '      <div class="modal-header">';
340			html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
341			html += '        <h4 class="modal-title">' + $(element).text() + '</h4>';
342			html += '      </div>';
343			html += '      <div class="modal-body">' + data + '</div>';
344			html += '    </div';
345			html += '  </div>';
346			html += '</div>';
347
348			$('body').append(html);
349
350			$('#modal-agree').modal('show');
351		}
352	});
353});
354
355// Autocomplete */
356(function($) {
357	$.fn.autocomplete = function(option) {
358		return this.each(function() {
359			this.timer = null;
360			this.items = new Array();
361
362			$.extend(this, option);
363
364			$(this).attr('autocomplete', 'off');
365
366			// Focus
367			$(this).on('focus', function() {
368				this.request();
369			});
370
371			// Blur
372			$(this).on('blur', function() {
373				setTimeout(function(object) {
374					object.hide();
375				}, 200, this);
376			});
377
378			// Keydown
379			$(this).on('keydown', function(event) {
380				switch(event.keyCode) {
381					case 27: // escape
382						this.hide();
383						break;
384					default:
385						this.request();
386						break;
387				}
388			});
389
390			// Click
391			this.click = function(event) {
392				event.preventDefault();
393
394				value = $(event.target).parent().attr('data-value');
395
396				if (value && this.items[value]) {
397					this.select(this.items[value]);
398				}
399			}
400
401			// Show
402			this.show = function() {
403				var pos = $(this).position();
404
405				$(this).siblings('ul.dropdown-menu').css({
406					top: pos.top + $(this).outerHeight(),
407					left: pos.left
408				});
409
410				$(this).siblings('ul.dropdown-menu').show();
411			}
412
413			// Hide
414			this.hide = function() {
415				$(this).siblings('ul.dropdown-menu').hide();
416			}
417
418			// Request
419			this.request = function() {
420				clearTimeout(this.timer);
421
422				this.timer = setTimeout(function(object) {
423					object.source($(object).val(), $.proxy(object.response, object));
424				}, 200, this);
425			}
426
427			// Response
428			this.response = function(json) {
429				html = '';
430
431				if (json.length) {
432					for (i = 0; i < json.length; i++) {
433						this.items[json[i]['value']] = json[i];
434					}
435
436					for (i = 0; i < json.length; i++) {
437						if (!json[i]['category']) {
438							html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>';
439						}
440					}
441
442					// Get all the ones with a categories
443					var category = new Array();
444
445					for (i = 0; i < json.length; i++) {
446						if (json[i]['category']) {
447							if (!category[json[i]['category']]) {
448								category[json[i]['category']] = new Array();
449								category[json[i]['category']]['name'] = json[i]['category'];
450								category[json[i]['category']]['item'] = new Array();
451							}
452
453							category[json[i]['category']]['item'].push(json[i]);
454						}
455					}
456
457					for (i in category) {
458						html += '<li class="dropdown-header">' + category[i]['name'] + '</li>';
459
460						for (j = 0; j < category[i]['item'].length; j++) {
461							html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#">&nbsp;&nbsp;&nbsp;' + category[i]['item'][j]['label'] + '</a></li>';
462						}
463					}
464				}
465
466				if (html) {
467					this.show();
468				} else {
469					this.hide();
470				}
471
472				$(this).siblings('ul.dropdown-menu').html(html);
473			}
474
475			$(this).after('<ul class="dropdown-menu"></ul>');
476			$(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));
477
478		});
479	}
480})(window.jQuery);
481(function($) {
482    $.fn.prmn_autocomplete = function(option) {
483        return this.each(function() {
484            this.timer = null;
485            this.items = [];
486
487            $.extend(this, option);
488
489            $(this).attr('autocomplete', 'off');
490
491            // Focus
492            $(this).on('focus', function() {
493                this.request();
494            });
495
496            // Blur
497            $(this).on('blur', function() {
498                setTimeout(function(object) {
499                    object.hide();
500                }, 200, this);
501            });
502
503            // Keydown
504            $(this).on('keydown', function(event) {
505                switch (event.keyCode) {
506                    case 27: // escape
507                        this.hide();
508                        break;
509                    default:
510                        this.request();
511                        break;
512                }
513            });
514
515            // Click
516            this.click = function(event) {
517                event.preventDefault();
518
519                value = $(event.target).parent().attr('data-value');
520
521                if (value && this.items[value]) {
522                    this.select(this.items[value]);
523                }
524            };
525
526            // Show
527            this.show = function() {
528                var pos = $(this).position();
529
530                $(this).siblings('ul.dropdown-menu').css({
531                    top: pos.top + $(this).outerHeight(),
532                    left: pos.left
533                });
534
535                $(this).siblings('ul.dropdown-menu').show();
536            };
537
538            // Hide
539            this.hide = function() {
540                $(this).siblings('ul.dropdown-menu').hide();
541            };
542
543            // Request
544            this.request = function() {
545                clearTimeout(this.timer);
546
547                this.timer = setTimeout(function(object) {
548                    object.source($(object).val(), $.proxy(object.response, object));
549                }, 200, this);
550            };
551
552            // Response
553            this.response = function(json) {
554                var html = '', i;
555
556                if (json.length) {
557                    for (i = 0; i < json.length; i++) {
558                        this.items[json[i]['value']] = json[i];
559                    }
560
561                    for (i = 0; i < json.length; i++) {
562                        if (!json[i]['category']) {
563                            html += '<li data-value="' + json[i]['value'] + '"><a href="#">
563' + json[i]['label'] + '</a></li>';
564                        }
565                    }
566
567                    // Get all the ones with a categories
568                    var category = [];
569
570                    for (i = 0; i < json.length; i++) {
571                        if (json[i]['category']) {
572                            if (!category[json[i]['category']]) {
573                                category[json[i]['category']] = [];
574                                category[json[i]['category']]['name'] = json[i]['category'];
575                                category[json[i]['category']]['item'] = [];
576                            }
577
578                            category[json[i]['category']]['item'].push(json[i]);
579                        }
580                    }
581
582                    for (i in category) {
583                        html += '<li class="dropdown-header">' + category[i]['name'] + '</li>';
584
585                        for (j = 0; j < category[i]['item'].length; j++) {
586                            html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#">&nbsp;&nbsp;&nbsp;' + category[i]['item'][j]['label'] + '</a></li>';
587                        }
588                    }
589                }
590
591                if (html) {
592                    this.show();
593                } else {
594                    this.hide();
595                }
596
597                $(this).siblings('ul.dropdown-menu').html(html);
598            };
599
600            $(this).after('<ul class="dropdown-menu"></ul>');
601            $(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));
602        });
603    }
604})(jQuery);
605if (window.Prmn === undefined) { Prmn = {}; }
606
607Prmn.CityManager = function(options) {
608    this.switchers = [];
609    this.messages = [];
610    this.options = $.extend({}, Prmn.CityManager.DEFAULTS, options);
611    this.http_host = this.getHttpHost();
612    this.cities_popup = null;
613};
614
615Prmn.CityManager.DEFAULTS = {
616    base_path: 'auto'
617};
618
619Prmn.CityManager.prototype.addSwitcher = function(el) {
620    this.switchers.push(new Prmn.CitySwitcher(el, this));
621};
622
623Prmn.CityManager.prototype.addMessage = function(el) {
624    this.messages.push(new Prmn.CityMessage(el, this));
625};
626
627Prmn.CityManager.prototype.loadData = function() {
628    var self = this;
629    $.get(
630        this.http_host + 'index.php?route=extension/module/progroman/city_manager/init',
631        {url: location.pathname + location.search},
632        function(json) {
633            var i, j;
634            for (i in self.switchers) if (self.switchers.hasOwnProperty(i)) {
635                self.switchers[i].setContent(json.content);
636                if (json.confirm) {
637                    self.switchers[i].setConfirm(json.confirm, json.confirm_redirect);
638                }
639            }
640            if (json.messages) {
641                for (i in json.messages) {
642                    for (j in self.messages) if (self.messages.hasOwnProperty(j)) {
643                        if (self.messages[j].key === i) {
644                            self.messages[j].setContent(json.messages[i]);
645                        }
646                    }
647                }
648            }
649
650            for (i in self.messages) if (self.messages.hasOwnProperty(i)) {
651                self.messages[i].setDefault();
652            }
653        },
654        'json');
655};
656
657Prmn.CityManager.prototype.showCitiesPopup = function() {
658    var self = this;
659    if (!this.cities_popup) {
660        $.get(this.http_host + 'index.php?route=extension/module/progroman/city_manager/cities', function(html) {
661            self.cities_popup = $(html);
662            $('body').append(self.cities_popup);
663            self.cities_popup.find('.prmn-cmngr-cities__city-name').click(function() {
664                self.setFias($(this).data('id'));
665                self.cities_popup.modal('hide');
666            });
667
668            self.cities_popup.modal('show');
669
670            var input = self.cities_popup.find('.prmn-cmngr-cities__search');
671            self.autocomplete(input);
672            input.focus();
673        }, 'html');
674    } else {
675        self.cities_popup.modal('show');
676    }
677};
678
679Prmn.CityManager.prototype.autocomplete = function(el) {
680    var xhr = false;
681    var self = this;
682    el.prmn_autocomplete({
683        'source': function(request, response) {
684            if (xhr) {
685                xhr.abort();
686            }
687
688            request = $.trim(request);
689            if (request && request.length > 2) {
690                xhr = $.get(self.http_host + 'index.php?route=extension/module/progroman/city_manager/search&term=' + encodeURIComponent(request),
691                    function(json) {
692                        response(json);
693                    }, 'json');
694            }
695            else {
696                response([]);
697            }
698        },
699        'select': function(item) {
700            el.val(item.name);
701            self.setFias(item.value);
702            self.cities_popup.modal('hide');
703        }
704    });
705    el.siblings('ul.dropdown-menu').css({'maxHeight': 300, 'overflowY': 'auto', 'overflowX': 'hidden'});
706};
707
708Prmn.CityManager.prototype.setFias = function(id) {
709    $.get(this.http_host + 'index.php?route=extension/module/progroman/city_manager/save&fias_id=' + id,
710        function(json) {
711            if (json.success) {
712                location.reload();
713            }
714        },
715        'json'
716    );
717};
718
719Prmn.CityManager.prototype.getHttpHost = function() {
720    if (!Prmn.CityManager.host) {
721        Prmn.CityManager.host = location.protocol + '//' + location.host + '/';
722
723        if (this.options.base_path == 'auto') {
724            var base = $('base').attr('href'), matches;
725            if (base && (matches = base.match(/^http(?:s)?:\/\/[^/]*\/(.*)/))) {
726                Prmn.CityManager.host += matches[1];
727            }
728        } else if (this.options.base_path) {
729            Prmn.CityManager.host += this.options.base_path;
730        }
731    }
732
733    return Prmn.CityManager.host;
734};
735
736Prmn.CitySwitcher = function(el, manager) {
737    this.manager = manager;
738    this.$element = el;
739    this.loaded = el.children('div').length > 0;
740    this.options = {confirm: el.data('confirm')};
741};
742
743Prmn.CitySwitcher.prototype.setContent = function(html) {
744    if (!this.loaded) {
745        html = $(html);
746        this.$element.html(html);
747        this.loaded = true;
748    }
749
750    var self = this;
751    this.$element.find('.prmn-cmngr__city').click(function() {
752        self.manager.showCitiesPopup();
753    });
754};
755
756Prmn.CitySwitcher.prototype.setConfirm = function(html, confirm_redirect) {
757    if (this.options.confirm) {
758        var confirm = $(html), self = this;
759        this.$element.append(confirm);
760        confirm.find('input[type=button]').click(function() {
761            if ($(this).data('value') == 'no') {
762                self.manager.showCitiesPopup();
763            } else if (confirm_redirect) {
764                location.href = confirm_redirect;
765            }
766            confirm.hide();
767        });
768    }
769};
770
771Prmn.CityMessage = function(el, manager) {
772    this.manager = manager;
773    this.$element = el;
774    this.key = el.data('key');
775    this.default = el.data('default');
776    this.$element.removeAttr('data-key').removeAttr('data-default');
777    this.found = false;
778};
779
780Prmn.CityMessage.prototype.setContent = function(html) {
781    this.$element.html(html);
782    this.found = true;
783};
784
785Prmn.CityMessage.prototype.setDefault = function() {
786    if (!this.found) {
787        this.$element.html(this.default);
788    }
789};
790
791$(function() {
792    var switchers = $('.prmn-cmngr'), messages = $('.prmn-cmngr-message');
793    if (switchers.length || messages.length) {
794        Prmn.city_manager = new Prmn.CityManager();
795        switchers.each(function() { Prmn.city_manager.addSwitcher($(this)); });
796        messages.each(function() { Prmn.city_manager.addMessage($(this)); });
797        Prmn.city_manager.loadData();
798    }
799});
800

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.