/**
* Globale setting
*/
(async function () {
window.knoseSetting = {};
let domain = window.location.origin;
let options = {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
};
const isLocal = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
const isTest =
isLocal || domain === 'https://breederportal-staging.knose.com.au'
? true
: false;
let wait_url = domain + '/' + (isLocal ? 'wait-dev.json' : 'wait.json');
let version_url = isTest
? 'https://uat.knose.com.au/OrigamiKnose/web/version'
: 'https://portal.knose.com.au/OrigamiKnose/web/version';
window.knoseSetting.isTest = isTest;
window.knoseSetting.isLocal = isLocal;
try {
let response = await fetch(wait_url, options);
let data = await response.json();
window.knoseSetting = { ...window.knoseSetting, ...data };
} catch (error) {
console.log(error);
}
})();
function reloadQuoteSidebar() {
var width = $(window).width();
var height = $(window).height();
var hContent = $('html').height();
if (width > 1444) {
let extra = (width - 1444) / 2;
let right = extra + 'px';
let bottom = height - hContent + 60 + 'px';
if (height < hContent) {
bottom = '60px';
}
$('#wrapper').css(
'background-position',
'right ' + right + ' bottom ' + bottom
);
} else {
$('#wrapper').removeAttr('style');
}
}
function reloadStickyLine() {
var width = $('header').width();
var wSticky = $('.sticky').width();
$('.sticky-line').css('width', width + 'px');
$('.sticky-line').css(
'left',
'-' + ((width - wSticky) / 2).toFixed(2) + 'px'
);
}
$(document).ready(function () {
// reloadQuoteSidebar();
$(window).resize(function () {
reloadStickyLine();
});
$(document).on('click ontouchstart', '.tooltip-close, #mask', function () {
$('[data-toggle="popover"]').popover('hide');
});
});
function loadTooltip() {
var isMobile =
'ontouchstart' in document.documentElement &&
navigator.userAgent.match(/Mobi/);
$('[data-toggle="popover"]').popover({
// trigger: isMobile ? 'click' : 'hover',
trigger: 'click',
placement: 'left',
html: true,
template:
'
',
content: function () {
var content = $(this).attr('data-popover-content');
return $(content).html();
},
});
}
function loadLiveChat() {
setTimeout(function () {
let currentUser = JSON.parse(localStorage.getItem('vetAuthInfo'));
if (!currentUser) {
console.log('Lost storage session');
currentUser = { name: '', role: '', clinic: '', sub: '' };
}
window.fcWidget.setExternalId(currentUser.sub);
window.fcWidget.user.setFirstName(currentUser.name);
window.fcWidget.user.setEmail(currentUser.sub);
window.fcWidget.user.setProperties({
clinic: currentUser.clinic,
role: currentUser.role,
});
}, 2000);
}
function knoseGetCookie(e) {
var r = e + '=';
var a = decodeURIComponent(document.cookie);
var o = a.split(';');
for (var n = 0; n < o.length; n++) {
var t = o[n];
while (t.charAt(0) == ' ') {
t = t.substring(1);
}
if (t.indexOf(r) == 0) {
return t.substring(r.length, t.length);
}
}
return '';
}
function knoseSetCookie(e, a, r, s, t) {
if (e && a) {
var o,
n = s ? '; path=' + s : '',
i = t ? '; domain=' + t : '',
l = '';
r &&
((o = new Date()).setTime(o.getTime() + r),
(l = '; expires=' + o.toUTCString())),
(document.cookie = e + '=' + a + l + n + i);
}
}
function knoseDeleteCookie() {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf('=');
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
}
}
function shareasaleGetCookie(e) {
var r = e + '=';
var a = decodeURIComponent(document.cookie);
var o = a.split(';');
for (var n = 0; n < o.length; n++) {
var t = o[n];
while (t.charAt(0) == ' ') {
t = t.substring(1);
}
if (t.indexOf(r) == 0) {
return t.substring(r.length, t.length);
}
}
return '';
}
//dd soretor scrip
function LoadSoreto(d, s, id) {
var script,
first_script = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
script = d.createElement(s);
script.id = id;
script.src = 'https://api.soreto.com/scripts/' + id + '.min.js';
first_script.parentNode.insertBefore(script, first_script);
}
function loadProductReview() {
window.__productReviewCallbackQueue =
window.__productReviewCallbackQueue || [];
window.__productReviewCallbackQueue.push(function (ProductReview) {
ProductReview.use('inline-rating', {
identificationStrategy: 'from-internal-entry-id',
});
});
}
function includeJs(jsFilePath) {
console.log(`jsFilePath`, jsFilePath);
var js = document.createElement('script');
js.type = 'text/javascript';
js.src = jsFilePath;
document.head.appendChild(js);
}
function showPetSpinner() {
$('.pet-spinner').removeClass('pet-hidden');
}
function hidePetSpinner() {
$('.pet-spinner').removeClass('pet-hidden').addClass('pet-hidden');
}
function loadSmallTooltip() {
$('[data-toggle="tooltip"]').tooltip();
}