Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * this helper script will try to determine if the visitor is viewing
- * the shop preferable for his/her region. This should prevent
- * accidental filling of a shopping basket and finding out one can't
- * order when attempting to checkout.
- *
- *
- */
- //
- // /** Add following CSS and assign classname 'bbuilder-hide' to the node */
- //
- // html:not(.fl-builder-edit) .bbuilder-hide {
- // opacity:0;
- // /* prevent click event when this class is active */
- // pointer-events: none;
- // }
- const bobino = {
- /**
- * Set a Cookie value with a certain expiration time (in days)
- * @param {[type]} cname [description]
- * @param {[type]} cvalue [description]
- * @param {[type]} exdays [description]
- */
- setCookie: function (cname, cvalue, exdays ) {
- // set a default value for exdays
- if ( typeof exdays == 'undefined' ) var exdays = 365;
- var d = new Date();
- d.setTime(d.getTime() + ( 1000 * 60 * 60 * 24 * exdays ) );
- var expires = "expires="+d.toUTCString();
- document.cookie = cname + "=" + cvalue + ";path=/; " + expires;
- },
- /**
- * Get the value of a Cookie
- *
- * @param {[type]} cname [description]
- * @return {[type]} [description]
- */
- getCookie: function (cname) {
- var name = cname + "=";
- var ca = document.cookie.split(';');
- for(var i=0; i<ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1);
- if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
- }
- return "";
- }
- };
- const getGeoIp = () => {
- let myPromise = new Promise(
- resolve => {
- jQuery.ajax( {
- url: 'https://freegeoip.app/json/',
- method : 'GET',
- }).done( function( data ) {
- resolve(data);
- })
- }
- );
- myPromise.then( ( data ) => {
- console.log( data.country_name );
- if ( data.country_code !== 'CA' || data.country_code !== 'US' ) {
- setTimeout( function() { jQuery( '.bobino-geo-message' ).removeClass( 'bbuilder-hide' ); } , 2000 );
- }
- } );
- }
- /**
- * Wait for document ready
- */
- (function($){
- $( document ).ready( function() {
- if ( bobino.getCookie( 'shop-accepted' ) ) return;
- // if cookie not found, do a geo-check to warn the visitor
- getGeoIp();
- });
- $( '.accept-and-continue a' ).on( 'click' , function() {
- bobino.setCookie( 'shop-accepted' , true , 1 );
- setTimeout( function() { jQuery( '.bobino-geo-message' ).addClass( 'bbuilder-hide' ); } , 200 );
- } );
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement