'use strict';
element.
?>
var supportsDatalist = function supportsDatalist() {
.
?>
return ('list' in document.createElement('input')) &&
('options' in document.createElement('datalist')) &&
(window.HTMLDataListElement !== undefined);
};
var adjustLabelWidths = function adjustLabelWidths() {
var standardFieldset = $('.standard fieldset');
if ((standardFieldset.length !== 0) && (standardFieldset.css('display') === 'table'))
{
var labels = standardFieldset.children('div').children('label').not('.rep_type_details label');
labels.width('auto');
labels.width(getMaxWidth(labels) + 1);
}
}
function fillUsernameFields()
{
var select = $('.ajax_usernames');
if (select.length === 0)
{
return;
}
select.each(function() {
var el = $(this);
el.mrbsSelect(el.hasClass('datalist'));
$('body').addClass('ajax-loading');
});
$.post({
url: 'ajax/usernames.php',
dataType: 'json',
data: {csrf_token: getCSRFToken(), site: args.site},
success: function(data) {
select.each(function() {
var el = $(this);
var newOption;
var currentOption = el.find('option').first();
var currentValue = currentOption.val();
var currentValueUpper = currentValue.toString().toUpperCase();
var currentText = currentOption.text();
el.empty();
var foundCurrent = false;
$.each(data, function(index, option) {
if (option.username !== null)
{
// Make it a case-insensitive comparison as usernames are case-insensitive
var selected = (option.username.toString().toUpperCase() === currentValueUpper);
foundCurrent = foundCurrent || selected;
var newOption = new Option(option.display_name, option.username, selected, selected);
el.append(newOption);
}
});
if (!foundCurrent)
{
newOption = new Option(currentText, currentValue, true, true);
el.append(newOption);
}
if (el.hasClass('select2-hidden-accessible'))
{
var wasOpen = el.select2('isOpen');
el.select2('close').trigger('change');
if (wasOpen)
{
el.select2('open');
}
}
});
$('body').removeClass('ajax-loading');
}
});
}
var args;
$(document).on('page_ready', function() {
args = $('body').data();
fillUsernameFields();
var recordActivity = function recordActivity() {
var d = new Date(),
t = d.getTime()/1000;
if ((typeof recordActivity.lastRecorded === 'undefined') ||
((t - recordActivity.lastRecorded) > ( - 1)))
{
recordActivity.lastRecorded = t;
var params = {activity: 1};
if(args.site)
{
params.site = args.site;
}
$.post('ajax/record_activity.php', params, function() {
});
}
};
$(document).on('keydown mousemove mousedown', function() {
recordActivity();
});
$('').attr({
type: 'hidden',
name: 'datatable',
value: '1'
}).appendTo('form[action="search.php"]');
$('header a[href^="edit_users.php"]').each(function() {
var href = $(this).attr('href');
href += (href.indexOf('?') < 0) ? '?' : '&';
href += 'datatable=1';
$(this).attr('href', href);
});
$('form input.default_action').each(function() {
var defaultSubmitButton = $(this);
$(this).parents('form').find('input').on('keypress', function(event) {
if (event.which === 13) // the Enter key
{
defaultSubmitButton.trigger('click');
return false;
}
else
{
return true;
}
});
});
$('.enabler').on('change', function(){
var enablerChecked = $(this).is(':checked');
var elements;
switch ($(this).attr('name'))
{
case 'area_max_duration_enabled':
elements = $('[name^="area_max_duration"]').not($(this));
break;
case 'registrant_limit_enabled':
elements = $('[name="registrant_limit"]');
break;
default:
elements = $(this).nextAll('input, select')
break;
}
elements.prop('disabled', !enablerChecked);
})
.trigger('change');
if (supportsDatalist())
{
$('input[list]').each(function() {
var input = $(this),
hiddenInput = $('');
hiddenInput.attr('id', input.attr('id'))
.attr('name', input.attr('name'))
.val(input.val());
input.removeAttr('id')
.removeAttr('name')
.after(hiddenInput);
input.on('input', function() {
hiddenInput.val($(this).val());
});
});
$('form:has(input[list]) input[type="submit"]').on('click', function() {
$(this).closest('form')
.find('input:not([name])')
.not('input[type="submit"]')
.each(function() {
if (!$(this).prop('required') &&
(typeof($(this).attr('pattern')) == 'undefined'))
{
$(this).val('');
}
});
});
}
else
{
element.
?>
$('datalist').each(function() {
var datalist = $(this);
var options = [];
datalist.parent().find('option').each(function() {
var option = {};
option.label = $(this).text();
option.value = $(this).val();
options.push(option);
});
var minLength = 0;
var breaks = [];
var nOptions = options.length;
var i=0;
while ((i= breaks[i]))
{
i++;
minLength++;
}
var formInput = datalist.prev();
formInput.empty().autocomplete({
source: options,
minLength: minLength
});
if (minLength === 0)
{
formInput.on('focus', function() {
$(this).autocomplete('search', '');
});
}
});
}
$('[type="time"]').each(function() {
if ($(this).prop('type') !== 'time')
{
$(this).attr('placeholder', 'hh:mm')
.attr('pattern', '')
.on('input', function(e) {
e.target.setCustomValidity('');
if (!e.target.validity.valid)
{
e.target.setCustomValidity('');
}
});
}
});
adjustLabelWidths();
$(window)
.on('resize', throttle(function() {
adjustLabelWidths();
}, 100));
$('input[type="password"]').each(function() {
$(this).after($(''))
.after($(''));
});
$('.eye svg').on('mousedown', function(e) {
e.preventDefault();
var parent = $(this).parent();
var grandparent = parent.parent();
var input = grandparent.find('input');
var newType = (parent.hasClass('off')) ? 'password' : 'text';
grandparent.find('.eye svg').toggle();
input.attr('type', newType);
});
$('.contact').each(function() {
var decoded = base64Decode($(this).data('html'));
if (decoded !== false) {
$(this).replaceWith(decoded);
}
});
$('input[type="file"]').on('change input', function(e) {
var maxFileSize = $(this).closest('form').find('[name="MAX_FILE_SIZE"]').val();
var message = ''
if(maxFileSize && e.target.files && e.target.files.length === 1) {
if (e.target.files[0].size > maxFileSize) {
e.target.setCustomValidity(message);
e.target.reportValidity();
}
else {
e.target.setCustomValidity('');
}
}
});
$('input[type="email"][multiple]').each(function() {
$(this).attr('type', 'text').attr('type', 'email');
});
});
$(function() {
$(document).trigger('page_ready');
});