first commit
This commit is contained in:
commit
aee061ddba
7322 files changed
+2918816
No files matched your search
@@ -0,0 +1,34 @@
|
||||
if (!Array.prototype.filter) {
|
||||
Array.prototype.filter = function (func, thisArg) {
|
||||
'use strict';
|
||||
if (!((typeof func === 'Function' || typeof func === 'function') && this))
|
||||
throw new TypeError();
|
||||
|
||||
var len = this.length >>> 0,
|
||||
res = new Array(len), // preallocate array
|
||||
t = this, c = 0, i = -1;
|
||||
if (thisArg === undefined) {
|
||||
while (++i !== len) {
|
||||
// checks to see if the key was set
|
||||
if (i in this) {
|
||||
if (func(t[i], i, t)) {
|
||||
res[c++] = t[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (++i !== len) {
|
||||
// checks to see if the key was set
|
||||
if (i in this) {
|
||||
if (func.call(thisArg, t[i], i, t)) {
|
||||
res[c++] = t[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.length = c; // shrink down array to proper size
|
||||
return res;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// https://tc39.github.io/ecma262/#sec-array.prototype.find
|
||||
if (!Array.prototype.find) {
|
||||
Object.defineProperty(Array.prototype, 'find', {
|
||||
value: function (predicate) {
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
if (this == null) {
|
||||
throw new TypeError('"this" is null or not defined');
|
||||
}
|
||||
|
||||
var o = Object(this);
|
||||
|
||||
// 2. Let len be ? ToLength(? Get(O, "length")).
|
||||
var len = o.length >>> 0;
|
||||
|
||||
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
|
||||
if (typeof predicate !== 'function') {
|
||||
throw new TypeError('predicate must be a function');
|
||||
}
|
||||
|
||||
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
var thisArg = arguments[1];
|
||||
|
||||
// 5. Let k be 0.
|
||||
var k = 0;
|
||||
|
||||
// 6. Repeat, while k < len
|
||||
while (k < len) {
|
||||
// a. Let Pk be ! ToString(k).
|
||||
// b. Let kValue be ? Get(O, Pk).
|
||||
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
|
||||
// d. If testResult is true, return kValue.
|
||||
var kValue = o[k];
|
||||
if (predicate.call(thisArg, kValue, k, o)) {
|
||||
return kValue;
|
||||
}
|
||||
// e. Increase k by 1.
|
||||
k++;
|
||||
}
|
||||
|
||||
// 7. Return undefined.
|
||||
return undefined;
|
||||
},
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
//find and place wg-ajax-button-switcher
|
||||
|
||||
function switcherPlacement() {
|
||||
const button_switcher_ajax = document.querySelectorAll(".weglot-custom-switcher-ajax")
|
||||
Array.prototype.forEach.call(button_switcher_ajax, function (el, i) {
|
||||
let button_sibling = null;
|
||||
let button_target = null;
|
||||
let targetSelector = null;
|
||||
let siblingSelector = null;
|
||||
|
||||
if (el.getAttribute('data-wg-target') !== '') {
|
||||
targetSelector = el.getAttribute('data-wg-target');
|
||||
}
|
||||
|
||||
if (el.getAttribute('data-wg-sibling') !== '') {
|
||||
siblingSelector = el.getAttribute('data-wg-sibling');
|
||||
}
|
||||
|
||||
if (targetSelector) {
|
||||
button_target = document.querySelector(targetSelector)
|
||||
}
|
||||
if (siblingSelector) {
|
||||
button_sibling = document.querySelector(siblingSelector)
|
||||
}
|
||||
|
||||
if (button_target != null && button_sibling != null) {
|
||||
button_target.insertBefore(el, button_sibling)
|
||||
el.classList.remove("weglot-custom-switcher-ajax")
|
||||
} else if (button_target && button_sibling == null) {
|
||||
button_target.insertBefore(el, button_target.firstChild)
|
||||
el.classList.remove("weglot-custom-switcher-ajax")
|
||||
} else if (button_sibling && button_target == null) {
|
||||
button_sibling.parentNode.insertBefore(el, button_sibling)
|
||||
el.classList.remove("weglot-custom-switcher-ajax")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//detect iframe
|
||||
function inFrame() {
|
||||
try {
|
||||
return window.frameElement || window.self !== window.top;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener( "DOMContentLoaded", () => switcherPlacement() );
|
||||
} else {
|
||||
switcherPlacement();
|
||||
}
|
||||
}, 1500);
|
||||
|
||||
document.addEventListener( "DOMContentLoaded", function ( event ) {
|
||||
|
||||
function getOffset(element) {
|
||||
let top = 0, left = 0;
|
||||
do {
|
||||
top += element.offsetTop || 0;
|
||||
left += element.offsetLeft || 0;
|
||||
element = element.offsetParent;
|
||||
} while (element);
|
||||
|
||||
return {
|
||||
top: top, left: left
|
||||
};
|
||||
}
|
||||
|
||||
const button = document.querySelector(".country-selector");
|
||||
if (!button) {
|
||||
return;
|
||||
}
|
||||
const h = getOffset(button).top;
|
||||
const body = document.body, html = document.documentElement;
|
||||
const page_height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
||||
|
||||
const position = window.getComputedStyle(button).getPropertyValue("position");
|
||||
const bottom = window.getComputedStyle(button).getPropertyValue("bottom");
|
||||
const top = window.getComputedStyle(button).getPropertyValue("top");
|
||||
|
||||
if ((position !== "fixed" && h > page_height / 2) || (position === "fixed" && h > 100)) {
|
||||
button.className += " weglot-invert";
|
||||
}
|
||||
|
||||
//check if your page is load by an iframe
|
||||
if (inFrame()) {
|
||||
const switchers = document.querySelectorAll('.weglot-dropdown')
|
||||
if (switchers !== null) {
|
||||
[].forEach.call(switchers, function (switcher) {
|
||||
switcher.style.display = "none";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("click", (evt) => {
|
||||
let targetEl = evt.target;
|
||||
|
||||
if(targetEl.closest('.country-selector.close_outside_click') == null){
|
||||
document.querySelectorAll(".country-selector.close_outside_click.weglot-dropdown input").forEach( (node) => {
|
||||
node.checked = false
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
const asides = document.getElementsByClassName("country-selector");
|
||||
const isOpen = link => !link.className.includes("closed");
|
||||
let focusedLang;
|
||||
if (asides.length > 0) {
|
||||
const selectedLang = document.getElementsByClassName("wgcurrent");
|
||||
for (let aside of asides) {
|
||||
|
||||
// accessiblity button
|
||||
const KEYCODE = {
|
||||
ENTER: 13, ESCAPE: 27, ARROWUP: 38, ARROWDOWN: 40,
|
||||
};
|
||||
|
||||
const isOpenUp = () => {
|
||||
// If switcher is in second half of page, set weg-openup class
|
||||
const {bottom = 0} = aside.getBoundingClientRect();
|
||||
return bottom > window.innerHeight / 2;
|
||||
};
|
||||
|
||||
const openSwitcher = () => {
|
||||
aside.classList.remove("closed");
|
||||
document.querySelectorAll(".country-selector.weglot-dropdown input").checked = true;
|
||||
aside.setAttribute("aria-expanded", "true");
|
||||
};
|
||||
|
||||
const closeSwitcher = () => {
|
||||
aside.classList.add("closed");
|
||||
document.querySelectorAll(".country-selector.weglot-dropdown input").checked = false
|
||||
aside.setAttribute("aria-expanded", "false");
|
||||
if (focusedLang) {
|
||||
focusedLang.classList.remove("focus");
|
||||
focusedLang = null;
|
||||
}
|
||||
};
|
||||
|
||||
const setAriaLabel = code => {
|
||||
const fullNameLang = getLangNameFromCode(code);
|
||||
//aside.setAttribute("aria-activedescendant", "weglot-language-" + code);
|
||||
aside.setAttribute("aria-label", "Language selected: " + code);
|
||||
};
|
||||
|
||||
const toggleSwitcher = () => {
|
||||
if (aside.classList.contains("closed")) {
|
||||
openSwitcher();
|
||||
} else {
|
||||
closeSwitcher();
|
||||
}
|
||||
if (focusedLang) {
|
||||
focusedLang.classList.remove("focus");
|
||||
}
|
||||
focusedLang = null;
|
||||
};
|
||||
|
||||
// Toggle when focused and keydown ENTER.
|
||||
aside.addEventListener("keydown", event => {
|
||||
if (event.keyCode === KEYCODE.ENTER) {
|
||||
//event.preventDefault();
|
||||
//selectedLang.click();
|
||||
for (var i = 0; i < selectedLang.length; i++) {
|
||||
selectedLang[i].click();
|
||||
}
|
||||
if (focusedLang) {
|
||||
const destinationLanguage = focusedLang.getAttribute("data-l");
|
||||
setAriaLabel(destinationLanguage);
|
||||
aside.focus();
|
||||
}
|
||||
toggleSwitcher();
|
||||
return;
|
||||
}
|
||||
if (event.keyCode === KEYCODE.ARROWDOWN || event.keyCode === KEYCODE.ARROWUP) {
|
||||
event.preventDefault();
|
||||
moveFocus(event.keyCode);
|
||||
return;
|
||||
}
|
||||
if (event.keyCode === KEYCODE.ESCAPE && isOpen(aside)) {
|
||||
// Close switcher.
|
||||
event.preventDefault();
|
||||
closeSwitcher();
|
||||
aside.focus();
|
||||
}
|
||||
});
|
||||
|
||||
aside.addEventListener("mousedown", event => {
|
||||
if (focusedLang) {
|
||||
const destinationLanguage = focusedLang.getAttribute("data-l");
|
||||
setAriaLabel(destinationLanguage);
|
||||
aside.focus();
|
||||
}
|
||||
toggleSwitcher();
|
||||
return;
|
||||
});
|
||||
|
||||
if(aside.className.includes("open_hover")){
|
||||
aside.addEventListener("mouseenter", event => {
|
||||
if (focusedLang) {
|
||||
const destinationLanguage = focusedLang.getAttribute("data-l");
|
||||
setAriaLabel(destinationLanguage);
|
||||
aside.focus();
|
||||
}
|
||||
toggleSwitcher();
|
||||
aside.querySelector("input.weglot_choice").checked = true
|
||||
return;
|
||||
});
|
||||
|
||||
aside.addEventListener("mouseleave", event => {
|
||||
if (focusedLang) {
|
||||
const destinationLanguage = focusedLang.getAttribute("data-l");
|
||||
setAriaLabel(destinationLanguage);
|
||||
aside.focus();
|
||||
}
|
||||
toggleSwitcher();
|
||||
aside.querySelector("input.weglot_choice").checked = false
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const moveFocus = keyCode => {
|
||||
const direction = keyCode === KEYCODE.ARROWDOWN ? "nextSibling" : "previousSibling";
|
||||
const openUp = isOpenUp();
|
||||
|
||||
if (!focusedLang || !isOpen(aside)) {
|
||||
// Focus the first or last language
|
||||
const selector = openUp ? "ul li.wg-li:last-child" : "ul li.wg-li";
|
||||
|
||||
for (var i = 0; i < selectedLang.length; i++) {
|
||||
//selectedLang[i].click();
|
||||
focusedLang = selectedLang[i].parentNode.querySelector(selector);
|
||||
}
|
||||
|
||||
if (!focusedLang) {
|
||||
return;
|
||||
}
|
||||
focusedLang.classList.add("focus");
|
||||
focusedLang.childNodes[0].focus();
|
||||
focusedLang.scrollIntoView({block: "center"});
|
||||
|
||||
// if right direction, open it
|
||||
const needToOpen = (keyCode === KEYCODE.ARROWUP && openUp) || (keyCode === KEYCODE.ARROWDOWN && !openUp);
|
||||
if (!isOpen(aside) && needToOpen) {
|
||||
openSwitcher();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Focus next or prev language, if exists
|
||||
if (!focusedLang[direction]) {
|
||||
// if last element, close it
|
||||
if ((keyCode === KEYCODE.ARROWUP && !openUp) || (keyCode === KEYCODE.ARROWDOWN && openUp)) {
|
||||
closeSwitcher();
|
||||
aside.focus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
focusedLang.classList.remove("focus");
|
||||
focusedLang = focusedLang[direction];
|
||||
focusedLang.classList.add("focus");
|
||||
focusedLang.childNodes[0].focus();
|
||||
focusedLang.scrollIntoView({block: "center"});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import InitAdminSelect from './settings/admin-select'
|
||||
import InitAdminWeglotBox from './settings/admin-weglot-box'
|
||||
import InitAdminButtonPreview from './settings/admin-button-preview'
|
||||
import InitAdminCheckApiKey from './settings/admin-check-api-key'
|
||||
import initAdminCodeEditor from './settings/admin-code-editor'
|
||||
import InitAdminChangeCountry from './settings/admin-change-country'
|
||||
import InitAdminPrivateMode from './settings/admin-private-mode'
|
||||
import './find-polyfill'
|
||||
import './filter-polyfill'
|
||||
|
||||
InitAdminSelect()
|
||||
InitAdminWeglotBox();
|
||||
InitAdminButtonPreview();
|
||||
InitAdminCheckApiKey();
|
||||
initAdminCodeEditor();
|
||||
InitAdminChangeCountry();
|
||||
InitAdminPrivateMode();
|
||||
@@ -0,0 +1,105 @@
|
||||
import slugify from 'slugify'
|
||||
|
||||
const init_url_translate = () => {
|
||||
const $ = jQuery;
|
||||
|
||||
const execute = () => {
|
||||
let old_text = {}
|
||||
|
||||
const edit_weglot_post_name = function(e) {
|
||||
const code = $(this).data('lang')
|
||||
const post_name = slugify($(`#lang-${code}`).val(), {
|
||||
lower: true,
|
||||
replacement: '-'
|
||||
});
|
||||
|
||||
$(`#text-edit-${code}`).text( post_name );
|
||||
|
||||
$(`#lang-${code}`).hide();
|
||||
$(this).hide()
|
||||
$(`.button-weglot-lang[data-lang=${code}]`).show()
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
method: "POST",
|
||||
data: {
|
||||
action: "weglot_post_name",
|
||||
lang: code,
|
||||
id: $("#weglot_post_id").data('id'),
|
||||
post_name: post_name
|
||||
},
|
||||
success: function(res) {
|
||||
if(res.data && res.data.code && res.data.code === 'same_post_name'){
|
||||
$(`#text-edit-${code}`).text(old_text[code]);
|
||||
$(`#lang-${code}`).val('');
|
||||
return
|
||||
}
|
||||
else if (res.data && res.data.code && res.data.code ==='not_available'){
|
||||
$(`#weglot_permalink_not_available_${code}`).show();
|
||||
$(`#lang-${code}`).val("");
|
||||
setTimeout(() => {
|
||||
$(`#weglot_permalink_not_available_${code}`).hide();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
$(`#text-edit-${code}`).text(res.data.result.slug);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(".button-weglot-lang").each((key, itm) => {
|
||||
$(itm).on('click', function (e) {
|
||||
e.preventDefault()
|
||||
|
||||
const code = $(this).data('lang')
|
||||
const text = $(`#text-edit-${code}`).text();
|
||||
old_text[code] = text
|
||||
|
||||
$(`#text-edit-${code}`).text(' ');
|
||||
$(`#lang-${code}`).val(text).show();
|
||||
$(`.button-weglot-lang-submit[data-lang=${code}]`).show();
|
||||
$(this).hide()
|
||||
})
|
||||
|
||||
const code = $(itm).data('lang')
|
||||
|
||||
$(`.button-weglot-lang-submit[data-lang=${code}]`)
|
||||
.on("click", edit_weglot_post_name);
|
||||
})
|
||||
|
||||
$(".weglot_reset").each((key, itm) => {
|
||||
$(itm).on("click", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const code = $(this).data("lang");
|
||||
const custom_url = $(this).attr('href')
|
||||
const id = $(this).data('id')
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
method: "POST",
|
||||
data: {
|
||||
action: "weglot_reset_custom_url",
|
||||
code_lang: code,
|
||||
id: id,
|
||||
custom_url: custom_url
|
||||
},
|
||||
success: function(res) {
|
||||
$(`#text-edit-${code}`).text(
|
||||
res.data.result.slug
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
execute();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export default init_url_translate
|
||||
@@ -0,0 +1,63 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
$('#update-nav-menu').bind('click', function (e) {
|
||||
|
||||
if (e.target && e.target.className && -1 != e.target.className.indexOf('item-edit')) {
|
||||
|
||||
$("input[value='#weglot_switcher'][type=text]").parents('.menu-item-settings').each(function () {
|
||||
const id = $(this).attr('id').substring(19);
|
||||
$(this).children('p:not( .field-move )').remove(); // remove default fields we don't need
|
||||
|
||||
$(this).append($('<input>').attr({ // phpcs:ignore
|
||||
type: 'hidden',
|
||||
id: 'edit-menu-item-title-' + id,
|
||||
name: 'menu-item-title[' + id + ']',
|
||||
value: weglot_data.title
|
||||
}));
|
||||
|
||||
$(this).append($("<input>").attr({ // phpcs:ignore
|
||||
type: "hidden",
|
||||
id: "edit-menu-item-url-" + id,
|
||||
name: "menu-item-url[" + id + "]",
|
||||
value: "#weglot_switcher"
|
||||
}));
|
||||
|
||||
$(this).append($('<input>').attr({ // phpcs:ignore
|
||||
type: 'hidden',
|
||||
id: 'edit-menu-item-weglot-detect-' + id,
|
||||
name: 'menu-item-weglot-detect[' + id + ']',
|
||||
value: 1
|
||||
}));
|
||||
|
||||
|
||||
$.each(weglot_data.list_options, (key, option) => {
|
||||
const paragraph = $("<p>").attr("class", "description");
|
||||
const label = $("<label>")
|
||||
.attr("for", `edit-menu-item-${option.key}-${id}`)
|
||||
.text(` ${option.title}`);
|
||||
|
||||
$(this).prepend(paragraph); // phpcs:ignore
|
||||
paragraph.append(label); // phpcs:ignore
|
||||
|
||||
const checkbox = $("<input>").attr({
|
||||
type: "checkbox",
|
||||
id: `edit-menu-item-${
|
||||
option.key
|
||||
}-${id}`,
|
||||
name: `menu-item-weglot-${
|
||||
option.key
|
||||
}[${id}]`,
|
||||
value: 1
|
||||
});
|
||||
|
||||
|
||||
if (weglot_data.options && weglot_data.options[`menu-item-${id}`] && weglot_data.options[`menu-item-${id}`][ option.key ] === 1 ){
|
||||
checkbox.prop("checked", true);
|
||||
}
|
||||
|
||||
label.prepend(checkbox); // phpcs:ignore
|
||||
})
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
/*! selectize.js - v0.12.4 | https://github.com/selectize/selectize.js | Apache License (v2) */
|
||||
!function(a,b){"function"==typeof define&&define.amd?define("sifter",b):"object"==typeof exports?module.exports=b():a.Sifter=b()}(this,function(){var a=function(a,b){this.items=a,this.settings=b||{diacritics:!0}};a.prototype.tokenize=function(a){if(a=e(String(a||"").toLowerCase()),!a||!a.length)return[];var b,c,d,g,i=[],j=a.split(/ +/);for(b=0,c=j.length;b<c;b++){if(d=f(j[b]),this.settings.diacritics)for(g in h)h.hasOwnProperty(g)&&(d=d.replace(new RegExp(g,"g"),h[g]));i.push({string:j[b],regex:new RegExp(d,"i")})}return i},a.prototype.iterator=function(a,b){var c;c=g(a)?Array.prototype.forEach||function(a){for(var b=0,c=this.length;b<c;b++)a(this[b],b,this)}:function(a){for(var b in this)this.hasOwnProperty(b)&&a(this[b],b,this)},c.apply(a,[b])},a.prototype.getScoreFunction=function(a,b){var c,e,f,g,h;c=this,a=c.prepareSearch(a,b),f=a.tokens,e=a.options.fields,g=f.length,h=a.options.nesting;var i=function(a,b){var c,d;return a?(a=String(a||""),d=a.search(b.regex),d===-1?0:(c=b.string.length/a.length,0===d&&(c+=.5),c)):0},j=function(){var a=e.length;return a?1===a?function(a,b){return i(d(b,e[0],h),a)}:function(b,c){for(var f=0,g=0;f<a;f++)g+=i(d(c,e[f],h),b);return g/a}:function(){return 0}}();return g?1===g?function(a){return j(f[0],a)}:"and"===a.options.conjunction?function(a){for(var b,c=0,d=0;c<g;c++){if(b=j(f[c],a),b<=0)return 0;d+=b}return d/g}:function(a){for(var b=0,c=0;b<g;b++)c+=j(f[b],a);return c/g}:function(){return 0}},a.prototype.getSortFunction=function(a,c){var e,f,g,h,i,j,k,l,m,n,o;if(g=this,a=g.prepareSearch(a,c),o=!a.query&&c.sort_empty||c.sort,m=function(a,b){return"$score"===a?b.score:d(g.items[b.id],a,c.nesting)},i=[],o)for(e=0,f=o.length;e<f;e++)(a.query||"$score"!==o[e].field)&&i.push(o[e]);if(a.query){for(n=!0,e=0,f=i.length;e<f;e++)if("$score"===i[e].field){n=!1;break}n&&i.unshift({field:"$score",direction:"desc"})}else for(e=0,f=i.length;e<f;e++)if("$score"===i[e].field){i.splice(e,1);break}for(l=[],e=0,f=i.length;e<f;e++)l.push("desc"===i[e].direction?-1:1);return j=i.length,j?1===j?(h=i[0].field,k=l[0],function(a,c){return k*b(m(h,a),m(h,c))}):function(a,c){var d,e,f;for(d=0;d<j;d++)if(f=i[d].field,e=l[d]*b(m(f,a),m(f,c)))return e;return 0}:null},a.prototype.prepareSearch=function(a,b){if("object"==typeof a)return a;b=c({},b);var d=b.fields,e=b.sort,f=b.sort_empty;return d&&!g(d)&&(b.fields=[d]),e&&!g(e)&&(b.sort=[e]),f&&!g(f)&&(b.sort_empty=[f]),{options:b,query:String(a||"").toLowerCase(),tokens:this.tokenize(a),total:0,items:[]}},a.prototype.search=function(a,b){var c,d,e,f,g=this;return d=this.prepareSearch(a,b),b=d.options,a=d.query,f=b.score||g.getScoreFunction(d),a.length?g.iterator(g.items,function(a,e){c=f(a),(b.filter===!1||c>0)&&d.items.push({score:c,id:e})}):g.iterator(g.items,function(a,b){d.items.push({score:1,id:b})}),e=g.getSortFunction(d,b),e&&d.items.sort(e),d.total=d.items.length,"number"==typeof b.limit&&(d.items=d.items.slice(0,b.limit)),d};var b=function(a,b){return"number"==typeof a&&"number"==typeof b?a>b?1:a<b?-1:0:(a=i(String(a||"")),b=i(String(b||"")),a>b?1:b>a?-1:0)},c=function(a,b){var c,d,e,f;for(c=1,d=arguments.length;c<d;c++)if(f=arguments[c])for(e in f)f.hasOwnProperty(e)&&(a[e]=f[e]);return a},d=function(a,b,c){if(a&&b){if(!c)return a[b];for(var d=b.split(".");d.length&&(a=a[d.shift()]););return a}},e=function(a){return(a+"").replace(/^\s+|\s+$|/g,"")},f=function(a){return(a+"").replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")},g=Array.isArray||"undefined"!=typeof $&&$.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},h={a:"[aḀḁĂăÂâǍǎȺⱥȦȧẠạÄäÀàÁáĀāÃãÅåąĄÃąĄ]",b:"[b␢βΒB฿𐌁ᛒ]",c:"[cĆćĈĉČčĊċC̄c̄ÇçḈḉȻȼƇƈɕᴄCc]",d:"[dĎďḊḋḐḑḌḍḒḓḎḏĐđD̦d̦ƉɖƊɗƋƌᵭᶁᶑȡᴅDdð]",e:"[eÉéÈèÊêḘḙĚěĔĕẼẽḚḛẺẻĖėËëĒēȨȩĘęᶒɆɇȄȅẾếỀềỄễỂểḜḝḖḗḔḕȆȇẸẹỆệⱸᴇEeɘǝƏƐε]",f:"[fƑƒḞḟ]",g:"[gɢ₲ǤǥĜĝĞğĢģƓɠĠġ]",h:"[hĤĥĦħḨḩẖẖḤḥḢḣɦʰǶƕ]",i:"[iÍíÌìĬĭÎîǏǐÏïḮḯĨĩĮįĪīỈỉȈȉȊȋỊịḬḭƗɨɨ̆ᵻᶖİiIıɪIi]",j:"[jȷĴĵɈɉʝɟʲ]",k:"[kƘƙꝀꝁḰḱǨǩḲḳḴḵκϰ₭]",l:"[lŁłĽľĻļĹĺḶḷḸḹḼḽḺḻĿŀȽƚⱠⱡⱢɫɬᶅɭȴʟLl]",n:"[nŃńǸǹŇňÑñṄṅŅņṆṇṊṋṈṉN̈n̈ƝɲȠƞᵰᶇɳȵɴNnŊŋ]",o:"[oØøÖöÓóÒòÔôǑǒŐőŎŏȮȯỌọƟɵƠơỎỏŌōÕõǪǫȌȍՕօ]",p:"[pṔṕṖṗⱣᵽƤƥᵱ]",q:"[qꝖꝗʠɊɋꝘꝙq̃]",r:"[rŔŕɌɍŘřŖŗṘṙȐȑȒȓṚṛⱤɽ]",s:"[sŚśṠṡṢṣꞨꞩŜŝŠšŞşȘșS̈s̈]",t:"[tŤťṪṫŢţṬṭƮʈȚțṰṱṮṯƬƭ]",u:"[uŬŭɄʉỤụÜüÚúÙùÛûǓǔŰűŬŭƯưỦủŪūŨũŲųȔȕ∪]",v:"[vṼṽṾṿƲʋꝞꝟⱱʋ]",w:"[wẂẃẀẁŴŵẄẅẆẇẈẉ]",x:"[xẌẍẊẋχ]",y:"[yÝýỲỳŶŷŸÿỸỹẎẏỴỵɎɏƳƴ]",z:"[zŹźẐẑŽžŻżẒẓẔẕƵƶLine truncated
|
||||
f.$input.html(d.join(""))}else f.$input.val(f.getValue()),f.$input.attr("value",f.$input.val());f.isSetup&&(a.silent||f.trigger("change",f.$input.val()))},updatePlaceholder:function(){if(this.settings.placeholder){var a=this.$control_input;this.items.length?a.removeAttr("placeholder"):a.attr("placeholder",this.settings.placeholder),a.triggerHandler("update",{force:!0})}},open:function(){var a=this;a.isLocked||a.isOpen||"multi"===a.settings.mode&&a.isFull()||(a.focus(),a.isOpen=!0,a.refreshState(),a.$dropdown.css({visibility:"hidden",display:"block"}),a.positionDropdown(),a.$dropdown.css({visibility:"visible"}),a.trigger("dropdown_open",a.$dropdown))},close:function(){var a=this,b=a.isOpen;"single"===a.settings.mode&&a.items.length&&(a.hideInput(),a.$control_input.blur()),a.isOpen=!1,a.$dropdown.hide(),a.setActiveOption(null),a.refreshState(),b&&a.trigger("dropdown_close",a.$dropdown)},positionDropdown:function(){var a=this.$control,b="body"===this.settings.dropdownParent?a.offset():a.position();b.top+=a.outerHeight(!0),this.$dropdown.css({width:a.outerWidth(),top:b.top,left:b.left})},clear:function(a){var b=this;b.items.length&&(b.$control.children(":not(input)").remove(),b.items=[],b.lastQuery=null,b.setCaret(0),b.setActiveItem(null),b.updatePlaceholder(),b.updateOriginalInput({silent:a}),b.refreshState(),b.showInput(),b.trigger("clear"))},insertAtCaret:function(b){var c=Math.min(this.caretPos,this.items.length);0===c?this.$control.prepend(b):a(this.$control[0].childNodes[c]).before(b),this.setCaret(c+1)},deleteSelection:function(b){var c,d,e,f,g,h,i,j,k,l=this;if(e=b&&b.keyCode===p?-1:1,f=G(l.$control_input[0]),l.$activeOption&&!l.settings.hideSelected&&(i=l.getAdjacentOption(l.$activeOption,-1).attr("data-value")),g=[],l.$activeItems.length){for(k=l.$control.children(".active:"+(e>0?"last":"first")),h=l.$control.children(":not(input)").index(k),e>0&&h++,c=0,d=l.$activeItems.length;c<d;c++)g.push(a(l.$activeItems[c]).attr("data-value"));b&&(b.preventDefault(),b.stopPropagation())}else(l.isFocused||"single"===l.settings.mode)&&l.items.length&&(e<0&&0===f.start&&0===f.length?g.push(l.items[l.caretPos-1]):e>0&&f.start===l.$control_input.val().length&&g.push(l.items[l.caretPos]));if(!g.length||"function"==typeof l.settings.onDelete&&l.settings.onDelete.apply(l,[g])===!1)return!1;for("undefined"!=typeof h&&l.setCaret(h);g.length;)l.removeItem(g.pop());return l.showInput(),l.positionDropdown(),l.refreshOptions(!0),i&&(j=l.getOption(i),j.length&&l.setActiveOption(j)),!0},advanceSelection:function(a,b){var c,d,e,f,g,h,i=this;0!==a&&(i.rtl&&(a*=-1),c=a>0?"last":"first",d=G(i.$control_input[0]),i.isFocused&&!i.isInputHidden?(f=i.$control_input.val().length,g=a<0?0===d.start&&0===d.length:d.start===f,g&&!f&&i.advanceCaret(a,b)):(h=i.$control.children(".active:"+c),h.length&&(e=i.$control.children(":not(input)").index(h),i.setActiveItem(null),i.setCaret(a>0?e+1:e))))},advanceCaret:function(a,b){var c,d,e=this;0!==a&&(c=a>0?"next":"prev",e.isShiftDown?(d=e.$control_input[c](),d.length&&(e.hideInput(),e.setActiveItem(d),b&&b.preventDefault())):e.setCaret(e.caretPos+a))},setCaret:function(b){var c=this;if(b="single"===c.settings.mode?c.items.length:Math.max(0,Math.min(c.items.length,b)),!c.isPending){var d,e,f,g;for(f=c.$control.children(":not(input)"),d=0,e=f.length;d<e;d++)g=a(f[d]).detach(),d<b?c.$control_input.before(g):c.$control.append(g)}c.caretPos=b},lock:function(){this.close(),this.isLocked=!0,this.refreshState()},unlock:function(){this.isLocked=!1,this.refreshState()},disable:function(){var a=this;a.$input.prop("disabled",!0),a.$control_input.prop("disabled",!0).prop("tabindex",-1),a.isDisabled=!0,a.lock()},enable:function(){var a=this;a.$input.prop("disabled",!1),a.$control_input.prop("disabled",!1).prop("tabindex",a.tabIndex),a.isDisabled=!1,a.unlock()},destroy:function(){var b=this,c=b.eventNS,d=b.revertSettings;b.trigger("destroy"),b.off(),b.$wrapper.remove(),b.$dropdown.remove(),b.$input.html("").append(d.$children).removeAttr("tabindex").removeClass("selectized").attr({tabindex:d.tabindex}).show(),b.$control_input.removeData("grow"),b.$input.removeData("selectize"),a(window).off(c),a(document).off(c),a(document.body).off(c),delete b.$input[0].selectize},render:function(b,c){var d,e,f="",g=!1,h=this;return"option"!==b&&"item"!==b||(d=z(c[h.settings.valueField]),g=!!d),g&&(y(h.renderCache[b])||(h.renderCache[b]={}),h.renderCache[b].hasOwnProperty(d))?h.renderCache[b][d]:(f=a(h.settings.render[b].apply(this,[c,A])),"option"===b||"option_create"===b?f.attr("data-selectable",""):"optgroup"===b&&(e=c[h.settings.optgroupValueField]||"",f.attr("data-group",e)),"option"!==b&&"item"!==b||f.attr("data-value",d||""),g&&(h.renderCache[b][d]=f[0]),f[0])},clearCache:function(a){var b=this;"undefined"==typeof a?b.renderCache={}:delete b.renderCache[a]},canCreate:function(a){var b=this;if(!b.settings.create)return!1;var c=b.settings.createFilter;return a.length&&("function"!=typeof c||c.apply(b,[a]))&&("string"!=typeofLine truncated
|
||||
@@ -0,0 +1,114 @@
|
||||
const init_admin_button_preview = function () {
|
||||
const $ = jQuery
|
||||
|
||||
const execute = () => {
|
||||
// Init old type flags
|
||||
let old_type_flags = $("#type_flags option:selected").data('value')
|
||||
|
||||
let destination_languages = []
|
||||
destination_languages.push($(".country-selector label").data("code-language"));
|
||||
$(".country-selector li").each((key, itm) => {
|
||||
destination_languages.push($(itm).data("code-language"));
|
||||
})
|
||||
|
||||
const weglot_desination_languages = weglot_languages.available.filter(itm => {
|
||||
return destination_languages.indexOf(itm.external_code) >= 0;
|
||||
})
|
||||
|
||||
$("#weglot-css-inline").text(weglot_css.inline);
|
||||
|
||||
// Change dropdown
|
||||
$("#is_dropdown").on("change", function(){
|
||||
$(".country-selector").toggleClass("weglot-inline");
|
||||
$(".country-selector").toggleClass("weglot-dropdown");
|
||||
})
|
||||
|
||||
// Change with flags
|
||||
$("#with_flags").on("change", function() {
|
||||
$(".country-selector label, .country-selector li").toggleClass("weglot-flags");
|
||||
});
|
||||
|
||||
// Change type flags
|
||||
$("#type_flags").on("change", function(e) {
|
||||
$(".country-selector label, .country-selector li").removeClass(`flag-${old_type_flags}`);
|
||||
const new_type_flags = $(':selected', this).data('value')
|
||||
$(".country-selector label, .country-selector li").addClass(`flag-${new_type_flags}`);
|
||||
old_type_flags = new_type_flags;
|
||||
});
|
||||
|
||||
const set_languages = () => {
|
||||
const label_language = weglot_desination_languages.find(
|
||||
(itm) => itm.external_code === $(".country-selector label").data("code-language")
|
||||
);
|
||||
const is_fullname = $("#is_fullname").is(":checked");
|
||||
|
||||
const label = is_fullname ? label_language.local : label_language.internal_code.toUpperCase();
|
||||
|
||||
$(".country-selector label a, .country-selector label span").text(label);
|
||||
|
||||
$(".country-selector li").each((key, itm) => {
|
||||
const li_language = weglot_desination_languages.find(
|
||||
(lang) => lang.internal_code === $(itm).data("code-language")
|
||||
);
|
||||
|
||||
const label = is_fullname ? li_language.local : li_language.internal_code.toUpperCase();
|
||||
|
||||
$(itm)
|
||||
.find("a")
|
||||
.text(label);
|
||||
})
|
||||
}
|
||||
|
||||
// Change with name
|
||||
$("#with_name").on("change", function(e) {
|
||||
if (e.target.checked) {
|
||||
set_languages();
|
||||
} else {
|
||||
$(".country-selector label a, .country-selector label span").text("");
|
||||
$(".country-selector li a, .country-selector li span").each(
|
||||
(key, itm) => {
|
||||
$(itm).text("");
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
$("#is_fullname").on("change", function(e){
|
||||
if ( !$("#with_name").is(":checked") ) {
|
||||
return
|
||||
}
|
||||
|
||||
if (e.target.checked) {
|
||||
set_languages();
|
||||
}
|
||||
else {
|
||||
const label_language = weglot_desination_languages.find(itm => itm.internal_code === $(".country-selector label").data("code-language"));
|
||||
|
||||
$(".country-selector label a, .country-selector label span").text(label_language.internal_code.toUpperCase());
|
||||
$(".country-selector li").each((key, itm) => {
|
||||
const language = weglot_desination_languages.find(lang => lang.internal_code === $(itm).data("code-language"));
|
||||
|
||||
$(itm).find("a").text(language.internal_code.toUpperCase());
|
||||
$(itm).find("span").text(language.internal_code.toUpperCase());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$("#override_css").on("keyup", function(e) {
|
||||
$("#weglot-css-inline").text(e.target.value);
|
||||
})
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if ($(".weglot-preview").length === 0){
|
||||
return
|
||||
}
|
||||
|
||||
execute();
|
||||
})
|
||||
}
|
||||
|
||||
export default init_admin_button_preview;
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
const init_admin_change_country = function() {
|
||||
const $ = jQuery;
|
||||
|
||||
if(typeof weglot_css !== "undefined"){
|
||||
$("#weglot-css-flag-css").text(weglot_css.flag_css);
|
||||
}
|
||||
|
||||
function refresh_flag_css() {
|
||||
var en_flags = new Array();
|
||||
var es_flags = new Array();
|
||||
var fr_flags = new Array();
|
||||
var ar_flags = new Array();
|
||||
var tw_flags = new Array();
|
||||
var zh_flags = new Array();
|
||||
var pt_flags = new Array();
|
||||
|
||||
en_flags[1] = [3570, 7841, 48, 2712];
|
||||
en_flags[2] = [3720, 449, 3048, 4440];
|
||||
en_flags[3] = [3840, 1281, 2712, 4224];
|
||||
en_flags[4] = [3240, 5217, 1224, 2112];
|
||||
en_flags[5] = [4050, 3585, 1944, 2496];
|
||||
en_flags[6] = [2340, 3457, 2016, 2016];
|
||||
|
||||
es_flags[1] = [4320, 4641, 3144, 3552];
|
||||
es_flags[2] = [3750, 353, 2880, 4656];
|
||||
es_flags[3] = [4200, 1601, 2568, 3192];
|
||||
es_flags[4] = [3990, 5793, 1032, 2232];
|
||||
es_flags[5] = [5460, 897, 4104, 3120];
|
||||
es_flags[6] = [3810, 7905, 216, 3888];
|
||||
es_flags[7] = [3630, 8065, 192, 2376];
|
||||
es_flags[8] = [3780, 1473, 2496, 4104];
|
||||
es_flags[9] = [6120, 2145, 4680, 2568];
|
||||
es_flags[10] = [4440, 3009, 3240, 1176];
|
||||
es_flags[11] = [5280, 1825, 3936, 2976];
|
||||
es_flags[12] = [4770, 2081, 3624, 1008];
|
||||
es_flags[13] = [4080, 3201, 2160, 2544];
|
||||
es_flags[14] = [4590, 5761, 3432, 624];
|
||||
es_flags[15] = [4350, 2209, 3360, 2688];
|
||||
es_flags[16] = [5610, 5249, 3168, 528];
|
||||
es_flags[17] = [5070, 1729, 3792, 2952];
|
||||
es_flags[18] = [6870, 5953, 96, 3408];
|
||||
es_flags[19] = [4020, 5697, 1056, 1224];
|
||||
|
||||
fr_flags[1] = [2760, 736, 2856, 4416];
|
||||
fr_flags[2] = [3840, 1280, 2712, 4224];
|
||||
fr_flags[3] = [5700, 7201, 5016, 2400];
|
||||
fr_flags[4] = [2220, 4160, 1632, 1944];
|
||||
|
||||
ar_flags[1] = [1830, 129, 3096, 5664];
|
||||
ar_flags[2] = [5100, 2177, 3840, 2904];
|
||||
ar_flags[3] = [4890, 3425, 3648, 2136];
|
||||
ar_flags[4] = [1320, 3681, 1896, 4080];
|
||||
ar_flags[5] = [1260, 3841, 1824, 1200];
|
||||
ar_flags[6] = [1020, 3969, 1608, 312];
|
||||
ar_flags[7] = [4800, 4065, 3600, 72];
|
||||
ar_flags[8] = [4710, 4865, 3504, 480];
|
||||
ar_flags[9] = [6720, 5984, 5112, 3792];
|
||||
ar_flags[10] = [4500, 7233, 3288, 1800];
|
||||
ar_flags[11] = [720, 7522, 384, 3936];
|
||||
ar_flags[12] = [690, 7745, 336, 1104];
|
||||
ar_flags[13] = [600, 8225, 120, 1272];
|
||||
ar_flags[14] = [660, 5569, 840, 576];
|
||||
|
||||
tw_flags[1] = [3690, 1505, 2592, 3240]; // China
|
||||
tw_flags[2] = [3600, 3233, 2112, 48]; // Hong Kong
|
||||
|
||||
zh_flags[1] = [2970, 6369, 3408, 4008]; // Taiwan
|
||||
zh_flags[2] = [3600, 3233, 2112, 48]; // Hong Kong
|
||||
|
||||
pt_flags[1] = [6630, 993, 2784, 4344];
|
||||
|
||||
var enval = $("select.flag-en-type").val();
|
||||
var esval = $("select.flag-es-type").val();
|
||||
var frval = $("select.flag-fr-type").val();
|
||||
var arval = $("select.flag-ar-type").val();
|
||||
var twval = $("select.flag-tw-type").val();
|
||||
var zhval = $("select.flag-zh-type").val();
|
||||
var ptval = $("select.flag-pt-type").val();
|
||||
var en_style = enval <= 0 ? "" : ".weglot-flags.en > a:before, .weglot-flags.en > span:before { background-position: -" + en_flags[enval][0] + "px 0 !important; } .weglot-flags.flag-1.en > a:before, .weglot-flags.flag-1.en > span:before { background-position: -" + en_flags[enval][1] + "px 0 !important; } .weglot-flags.flag-2.en > a:before, .weglot-flags.flag-2.en > span:before { background-position: -" + en_flags[enval][2] + "px 0 !important; } .weglot-flags.flag-3.en > a:before, .weglot-flags.flag-3.en > span:before { background-position: -" + en_flags[enval][3] + "px 0 !important; } ";
|
||||
var es_style = esval <= 0 ? "" : ".weglot-flags.es > a:before, .weglot-flags.es > span:before { background-position: -" + es_flags[esval][0] + "px 0 !important; } .weglot-flags.flag-1.es > a:before, .weglot-flags.flag-1.es > span:before { background-position: -" + es_flags[esval][1] + "px 0 !important; } .weglot-flags.flag-2.es > a:before, .weglot-flags.flag-2.es > span:before { background-position: -" + es_flags[esval][2] + "px 0 !important; } .weglot-flags.flag-3.es > a:before, .weglot-flags.flag-3.es > span:before { background-position: -" + es_flags[esval][3] + "px 0 !important; } ";
|
||||
var fr_style = frval <= 0 ? "" : ".weglot-flags.fr > a:before, .weglot-flags.fr > span:before { background-position: -" + fr_flags[frval][0] + "px 0 !important; } .weglot-flags.flag-1.fr > a:before, .weglot-flags.flag-1.fr > span:before { background-position: -" + fr_flags[frval][1] + "px 0 !important; } .weglot-flags.flag-2.fr > a:before, .weglot-flags.flag-2.fr > span:before { background-position: -" + fr_flags[frval][2] + "px 0 !important; } .weglot-flags.flag-3.fr > a:before, .weglot-flags.flag-3.fr > span:before { background-position: -" + fr_flags[frval][3] + "px 0 !important; } ";
|
||||
var ar_style = arval <= 0 ? "" : ".weglot-flags.ar > a:before, .weglot-flags.ar > span:before { background-position: -" + ar_flags[arval][0] + "px 0 !important; } .weglot-flags.flag-1.ar > a:before, .weglot-flags.flag-1.ar > span:before { background-position: -" + ar_flags[arval][1] + "px 0 !important; } .weglot-flags.flag-2.ar > a:before, .weglot-flags.flag-2.ar > span:before { background-position: -" + ar_flags[arval][2] + "px 0 !important; } .weglot-flags.flag-3.ar > a:before, .weglot-flags.flag-3.ar > span:before { background-position: -" + ar_flags[arval][3] + "px 0 !important; } ";
|
||||
var tw_style = twval <= 0 ? "" : ".weglot-flags.tw > a:before, .weglot-flags.tw > span:before { background-position: -" + tw_flags[twval][0] + "px 0 !important; } .weglot-flags.flag-1.tw > a:before, .weglot-flags.flag-1.tw > span:before { background-position: -" + tw_flags[twval][1] + "px 0 !important; } .weglot-flags.flag-2.tw > a:before, .weglot-flags.flag-2.tw > span:before { background-position: -" + tw_flags[twval][2] + "px 0 !important; } .weglot-flags.flag-3.tw > a:before, .weglot-flags.flag-3.tw > span:before { background-position: -" + tw_flags[twval][3] + "px 0 !important; } ";
|
||||
var zh_style = zhval <= 0 ? "" : ".weglot-flags.zh > a:before, .weglot-flags.zh > span:before { background-position: -" + zh_flags[zhval][0] + "px 0 !important; } .weglot-flags.flag-1.zh > a:before, .weglot-flags.flag-1.zh > span:before { background-position: -" + zh_flags[zhval][1] + "px 0 !important; } .weglot-flags.flag-2.zh > a:before, .weglot-flags.flag-2.zh > span:before { background-position: -" + zh_flags[zhval][2] + "px 0 !important; } .weglot-flags.flag-3.zh > a:before, .weglot-flags.flag-3.zh > span:before { background-position: -" + zh_flags[zhval][3] + "px 0 !important; } ";
|
||||
var pt_style = ptval <= 0 ? "" : ".weglot-flags.pt > a:before, .weglot-flags.pt > span:before { background-position: -" + pt_flags[ptval][0] + "px 0 !important; } .weglot-flags.flag-1.pt > a:before, .weglot-flags.flag-1.pt > span:before { background-position: -" + pt_flags[ptval][1] + "px 0 !important; } .weglot-flags.flag-2.pt > a:before, .weglot-flags.flag-2.pt > span:before { background-position: -" + pt_flags[ptval][2] + "px 0 !important; } .weglot-flags.flag-3.pt > a:before, .weglot-flags.flag-3.pt > span:before { background-position: -" + pt_flags[ptval][3] + "px 0 !important; } ";
|
||||
|
||||
$("#flag_css, #weglot-css-flag-css").text(en_style + es_style + fr_style + ar_style + tw_style + zh_style + pt_style);
|
||||
}
|
||||
|
||||
const execute = () => {
|
||||
|
||||
$('.flag-style-openclose').on('click',
|
||||
function () {
|
||||
$('.flag-style-wrapper').toggle();
|
||||
}
|
||||
);
|
||||
|
||||
$('.old-flag-style').on('click',
|
||||
function () {
|
||||
$('.old-flag-wrapper').toggle();
|
||||
}
|
||||
);
|
||||
|
||||
$("select.flag-en-type, select.flag-es-type, select.flag-pt-type, select.flag-fr-type, select.flag-ar-type, select.flag-tw-type, select.flag-zh-type").on('change',
|
||||
function () {
|
||||
refresh_flag_css()
|
||||
}
|
||||
);
|
||||
|
||||
var flag_css = $("#flag_css").text();
|
||||
if (flag_css.trim()) {
|
||||
$("#weglot-css-flag-css").text(flag_css);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
execute();
|
||||
});
|
||||
};
|
||||
|
||||
export default init_admin_change_country;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
const init_admin_button_preview = function () {
|
||||
const $ = jQuery
|
||||
|
||||
const execute = () => {
|
||||
|
||||
$("#api_key_private").blur(function() {
|
||||
var key = $(this).val();
|
||||
if( key.length === 0){
|
||||
$(".weglot-keyres").remove();
|
||||
$("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span>');
|
||||
$("#wrap-weglot #submit").prop("disabled", true);
|
||||
return;
|
||||
}
|
||||
|
||||
function validApiKey(response){
|
||||
|
||||
$(".weglot-keyres").remove();
|
||||
$("#api_key_private").after(
|
||||
'<span class="weglot-keyres weglot-okkey"></span>'
|
||||
);
|
||||
|
||||
$("#wrap-weglot #submit").prop(
|
||||
"disabled",
|
||||
false
|
||||
);
|
||||
|
||||
const evt = new CustomEvent("weglotCheckApi", {
|
||||
detail: response
|
||||
});
|
||||
|
||||
window.dispatchEvent(evt);
|
||||
}
|
||||
|
||||
function unvalidApiKey(){
|
||||
$(".weglot-keyres").remove();
|
||||
$("#api_key_private").after('<span class="weglot-keyres weglot-nokkey"></span><p class="weglot-keyres">Make sure you enter a valid Weglot API key. If the key is still not validating, you can contact your host provider and ask if it\'s possible to whitelist api.weglot.com and weglot.com</p>');
|
||||
$("#wrap-weglot #submit").prop("disabled", true);
|
||||
}
|
||||
|
||||
$(".weglot-keyres").remove();
|
||||
$("#api_key_private").after('<span class="weglot-keyres weglot-ckeckkey"></span>');
|
||||
|
||||
$.ajax(
|
||||
{
|
||||
method: 'POST',
|
||||
url: ajaxurl,
|
||||
data : {
|
||||
action: 'get_user_info',
|
||||
api_key: key,
|
||||
},
|
||||
success: ({data, success}) => {
|
||||
$(".weglot-keyres").remove();
|
||||
if (success ){
|
||||
validApiKey(data)
|
||||
}
|
||||
else{
|
||||
unvalidApiKey()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
).fail(function() {
|
||||
unvalidApiKey()
|
||||
});
|
||||
});
|
||||
|
||||
$( ".toplevel_page_weglot-settings form" ).submit(function( event ) {
|
||||
$("#wrap-weglot #submit").prop("disabled", true);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
execute();
|
||||
})
|
||||
}
|
||||
|
||||
export default init_admin_button_preview;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
const init_admin_weglot_code_editor = function () {
|
||||
const $ = jQuery
|
||||
|
||||
const execute = () => {
|
||||
jQuery(document).ready(function($) {
|
||||
wp.codeEditor.initialize($('#override_css'), cm_settings);
|
||||
})
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
execute();
|
||||
})
|
||||
}
|
||||
|
||||
export default init_admin_weglot_code_editor;
|
||||
@@ -0,0 +1,31 @@
|
||||
const init_private_mode = function () {
|
||||
|
||||
const $ = jQuery
|
||||
|
||||
const execute = () => {
|
||||
document.querySelector("#private_mode").addEventListener('change', function(e) {
|
||||
|
||||
document.querySelectorAll(".private-mode-lang--input").forEach((itm) => {
|
||||
itm.checked = e.target.checked;
|
||||
})
|
||||
})
|
||||
|
||||
document.querySelectorAll(".private-mode-lang--input").forEach((itm) => {
|
||||
itm.addEventListener('change', function(e){
|
||||
if (document.querySelectorAll(".private-mode-lang--input:checked").length === 0){
|
||||
document.querySelector("#private_mode").checked = false
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const private_mode = document.querySelector("#private_mode")
|
||||
if (private_mode && private_mode.length != 0){
|
||||
execute();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default init_private_mode;
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
const init_admin_select = function(){
|
||||
|
||||
const $ = jQuery
|
||||
const generate_destination_language = () => {
|
||||
return weglot_languages.available.filter(itm => {
|
||||
return itm.internal_code !== $("#original_language").val()
|
||||
});
|
||||
}
|
||||
|
||||
let destination_selectize
|
||||
|
||||
const load_destination_selectize = () => {
|
||||
destination_selectize = $(".weglot-select-destination")
|
||||
.selectize({
|
||||
delimiter: "|",
|
||||
persist: false,
|
||||
valueField: "internal_code",
|
||||
labelField: "local",
|
||||
searchField: ["internal_code", "english", "local"],
|
||||
sortField: [{ field: "english", direction: "asc" }],
|
||||
maxItems: weglot_languages.limit,
|
||||
plugins: ["remove_button"],
|
||||
options: generate_destination_language(),
|
||||
render: {
|
||||
option: function(item, escape) {
|
||||
var english = escape(item.english);
|
||||
var local = escape(item.local);
|
||||
var external = escape(item.external_code);
|
||||
return `<div class="weglot__choice__language"><span class="weglot__choice__language--english">${english}</span><span class="weglot__choice__language--local">${local}[${external}]</span></div>`;
|
||||
}
|
||||
}
|
||||
})
|
||||
.on("change", (value) => {
|
||||
const code_languages = destination_selectize[0].selectize.getValue()
|
||||
|
||||
const template = $("#li-button-tpl");
|
||||
|
||||
if (template.length === 0){
|
||||
return;
|
||||
}
|
||||
|
||||
const is_fullname = $("#is_fullname").is(":checked")
|
||||
const with_name = $("#with_name").is(":checked")
|
||||
const with_flags = $("#with_flags").is(":checked")
|
||||
|
||||
let classes = ''
|
||||
if (with_flags) {
|
||||
classes = "weglot-flags";
|
||||
}
|
||||
|
||||
let new_dest_language = ''
|
||||
var currentFlagClasses = $("label.weglot-flags").attr("class")
|
||||
var classArr = currentFlagClasses.split(/\s+/);
|
||||
$.each(classArr, function(index, value){
|
||||
if(value.includes('flag-') == true){
|
||||
classes += ' '+value;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
code_languages.forEach(element => {
|
||||
const language = weglot_languages.available.find(itm => itm.internal_code === element);
|
||||
let label = ''
|
||||
if(with_name){
|
||||
if (is_fullname){
|
||||
label = language.local
|
||||
}
|
||||
else{
|
||||
label = element.toUpperCase()
|
||||
}
|
||||
}
|
||||
|
||||
new_dest_language += template
|
||||
.html()
|
||||
.replace("{LABEL_LANGUAGE}", label)
|
||||
.replace(new RegExp("{CODE_LANGUAGE}", "g"), element)
|
||||
.replace("{CLASSES}", classes)
|
||||
});
|
||||
$(".country-selector ul").html(new_dest_language) //phpcs:ignore
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
const execute = () => {
|
||||
let work_original_language = $("#original_language").val()
|
||||
|
||||
$("#original_language").on("change", function (e) {
|
||||
const old_original_language = work_original_language;
|
||||
const new_destination_option = work_original_language;
|
||||
work_original_language = e.target.value;
|
||||
destination_selectize[0].selectize.removeOption(work_original_language);
|
||||
|
||||
const new_option = weglot_languages.available.find(itm => {
|
||||
return itm.internal_code === new_destination_option
|
||||
});
|
||||
|
||||
const new_original_option = weglot_languages.available.find(itm => {
|
||||
return itm.internal_code === work_original_language;
|
||||
});
|
||||
|
||||
destination_selectize[0].selectize.addOption(new_option);
|
||||
|
||||
|
||||
const is_fullname = $("#is_fullname").is(":checked")
|
||||
const with_name = $("#with_name").is(":checked")
|
||||
let label = ''
|
||||
if(with_name){
|
||||
label = is_fullname ? new_original_option.local : new_original_option.internal_code.toUpperCase();
|
||||
}
|
||||
|
||||
$(".wgcurrent.wg-li")
|
||||
.removeClass(old_original_language)
|
||||
.addClass(work_original_language)
|
||||
.attr("data-code-language", work_original_language)
|
||||
.find('span').text(label)
|
||||
});
|
||||
|
||||
|
||||
load_destination_selectize();
|
||||
|
||||
window.addEventListener("weglotCheckApi", (data) => {
|
||||
destination_selectize[0].selectize.settings.maxItems = weglot_languages.limit;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
execute();
|
||||
})
|
||||
}
|
||||
|
||||
export default init_admin_select;
|
||||
@@ -0,0 +1,49 @@
|
||||
const init_admin_weglot_box = function () {
|
||||
const $ = jQuery
|
||||
|
||||
const execute = () => {
|
||||
$("#weglot-box-first-settings .weglot-btn-close").on("click", function (e) {
|
||||
e.preventDefault();
|
||||
$("#weglot-box-first-settings").hide();
|
||||
})
|
||||
|
||||
$('a[href*="#"]')
|
||||
// Remove links that don't actually link to anything
|
||||
.not('[href="#"]')
|
||||
.not('[href="#0"]')
|
||||
.click(function (event) {
|
||||
// On-page links
|
||||
// Figure out element to scroll to
|
||||
var target = $(this.hash);
|
||||
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
|
||||
// Does a scroll target exist?
|
||||
if (target.length) {
|
||||
// Only prevent default if animation is actually gonna happen
|
||||
event.preventDefault();
|
||||
$('html, body').animate({
|
||||
scrollTop: target.offset().top
|
||||
}, 1000, function () {
|
||||
// Callback after animation
|
||||
// Must change focus!
|
||||
var $target = $(target);
|
||||
$target.focus();
|
||||
if ($target.is(":focus")) { // Checking if the target was focused
|
||||
return false;
|
||||
} else {
|
||||
$target.attr('tabindex', '-1'); // Adding tabindex for elements not focusable
|
||||
$target.focus(); // Set focus again
|
||||
}
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
execute();
|
||||
})
|
||||
}
|
||||
|
||||
export default init_admin_weglot_box;
|
||||
|
||||
Reference in new issue
Block a user