window.guid = function( len )
{
len = len || 8;
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var unique = '';
for ( var x = 0; x < len; x++ )
{
var random = Math.floor( Math.random() * chars.length );
unique += chars.substring( random, random + 1 );
}
return unique;
};
window.template = function( tests, callback, interations, timer )
{
interations = interations || 0;
timer = timer || window.guid();
if ( interations > 20 )
{
console.log('Template Autoloader: All tests failed after ' + interations + ' attemps.' );
return;
}
interations++;
for( var test in tests )
{
if ( tests.hasOwnProperty( test ) )
{
let type = typeof( window[ tests[ test ] ] );
if ( type === 'function' || type === 'object' )
{
clearTimeout( window[ timer ] );
callback();
return;
}
}
}
clearTimeout( window[ timer ] );
window[ timer ] = setTimeout( function() { window.template( tests, callback, interations, timer ); }, 500 );
};
window.authorized = function ( params, cb )
{
if ( params && params.History && params.route && params.route.indexOf("signin") !== -1 )
{
var redirectUrl = ( params.ComponentUrl ? params.ComponentUrl + params.route : params.route );
if ( window.parent )
{
if ( cb && typeof cb === 'function' ) { return cb( redirectUrl ); }
window.top.location.href = redirectUrl;
return;
}
if ( cb && typeof cb === 'function' ) { return cb( redirectUrl ); }
window.location.href = redirectUrl;
}
else
{
if ( window.location != window.parent.location && window.location.href.indexOf("signin") !== -1 )
{
if ( cb && typeof cb === 'function' ) { return cb( redirectUrl ); }
/* works but initial login form is displayed so hide the document */
document.body.style.display = "none";
window.top.location.href = window.location.href;
}
}
};
window.freeze = function( redirectAjax, useMask )
{
if ( useMask && useMask == true )
{
var mask = document.createElement("div");
mask.style.top = '0px';
mask.style.left = '0px';
mask.style.position = 'absolute';
mask.style.width = document.documentElement.clientWidth + 'px';
mask.style.height = document.documentElement.scrollHeight + 'px';
mask.style.zIndex = '2147483647';
document.body.appendChild( mask );
}
/* disable all ajax */
var xhr = ( window.XMLHttpRequest || window.ActiveXObject );
if ( !redirectAjax )
{
xhr.prototype.send = function() { };
}
else
{
var native = xhr.prototype.open;
xhr.prototype.open = function()
{
/* arguments are managed in another xhr function and do not need to be parsed into
* the new url */
if ( arguments[ 1 ] )
{
arguments[ 1 ] = redirectAjax;
}
return native.apply( this, [].slice.call( arguments ) );
};
}
/* disable submits */
var forms = document.getElementsByTagName( 'form' );
for( var x = 0; x < forms.length; x++ )
{
forms[x].onsubmit = function(e) { e.preventDefault(); return false; };
}
/* disable links */
var anchors = document.getElementsByTagName( 'a' );
for( var x = 0; x < anchors.length; x++)
{
anchors[x].onclick = function() { return false; };
}
/* overload addEventListener to do nothing as a last stop measure */
const originalAdd = Element.prototype.addEventListener;
Element.prototype.addEventListener = function( type, listener, options )
{
const forbiddenEvents = ['click', 'submit', 'mousedown', 'touchstart'];
if ( forbiddenEvents.includes( type ) )
{
// refuse to attach the listener
return;
}
return originalAdd.call( this, type, listener, options );
};
};
window.busy = function( showStatus )
{
var element = document.getElementById( 'busy-window' );
if ( !element )
{
let loading = `
`;
document.body.prepend( document.createRange().createContextualFragment( loading ) );
element = document.getElementById( 'busy-window' );
}
if ( element )
{
if ( showStatus )
{
var css = element.className.split(' ');
if ( css.indexOf( 'fl-busy-visible' ) == -1 )
{
css.push( 'fl-busy-visible' );
element.className = css.join(' ');
}
}
else
{
element.className = element.className.replace(/\bfl-busy-visible\b/g, "");
}
}
};
window.ifloaders = function()
{
var elements = document.getElementsByTagName('iframe');
for( var x = 0; x < elements.length; x++ )
{
var iframe = elements[x];
var id = ( iframe && iframe.id ? iframe.id : window.quid() );
var view = iframe.getBoundingClientRect();
var loader = document.getElementById( 'frames-ld-' + id );
if ( !loader )
{
var loader = document.createElement("div");
/* this function breaks stripejs so we need to ignore private stripe iframes */
var iframe = elements[x];
if ( iframe.name && iframe.name.indexOf('private') !== -1 )
{
continue;
}
loader.id = 'frames-ld-' + id;
loader.style.position = "absolute";
loader.style.top = "50%";
loader.style.left = "50%";
loader.className = "fl-loading fl-loading-sm fl-loading-blue";
if ( iframe.contentWindow.document.readyState != 'complete' )
{
document.getElementsByTagName("body")[0].appendChild( loader );
iframe.contentWindow.addEventListener( 'load', function(e){
document.getElementById( 'frames-ld-' + id ).remove();
} );
}
}
}
};
window.cssfiles = function( domain )
{
var doc = document;
if ( window.top != window.self )
{
doc = window.top.document;
}
files = [];
for( var x = 0; x < doc.styleSheets.length; x++ )
{
files.push( doc.styleSheets[x].href );
}
if ( domain )
{
for( var x = 0; x < files.length; x++ )
{
if ( files[x] )
{
files[x] = files[x].replace(/https?:\/\/[^\/]+/, domain );
}
}
}
return files;
};
window.jsfiles = function( domain )
{
var doc = document;
if ( window.top != window.self )
{
doc = window.top.document;
}
files = [];
for( var x = 0; x < doc.scripts.length; x++ )
{
files.push( doc.scripts[x].href );
}
if ( domain )
{
for( var x = 0; x < files.length; x++ )
{
if ( files[x] )
{
files[x] = files[x].replace(/https?:\/\/[^\/]+/, domain );
}
}
}
return files;
};
window.ajaxComplete = function( cb )
{
var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function()
{
if ( cb )
{
var ocb = this.onreadystatechange;
this.onreadystatechange = function()
{
if ( this.readyState == XMLHttpRequest.DONE )
{
try
{
this.responseJSON = JSON.parse( this.responseText );
}
catch( error )
{
this.responseJSON = {};
};
cb( this );
}
ocb && ocb();
}
}
return send.apply( this, arguments );
}
}
window.stopKeySubmit = function() {
const keydownHandler = ( e ) => {
var keyStop = {
8: ":not(input[type='text'], textarea, input[type='file'], input[type='password'])", /* stop backspace = back */
13: "input[type='text'], input[type='password']", /* stop enter = submit */
};
var selector = keyStop[ e.which ];
var wrapper = document.createElement('div');
wrapper.innerHTML = e.target.outerHTML;
if( selector !== undefined && wrapper.querySelector( selector ) )
{
e.preventDefault();
}
return true;
};
document.removeEventListener( 'keydown', keydownHandler, true );
document.addEventListener( 'keydown', keydownHandler, true );
}
window.signin = function() {
if ( !tcDialogBox ) { return; }
tcDialogBox.OkButton = true;
tcDialogBox.CancelButton = false;
tcDialogBox.DimentionRatio = 60;
tcDialogBox.RepositionScreen = true;
let template = `
`;
if ( !document.getElementById( 'login-session' ) )
{
document.body.insertAdjacentHTML( 'beforeend', template );
}
tcDialogBox.showModal( { 'modalId': 'login-session', title: 'Login',
'onOk': function( element ){
$.ajax( {
url: 'https://' + window.location.hostname + '/members/signin/logon',
dataType: 'json',
method: 'POST',
data: {
'Email': $('#Email').val(),
'Password': $('#Password').val()
},
success: function ( data ) {
if ( data.errors && data.errors.length > 0 )
{
$('#login-session-message').html( data.errors[0] );
window.signin();
}
}
});
}
});
};
window.captcha = function()
{
let time = new Date().getTime();
let form = document.getElementById('form-captcha');
let captcha = document.getElementById('captcha');
if ( !document.defaultView.rtime )
{
form.src = '/system/action/captcha/id/' + time;
document.defaultView.rtime = time;
captcha.value = "";
}
if ( time - 5000 > document.defaultView.rtime )
{
form.src = '/system/action/captcha/id/' + time;
document.defaultView.rtime = time;
captcha.value = "";
}
}
window.analytics = function()
{
let SiteAnalytics = {
token: 'TR_ANALYTICS',
update: function()
{
var cValue = new tcCookieValue( this.token );
var reference = Math.random().toString(36).substr(2, 9);
cValue.storage.expires = 7;
cValue.add( reference );
return reference;
},
get: function()
{
var cValue = new tcCookieValue( this.token );
return ( cValue.storage.value ? cValue.storage.value : false );
}
};
let id = SiteAnalytics.get();
if ( !id )
{
id = SiteAnalytics.update();
}
const data = {
SessionId: id, // Use the tracking ID as the session ID
Url: window.location.href,
Referer: document.referrer || '',
UserAgent: navigator.userAgent
};
const blob = new Blob( [ JSON.stringify( data ) ], { type: 'application/json' } );
navigator.sendBeacon( window.location.protocol + '//' + window.location.host + '/system/action/analytics', blob );
}
window.contact = function(){
$(document).on('submit', 'form', function(e) {
const form = $(this);
const action = form.attr('action') || '';
const path = action.split('?')[0].toLowerCase();
if ( !path.endsWith('/contact/message') ) {
return;
}
e.preventDefault();
const formdata = form.serializeArray();
const dataset = {};
$.map(formdata, function(n, i){
dataset[n['name']] = n['value'];
});
$.ajax({
url: action,
method: 'POST',
dataType: 'json',
data: dataset,
success: function(data) {
$('#contact-messages').remove();
if ( ( data.errors && data.errors.length > 0 ) || ( data.messages && data.messages.length > 0 ) ) {
let section = $('');
if ( data.errors && data.errors.length > 0 ) {
$.each( data.errors, function( i, error ) {
section.append(
`
${error}
`
);
});
}
if ( data.messages && data.messages.length > 0 ) {
$.each( data.messages, function( i, msg ) {
section.append(
`
${msg}
`
);
});
if ( !data.errors || data.errors.length === 0 ) {
form[0].reset();
}
}
/* compile the style tag string so the backend doesn't report a invalid template/css error */
let string = '<' + 'style' + '>';
let style = $(string).prop('type', 'text/css').html( `.msg-container { width: 100%; max-width: 1280px; margin: 0 auto 20px auto; padding: 16px; box-sizing: border-box; display: flex; flex-direction: column; gap: 10px; }
.msg-card { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 8px; font-size: 14px; line-height: 1.5; font-weight: 500; box-sizing: border-box; }
.msg-icon { font-size: 16px; flex-shrink: 0; }
.msg-text { flex: 1; }
.msg-error { background-color: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.msg-error .msg-icon { color: #dc2626; }
.msg-success { background-color: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.msg-success .msg-icon { color: #16a34a; }
@media (max-width: 768px) { .msg-container { padding: 0 16px; } }` );
form.prepend( section );
form.prepend( style );
}
},
error: function(xhr, status, error) {
console.error("Critical connection error.");
}
});
});
}
Defaulthomepage
Something great is brewing.
Our new digital home is currently under construction. We're busy laying the bricks for a better experience.
Official Launch: Coming Soon