var yj_ANIM_SPEED = 300;
navigator.serviceWorker.register('https://yakajack.io/sw.js');
navigator.serviceWorker.onmessage = function (e) {
if (e.data.url.indexOf('agent-console') >= 0) {
if (e.data.data && e.data.data.chatkey) {
$('#nav-item-' + e.data.data.chatkey).trigger('click');
}
}
}
class DesktopNotifications {
static isAvailable = function () {
return (window.Notification != null);
}
static isEnabled = function () {
return (Notification.permission === 'granted');
}
static requestPermission = function () {
return new Promise(function (resolve) {
Notification.requestPermission()
.then(function (permission) {
if (permission === 'granted') {
resolve(true);
} else {
resolve(false);
}
});
});
}
static send = function (title, body, url, additionalData) {
navigator.serviceWorker.ready
.then(function (registration) {
var notif = registration.showNotification(title, {
body: body,
icon: 'https://yakajack.io/img/YakaJack_512px.png',
silent: false,
vibrate: [200, 100, 200, 100, 200, 100],
data: {
url: url,
data: additionalData
}
});
});
}
}
function sendDesktopNotification(title, body, url, additionalData) {
if (DesktopNotifications.isAvailable()) {
if (DesktopNotifications.isEnabled()) {
DesktopNotifications.send(title, body, url, additionalData);
} else {
DesktopNotifications.requestPermission()
.then(function (result) {
if (result) {
DesktopNotifications.send(title, body, url, additionalData);
} else {
console.warn('Desktop notifications were denied or ignored. In order to see desktop notifications for new chats, etc., please allow the permission in your browser.');
}
});
}
} else {
console.warn('Desktop notifications are not available in this browser. We recommend you upgrade your browser.');
}
}
function getAdditionalFeature(item, isAvailable, title, text, reditrectTo) {
if (isAvailable) {
if ($(item).attr('data-navigateto'))
window.location.href = $(item).attr('data-navigateto');
else
window.location.href = $(item).attr('href');
} else {
new modalOptions({
title: title,
text: text + ' But you can get more by either uprading your package or paying to get extra.
What would you like to do?',
text: text + ' You can either buy additional websites or upgrade your package.',
opt1: 'Upgrade Package',
opt2: 'Purchase Additional Websites'
})
.action1(function () {
window.location.href = 'https://yakajack.io/account/features/upgrade.aspx';
})
.action2(function () {
window.location.href = reditrectTo;
});
}
}
function htmlDecode(encodedString) {
return $('
').html(encodedString).text();
}
function htmlEncode(decodedString) {
return $('').text(decodedString).html();
}
function scrollTo(ele, additionalOffset, useParent) {
if (additionalOffset == undefined) {
additionalOffset = 0;
}
if (useParent == undefined) {
useParent = false;
}
_useParent = false;
if ((typeof (useParent) === 'boolean' && useParent) || typeof(useParent) === 'string') {
_useParent = true;
}
if (_useParent) {
var parent = null;
if (typeof (useParent) === 'boolean') {
parent = $(ele).parent();
} else {
parent = $(ele).closest(useParent);
}
$(parent).animate({ scrollTop: $(ele).offset().top - additionalOffset });
} else {
$('html,body').animate({ scrollTop: $(ele).offset().top - additionalOffset });
}
}
var ajaxParams = {
url: 'https://yakajack.io/api/ajax.asmx/',
type: 'post',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({}),
dataType: 'json',
sync: false,
async: true
};
function formatJSONResponse(data) {
data = $.parseJSON(data.d);
info = $.parseJSON(data.info);
data.info = info;
if (data.error == 'USER NOT AUTHED') {
data.error = 'none';
new modalAlert({ title: 'Not Logged In', text: 'Sorry, but we have had a problem checking if you are logged in or not.
You will be asked to log back in and will then be redirected back here.' })
.ok(function () {
window.location.href = 'https://yakajack.io/account/login.aspx?ref=' + encodeURI(window.location.href);
});
}
return data;
}
function configureAJAXParams(mthd, params) {
var _ajaxParams = JSON.parse(JSON.stringify(ajaxParams));
_ajaxParams.url += mthd;
_ajaxParams.data = JSON.stringify(params);
return _ajaxParams;
}
// JavaScript autoComplete v1.0.4
// https://github.com/Pixabay/JavaScript-autoComplete
var autoComplete=function(){function e(e){function t(e,t){return e.classList?e.classList.contains(t):new RegExp("\\b"+t+"\\b").test(e.className)}function o(e,t,o){e.attachEvent?e.attachEvent("on"+t,o):e.addEventListener(t,o)}function s(e,t,o){e.detachEvent?e.detachEvent("on"+t,o):e.removeEventListener(t,o)}function n(e,s,n,l){o(l||document,s,function(o){for(var s,l=o.target||o.srcElement;l&&!(s=t(l,e));)l=l.parentElement;s&&n.call(l,o)})}if(document.querySelector){var l={selector:0,source:0,minChars:3,delay:150,offsetLeft:0,offsetTop:1,cache:1,menuClass:"",renderItem:function(e,t){t=t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");var o=new RegExp("("+t.split(" ").join("|")+")","gi");return'
'+e.replace(o,"$1")+"
"},onSelect:function(){}};for(var c in e)e.hasOwnProperty(c)&&(l[c]=e[c]);for(var a="object"==typeof l.selector?[l.selector]:document.querySelectorAll(l.selector),u=0;u0?i.sc.scrollTop=n+i.sc.suggestionHeight+s-i.sc.maxHeight:0>n&&(i.sc.scrollTop=n+s)}else i.sc.scrollTop=0},o(window,"resize",i.updateSC),document.body.appendChild(i.sc),n("autocomplete-suggestion","mouseleave",function(){var e=i.sc.querySelector(".autocomplete-suggestion.selected");e&&setTimeout(function(){e.className=e.className.replace("selected","")},20)},i.sc),n("autocomplete-suggestion","mouseover",function(){var e=i.sc.querySelector(".autocomplete-suggestion.selected");e&&(e.className=e.className.replace("selected","")),this.className+=" selected"},i.sc),n("autocomplete-suggestion","mousedown",function(e){if(t(this,"autocomplete-suggestion")){var o=this.getAttribute("data-val");i.value=o,l.onSelect(e,o,this),i.sc.style.display="none"}},i.sc),i.blurHandler=function(){try{var e=document.querySelector(".autocomplete-suggestions:hover")}catch(t){var e=0}e?i!==document.activeElement&&setTimeout(function(){i.focus()},20):(i.last_val=i.value,i.sc.style.display="none",setTimeout(function(){i.sc.style.display="none"},350))},o(i,"blur",i.blurHandler);var r=function(e){var t=i.value;if(i.cache[t]=e,e.length&&t.length>=l.minChars){for(var o="",s=0;st||t>40)&&13!=t&&27!=t){var o=i.value;if(o.length>=l.minChars){if(o!=i.last_val){if(i.last_val=o,clearTimeout(i.timer),l.cache){if(o in i.cache)return void r(i.cache[o]);for(var s=1;s in the .tabbed container
tablist.setAttribute('role', 'tablist');
// Add semantics are remove user focusability for each tab
Array.prototype.forEach.call(tabs, function (tab, i) {
tab.setAttribute('role', 'tab');
tab.setAttribute('id', 'tab' + (i + 1));
tab.setAttribute('tabindex', '-1');
tab.parentNode.setAttribute('role', 'presentation');
if (addEvents) {
// Handle clicking of tabs for mouse users
tab.addEventListener('click', function (e) {
e.preventDefault();
var currentTab = tablist.querySelector('[aria-selected]');
if (e.currentTarget !== currentTab) {
switchTab(currentTab, e.currentTarget);
}
});
// Handle keydown events for keyboard users
tab.addEventListener('keydown', function (e) {
// Get the index of the current tab in the tabs node list
var index = Array.prototype.indexOf.call(tabs, e.currentTarget);
// Work out which key the user is pressing and
// Calculate the new tab's index where appropriate
var dir = e.which === 37 ? index - 1 : e.which === 39 ? index + 1 : e.which === 40 ? 'down' : null;
if (dir !== null) {
e.preventDefault();
// If the down key is pressed, move focus to the open panel,
// otherwise switch to the adjacent tab
dir === 'down' ? panels[i].focus() : tabs[dir] ? switchTab(e.currentTarget, tabs[dir]) : void 0;
}
});
}
});
// Add tab panel semantics and hide them all
Array.prototype.forEach.call(panels, function (panel, i) {
panel.setAttribute('role', 'tabpanel');
panel.setAttribute('tabindex', '-1');
var id = panel.getAttribute('id');
panel.setAttribute('aria-labelledby', tabs[i].id);
panel.hidden = true;
});
// Initially activate the first tab and reveal the first tab panel
tabs[sel.value].removeAttribute('tabindex');
tabs[sel.value].setAttribute('aria-selected', 'true');
panels[sel.value].hidden = false;
})();
});
}
function doModals() {
var modal_trigger_arr = document.querySelectorAll('.modal-trigger');
Array.prototype.forEach.call(modal_trigger_arr, function(modal_trigger) {
modal_trigger.addEventListener('click', function (e) {
modal = document.querySelector('#' + modal_trigger.getAttribute('data-modal'));
modal.classList.add('show');
close_arr = document.querySelectorAll('.modal-close,.overlay');
Array.prototype.forEach.call(close_arr, function(close) {
close.addEventListener('click', function(e) {
modal.classList.remove('show');
});
});
});
});
}
function doMainNav(eleID) {
if (eleID) {
document.getElementById(eleID).classList.add('active');
}
var subnav_arr = document.querySelectorAll('.main-nav .submenu > a');
Array.prototype.forEach.call(subnav_arr, function(subnav_trigger) {
$(subnav_trigger).off('click');
$(subnav_trigger).on('click', function(e) {
this.classList.toggle('active');
});
});
}
function doCollapsible() {
$('.collapser').each(function(idx, itm) {
if (!$(itm).hasEvent('click')) {
$(itm).on('click', function() {
var expanded = $(itm).attr('aria-expanded') === 'true';
$(itm).attr('aria-expanded', !expanded);
var nextDiv = $(this).parent().find('div.js_collapser');
//if (nextDiv.length < 1) {
// nextDiv = $(this).nextUntil('div.js_collapser').next();
//}
$(nextDiv).each(function(_idx, _itm) {
if (!expanded) {
$(_itm).show(yj_ANIM_SPEED);
} else {
$(_itm).hide(yj_ANIM_SPEED);
}
});
});
}
});
/*var collapsers = document.querySelectorAll('.collapser');
Array.prototype.forEach.call(collapsers, function (c) {
//var collapse_btn = c.querySelector('button');
var collapse_btn = c;
console.log('collapse_btn', collapse_btn);
//var collapse_target = c.nextElementSibling;
var collapse_target = c.parentNode.querySelector('div[hidden]');
console.log('c.parentNode', c.parentNode);
console.log('collapse_target', collapse_target);
collapse_btn.onclick = function () {
var expanded = collapse_btn.getAttribute('aria-expanded') === 'true';
collapse_btn.setAttribute('aria-expanded', !expanded);
collapse_target.hidden = expanded;
};
});*/
}
function doCopy(copy_text, txt, appendAlertTo) {
var el = document.createElement("textarea");
el.value = copy_text.innerText;
document.body.appendChild(el);
el.select();
try {
var successful = document.execCommand('copy');
if (appendAlertTo != null) {
if (successful) {
new inlineAlert({
type: 'success',
text: 'Your ' + txt + ' has been copied.',
timeout: 2000
}).show(appendAlertTo);
} else {
new inlineAlert({
type: 'error',
text: 'Sorry. Your browser won\'t let us copy the ' + txt + '. You should be able to copy it manually though.',
timeout: 5000
}).show(appendAlertTo);
}
}
} catch (err) {
console.log('Oops, unable to copy', err);
} finally {
document.body.removeChild(el);
}
}
function validateForm() {
$('#fMain').validate();
}
function formIsValid() {
return $('#fMain').valid();
}
function validateFormElements(divForm) {
var formIsValid = true;
var validator = $('#fMain').validate();
$(divForm).find('input').each(function () {
if (!validator.element(this)) {
if ($(this).next('.error-msg'))
$(this).next('.error-msg').show(300);
formIsValid = false;
}
})
return formIsValid;
}
function doScrollableNavs() {
$('.js_scrollable-nav').each(function () {
$(this).children().each(function (idx) {
if (idx == 0) {
$(this).addClass('selected');
}
$(this).on('click', function () {
var prnt = $(this).parent('ul');
$(prnt).children().each(function () {
$(this).removeClass('selected')
});
$(this).addClass('selected');
if ($(prnt).attr('data-onclick')) {
window[$(prnt).attr('data-onclick')](this);
}
});
});
if ($(this).attr('data-onload')) {
window[$(this).attr('data-onload')](this);
}
});
}
function doPostMessage(ele) {
if (formIsValid()) {
$(ele).attr('disabled', true);
if (!$(ele).attr('data-orig-msg')) {
if ($(ele).is('button') || $(ele).is('a')) {
$(ele).attr('data-orig-msg', $(ele).html());
} else {
$(ele).attr('data-orig-msg', $(ele).val());
}
}
if ($(ele).is('button') || $(ele).is('a')) {
$(ele).html($(ele).attr('data-post-msg'));
} else {
$(ele).val($(ele).attr('data-post-msg'));
}
var events = $._data($(ele)[0], "events");
if ((!events || !events.click) && !$(ele).attr('data-post-none')) {
__doPostBack($(ele).attr('name'), null);
}
}
}
$(document).on('click', '[data-post-msg]', function (e) {
doPostMessage(this);
});
jQuery.fn.extend({
revertState: function () {
var _this = this;
setTimeout(function () {
_this.each(function () {
if ($(this).attr('data-orig-msg')) {
$(this).attr('disabled', false);
if ($(this).is('button') || $(this).is('a')) {
$(this).html($(this).attr('data-orig-msg'));
} else {
$(this).val($(this).attr('data-orig-msg'));
}
}
});
}, 100);
},
hasEvent: function() {
var ty = arguments[0], fn = arguments[1], da = $._data(this[0], 'events') || undefined;
if (da === undefined || ty === undefined || da[ty] === undefined || da[ty].length === 0) return false;
if (fn === undefined) return true;
return Boolean(fn == da[ty][0].handler);
}
});
function waitForElement(selector, handler) {
var waitingFor = setInterval(function() {
if ($(selector).length > 0) {
clearInterval(waitingFor);
handler();
}
}, 10);
}
function waitUntilElementGone(selector, handler) {
var waitingFor = setInterval(function() {
if ($(selector).length < 1) {
clearInterval(waitingFor);
handler();
}
}, 10);
}
function doProgressDonutCharts() {
var charts = document.querySelectorAll('.progress-donut');
Array.prototype.forEach.call(charts, function (chart) {
var tot = chart.getAttribute('data-total');
var val = chart.getAttribute('data-value');
var p = (isNaN(val) || isNaN(tot)) ? 100 : (val / tot) * 100;
var rad = 16;
var NS = "http://www.w3.org/2000/svg";
var svg = document.createElementNS(NS, "svg");
var segment = document.createElementNS(NS, "circle");
var ring = document.createElementNS(NS, "circle");
var value = document.createElementNS(NS, "text");
var title = document.createElementNS(NS, "title");
segment.setAttribute("r", rad);
segment.setAttribute("cx", rad);
segment.setAttribute("cy", rad);
segment.setAttribute('class', 'fill');
segment.style.strokeDashoffset = p;
segment.style.strokeDasharray = p + 0.5 + " 100";
ring.setAttribute("r", rad);
ring.setAttribute("cx", rad);
ring.setAttribute("cy", rad);
ring.setAttribute('class', 'track');
value.setAttribute("x", rad);
value.setAttribute("y", -rad);
value.setAttribute("text-anchor", "middle");
value.setAttribute("dy", ".4em");
value.textContent = val;
title.textContent = chart.getAttribute('data-label');
svg.setAttribute("viewBox", "0 0 " + rad*2 + " " + rad*2);
if (p <= 25) svg.setAttribute('class', 'medium');
if (p <= 10) svg.setAttribute('class', 'low');
svg.appendChild(title);
svg.appendChild(ring);
svg.appendChild(segment);
svg.appendChild(value);
chart.insertBefore(svg, chart.children[0]);
});
}
function doVerticalBarCharts() {
var charts = document.querySelectorAll('.vertical-bars');
Array.prototype.forEach.call(charts, function (chart) {
var data = chart.getAttribute('data-values').split(',');
var labels = chart.getAttribute('data-labels').split(',');
var bar_width = 7;
var gap = 1;
var step = gap + bar_width;
var left_pad = 9;
var top_pad = 4;
var bottom_pad = 5;
var width = (data.length * step) + left_pad;
var height = 60;
var largest = 2 * Math.round(Math.max.apply(Math, data) / 2);
var largestOverride = chart.getAttribute('data-maxy');
if (largestOverride !== '') {
largest = largestOverride;
}
var scale = ((height - bottom_pad - top_pad)/largest);
var NS = "http://www.w3.org/2000/svg";
var svg = document.createElementNS(NS, "svg");
var ylines = (largest > 0) ? [0, Math.floor(largest * 0.75) * scale, Math.floor(largest / 2) * scale, Math.floor(largest * 0.25) * scale, height - bottom_pad - top_pad] : [height - bottom_pad - top_pad];
var yvalues = [largest, Math.ceil(largest * 0.25), Math.ceil(largest / 2), Math.ceil(largest * 0.75), 0];
svg.setAttribute("viewBox", "0 0 " + width + " " + height);
svg.setAttribute("preserveAspectRatio", "xMinYMax meet");
for (var i = 0; i < ylines.length; i++) {
var line = document.createElementNS(NS, 'line');
var label = document.createElementNS(NS, 'text');
line.setAttribute("x1", left_pad);
line.setAttribute("y1", ylines[i] + top_pad);
line.setAttribute("x2", width);
line.setAttribute("y2", ylines[i] + top_pad);
label.textContent = yvalues[i];
label.setAttribute("x", left_pad - 2);
label.setAttribute("y", ylines[i] + top_pad);
label.setAttribute("text-anchor", "end");
label.setAttribute("dy", ".4em");
svg.appendChild(line);
svg.appendChild(label);
}
var bars = document.createElementNS(NS, 'g');
bars.setAttribute("transform", "translate(0, " + (height - bottom_pad) + ") scale(1,-1)");
for (var i = 0; i < data.length; i++) {
var bar = document.createElementNS(NS, 'rect');
var label = document.createElementNS(NS, 'text');
var value = document.createElementNS(NS, 'text');
label.textContent = labels[i];
label.setAttribute("x", gap/2 + (i * step) + (bar_width / 2) + left_pad);
label.setAttribute("y", height-1);
label.setAttribute("text-anchor", "middle");
if (data[i] > 0) {
bar.setAttribute("width", bar_width);
bar.setAttribute("height", data[i] * scale);
bar.setAttribute("x", gap/2 + (i * step) + left_pad);
value.textContent = data[i];
value.setAttribute("x", gap/2 + (i * step) + (bar_width / 2) + left_pad);
value.setAttribute("text-anchor", "middle");
value.setAttribute("transform", "translate(0," + ((data[i] * scale) + 1) + ") scale(1,-1)");
bars.appendChild(bar);
bars.appendChild(value);
}
svg.appendChild(label);
}
svg.appendChild(bars);
chart.insertBefore(svg, chart.children[0]);
});
}
function togglePaginationLinks(children, slctr, state) {
children.each(function (idx, itm) {
var a = $(itm).find(slctr);
if (a.length > 0) {
if (state) { $(a).attr('disabled', 'disabled'); }
else { $(a).removeAttr('disabled'); }
}
});
}
document.addEventListener("DOMContentLoaded", function () {
//doTabs(true);
doModals();
doMainNav();
doCollapsible();
doScrollableNavs();
doProgressDonutCharts();
doVerticalBarCharts();
var demo1 = new autoComplete({
selector: '#input-autocomplete',
minChars: 1,
source: function(term, suggest){
term = term.toLowerCase();
var choices = ['ActionScript', 'AppleScript', 'Asp', 'Assembly', 'BASIC', 'Batch', 'C', 'C++', 'CSS', 'Clojure', 'COBOL', 'ColdFusion', 'Erlang', 'Fortran', 'Groovy', 'Haskell', 'HTML', 'Java', 'JavaScript', 'Lisp', 'Perl', 'PHP', 'PowerShell', 'Python', 'Ruby', 'Scala', 'Scheme', 'SQL', 'TeX', 'XML'];
var suggestions = [];
for (i=0;i= param;
}
return this.optional(element) || length >= param;
});
$.validator.addMethod('password', function (value, element, param) {
if (value.length < 8) { return false; }
if (!(/\d+/.test(value))) { return false; }
var specialChars = "`¬!\"£$%^&*()_-+=[]}{;'#~@:,./?><\\|"
var check = function(string){
for (i = 0; i < specialChars.length;i++){
if(string.indexOf(specialChars[i]) > -1){
return true
}
}
return false;
}
if (!check(value)) { return false; }
return true;
});
$.validator.addMethod('passwordconfirm', function (value, element, param) {
var selector = '#' + param;
return (value == $(selector).val());
});
$.validator.addMethod('domain', function (value, element, param) {
if (value === 'localhost' && (window.location.href.indexOf('localhost') > -1 || window.location.href.indexOf('chatdev') > -1)) {
return true;
} else {
return /([a-z0-9A-Z]\.)*[a-z0-9-]+\.([a-z0-9]{2,24})+(\.co\.([a-z0-9]{2,24})|\.([a-z0-9]{2,24}))*/g.test(value);
}
});
validateForm();
var currentPageTbl = [];
$('table').each(function (idx, itm) {
$(itm).attr('data-table-id', idx);
currentPageTbl[idx] = 1;
});
var currentPageUl = [];
$('ul').each(function (idx, itm) {
$(itm).attr('data-ul-id', idx);
currentPageUl[idx] = 1;
});
$('.js_page-nav').click(function (e) {
e.preventDefault();
if ($(this).find('a').attr('disabled') !== 'disabled') {
var maxPages = $(this).closest('ul').children().length - 2;
var toPage = $(this).attr('data-topage');
var idRef = 'table';
var currentPage = currentPageTbl;
var eleTag = 'tr';
var eleID = 'trRow';
var ele = $(this).closest('ul').prev('div.table-container').find('table');
if (ele.length === 0) {
idRef = 'ul';
currentPage = currentPageUl;
eleTag = 'li';
eleID = 'liItem';
ele = $(this).closest('ul').prev('ul');
}
var index = parseInt($(ele).attr('data-' + idRef + '-id'));
$(this).closest('ul').children().each(function (idx, itm) {
$(itm).find('a').attr('href', '#');
});
if (toPage === 'minus') { toPage = currentPage[index] - 1; }
else if (toPage === 'plus') { toPage = currentPage[index] + 1; }
if (toPage < 1) { toPage = 1; }
else if (toPage > maxPages) { toPage = maxPages; }
togglePaginationLinks($(this).closest('ul').children(), 'a', false);
toPage = parseInt(toPage);
togglePaginationLinks($(this).closest('ul').children(), 'a.prev', false);
togglePaginationLinks($(this).closest('ul').children(), 'a.next', false);
if (toPage === 1) {
$('a.prev').hide(300);
$('a.next').show(300);
} else if (toPage === maxPages) {
$('a.next').hide(300);
$('a.prev').show(300);
}
else {
$('a.prev').show(300);
$('a.next').show(300);
}
togglePaginationLinks($(this), 'a' , true);
currentPage[index] = toPage;
$(this).parent().find('li[data-topage="' + toPage.toString() + '"]').find('a').removeAttr('href');
$(ele).find(eleTag + ':visible[id*="' + eleID + '"]').hide(yj_ANIM_SPEED);
$(ele).find(eleTag + '[data-page-num="' + toPage.toString() + '"]').css({ 'opacity': '0', 'display': 'table-row' }).animate({ opacity: 1 }, 300);
}
});
if ($('#search-support').length > 0) {
$('#search-support').on('click', function () {
var v = $('#search_support').val();
if (v !== '') {
__doPostBack('supportSearch', v);
}
});
}
$('[onload]').trigger('onload');
});
function setProgressBar(eleID, val, acc) {
eleID = '#' + eleID;
$(eleID).text(parseFloat(val).toFixed(acc).toString() + '%');
$(eleID).css('width', val + '%');
}
var modalPopUp = (function ($) {
var cls = function () {
var dfd = $.Deferred();
this.title = arguments[0].title;
this.text = arguments[0].text;
var t = new Date().getTime();
var html = '