first commit
This commit is contained in:
@@ -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