Merged in feature/plugins-update (pull request #9)

wp plugin updates from pantheon

* wp plugin updates from pantheon
This commit is contained in:
Tony Volpe
2023-12-15 18:08:21 +00:00
parent 28c21bf9b1
commit 779393381f
577 changed files with 154305 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
.fcomplete-wrap {
position: absolute;
border: 1px solid #ddd;
border-top: none;
background-color: #fff;
max-width: 400px;
}
.fcomplete-result,
.fcomplete-status {
padding: 6px 8px;
}
.fcomplete-result {
cursor: pointer;
}
.fcomplete-result:hover {
background-color: #f5f5f5;
}
.fcomplete-status {
font-size: 13px;
font-style: italic;
}
.fcomplete-hidden {
display: none;
}

View File

@@ -0,0 +1,283 @@
window.fComplete = (() => {
class fComplete {
constructor(selector, options) {
let that = this;
var defaults = {
data: [],
minChars: 3,
maxResults: 10,
searchDelay: 200,
loadingText: 'Loading...',
minCharsText: 'Enter {n} or more characters',
noResultsText: 'No results',
beforeRender: null,
onSelect: null
};
that.settings = Object.assign({}, defaults, options);
that.settings.minChars = Math.max(1, that.settings.minChars);
that.settings.maxResults = Math.max(1, that.settings.maxResults);
that.settings.searchDelay = Math.max(0, that.settings.searchDelay);
if ('string' === typeof selector) {
var nodes = Array.from(document.querySelectorAll(selector));
}
else if (selector instanceof Node) {
var nodes = [selector];
}
else if (Array.isArray(selector)) {
var nodes = selector;
}
else {
var nodes = [];
}
if ('undefined' === typeof window.fCompleteInit) {
window.fCompleteInit = {
lastFocus: null,
eventsBound: true
};
that.bindEvents();
}
nodes.forEach((input) => {
that.input = input;
input.fcomplete = that;
input.classList.add('fcomplete-enabled');
that.create();
});
}
create() {
var that = this;
var html = `
<div class="fcomplete-wrap fcomplete-hidden">
<div class="fcomplete-status"></div>
<div class="fcomplete-results"></div>
</div>
`;
var rect = that.input.getBoundingClientRect();
var tpl = document.createElement('template');
tpl.innerHTML = html;
var wrap = tpl.content.querySelector('.fcomplete-wrap');
wrap.style.minWidth = rect.width + 'px';
that.input.parentNode.insertBefore(wrap, that.input.nextSibling);
// add a relationship link
that.input._rel = wrap;
wrap._rel = that.input;
}
destroy() {
this.input._rel.remove();
delete this.input._rel;
}
reload() {
this.destroy();
this.create();
}
open() {
this.input._rel.classList.remove('fcomplete-hidden');
}
close() {
window.fCompleteInit.lastFocus = null;
this.input._rel.classList.add('fcomplete-hidden');
}
setStatus(text) {
var text = text.replace('{n}', this.settings.minChars);
var node = this.input._rel.querySelector('.fcomplete-status');
node.innerHTML = text;
var method = (text) ? 'remove' : 'add';
node.classList[method]('fcomplete-hidden');
}
render(data) {
var data = (this.settings.beforeRender) ? this.settings.beforeRender(data) : data;
var wrap = this.input._rel;
if (data.length) {
var html = '';
var len = Math.min(data.length, this.settings.maxResults);
for (var i = 0; i < len; i++) {
html += `<div class="fcomplete-result" data-value="${data[i].value}" tabindex="-1">${data[i].label}</div>`;
}
wrap.querySelector('.fcomplete-results').innerHTML = html;
this.setStatus('');
}
else {
wrap.querySelector('.fcomplete-results').innerHTML = '';
this.setStatus(this.settings.noResultsText);
}
this.input.fcomplete.open();
}
getAdjacentSibling(which) {
var that = this;
var which = which || 'next';
var sibling = window.fCompleteInit.lastFocus;
var selector = '.fcomplete-result';
if (sibling) {
sibling = sibling[which + 'ElementSibling'];
while (sibling) {
if (sibling.matches(selector)) break;
sibling = sibling[which + 'ElementSibling'];
}
return sibling;
}
else if ('next' == which) {
sibling = that.input._rel.querySelector(selector);
}
return sibling;
}
debounce(func, wait) {
var timeout;
return (...args) => {
var boundFunc = func.bind(this, ...args);
clearTimeout(timeout);
timeout = setTimeout(boundFunc, wait);
}
}
trigger(eventName, ...args) {
document.dispatchEvent(new CustomEvent(eventName, {detail: [...args]}));
}
on(eventName, elementSelector, handler) {
document.addEventListener(eventName, function(e) {
// loop parent nodes from the target to the delegation node
for (var target = e.target; target && target != this; target = target.parentNode) {
if (target.matches(elementSelector)) {
handler.call(target, e);
break;
}
}
}, false);
}
bindEvents() {
let that = this;
that.on('click', '*', function(e) {
var wrap = this.closest('.fcomplete-wrap');
var isInput = this.classList.contains('fcomplete-enabled');
if (isInput) {
var input = this;
var settings = input.fcomplete.settings;
var status = (settings.minChars > input.value.length) ? settings.minCharsText : '';
input.fcomplete.setStatus(status);
this.fcomplete.open();
}
else if (!wrap && !isInput) {
document.querySelectorAll('.fcomplete-wrap').forEach((node) => node.classList.add('fcomplete-hidden'));
}
});
that.on('click', '.fcomplete-result', function(e) {
var wrap = e.target.closest('.fcomplete-wrap');
var input = wrap._rel;
input.value = e.target.getAttribute('data-value');
if (typeof input.fcomplete.settings.onSelect === 'function') {
input.fcomplete.settings.onSelect();
}
input.fcomplete.close();
});
that.on('keydown', '*', function(e) {
var wrap = this.closest('.fcomplete-wrap');
var isInput = this.classList.contains('fcomplete-enabled');
if (!wrap && !isInput) return;
var input = (wrap) ? wrap._rel : this;
wrap = (wrap) ? wrap : input._rel;
if (-1 < [13, 38, 40, 27].indexOf(e.which)) {
e.preventDefault();
}
if (13 == e.which) { // enter
if (this.classList.contains('fcomplete-result')) {
this.click();
}
}
else if (38 == e.which) { // up
if (this.classList.contains('fcomplete-result')) {
var sibling = wrap._rel.fcomplete.getAdjacentSibling('previous');
window.fCompleteInit.lastFocus = sibling; // stop at the search box
(sibling) ? sibling.focus() : input.focus();
}
}
else if (40 == e.which) { // down
if (this === input) {
var firstResult = wrap.querySelector('.fcomplete-result');
if (firstResult) {
firstResult.focus();
window.fCompleteInit.lastFocus = firstResult;
}
}
else if (this.classList.contains('fcomplete-result')) {
var sibling = wrap._rel.fcomplete.getAdjacentSibling('next');
if (sibling) {
sibling.focus();
window.fCompleteInit.lastFocus = sibling; // stop at the bottom
}
}
}
else if (9 == e.which || 27 == e.which) { // tab, esc
wrap._rel.fcomplete.close();
}
});
that.on('keyup', '.fcomplete-enabled', that.debounce(function(e) {
if (-1 < [13, 38, 40, 27].indexOf(e.which)) {
return;
}
var input = e.target;
var settings = input.fcomplete.settings;
if (settings.minChars <= input.value.length) {
if (Array.isArray(settings.data)) {
input.fcomplete.render(settings.data);
}
else if (typeof settings.data === 'function') {
input.fcomplete.setStatus(settings.loadingText);
settings.data();
}
}
else {
input.fcomplete.render([]);
input.fcomplete.setStatus(settings.minCharsText);
}
}, that.settings.searchDelay));
}
}
var $ = (selector, options) => new fComplete(selector, options);
return $;
})();

View File

@@ -0,0 +1,7 @@
Copyright 2021 FacetWP, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,87 @@
.fdate-input {
outline: none;
}
.fdate-wrap {
width: 300px;
display: none;
background: #fff;
border-radius: 5px;
border: 1px solid #ddd;
font-size: 14px;
user-select: none;
-webkit-user-select: none;
z-index: 10000;
}
.fdate-wrap.opened {
display: block;
}
.fdate-wrap .disabled {
opacity: 0.1;
}
.fdate-nav {
display: grid;
grid-template-columns: 1fr 5fr 1fr;
}
.fdate-nav > div,
.fdate-clear {
padding: 10px 0;
text-align: center;
cursor: pointer;
}
.fdate-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
text-align: center;
}
.fdate-grid.grid-day {
grid-template-columns: repeat(7, 1fr);
}
.fdate-grid > div {
padding: 20px 0;
opacity: 0.3;
}
.fdate-grid > div:hover {
background-color: #ddd;
cursor: pointer;
}
.fdate-grid .fdate-day {
padding: 8px 0;
}
.fdate-grid .weekday,
.fdate-grid .inner {
opacity: 1;
}
.fdate-grid .today {
background-color: #F8F8F8;
}
.fdate-grid .selected {
background-color: #DDD6FE;
}
.fdate-day.weekday {
font-weight: bold;
padding-top: 0;
}
.fdate-grid .weekday:hover,
.fdate-grid .disabled:hover {
background-color: transparent;
cursor: default;
}
.fdate-wrap .disabled:hover {
cursor: not-allowed;
}

