PageSourceSearch

https://veterinarydental.com/wp-content/plugins/bt-pro/includes/co…/js/conditional-elements.js

js veterinarydental.com collected 2026-10-06 08:57:37 UTC 11,986 bytes, 416 lines download raw bytes

1jQuery(document).ready(function(){
2
3  
4  //todo minimize this
5  if(jQuery('body').hasClass('fl-builder-edit') )
6    return false;
7  
8  bt_cookie_check(); // check for custom display cookies
9  bt_time_check();
10  bt_query_check();
11  
12  if(jQuery("[bt_location_name]").length)
13  {
14    if(getConditionalCookie("bt_user_c") == undefined) // if the country isnt defined, update
15      btGetLocation();
16    else
17      check_locations();
18  }
19});
20  
21function bt_time_check(){
22    
23  jQuery("[bt_time_start]").each(function(index,value){
24    var time_schedule = jQuery(this).attr('bt_time_schedule');
25    var timeStart = jQuery(this).attr('bt_time_start');
26    var timeEnd = jQuery(this).attr('bt_time_end');
27    var timeNow = Date.now()/1000;
28    var bt_display_action = jQuery(this).attr('bt_display_action') ;
29
30
31    if(time_schedule == 'none' || !time_schedule)
32    {
33      if((timeNow > timeStart) && timeNow < timeEnd )
34      {
35        if(bt_display_action == 'show')
36          jQuery(this).show();
37        else
38          jQuery(this).hide();
39      }  
40      else
41      {
42        if(bt_display_action == 'hide')
43          jQuery(this).show();
44        else
45          jQuery(this).hide();
46      }
47    }
48
49    if(time_schedule == 'daily')
50    {
51      //need time
52      timeStart = time_from_stamp(timeStart);
53      timeEnd = time_from_stamp(timeEnd);
54
55    }
56
57
58    if(time_schedule == 'weekly')
59    {
60
61      //need day of week and time
62      timeStart = day_of_week_from_stamp(timeStart);
63      timeEnd = day_of_week_from_stamp(timeEnd);
64
65
66    }
67
68    if(time_schedule == 'monthly')
69    {
70      timeStart = day_of_month_from_stamp(timeStart);
71      timeEnd = day_of_month_from_stamp(timeEnd);
72
73    }
74
75    if((timeNow > timeStart) && timeNow < timeEnd )
76    {
77      if(bt_display_action == 'show')
78        jQuery(this).show();
79      else
80        jQuery(this).hide();
81    }  
82    else
83    {
84      if(bt_display_action == 'hide')
85        jQuery(this).show();
86      else
87        jQuery(this).hide();
88    }
89
90  });
91}
92
93function time_from_stamp(timestamp){
94  //get timestamp
95
96  newTime = new Date(timestamp*1000);
97
98  h = newTime.getHours();
99  m = newTime.getMinutes();
100
101
102  now = new Date();
103  now.setHours(h);
104  now.setHours(m);
105  //convert to hours and minutes
106  return Math.floor(now.getTime() / 1000)
107}
108
109function day_of_month_from_stamp(timestamp){
110  //get timestamp
111  newTime = new Date(timestamp*1000);
112  now = new Date();
113
114  nowDay = now.getDate();
115  d = newTime.getDate(); // day of month
116
117  now.setDate(newTime.getDate());
118  now.setHours(newTime.getHours());
119  now.setMinutes(newTime.getMinutes());
120
121  //convert to hours and minutes
122  return Math.floor(now.getTime() / 1000)
123}
124
125
126function day_of_week_from_stamp(timestamp){
127  //get timestamp
128  newTime = new Date(timestamp*1000);
129  now = new Date();
130
131  nowDay = now.getDay();
132  d =  newTime.getDay() - nowDay; // does the day of week offset calc
133
134  console.log('offset',d);
135
136  now.setDate(now.getDate() + d);
137  now.setHours(newTime.getHours());
138  now.setMinutes(newTime.getMinutes());
139
140  //convert to hours and minutes
141  return Math.floor(now.getTime() / 1000);
142}
143
144
145function bt_query_check(){
146  
147  jQuery("[bt_url_text]").each(function(index,value){
148    var urlName = jQuery(this).attr('bt_url_text');
149    var urlType = jQuery(this).attr('bt_url_type');
150    var urlValue = jQuery(this).attr('bt_url_value');
151    var bt_display_action = jQuery(this).attr('bt_display_action') ;
152    var queryMatch = false;
153    
154    
155    if(urlType == 'exists')
156      if(getParameterByName(urlName) != null)
157         queryMatch = true;
158
159    if(urlType == 'notexist')
160      if(getParameterByName(urlName) == null)
161        queryMatch = true;
162
163    if(urlType == 'equals')
164      if(getParameterByName(urlName) == urlValue)
165        queryMatch = true;
166
167    if(urlType == 'notequals')
168      if(getParameterByName(urlName) != urlValue)
169        queryMatch = true;
170
171    if(queryMatch)
172    {
173      if(bt_display_action == 'show')
174        jQuery(this).show();
175      else
176        jQuery(this).hide();
177    }  
178    else
179    {
180      if(bt_display_action == 'hide')
181        jQuery(this).show();
182      else
183        jQuery(this).hide();
184    }
185  });
186}
187
188function check_locations(){
189
190
191
192  var eu_countries = "ad,al,at,ba,be,bg,by,ch,cs,cz,de,dk,ee,es,fi,fo,fr,fx,gb,gi,gr,hr,hu,ie,is,it,li,lt,lu,lv,mc,md,mk,mt,nl,no,pl,pt,ro,se,si,sj,sk,sm,ua,va";
193  var bt_user_loc = getConditionalCookie("bt_user_loc");
194  var bt_user_s = getConditionalCookie("bt_user_s");
195  var bt_user_c = getConditionalCookie("bt_user_c");
196  var bt_user_city = getConditionalCookie("bt_user_city");
197  var bt_user_timezone = getConditionalCookie("bt_user_timezone");
198  var bt_user_continent = getConditionalCookie("bt_user_continent");
199  var bt_user_continentCode = getConditionalCookie("bt_user_continentCode");
200  var bt_user_currency = getConditionalCookie("bt_user_currency");
201  var bt_user_zip = getConditionalCookie("bt_user_zip");
202
203  
204  jQuery("[bt_location_name]").each(function(index,value){
205    
206    var bt_location_type = bt_lc(jQuery(this).attr('bt_location_type'));
207    var bt_location_condition = jQuery(this).attr('bt_location_condition');
208    var bt_location_name = bt_lc(jQuery(this).attr('bt_location_name'));
209    var bt_display_action = jQuery(this).attr('bt_display_action');
210    var nodeId  = jQuery(this).attr('data-node');
211    
212    if(bt_location_type == "state")
213      bt_user_loc = bt_user_s;
214    if(bt_location_type == "countrycode")
215      bt_user_loc = bt_user_c;
216    if(bt_location_type == "city")
217      bt_user_loc = bt_user_city;
218    if(bt_location_type == "timezone")
219      bt_user_loc = bt_user_timezone;
220    if(bt_location_type == "continent")
221      bt_user_loc = bt_user_continent;
222    if(bt_location_type == "continentCode")
223      bt_user_loc = bt_user_continentCode;
224    if(bt_location_type == "currency")
225      bt_user_loc = bt_user_currency;
226    if(bt_location_type == "zip")
227      bt_user_loc = bt_user_zip;
228
229    //EU tweak todo APAC?  
230    if((bt_location_type == "country" || bt_location_type == "countrycode") && (bt_location_name == "eu" || bt_location_name == "europe"))
231    {
232      bt_location_type = 'countrycode'; //force countrycode 
233      bt_location_name = eu_countries;
234      if(bt_location_condition == 'equals')
235        bt_location_condition = 'contains'; // fix equals -> contains
236      if(bt_location_condition == 'notequal')
237        bt_location_condition = 'doesnotcontain'; //fix contains -> not contain
238    }
239    
240    if(bt_display_action == 'show')
241      bt_display_action = true;
242    else
243      bt_display_action = false;
244    
245    if(bt_location_condition == 'equals')
246    {
247      btShowElement(nodeId, bt_user_loc == bt_location_name, bt_display_action);
248    }
249    else if (bt_location_condition == 'notequal')
250    {
251      btShowElement(nodeId,  bt_user_loc != bt_location_name, bt_display_action);
252    }
253    else if (bt_location_condition == 'contains')
254    {
255      btShowElement(nodeId,  bt_location_name.indexOf(bt_user_loc) !== -1, bt_display_action);
256    }
257    else if (bt_location_condition == 'doesnotcontain')
258    {
259      btShowElement(nodeId,  bt_location_name.indexOf(bt_user_loc) == -1, bt_display_action);
260    }
261  });
262  
263}
264
265function bt_cookie_check(){
266    
267  jQuery("[bt_cookie_name]").each(function(index,value){
268    
269    var bt_cookie_name = bt_lc(jQuery(this).attr('bt_cookie_name'));
270    var bt_cookie_relationship = jQuery(this).attr('bt_cookie_relationship');
271    var bt_cookie_value = bt_lc(jQuery(this).attr('bt_cookie_value'));
272    var bt_display_action = jQuery(this).attr('bt_display_action');
273    var nodeId  = jQuery(this).attr('data-node');
274    
275    // empty handler
276    if(!bt_cookie_value)
277      bt_cookie_value = "";
278    else
279      bt_cookie_value = bt_lc(bt_cookie_value);
280        
281    var visitor_cookie_value = bt_lc(getConditionalCookie(bt_cookie_name));
282    
283    if(bt_display_action == 'show')
284      bt_display_action = true;
285    else
286      bt_display_action = false;
287    
288    if(bt_cookie_relationship == 'equals')
289    {
290      btShowElement(nodeId, visitor_cookie_value == bt_cookie_value, bt_display_action);
291    }
292    else if (bt_cookie_relationship == 'notequal')
293    {
294      btShowElement(nodeId,  visitor_cookie_value != bt_cookie_value, bt_display_action);
295    }
296    else if (bt_cookie_relationship == 'contains')
297    {
298      btShowElement(nodeId,  bt_cookie_value.indexOf(visitor_cookie_value) !== -1, bt_display_action);
299    }
300    else if (bt_cookie_relationship == 'doesnotcontain')
301    {
302      btShowElement(nodeId,  bt_cookie_value.indexOf(visitor_cookie_value) == -1, bt_display_action);
303    }
304    else if (bt_cookie_relationship == 'exists')
305    {
306      btShowElement(nodeId,  visitor_cookie_value !== null , bt_display_action);
307    }
308    else if (bt_cookie_relationship == 'doesnotexist')
309    {
310      btShowElement(nodeId,  visitor_cookie_value == null, bt_display_action);
311    }
312  });
313}
314
315function bt_lc(text)
316{
317  if(text == null)
318    return text;
319  if(text !== '')
320    return text.toLowerCase();
321  return text;
322}
323
324function btShowElement(node, result, show ){
325  
326  if(result === true)
327  {
328    if(show === true)
329      jQuery('.fl-node-'+node).show();
330    else
331      jQuery('.fl-node-'+node).hide();
332  }
333  else
334  {
335    if(show === true)
336      jQuery('.fl-node-'+node).hide();
337    else
338      jQuery('.fl-node-'+node).show();
339  }
340}
341
342
343/*
344    'country'      => __( 'Country Name', 'btbb' ),
345    'countrycode'      => __( 'Country Code', 'btbb' ),
346    'state'      => __( 'State / Province / Region', 'btbb' ),
347    'city'      => __( 'City', 'btbb' ),
348    'timezone'      => __( 'Timezone', 'btbb' ),
349    'continent'      => __( 'Continent', 'btbb' ),
350    'continentCode'      => __( 'Continent Code', 'btbb' ),
351    'currency'      => __( 'Currency', 'btbb' ),
352  */
353
354function btGetLocation(){
355  //get the users location with JS
356
357  var ipURL = "aHR0cHM6Ly9wcm8uaXAtYXBpLmNvbS9qc29uP2ZpZWxkcz1zdGF0dXMsbWVzc2FnZSxjb250aW5lbnQsY29udGluZW50Q29kZSxjb3VudHJ5LGNvdW50cnlDb2RlLHJlZ2lvbixyZWdpb25OYW1lLGNpdHksemlwLHRpbWV6b25lLGN1cnJlbmN5JmtleT1CSmZ3UG5GVGFNQTRId0o=";
358  jQuery.ajax({
359    url: atob(ipURL),
360    jsonpCallback: "callback",
361    crossDomain: true,
362    dataType: "jsonp",        
363    success: function( location ) {
364      createCookie('bt_user_loc',bt_lc(location.countryCode),4);
365      createCookie('bt_user_c',bt_lc(location.country),4);
366      createCookie('bt_user_s',bt_lc(location.region),4);
367      createCookie('bt_user_city',bt_lc(location.city),4);
368      createCookie('bt_user_timezone',bt_lc(location.timezone),4);
369      createCookie('bt_user_continent',bt_lc(location.continent),4);
370      createCookie('bt_user_continentCode',bt_lc(location.continentCode),4);
371      createCookie('bt_user_currency',bt_lc(location.currency),4);
372      createCookie('bt_user_zip',bt_lc(location.zip),4);
373      check_locations();
374    },
375    error: function( error ) {
376      console.log('bt location error');
377      console.log(error.message);
378    }
379  });
380}
381
382
383// Cookies
384function createCookie(name, value, hours) {
385  var expires = "";                 
386  if (hours) {
387    var date = new Date();
388    date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
389    expires = "; expires=" + date.toGMTString();
390  }
391  
392  document.cookie = name + "=" + value + expires + "; path=/";
393}
394
395function getConditionalCookie(c_name) {
396    var i, x, y, ARRcookies = document.cookie.split(';');
397    for (i = 0; i < ARRcookies.length; i++) {
398        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf('='));
399        y = ARRcookies[i].substr(ARRcookies[i].indexOf('=') + 1);
400        x = x.replace(/^\s+|\s+$/g, '');
401        if (x == c_name) {
402            return decodeURI(y);
403        }
404    }
405}
406
407
408function getParameterByName(name, url) {
409    if (!url) url = window.location.href;
410    name = name.replace(/[\[\]]/g, '\\$&');
411    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
412        results = regex.exec(url);
413    if (!results) return null;
414    if (!results[2]) return '';
415    return decodeURIComponent(results[2].replace(/\+/g, ' '));
416}

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.