PageSourceSearch

https://travel-free.bg/verification/jquery.agecheck-bg.js

js travel-free.bg collected 2026-10-02 00:44:13 UTC 7,732 bytes, 171 lines download raw bytes

1/* 
2 * Plugin: ageCheck.js
3 * Description: A simple plugin to verify user's age. Uses sessionStorage API to store if user is verified - only kept until browser is closed.
4 * Options can be passed for easy customization. 
5 * Author: Michael Soriano
6 * Author's website: http://fearlessflyer.com*
7 * 
8 */
9(function ($){   
10    
11    $.ageCheck = function(options) {
12                
13        var settings = $.extend({
14            minAge : 18,          
15            redirectTo : $(location).prop('href'),
16            redirectOnFail : '',
17            title : 'Имате ли навършени 18 години?', 
18            copy : 'Ние подкрепяме отговорната консумация, а вие трябва да потвърдите, че сте над 18-годишна възраст преди да продължите към нашия магазин.:'
19        }, options);
20        
21        
22        var _this = {
23            month : '',  
24            day : '',  
25            year : '',   
26            age : '',
27            errors : Array(), 
28            setValues : function(){
29                var month = $('.ac-container .month').val();
30                var day = $('.ac-container .day').val()
31                _this.month = month; 
32                _this.day = day.replace(/^0+/, ''); //remove leading zero
33                _this.year = $('.ac-container .year').val();
34            },
35            validate : function(){
36                _this.errors = [];
37                if (/^([0-9]|[12]\d|3[0-1])$/.test(_this.day) === false) {
38                    _this.errors.push('Дните са невалидни');
39                };
40                if (/^(19|20)\d{2}$/.test(_this.year) === false) {
41                    _this.errors.push('Годината е невалидна');
42                };
43                _this.clearErrors();
44                _this.displayErrors();
45                return _this.errors.length < 1;
46            }, 
47            clearErrors : function(){         
48                $('.errors').html('');
49            }, 
50            displayErrors : function(){
51                var html = '<ul>';
52                for (var i = 0; i < _this.errors.length; i++) {
53                    html += '<li><span>x</span>' + _this.errors[i] + '</li>';
54                }
55                html += '</ul>';
56                setTimeout(function(){$('.ac-container .errors').html(html)},200);
57            },
58            reCenter : function (b){
59                b.css("top", Math.max(0, (($(window).height() - (b.outerHeight() + 150)) / 2) + 
60                                            $(window).scrollTop()) + "px");
61                b.css("left", Math.max(0, (($(window).width() - b.outerWidth()) / 2) + 
62                                            $(window).scrollLeft()) + "px");
63            }, 
64            buildHtml : function(){
65            
66                var copy = settings.copy; 
67                var months = ['Януари','Февруари','Март','Април','Май','Юни','Юли','Август','Септември','Октомври','Ноември','Декември'];
68                var html = '';
69                html += '<div class="ac-overlay"></div>';
70                html += '<div class="ac-container">';
71                html += '<h2>' + settings.title + '</h2>';
72                html += '<p>' + copy.replace('[21]','<strong>'+settings.minAge+'</strong>'); + '</p>';
73                html += '<div class="errors"></div>';
74                html += '<div class="fields"><select class="month">';
75                for(var i=0;i<months.length;i++){
76                    html += '<option value="'+i+'">'+months[i]+'</option>'
77                }
78                html += '</select>';
79                html += '<input class="day" value="10" maxlength="2" placeholder="01" />';
80                html += '<input class="year" value="1984" maxlength="4" placeholder="1989"/>';
81                html += '<a href="http://konsumirai-otgovorno.bg/">Отказ</a><a href="javascript:void(0)" class="confirm">Потвърждавам</a></div></div>';
82                
83                $('body').append(html);
84                
85                $('.ac-overlay').animate({
86                    opacity: 0.8
87                }, 500, function() {
88                    _this.reCenter($('.ac-container'));
89                    $('.ac-container').css({opacity: 1})
90                });
91                
92                $(".ac-container .day, .ac-container .year").focus(function(){
93                   $(this).removeAttr('placeholder');
94                });
95            }, 
96            setAge : function(){
97                _this.age = '';                 
98                var birthday = new Date(_this.year, _this.month, _this.day);  
99                var ageDifMs = Date.now() - birthday.getTime();
100                var ageDate = new Date(ageDifMs); // miliseconds from epoch
101                _this.age = Math.abs(ageDate.getUTCFullYear() - 1970);
102            }, 
103            setSessionStorage  : function(key, val){
104                try {
105                    localStorage.setItem(key,val);
106                    return true;
107                } catch (e) {
108                    return false;
109                }
110            },
111            handleSuccess : function(){                
112                //var successMsg = '<h3>Success!</h3><p>You are now being redirected back to the application...</p>';
113                //$('.ac-container').html(successMsg);
114                localStorage.setItem("ageVerified", "true");
115                setTimeout(function(){
116                    $('.ac-container').animate({'top':'-350px'},200, function(){
117                         $('.ac-overlay').animate({'opacity':'0'},500, function(){
118                            if (settings.redirectTo != '') {
119                                //window.location.replace(settings.redirectTo);
120                                $('.ac-overlay, .ac-container').remove();
121                            }else{
122                                $('.ac-overlay, .ac-container').remove();
123                            }
124                         });
125                    });
126                },1000);
127            },
128            handleUnderAge : function() {
129                var underAgeMsg = '<h3>
129Съжаляваме, но нямате навършени 18 години...</h3>';
130                $('.ac-container').html(underAgeMsg);
131                if (settings.redirectOnFail != '') {
132                    setTimeout(function(){
133                        window.location.replace(settings.redirectOnFail);
134                    },2000);
135                }
136            }
137        }; //end _this
138         
139        if(localStorage.getItem("ageVerified") == "true"){
140            $('.ac-overlay, .ac-container').hide()
141            return false;
142        }
143        
144        _this.buildHtml();  
145        
146        $('.ac-container .confirm').on('click', function(){
147            _this.setValues();
148            if (_this.validate() === true) {
149                _this.setAge();
150                
151                if(_this.age >= settings.minAge){
152                    if(!_this.setSessionStorage("ageVerified", "true")){
153                        console.log('sessionStorage not supported by your browser');
154                    };
155                    _this.handleSuccess();
156                }else{
157                    _this.handleUnderAge();
158                    window.recirect = 'http://konsumirai-otgovorno.bg/'
159                }
160            }
161        });
162        
163        
164        $(window).resize(function() {
165            _this.reCenter($('.ac-container'));
166            setTimeout(function() {
167                _this.reCenter($('.ac-container'));
168            }, 500);
169        });
170    };
171}(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.