View File

@@ -0,0 +1,679 @@
window.fDate = (() => {
var qs = (selector) => document.querySelector(selector);
var isset = (input) => 'undefined' !== typeof input;
var ymd = (...args) => {
var d = new Date(...args);
var zeroed = (num) => (num > 9) ? num : '0' + num;
// toJSON() produces unexpected results due to timezones
return d.getFullYear() + '-' + zeroed(d.getMonth() + 1) + '-' + zeroed(d.getDate());
};
class fDate {
constructor(selector, options) {
let that = this;
var defaults = {
i18n: {
weekdays_short: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
months_short: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
clearText: 'Clear',
firstDayOfWeek: 0
},
minDate: '',
maxDate: '',
altFormat: '',
onChange: null
};
that.settings = Object.assign({}, defaults, options);
if ('string' === typeof selector) {
var inputs = document.querySelectorAll(selector);
}
else if (selector instanceof Node) {
var inputs = [selector];
}
else {
var inputs = selector;
}
if (inputs.length) {
inputs.forEach(function(input) {
input.setAttribute('readonly', 'readonly');
if ('' !== that.settings.altFormat) {
that.el = input;
let altInput = input.cloneNode();
altInput.classList.add('fdate-alt-input');
altInput.value = that.getAltDate();
altInput._input = input;
input._altInput = altInput;
input.setAttribute('type', 'hidden');
input.parentNode.insertBefore(altInput, input.nextSibling); // append()
}
input.classList.add('fdate-input');
input._input = input;
input.fdate = {
settings: that.settings,
refresh() {
input.click();
},
open() {
input.click();
},
close() {
that.setCalVisibility('hide');
},
clear() {
input.value = '';
if (isset(input._altInput)) {
input._altInput.value = '';
}
that.triggerEvent('onChange');
},
destroy() {
input.classList.remove('fdate-input');
delete input._altInput;
delete input._input;
delete input.fdate;
}
};
});
}
if (null === qs('.fdate-wrap')) {
this.initCalendar();
this.bindEvents();
}
}
initCalendar() {
var html = `
<div class="fdate-wrap">
<div class="fdate-nav">
<div class="fdate-nav-prev">&lt;</div>
<div class="fdate-nav-label" tabindex="-1"></div>
<div class="fdate-nav-next">&gt;</div>
</div>
<div class="fdate-grid"></div>
<div class="fdate-clear" tabindex="-1">${this.settings.i18n.clearText}</div>
</div>
`;
document.body.insertAdjacentHTML('beforeend', html);
}
setInput(input) {
this.el = input;
this.mode = 'day';
this.settings = input.fdate.settings;
this.setDateBounds();
// valid YYYY-MM-DD?
if (null !== input.value.match(/^\d{4}-\d{2}-\d{2}$/)) {
var date_str = input.value;
}
// use the min date or today, whichever is higher
else {
var today = ymd();
var date_str = (this.min.str < today) ? today : this.min.str;
}
// rewind the calendar if beyond the maxDate
if (date_str < this.max.str) {
var temp_date = new Date(date_str + 'T00:00');
this.year = temp_date.getFullYear();
this.month = temp_date.getMonth();
}
else {
this.year = this.max.year;
this.month = this.max.month;
}
}
setDateBounds() {
let min = this.settings.minDate || '1000-01-01';
let max = this.settings.maxDate || '3000-01-01';
let minDate = new Date(min + 'T00:00');
let maxDate = new Date(max + 'T00:00');
this.min = {
year: minDate.getFullYear(),
month: minDate.getMonth(),
str: min
};
this.max = {
year: maxDate.getFullYear(),
month: maxDate.getMonth(),
str: max
};
}
isInBounds(val) {
if ('year' == this.mode) {
let year = parseInt(val);
if (year < this.min.year || year > this.max.year) {
return false;
}
}
else if ('month' == this.mode) {
let month = parseInt(val);
let valStr = ymd(this.year, month).substr(0, 7);
let monthMin = this.min.str.substr(0, 7);
let monthMax = this.max.str.substr(0, 7);
if (valStr < monthMin || valStr > monthMax) {
return false;
}
}
else if ('day' == this.mode) {
if (val < this.min.str || val > this.max.str) {
return false;
}
}
return true;
}
isNavAllowed(type) {
if ('year' == this.mode) {
let decade = parseInt(this.year.toString().substr(0, 3) + '0');
return ('next' == type) ?
decade < parseInt(this.max.str.substr(0, 4)) :
decade > parseInt(this.min.str.substr(0, 4));
}
else if ('month' == this.mode) {
return ('next' == type) ?
ymd(this.year + 1, 0, 0) < this.max.str :
ymd(this.year, 0) > this.min.str;
}
else if ('day' == this.mode) {
return ('next' == type) ?
ymd(this.year, this.month + 1, 0) < this.max.str :
ymd(this.year, this.month) > this.min.str;
}
}
setDisplay(which) {
var that = this;
this.mode = which;
qs('.fdate-grid').classList.remove('grid-day');
// show or hide the nav arrows
qs('.fdate-nav-prev').classList.add('disabled');
qs('.fdate-nav-next').classList.add('disabled');
if (that.isNavAllowed('prev')) {
qs('.fdate-nav-prev').classList.remove('disabled');
}
if ( that.isNavAllowed('next')) {
qs('.fdate-nav-next').classList.remove('disabled');
}
// month
if ('month' == which) {
var output = '';
this.settings.i18n.months_short.forEach(function(item, index) {
var css = that.isInBounds(index) ? ' inner' : ' disabled';
output += '<div class="fdate-month' + css + '" data-value="' + index + '" tabindex="-1">' + item + '</div>';
});
qs('.fdate-grid').innerHTML = output;
qs('.fdate-nav-label').innerHTML = this.year;
}
// year
else if ('year' == which) {
var output = '';
var decade = parseInt(this.year.toString().substr(0, 3) + '0');
for (var i = 0; i < 10; i++) {
var css = that.isInBounds(decade + i) ? ' inner' : ' disabled';
output += '<div class="fdate-year' + css + '" data-value="' + (decade + i) + '" tabindex="-1">' + (decade + i) + '</div>';
}
qs('.fdate-grid').innerHTML = output;
var prefix = this.year.toString().substr(0, 3);
var decade = prefix + '0 - ' + prefix + '9';
qs('.fdate-nav-label').innerHTML = decade;
}
// day
else {
qs('.fdate-grid').classList.add('grid-day');
var output = '';
var days = this.generateDays(this.year, this.month);
days.forEach(function(item) {
output += '<div class="fdate-day' + item.class + '" data-value="' + item.value + '" tabindex="-1">' + item.text + '</div>';
});
qs('.fdate-grid').innerHTML = output;
qs('.fdate-nav-label').innerHTML = this.settings.i18n.months[this.month] + ' ' + this.year;
}
}
generateDays(year, month) {
let that = this;
var output = [];
let i18n = that.settings.i18n;
let weekdays = i18n.weekdays_short;
let firstDayOfWeek = i18n.firstDayOfWeek; // 0 = Sunday
let firstDayNum = new Date(year, month).getDay(); // between 0 and 6
let offset = firstDayNum - firstDayOfWeek;
offset = (offset < 0) ? 7 + offset : offset; // negative offset (e.g. August 2021)
let num_days = new Date(year, month + 1, 0).getDate();
let today = ymd();
// shift weekdays according to firstDayOfWeek
if (0 < firstDayOfWeek) {
let temp = JSON.parse(JSON.stringify(weekdays));
let append = temp.splice(0, firstDayOfWeek);
weekdays = temp.concat(append);
}
// get weekdays
weekdays.forEach(function(item) {
output.push({
text: item,
value: '',
class: ' weekday'
});
});
// get days from the previous month
if (0 < offset) {
let year_prev = (0 == month) ? year - 1 : year;
let month_prev = (0 == month) ? 11 : month - 1;
let num_days_prev = new Date(year_prev, month_prev + 1, 0).getDate();
for (var i = (num_days_prev - offset + 1); i <= num_days_prev; i++) {
var val = ymd(year_prev, month_prev, i);
var css = that.isInBounds(val) ? '' : ' disabled';
output.push({
text: i,
value: val,
class: css
});
}
}
// get days from the current month
for (var i = 1; i <= num_days; i++) {
var val = ymd(year, month, i);
if ( that.isInBounds(val)) {
var css = ' inner';
css += (val == today) ? ' today' : '';
css += (val == this.el.value) ? ' selected' : '';
}
else {
var css = ' disabled';
}
output.push({
text: i,
value: val,
class: css
});
}
// get days from the next month
let year_next = (11 == month) ? year + 1 : year;
let month_next = (11 == month) ? 0 : month + 1;
let num_filler = 42 - num_days - offset;
for (var i = 1; i <= num_filler; i++) {
var val = ymd(year_next, month_next, i);
var css = that.isInBounds(val) ? '' : ' disabled';
output.push({
text: i,
value: val,
class: css
});
}
return output;
}
adjustDate(increment, unit) {
var temp_year = ('year' == unit) ? this.year + increment : this.year;
var temp_month = ('month' == unit) ? this.month + increment : this.month;
var temp_date = new Date(temp_year, temp_month);
this.year = temp_date.getFullYear();
this.month = temp_date.getMonth();
}
on(eventName, elementSelector, handler) {
document.addEventListener(eventName, function(e) {
// loop parent nodes from the target to the delegation node
for (var target = e.target; target && target != this; target = target.parentNode) {
if (target.matches(elementSelector)) {
handler.call(target, e);
break;
}
}
}, false);
}
getAltDate() {
let that = this;
if ('' === that.el.value) {
return '';
}
let date_array = that.el.value.split('-');
let format_array = that.settings.altFormat.split('');
let output = '';
let escaped = false;
format_array.forEach(function(token) {
if ('\\' === token) {
escaped = true;
return;
}
output += escaped ? token : that.parseDateToken(token, date_array);
escaped = false;
});
return output;
}
parseDateToken(token, date_array) {
let i18n = this.settings.i18n;
let tokens = {
'd': () => date_array[2],
'j': () => parseInt(date_array[2]),
'm': () => date_array[1],
'n': () => parseInt(date_array[1]),
'F': () => i18n.months[parseInt(date_array[1]) - 1],
'M': () => i18n.months_short[parseInt(date_array[1]) - 1],
'y': () => date_array[0].substring(2),
'Y': () => date_array[0]
};
return isset(tokens[token]) ? tokens[token]() : token;
}
setPosition(input) {
let wrap = qs('.fdate-wrap');
let inputBounds = input.getBoundingClientRect();
let calendarWidth = wrap.getBoundingClientRect().width;
let calendarHeight = wrap.getBoundingClientRect().height;
let distanceFromRight = document.body.clientWidth - inputBounds.left;
let distanceFromBottom = document.body.clientHeight - inputBounds.bottom;
let showOnTop = (distanceFromBottom < calendarHeight && inputBounds.top > calendarHeight);
let showOnLeft = (distanceFromRight < calendarWidth && inputBounds.left > calendarWidth);
let top = window.pageYOffset + inputBounds.top + (!showOnTop ? input.offsetHeight + 2 : -calendarHeight - 2);
let left = window.pageXOffset + inputBounds.left;
let right = window.pageXOffset + inputBounds.right - calendarWidth;
let pixels = showOnLeft ? right : left;
wrap.style.position = 'absolute';
wrap.style.top = top + 'px';
wrap.style.left = pixels + 'px';
}
setCalVisibility(which) {
var wrap = qs('.fdate-wrap');
if ('hide' === which) {
if (wrap.classList.contains('opened')) {
wrap.classList.remove('opened');
}
}
else {
if (! wrap.classList.contains('opened')) {
wrap.classList.add('opened');
}
}
}
triggerEvent(name) {
if (typeof this.settings[name] === 'function') {
this.settings[name](this);
}
}
bindEvents() {
var that = this;
that.on('click', '.fdate-day:not(.disabled):not(.weekday)', function(e) {
that.el.value = e.target.getAttribute('data-value');
if (isset(that.el._altInput)) {
that.el._altInput.value = that.getAltDate();
}
that.triggerEvent('onChange');
that.setCalVisibility('hide');
e.stopImmediatePropagation(); // important
});
that.on('click', '.fdate-month:not(.disabled)', function(e) {
that.month = parseInt(e.target.getAttribute('data-value'));
that.setDisplay('day');
e.stopImmediatePropagation(); // important
});
that.on('click', '.fdate-year:not(.disabled)', function(e) {
that.year = parseInt(e.target.getAttribute('data-value'));
that.setDisplay('month');
e.stopImmediatePropagation(); // important
});
that.on('click', '.fdate-nav-prev:not(.disabled)', function() {
var incr = ('year' == that.mode) ? -10 : -1;
var unit = ('day' == that.mode) ? 'month' : 'year';
that.adjustDate(incr, unit);
that.setDisplay(that.mode);
});
that.on('click', '.fdate-nav-next:not(.disabled)', function() {
var incr = ('year' == that.mode) ? 10 : 1;
var unit = ('day' == that.mode) ? 'month' : 'year';
that.adjustDate(incr, unit);
that.setDisplay(that.mode);
});
that.on('click', '.fdate-nav-label', function() {
if ('day' == that.mode) {
that.setDisplay('month');
}
else if ('month' == that.mode) {
that.setDisplay('year');
}
else if ('year' == that.mode) {
that.setDisplay('day');
}
});
that.on('click', '.fdate-clear', function() {
that.el.fdate.clear();
});
that.on('click', '*', function(e) {
var is_input = e.target.classList.contains('fdate-input') || e.target.classList.contains('fdate-alt-input');
var is_cal = (null !== e.target.closest('.fdate-wrap'));
var is_clear = e.target.classList.contains('fdate-clear');
if (is_input || (is_cal && ! is_clear)) {
that.setCalVisibility('show');
// set position and render calendar
if (is_input) {
let visibleInput = e.target._altInput || e.target;
that.setInput(e.target._input);
that.setDisplay('day');
that.setPosition(visibleInput);
}
}
else {
that.setCalVisibility('hide');
}
});
// a11y support
window.addEventListener('keyup', function(e) {
if ('Tab' === e.key) {
if (e.target.classList.contains('fdate-input') || e.target.classList.contains('fdate-alt-input')) {
e.target._input.click();
}
else {
that.setCalVisibility('hide');
}
}
});
window.addEventListener('keydown', function(e) {
if ('Enter' === e.key) {
if (e.target.closest('.fdate-grid')) {
qs('.fdate-nav-label').focus();
}
if (e.target.closest('.fdate-wrap')) {
e.target.click();
}
}
else if ('Escape' === e.key) {
if (e.target.closest('.fdate-wrap') || e.target.classList.contains('fdate-input') || e.target.classList.contains('fdate-alt-input')) {
that.el.fdate.close();
}
}
else if ('ArrowUp' === e.key) {
if (e.target.classList.contains('fdate-input') || e.target.classList.contains('fdate-alt-input')) { // from input
qs('.fdate-clear').focus();
e.preventDefault();
}
else if (e.target.classList.contains('fdate-nav-label')) {
that.el.focus();
e.preventDefault();
}
else if (e.target.classList.contains('fdate-clear')) {
let days = document.querySelectorAll('.fdate-day.inner');
let item = (days.length) ? days[days.length - 1] : qs('.fdate-nav-label');
item.focus();
e.preventDefault();
}
else if (e.target.closest('.fdate-grid')) {
let offset = ('day' === that.mode) ? -7 : -4;
let el = that.getSibling(e.target, offset);
if (el) {
el.focus();
}
else {
qs('.fdate-nav-label').focus();
}
e.preventDefault();
}
}
else if ('ArrowDown' === e.key) {
if (e.target.classList.contains('fdate-input') || e.target.classList.contains('fdate-alt-input')) { // from input
let selected = qs('.fdate-grid .selected');
let today = qs('.fdate-grid .today');
if (selected) {
selected.focus();
}
else if (today) {
today.focus();
}
else {
qs('.fdate-nav-label').focus();
}
e.preventDefault();
}
else if (e.target.classList.contains('fdate-nav-label')) { // from nav
qs('.fdate-grid .inner').focus();
e.preventDefault();
}
else if (e.target.classList.contains('fdate-clear')) {
that.el.focus();
e.preventDefault();
}
else if (e.target.closest('.fdate-grid')) { // from grid
let offset = ('day' === that.mode) ? 7 : 4;
let el = that.getSibling(e.target, offset);
if (el) {
el.focus();
}
else {
qs('.fdate-clear').focus();
}
e.preventDefault();
}
}
else if ('ArrowLeft' === e.key) {
if (e.target.classList.contains('fdate-nav-label')) { // into the past
qs('.fdate-nav-prev').click();
e.preventDefault();
}
if (e.target.closest('.fdate-grid')) { // previous grid item
let prev = e.target.previousElementSibling;
if (prev && prev.classList.contains('inner')) {
prev.focus();
}
else {
let days = document.querySelectorAll('.fdate-day.inner');
days[days.length - 1].focus(); // last valid day of month
}
e.preventDefault();
}
}
else if ('ArrowRight' === e.key) {
if (e.target.classList.contains('fdate-nav-label')) { // into the future
qs('.fdate-nav-next').click();
e.preventDefault();
}
if (e.target.closest('.fdate-grid')) { // next grid item
let next = e.target.nextElementSibling;
if (next && next.classList.contains('inner')) {
next.focus();
}
else {
qs('.fdate-day.inner').focus(); // first valid day of month
}
e.preventDefault();
}
}
});
}
getSibling(orig, offset) {
let el = orig;
for (var i = 0; i < Math.abs(offset); i++) {
el = (0 < offset) ? el.nextElementSibling : el.previousElementSibling;
if (null === el || !el.classList.contains('inner')) {
return null;
}
}
return el;
}
}
return fDate;
})();

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,147 @@
.fs-wrap {
width: 220px;
display: inline-block;
position: relative;
cursor: pointer;
line-height: 1;
}
.fs-label-wrap {
position: relative;
background-color: #fff;
border: 1px solid #ddd;
cursor: default;
}
.fs-label-wrap,
.fs-dropdown {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.fs-label-wrap .fs-label {
padding: 6px 22px 6px 8px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.fs-arrow {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #333;
position: absolute;
top: 0;
right: 5px;
bottom: 0;
margin: auto;
transition: ease-in 0.15s;
}
.fs-open .fs-arrow {
transform: rotate(-180deg);
}
.fs-dropdown {
width: 100%;
position: absolute;
background-color: #fff;
border: 1px solid #ddd;
border-top: none;
z-index: 1000;
}
.fs-dropdown .fs-options {
max-height: 200px;
overflow: auto;
}
.fs-search {
background-color: #f8f8f8;
padding: 0 8px;
}
.fs-wrap .fs-search input {
border: none;
box-shadow: none;
background-color: transparent;
outline: none;
padding: 0;
width: 100%;
}
.fs-option,
.fs-search,
.fs-optgroup-label {
padding: 6px 8px;
cursor: default;
}
.fs-option:last-child {
border-bottom: none;
}
.fs-no-results {
padding: 6px 8px;
}
.fs-option {
cursor: pointer;
word-break: break-all;
}
.fs-option.disabled {
opacity: 0.4;
cursor: default;
}
.fs-wrap.single .fs-option.selected {
background-color: #dff3ff;
}
.fs-wrap.multiple .fs-option {
position: relative;
padding-left: 30px;
}
.fs-wrap.multiple .fs-checkbox {
position: absolute;
display: block;
width: 30px;
top: 0;
left: 0;
bottom: 0;
}
.fs-wrap.multiple .fs-option .fs-checkbox i {
position: absolute;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 14px;
height: 14px;
border: 1px solid #aeaeae;
border-radius: 2px;
background-color: #fff;
}
.fs-wrap.multiple .fs-option.selected .fs-checkbox i {
background-color: rgb(108, 138, 255);
border-color: transparent;
}
.fs-optgroup-label {
font-weight: bold;
text-align: center;
background-color: #f8f8f8;
}
.fs-hidden {
display: none;
}

View File

@@ -0,0 +1,420 @@
window.fSelect = (() => {
var build = {};
class fSelect {
constructor(selector, options) {
let that = this;
var defaults = {
placeholder: 'Select some options',
numDisplayed: 3,
overflowText: '{n} selected',
searchText: 'Search',
noResultsText: 'No results found',
showSearch: true,
optionFormatter: false
};
that.settings = Object.assign({}, defaults, options);
build = {output: '', optgroup: 0, idx: 0};
if ('string' === typeof selector) {
var nodes = Array.from(document.querySelectorAll(selector));
}
else if (selector instanceof Node) {
var nodes = [selector];
}
else if (Array.isArray(selector)) {
var nodes = selector;
}
else {
var nodes = [];
}
if ('undefined' === typeof window.fSelectInit) {
window.fSelectInit = {
searchCache: '',
lastChoice: null,
lastFocus: null,
activeEl: null
};
that.bindEvents();
}
nodes.forEach((input) => {
if (typeof input.fselect === 'object') {
input.fselect.destroy();
}
that.settings.multiple = input.matches('[multiple]');
input.fselect = that;
that.input = input;
that.create();
});
}
create() {
var that = this;
var options = that.buildOptions();
var label = that.getDropdownLabel();
var mode = (that.settings.multiple) ? 'multiple' : 'single';
var searchClass = (that.settings.showSearch) ? '' : ' fs-hidden';
var noResultsClass = (build.idx < 2) ? '' : ' fs-hidden';
var html = `
<div class="fs-wrap ${mode}" tabindex="0">
<div class="fs-label-wrap">
<div class="fs-label">${label}</div>
<span class="fs-arrow"></span>
</div>
<div class="fs-dropdown fs-hidden">
<div class="fs-search${searchClass}">
<input type="text" placeholder="${that.settings.searchText}" />
</div>
<div class="fs-no-results${noResultsClass}">${that.settings.noResultsText}</div>
<div class="fs-options">${options}</div>
</div>
</div>
`;
var tpl = document.createElement('template');
tpl.innerHTML = html;
var wrap = tpl.content.querySelector('.fs-wrap');
that.input.parentNode.insertBefore(wrap, that.input.nextSibling);
that.input.classList.add('fs-hidden');
// add a relationship link
that.input._rel = wrap;
wrap._rel = that.input;
}
destroy() {
this.input._rel.remove();
this.input.classList.remove('fs-hidden');
delete this.input._rel;
}
reload() {
this.destroy();
this.create();
}
open() {
var wrap = this.input._rel;
wrap.classList.add('fs-open');
wrap.querySelector('.fs-dropdown').classList.remove('fs-hidden');
// don't auto-focus for touch devices
if (! window.matchMedia("(pointer: coarse)").matches) {
wrap.querySelector('.fs-search input').focus();
}
window.fSelectInit.lastChoice = this.getSelectedOptions('value');
window.fSelectInit.activeEl = wrap;
this.trigger('fs:opened', wrap);
}
close() {
this.input._rel.classList.remove('fs-open');
this.input._rel.querySelector('.fs-dropdown').classList.add('fs-hidden');
window.fSelectInit.searchCache = '';
window.fSelectInit.lastChoice = null;
window.fSelectInit.lastFocus = null;
window.fSelectInit.activeEl = null;
this.trigger('fs:closed', this.input._rel);
}
buildOptions(parent) {
var that = this;
var parent = parent || that.input;
Array.from(parent.children).forEach((node) => {
if ('optgroup' === node.nodeName.toLowerCase()) {
var opt = `<div class="fs-optgroup-label" data-group="${build.optgroup}">${node.label}</div>`;
build.output += opt;
that.buildOptions(node);
build.optgroup++;
}
else {
var val = node.value;
// skip the first choice in multi-select mode
if (0 === build.idx && '' === val && that.settings.multiple) {
build.idx++;
return;
}
var classes = ['fs-option', 'g' + build.optgroup];
// append existing classes
node.className.split(' ').forEach((className) => {
if ('' !== className) {
classes.push(className);
}
});
if (node.matches('[disabled]')) classes.push('disabled');
if (node.matches('[selected]')) classes.push('selected');
classes = classes.join(' ');
if ('function' === typeof that.settings.optionFormatter) {
node.label = that.settings.optionFormatter(node.label, node);
}
var opt = `<div class="${classes}" data-value="${val}" data-idx="${build.idx}" tabindex="-1"><span class="fs-checkbox"><i></i></span><div class="fs-option-label">${node.label}</div></div>`;
build.output += opt;
build.idx++;
}
});
return build.output;
}
getSelectedOptions(field, context) {
var context = context || this.input;
return Array.from(context.selectedOptions).map((opt) => {
return (field) ? opt[field] : opt;
});
}
getAdjacentSibling(which) {
var that = this;
var which = which || 'next';
var sibling = window.fSelectInit.lastFocus;
var selector = '.fs-option:not(.fs-hidden):not(.disabled)';
if (sibling) {
sibling = sibling[which + 'ElementSibling'];
while (sibling) {
if (sibling.matches(selector)) break;
sibling = sibling[which + 'ElementSibling'];
}
return sibling;
}
else if ('next' == which) {
sibling = that.input._rel.querySelector(selector);
}
return sibling;
}
getDropdownLabel() {
var that = this;
var labelText = that.getSelectedOptions('text');
if (labelText.length < 1) {
labelText = that.settings.placeholder;
}
else if (labelText.length > that.settings.numDisplayed) {
labelText = that.settings.overflowText.replace('{n}', labelText.length);
}
else {
labelText = labelText.join(', ');
}
return labelText;
}
debounce(func, wait) {
var timeout;
return (...args) => {
var boundFunc = func.bind(this, ...args);
clearTimeout(timeout);
timeout = setTimeout(boundFunc, wait);
}
}
trigger(eventName, ...args) {
document.dispatchEvent(new CustomEvent(eventName, {detail: [...args]}));
}
on(eventName, elementSelector, handler) {
document.addEventListener(eventName, function(e) {
// loop parent nodes from the target to the delegation node
for (var target = e.target; target && target != this; target = target.parentNode) {
if (target.matches(elementSelector)) {
handler.call(target, e);
break;
}
}
}, false);
}
bindEvents() {
var that = this;
var optionSelector = '.fs-option:not(.fs-hidden):not(.disabled)';
var unaccented = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
// debounce search for better performance
that.on('keyup', '.fs-search input', that.debounce(function(e) {
var wrap = e.target.closest('.fs-wrap');
var options = wrap._rel.options;
var matchOperators = /[|\\{}()[\]^$+*?.]/g;
var keywords = e.target.value.replace(matchOperators, '\\$&');
keywords = unaccented(keywords);
// if the searchCache already has a prefixed version of this search
// then don't un-hide the existing exclusions
if (0 !== keywords.indexOf(window.fSelectInit.searchCache)) {
wrap.querySelectorAll('.fs-option, .fs-optgroup-label').forEach((node) => node.classList.remove('fs-hidden'));
}
window.fSelectInit.searchCache = keywords;
for (var i = 0; i < options.length; i++) {
if ('' === options[i].value) continue;
var needle = new RegExp(keywords, 'gi');
var haystack = unaccented(options[i].text);
if (null === haystack.match(needle)) {
wrap.querySelector('.fs-option[data-idx="' + i + '"]').classList.add('fs-hidden');
}
}
// hide optgroups if no choices
wrap.querySelectorAll('.fs-optgroup-label').forEach((node) => {
var group = node.getAttribute('data-group');
var container = node.closest('.fs-options');
var count = container.querySelectorAll('.fs-option.g' + group + ':not(.fs-hidden)').length;
if (count < 1) {
node.classList.add('fs-hidden');
}
});
// toggle the noResultsText div
if (wrap.querySelectorAll('.fs-option:not(.fs-hidden').length) {
wrap.querySelector('.fs-no-results').classList.add('fs-hidden');
}
else {
wrap.querySelector('.fs-no-results').classList.remove('fs-hidden');
}
}, 100));
that.on('click', optionSelector, function(e) {
var wrap = this.closest('.fs-wrap');
var value = this.getAttribute('data-value');
var input = wrap._rel;
var isMultiple = wrap.classList.contains('multiple');
if (!isMultiple) {
input.value = value;
wrap.querySelectorAll('.fs-option.selected').forEach((node) => node.classList.remove('selected'));
}
else {
var idx = parseInt(this.getAttribute('data-idx'));
input.options[idx].selected = !this.classList.contains('selected');
}
this.classList.toggle('selected');
var label = input.fselect.getDropdownLabel();
wrap.querySelector('.fs-label').innerHTML = label;
// fire a change event
input.dispatchEvent(new Event('change', { bubbles: true }));
input.fselect.trigger('fs:changed', wrap);
if (!isMultiple) {
input.fselect.close();
}
e.stopImmediatePropagation();
});
that.on('keydown', '*', function(e) {
var wrap = this.closest('.fs-wrap');
if (!wrap) return;
if (-1 < [38, 40, 27].indexOf(e.which)) {
e.preventDefault();
}
if (32 == e.which || 13 == e.which) { // space, enter
if (e.target.closest('.fs-search')) {
// preserve spaces for search
}
else if (e.target.matches(optionSelector)) {
e.target.click();
e.preventDefault();
}
else {
wrap.querySelector('.fs-label').click();
e.preventDefault();
}
}
else if (38 == e.which) { // up
var sibling = wrap._rel.fselect.getAdjacentSibling('previous');
window.fSelectInit.lastFocus = sibling; // stop at the search box
if (sibling) {
sibling.focus();
}
else {
wrap.querySelector('.fs-search input').focus();
}
}
else if (40 == e.which) { // down
var sibling = wrap._rel.fselect.getAdjacentSibling('next');
if (sibling) {
sibling.focus();
window.fSelectInit.lastFocus = sibling; // stop at the bottom
}
}
else if (9 == e.which || 27 == e.which) { // tab, esc
wrap._rel.fselect.close();
}
});
that.on('click', '*', function(e) {
var wrap = this.closest('.fs-wrap');
var lastActive = window.fSelectInit.activeEl;
if (wrap) {
var labelWrap = this.closest('.fs-label-wrap');
if (labelWrap) {
if (lastActive) {
lastActive._rel.fselect.close();
}
if (wrap !== lastActive) {
wrap._rel.fselect.open();
}
}
}
else {
if (lastActive) {
lastActive._rel.fselect.close();
}
}
});
}
}
var $ = (selector, options) => new fSelect(selector, options);
return $;
})();
if ('undefined' !== typeof fUtil) {
fUtil.fn.fSelect = function(opts) {
this.each(function() { // no arrow function to preserve "this"
fSelect(this, opts);
});
return this;
};
}

View File

@@ -0,0 +1,18 @@
.ftip-wrap {
position: absolute;
display: none;
max-width: 400px;
padding: 6px 8px;
background-color: #222;
border-radius: 6px;
opacity: 0;
color: #fff;
cursor: default;
transition: height 0s, opacity 1s;
}
.ftip-wrap.active {
height: auto;
display: inline-block;
opacity: 0.9;
}

View File

@@ -0,0 +1,100 @@
window.fTip = (() => {
var qs = (selector) => document.querySelector(selector);
class fTip {
constructor(selector, options) {
let that = this;
var defaults = {
content: (node) => node.getAttribute('title')
};
that.settings = Object.assign({}, defaults, options);
var inputs = [];
if ('string' === typeof selector) {
var inputs = Array.from(document.querySelectorAll(selector));
}
else if (selector instanceof Node) {
var inputs = [selector];
}
else if (Array.isArray(selector)) {
var inputs = selector;
}
if (null === qs('.ftip-wrap')) {
that.buildHtml();
that.bindEvents();
}
inputs.forEach(function(input) {
that.input = input;
input.ftip = that;
input.classList.add('ftip-enabled');
});
}
open() {
let input = this.input;
let wrap = qs('.ftip-wrap');
wrap.innerHTML = this.settings.content(input);
wrap.classList.add('active');
let wrapBounds = wrap.getBoundingClientRect();
let inputBounds = input.getBoundingClientRect();
let top = window.pageYOffset + inputBounds.top;
let left = window.pageXOffset + inputBounds.right;
let centered = ((inputBounds.height - wrapBounds.height) / 2);
wrap.style.top = (top + centered) + 'px';
wrap.style.left = (left + 10) + 'px';
}
buildHtml() {
let html = '<div class="ftip-wrap"></div>';
document.body.insertAdjacentHTML('beforeend', html);
}
bindEvents() {
var that = this;
let wrap = qs('.ftip-wrap');
var delayHandler = () => {
that.delay = setTimeout(() => {
wrap.classList.remove('active');
}, 250);
};
that.on('mouseover', '.ftip-enabled', function(e) {
clearTimeout(that.delay);
this.ftip.open();
});
that.on('mouseout', '.ftip-enabled', delayHandler);
that.on('mouseout', '.ftip-wrap', delayHandler);
that.on('mouseover', '.ftip-wrap', () => {
clearTimeout(that.delay);
});
}
on(eventName, elementSelector, handler) {
document.addEventListener(eventName, function(e) {
// loop parent nodes from the target to the delegation node
for (var target = e.target; target && target != this; target = target.parentNode) {
if (target.matches(elementSelector)) {
handler.call(target, e);
break;
}
}
}, false);
}
}
var $ = (selector, options) => new fTip(selector, options);
return $;
})();

View File

@@ -0,0 +1,7 @@
Copyright 2021 FacetWP, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,451 @@
window.fUtil = (() => {
class fUtil {
constructor(selector) {
if (typeof selector === 'string' || selector instanceof String) { // string
var selector = selector.replace(':selected', ':checked');
if ('' === selector) {
this.nodes = [];
}
else if (this.isValidSelector(selector)) {
this.nodes = Array.from(document.querySelectorAll(selector));
}
else {
var tpl = document.createElement('template');
tpl.innerHTML = selector;
this.nodes = [tpl.content];
}
}
else if (Array.isArray(selector)) { // array of nodes
this.nodes = selector;
}
else if (typeof selector === 'object' && selector.nodeName) { // node
this.nodes = [selector];
}
else if (typeof selector === 'function') { // function
this.ready(selector);
}
else if (selector === window) { // window
this.nodes = [window];
}
else { // document
this.nodes = [document];
}
// custom plugins
$.each($.fn, (handler, method) => {
this[method] = handler;
});
}
static isset(input) {
return typeof input !== 'undefined';
}
static post(url, data, settings) {
var settings = Object.assign({}, {
dataType: 'json',
contentType: 'application/json',
headers: {},
done: () => {},
fail: () => {}
}, settings);
settings.headers['Content-Type'] = settings.contentType;
data = ('application/json' === settings.contentType) ? JSON.stringify(data) : $.toEncoded(data);
fetch(url, {
method: 'POST',
headers: settings.headers,
body: data
})
.then(response => response[settings.dataType]())
.then(json => settings.done(json))
.catch(err => settings.fail(err));
}
static toEncoded(obj, prefix, out) {
var out = out || [];
var prefix = prefix || '';
if (Array.isArray(obj)) {
if (obj.length) {
obj.forEach((val) => {
$.toEncoded(val, prefix + '[]', out);
});
}
else {
$.toEncoded('', prefix, out);
}
}
else if (typeof obj === 'object' && obj !== null) {
Object.keys(obj).forEach((key) => {
var new_prefix = prefix ? prefix + '[' + key + ']' : key;
$.toEncoded(obj[key], new_prefix, out);
});
}
else {
out.push(encodeURIComponent(prefix) + '=' + encodeURIComponent(obj));
}
return out.join('&');
}
static forEach(items, callback) {
if (typeof items === 'object' && items !== null) {
if (Array.isArray(items)) {
items.forEach((val, key) => callback.bind(val)(val, key));
}
else {
Object.keys(items).forEach(key => {
var val = items[key];
callback.bind(val)(val, key);
});
}
}
return items;
}
isValidSelector(string) {
try {
document.createDocumentFragment().querySelector(string);
}
catch(err) {
return false;
}
return true;
}
clone() {
return $(this.nodes);
}
len() {
return this.nodes.length;
}
each(callback) {
this.nodes.forEach((node, key) => {
let func = callback.bind(node); // set "this"
func(node, key);
});
return this;
}
ready(callback) {
if (typeof callback !== 'function') return;
if (document.readyState === 'complete') {
return callback();
}
document.addEventListener('DOMContentLoaded', callback, false);
}
addClass(className) {
this.each(node => node.classList.add(className));
return this;
}
removeClass(className) {
this.each(node => node.classList.remove(className));
return this;
}
hasClass(className) {
return $.isset(this.nodes.find(node => node.classList.contains(className)));
}
toggleClass(className) {
this.each(node => node.classList.toggle(className));
return this;
}
is(selector) {
for (let i = 0; i < this.len(); i++) { // forEach prevents loop exiting
if (this.nodes[i].matches(selector)) {
return true;
}
}
return false;
}
find(selector) {
var selector = selector.replace(':selected', ':checked');
let nodes = [];
let clone = this.clone();
clone.each(node => {
nodes = nodes.concat(Array.from(node.querySelectorAll(selector)));
});
clone.nodes = nodes;
return clone;
}
first() {
let clone = this.clone();
if (clone.len()) {
clone.nodes = this.nodes.slice(0, 1);
}
return clone;
}
last() {
let clone = this.clone();
if (clone.len()) {
clone.nodes = this.nodes.slice(-1);
}
return clone;
}
prev(selector) {
let nodes = [];
let clone = this.clone();
clone.each(node => {
let sibling = node.previousElementSibling;
while (sibling) {
if (!$.isset(selector) || sibling.matches(selector)) break;
sibling = sibling.previousElementSibling;
}
if (sibling) {
nodes.push(sibling);
}
});
clone.nodes = nodes;
return clone;
}
next(selector) {
let nodes = [];
let clone = this.clone();
clone.each(node => {
let sibling = node.nextElementSibling;
while (sibling) {
if (!$.isset(selector) || sibling.matches(selector)) break;
sibling = sibling.nextElementSibling;
}
if (sibling) {
nodes.push(sibling);
}
});
clone.nodes = nodes;
return clone;
}
prepend(html) {
this.each(node => node.insertAdjacentHTML('afterbegin', html));
return this;
}
append(html) {
this.each(node => node.insertAdjacentHTML('beforeend', html));
return this;
}
parents(selector) {
let parents = [];
let clone = this.clone();
clone.each(node => {
let parent = node.parentNode;
while (parent && parent !== document) {
if (parent.matches(selector)) parents.push(parent);
parent = parent.parentNode;
}
});
clone.nodes = [...new Set(parents)]; // remove dupes
return clone;
}
closest(selector) {
let nodes = [];
let clone = this.clone();
clone.each(node => {
let closest = node.closest(selector);
if (closest) {
nodes.push(closest);
}
});
clone.nodes = nodes;
return clone;
}
remove() {
this.each(node => node.remove());
return this;
}
on(eventName, selector, callback) {
if (!$.isset(selector)) return;
if (!$.isset(callback)) {
var callback = selector;
var selector = null;
}
// Reusable callback
var checkForMatch = (e) => {
if (null === selector || e.target.matches(selector)) {
callback.bind(e.target)(e);
}
else if (e.target.closest(selector)) {
var $this = e.target.closest(selector);
callback.bind($this)(e);
}
};
this.each(node => {
// Attach a unique ID to each node
if (!$.isset(node._id)) {
node._id = $.event.count;
$.event.store[$.event.count] = node;
$.event.count++;
}
var id = node._id;
// Store the raw callback, needed for .off()
checkForMatch._str = callback.toString();
if (!$.isset($.event.map[id])) {
$.event.map[id] = {};
}
if (!$.isset($.event.map[id][eventName])) {
$.event.map[id][eventName] = {};
}
if (!$.isset($.event.map[id][eventName][selector])) {
$.event.map[id][eventName][selector] = [];
}
// Use $.event.map to store event references
// removeEventListener needs named callbacks, so we're creating
// one for every handler
let length = $.event.map[id][eventName][selector].push(checkForMatch);
node.addEventListener(eventName, $.event.map[id][eventName][selector][length - 1]);
});
return this;
}
off(eventName, selector, callback) {
if (!$.isset(callback)) {
var callback = selector;
var selector = null;
}
this.each(node => {
var id = node._id;
$.each($.event.map[id], (selectors, theEventName) => {
$.each(selectors, (callbacks, theSelector) => {
$.each(callbacks, (theCallback, index) => {
if (
(!eventName || theEventName === eventName) &&
(!selector || theSelector === selector) &&
(!callback || theCallback._str === callback.toString())
) {
node.removeEventListener(theEventName, $.event.map[id][theEventName][theSelector][index]);
delete $.event.map[id][theEventName][theSelector][index];
}
});
});
});
});
return this;
}
trigger(eventName, extraData) {
this.each(node => node.dispatchEvent(new CustomEvent(eventName, {
detail: extraData,
bubbles: true
})));
return this;
}
attr(attributeName, value) {
if (!$.isset(value)) {
return (this.len()) ? this.nodes[0].getAttribute(attributeName) : null;
}
this.each(node => node.setAttribute(attributeName, value));
return this;
}
data(key, value) {
if (!$.isset(value)) {
return (this.len()) ? this.nodes[0]._fdata[key] : null;
}
this.each(node => node._fdata[key] = value);
return this;
}
html(htmlString) {
if (!$.isset(htmlString)) {
return (this.len()) ? this.nodes[0].innerHTML : null;
}
this.each(node => node.innerHTML = htmlString);
return this;
}
text(textString) {
if (!$.isset(textString)) {
return (this.len()) ? this.nodes[0].textContent : null;
}
else {
this.each(node => node.textContent = textString);
return this;
}
}
val(value) {
if (!$.isset(value)) {
if (this.len()) {
var field = this.nodes[0];
if (field.nodeName.toLowerCase() === 'select' && field.multiple) {
return [...field.options].filter((x) => x.selected).map((x) => x.value);
}
return field.value;
}
return null;
}
else {
this.each(node => node.value = value);
return this;
}
}
}
var $ = selector => new fUtil(selector);
// Set object methods
$.fn = {};
$.post = fUtil.post;
$.isset = fUtil.isset;
$.each = fUtil.forEach;
$.toEncoded = fUtil.toEncoded;
$.event = {map: {}, store: [], count: 0};
return $;
})();

View File

@@ -0,0 +1,150 @@
.noUi-target,
.noUi-target * {
touch-action: none;
user-select: none;
box-sizing: border-box;
}
.noUi-target {
position: relative;
}
.noUi-base,
.noUi-connects {
width: 100%;
height: 100%;
position: relative;
z-index: 1;
}
.noUi-connects {
overflow: hidden;
z-index: 0;
}
.noUi-connect,
.noUi-origin {
will-change: transform;
position: absolute;
z-index: 1;
top: 0;
right: 0;
height: 100%;
width: 100%;
transform-origin: 0 0;
transform-style: flat;
}
.noUi-txt-dir-rtl.noUi-horizontal .noUi-origin {
left: 0;
right: auto;
}
.noUi-horizontal .noUi-origin {
height: 0;
}
.noUi-handle {
backface-visibility: hidden;
position: absolute;
}
.noUi-touch-area {
height: 100%;
width: 100%;
}
.noUi-state-tap .noUi-connect,
.noUi-state-tap .noUi-origin {
transition: transform 0.3s;
}
.noUi-horizontal {
height: 14px;
}
.noUi-horizontal .noUi-handle {
width: 20px;
height: 20px;
right: -10px;
top: -4px;
}
.noUi-target {
background: #FAFAFA;
border-radius: 4px;
border: 1px solid #D3D3D3;
padding: 0 8px;
}
.noUi-connects {
border-radius: 3px;
}
.noUi-connect {
background: #ddd;
}
.noUi-handle {
border: 1px solid #D9D9D9;
border-radius: 3px;
background: #FFF;
cursor: default;
}
.noUi-pips,
.noUi-pips * {
box-sizing: border-box;
}
.noUi-pips {
position: absolute;
color: #999;
}
.noUi-value {
position: absolute;
white-space: nowrap;
text-align: center;
}
.noUi-value-sub {
color: #ccc;
font-size: 10px;
}
.noUi-marker {
position: absolute;
background: #CCC;
}
.noUi-marker-sub {
background: #AAA;
}
.noUi-marker-large {
background: #AAA;
}
.noUi-pips-horizontal {
padding: 10px 0;
height: 80px;
top: 100%;
left: 0;
width: 100%;
}
.noUi-value-horizontal {
transform: translate(-50%, 50%);
}
.noUi-rtl .noUi-value-horizontal {
transform: translate(50%, 50%);
}
.noUi-marker-horizontal.noUi-marker {
margin-left: -1px;
width: 2px;
height: 5px;
}
.noUi-marker-horizontal.noUi-marker-sub {
height: 10px;
}
.noUi-marker-horizontal.noUi-marker-large {
height: 15px;
}
.noUi-tooltip {
display: block;
position: absolute;
border: 1px solid #D9D9D9;
border-radius: 3px;
background: #fff;
color: #000;
padding: 5px;
text-align: center;
white-space: nowrap;
}
.noUi-horizontal .noUi-tooltip {
transform: translate(-50%, 0);
left: 50%;
bottom: 120%;
}
.noUi-horizontal .noUi-origin > .noUi-tooltip {
transform: translate(50%, 0);
left: auto;
bottom: 10px;
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,87 @@
/**
* Nummy.js - A (very) lightweight number formatter
* @link https://github.com/mgibbs189/nummy
*/
(function() {
function isValid(input) {
return !isNaN(parseFloat(input)) && isFinite(input);
}
function toFixed(value, precision) {
var pow = Math.pow(10, precision);
return (Math.round(value * pow) / pow).toFixed(precision);
}
class Nummy {
constructor(value) {
this._value = isValid(value) ? value : 0;
}
format(format, opts) {
var value = this._value,
negative = false,
precision = 0,
valueStr = '',
wholeStr = '',
decimalStr = '',
abbr = '';
var opts = Object.assign({}, {
'thousands_separator': ',',
'decimal_separator': '.'
}, opts);
if (-1 < format.indexOf('a')) {
var abbrevs = ['K', 'M', 'B', 't', 'q', 'Q'];
var exp = Math.floor(Math.log(Math.abs(value)) * Math.LOG10E); // log10 polyfill
var nearest_exp = (exp - (exp % 3)); // nearest exponent divisible by 3
if (3 <= exp) {
value = value / Math.pow(10, nearest_exp);
abbr += abbrevs[Math.floor(exp / 3) - 1];
}
format = format.replace('a', '');
}
// Check for decimals format
if (-1 < format.indexOf('.')) {
precision = format.split('.')[1].length;
}
value = toFixed(value, precision);
valueStr = value.toString();
// Handle negative number
if (value < 0) {
negative = true;
value = Math.abs(value);
valueStr = valueStr.slice(1);
}
wholeStr = valueStr.split('.')[0] || '';
decimalStr = valueStr.split('.')[1] || '';
// Handle decimals
decimalStr = (0 < precision && '' != decimalStr) ? '.' + decimalStr : '';
// Use thousands separators
if (-1 < format.indexOf(',')) {
wholeStr = wholeStr.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
}
var output = (negative ? '-' : '') + wholeStr + decimalStr + abbr;
output = output.replace(/\./g, '{d}');
output = output.replace(/\,/g, '{t}');
output = output.replace(/{d}/g, opts.decimal_separator);
output = output.replace(/{t}/g, opts.thousands_separator);
return output;
}
}
window.nummy = function(input) {
return new Nummy(input);
}
})();

View File

@@ -0,0 +1 @@
!function(){"use strict";var a;(a=function(a){var t;this._value=(t=a,!isNaN(parseFloat(t))&&isFinite(t)?a:0)}).prototype.format=function(a,t){var e=this._value,r=!1,i=0,n="",o="",s="",l="";if(t=Object.assign({},{thousands_separator:",",decimal_separator:"."},t),-1<a.indexOf("a")){var p=Math.floor(Math.log(Math.abs(e))*Math.LOG10E),c=p-p%3;3<=p&&(e/=Math.pow(10,c),l+=["K","M","B","t","q","Q"][Math.floor(p/3)-1]),a=a.replace("a","")}-1<a.indexOf(".")&&(i=a.split(".")[1].length),e=function(a,t){var e=Math.pow(10,t);return(Math.round(a*e)/e).toFixed(t)}(e,i),n=e.toString(),e<0&&(r=!0,e=Math.abs(e),n=n.slice(1)),o=n.split(".")[0]||"",s=n.split(".")[1]||"",s=0<i&&""!=s?"."+s:"",-1<a.indexOf(",")&&(o=o.replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1,"));var d=(r?"-":"")+o+s+l;return d=(d=(d=(d=d.replace(/\./g,"{d}")).replace(/\,/g,"{t}")).replace(/{d}/g,t.decimal_separator)).replace(/{t}/g,t.thousands_separator)},window.nummy=function(t){return new a(t)}}();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long