|
I am in the process of building a website in Squarespace, I am using Javascript to create a multi-lingual website in English and French. I differentiate between English and French using the URL/Slug
Example
www.websitename.com/en/home
or
www.websitename.com/fr/home
Everything is translating, almost. I am having issues with the footer translating.
Here are some images
https://i.stack.imgur.com/rLjn1.png[^]
https://i.stack.imgur.com/ruE24.png[^]
https://i.stack.imgur.com/Bz1cx.png[^]
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/2.6.0/css/flag-icon.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(function() {
var defaultLanguage = 'en';
var lang = location.pathname.split("/")[1];
var defaultClass = 'lang-'+defaultLanguage+'';
var itemParent = "nav [class*='collection'],nav [class*='folder'],nav [class*='index'],nav [class*='group']";
if (lang == "" || lang.length > 2 ){
var lang = defaultLanguage;
}
$('a[href="/"]').addClass('lang-'+defaultLanguage+'').parents(itemParent).addClass('lang-'+defaultLanguage+'');
$('nav a:link:not([href^="http://"]):not([href^="https://"])').each(function () {
var langType = $(this).attr('href').split("/")[1];
var multiLanguageClass = 'multilanguage lang-' + langType + '';
if (undefined !== langType && langType.length <= 2)
$(this).addClass(multiLanguageClass).parents(itemParent).addClass(multiLanguageClass);
});
$('nav button').each(function () {
var langTypeFolder = $(this).attr('data-controller-folder-toggle').split("/")[0];
var multiLanguageClass = 'multilanguage lang-' + langTypeFolder + '';
if (undefined !== langTypeFolder && langTypeFolder.length <= 2)
$(this).addClass(multiLanguageClass);
});
if (lang == "fr") {
$('a[href="/"]').attr("href", "/fr/home/");
}
$('.exclude-me,.exclude-me a').addClass('exclude');
$('.sqs-svg-icon--list a,.SocialLinks-link').addClass('exclude');
$('.multilanguage:not(".lang-'+lang+',.exclude")').remove();
$('body').prepend('<div class="language"><a href="/en/home" class="lang-en"></a> <a href="/fr/home/" class="lang-fr"></a></div>');
});
</script>
[JavaScript] MULTI-LANGUAGE Javscript for Website - Pastebin.com[^]
|
|
|
|
|
Just debug your code and figure out what you're doing wrong. Should be pretty simple.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
function textToBinary(text) {
let alphabet;
let letter;
let binary = "";
let value;
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (letter in text) {
if (alphabet.includes(text[letter].toUpperCase())) {
if (text[letter] === text[letter].toUpperCase()) {
binary += "010";
} else {
binary += "011";
}
value = alphabet.indexOf(text[letter].toUpperCase()) + 1;
if (value >= 16) {
binary += "1";
value -= 16;
} else {
binary += "0";
}
if (value >= 8) {
binary += "1";
value -= 8;
} else {
binary += "0";
}
if (value >= 4) {
binary += "1";
value -= 4;
} else {
binary += "0";
}
if (value >= 2) {
binary += "1";
value -= 2;
} else {
binary += "0";
}
if (value >= 1) {
binary += "1";
value -= 1;
} else {
binary += "0";
}
} else {
binary += "00100000";
}
}
console.log(binary);
}
textToBinary("this is written in BINARY");
|
|
|
|
|
|
Any tips?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
For Numbers and BigInts toString() takes an optional parameter radix the value of radix must be minimum 2 and maximum 36.
By using radix you can also convert base 10 numbers (like 1,2,3,4,5,.........) to another base numbers, in example below we are converting base 10 number to a base 2 (binary) number ...
So your entire series of if (value >= ...) blocks can be replaced with a single call to toString , along with a call to padStart[^] to add any leading zeros:
value = alphabet.indexOf(text[letter].toUpperCase()) + 1;
binary += value.toString(2).padStart(5, "0");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yeah, get rid of the semicolons
|
|
|
|
|
I am using npm module xlsx to write and read JSON data.
I want to write this JSON to excel
{ "name": "John", "class": 1, "address" : [ { "street": "12th Cross" , "city": "London" }, { "street": "22nd Cross" , "city": "Cade" } ] }
Later when I read back I want to get same JSON from excel file
If you already solved, any suggestion or help will be of great help
Here is what I have tried
```
var XLSX = require("xlsx");
console.log("Node Version: " + process.versions.node);
console.log("XLSX Version: " + XLSX.version);
/* GENERATE TEST FILE */
(function() {
// create workbook
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.json_to_sheet([
{ "name": "John", "class": 1, "address" : [ { "street": "12th Cross" , "city": "London" }, { "street": "22nd Cross" , "city": "Cade" } ] }
], {header:["name","class","address","street","city"]});
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "testfile.xlsx");
let worksheet = wb.Sheets['Sheet1'];
let jsonArray= XLSX.utils.sheet_to_json(worksheet);
console.log(JSON.stringify(jsonArray));
})();
```
This returns
```
Node Version: 8.12.0
XLSX Version: 0.16.2
[{"name":"John","class":1}]
But I was expecting
{ "name": "John", "class": 1, "address" : [ { "street": "12th Cross" , "city": "London" }, { "street": "22nd Cross" , "city": "Cade" } ] }
```
Any help or suggestion will be of great help
|
|
|
|
|
I am creating a program where if an action occurs then a message box through visual basic script (.vbs). I plan to do I through a fstream file.
if (statement)
{
open fstream file }
|
|
|
|
|
I think that this one is a bit misplaced in the "Javascript" section
|
|
|
|
|
Unless things have changed, only IE will support running vb script files which means this won't work in FireFox, Chrome, or any other browser, probably not even Edge.
But you are writing this in C++ so I am confused as to what you are actually doing. How and why does vbs come into play with C++ code?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
<audio controls autoplay>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
|
|
|
|
|
1. PA is hard coded
2. open field for customer to manually enter the sterilization no
3. The last 2 digit are with ( ) with spacing from number before
4. If the customer enter PA-1234 (56) then Output is PA-1234 (56)
5. if the customer enter PA-1234(56) the Output is PA-1234 (56)
6. if the customer enter PA-123456 the Output is PA-1234 (56)
7. if the customer enter 123456 the Output is PA-1234 (56)
8. if the customer enter 1234 56 the Output is PA-1234 (56)
9. if the customer enter 1234(56) the Output is PA-1234 (56)
https:
|
|
|
|
|
You need to ask a specific question. It is rude to ask someone to do all your work for you.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Same answer(s) as you received on webdeveloper.com.
|
|
|
|
|
a newbie here...
I have an accordion that's content is being brought in through includes. The accordion is showing up but with all the tabs in the open position and they won't toggle open/close. I'm completely stuck on how to get these to work with the accordion content being brought in dynamically.
This is the code that works on the normal content accordions:
(function($, window, document, undefined) {
'use strict';
$(document).ready(function() {
var $container_class = $('.accordions');
var $default_class = $('.beefup');
var $toggle_buttons_class = $('.toggle-buttons');
var $default_options = {
openSingle: true,
openSpeed: 300,
closeSpeed: 300
};
if ($container_class.length) {
$container_class.each(function() {
if ($default_class.length) {
$(this).find($default_class).beefup($default_options);
}
});
}
if ($toggle_buttons_class.length) {
$toggle_buttons_class.each(function() {
var $this = $(this);
var $beefup = $this.find($default_class).beefup($default_options);
$this.find('.toggle-open-all').on('click', function() {
$beefup.open();
});
$this.find('.toggle-close-all').on('click', function() {
$beefup.close();
});
$this.find('.buttons-group').find('.button').each(function(index) {
$(this).on('click', function() {
if (!$(this).hasClass('toggle-open-all') && !$(this).hasClass('toggle-close-all')) {
$this.find($container_class).find($default_class).each(function(item) {
if (index === item) {
$beefup.click($(this));
}
});
}
});
});
});
}
The classes are different for the dynamic accordion, I tried to change them in a duplicated section of this JS, but no luck.
The page if wish to view is here: http://clear-talk.oiw11.com/motorola/bpr40.htm It's the section towards the bottom of the page under the "accessories" tab.
I'm wondering if there's a better/easier way to go about this.
Any and all help would be greatly appreciated.
Thank you in advance!
|
|
|
|
|
I have a page where values (monetary) are entered into boxes and the aim is to have them appear in a drop down list on the next page. I have searched and found this Transferring page values to another page[^] But wondered if there was a more upto date way of doing it?
I have the code below and whilst I can send the data to the URL the script doesn't put it in the drop down. I've read about doing it with cookies, is that a more reliable method?
<script>
from the url as a query string
var query = location.search;
var splitQuery = []; var value
= [];
function parseQuery(query){
if(query.search(/[&]/)){
splitQuery = query.split('&');
for (var x = 0; x <
splitQuery.length; x++){
var splitEach =
splitQuery[x].split('=');
document.getElementsByClassName
('dropdown')[x].textContent =
splitEach[1];
}
}
}
parseQuery(query);
</script>
|
|
|
|
|
So long as you don't need to support Internet Explorer, the modern way to parse the querystring is to use the URLSearchParams class:
URLSearchParams - Web APIs | MDN[^]
const searchParams = new URLSearchParams(location.search);
for (const [key, value] of searchParams) {
console.log(key, "=", value);
} It's not clear what the connection is between the querystring parameters and the form parameters, but the code you've shown requires that they're in exactly the same order. It would probably be better if you could match based on the name of the element.
You'll also need to use the value property, not the textContent property, to set the value for a form element.
const searchParams = new URLSearchParams(location.search);
for (const [key, value] of searchParams) {
let element = document.getElementsByName(key)[0];
if (element && element.classList.contains("dropdown") && (/^INPUT|SELECT$/i).test(element.tagName)) {
element.value = value;
}
else {
console.warn("Unknown element:", key, element);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard, thanks for replying.
When I input the data and press the submit button it correctly forwards me to this page;
overheads5.html?level-1=10&level-2=20&level-3=30&level-4=40&level-5=&level-6=
so the data is in the url but I can't get it from there into the dropdown to use in calculations.
Basically the idea is that other data in the destination page has the value in the drop down added to it. Would it help to show you the actual pages?
|
|
|
|
|
If you really want to match based on the index of the parameter, then you could try:
const searchParams = new URLSearchParams(location.search);
let index = 0;
for (const [key, value] of searchParams) {
let element = document.getElementsByClassName("dropdown")[index];
element.value = value;
index++;
} This assumes that the value already exists in the list. If you want to add a new option instead:
let element = document.getElementsByClassName("dropdown")[index];
let option = document.createElement("option");
option.value = value;
option.text = value;
element.add(option, null);
element.value = value;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard, this is how the inputs and the dropdown are laid out but can be changed if it makes it easier to get to the result I need. I have tried the code you have given me but still nothing in the dropdown. (All I get is level 1, level 2 etc)
<div class='payroll-container row p-5'>
<form action ="overheads5.html" method
= "get" name = "payrate" id =
"payrate"> Payrate
<br/>
Level 1
<input type = "text" name =
"level-1" id = "level-1" />
<br/>
Level 2
<input type = "text" name =
"level-2" id = "level-2" />
<br/>
Level 3
<input type = "text" name =
"level-3" id = "level-3" />
<br/>
Level 4
<input type = "text" name =
"level-4" id = "level-4" />
<br/>
Level 5
<input type = "text" name =
"level-5" id = "level-5" />
<br/>
Level 6
<input type = "text" name =
"level-6" id = "level-6" />
<br/>
<input type = "submit"/>
<div class='dropdown-container row p-4'>
<select>
<option class = 'dropdown'>level-1</option>
<option class = 'dropdown'>level-2</option>
<option class = 'dropdown'>level-3</option>
<option class = 'dropdown'>level-4</option>
<option class = 'dropdown'>level-5</option>
<option class = 'dropdown'>level-6</option>
</select></div>
|
|
|
|
|
Based on that markup and the querystring from your previous message, this should work:
const searchParams = new URLSearchParams(location.search);
for (const [key, value] of searchParams) {
let element = document.getElementById(key);
if (element) {
element.value = value;
}
else {
console.warn("Unknown element:", key, element);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard,
I'm thinking it's probably me as the code below still gives me nothing. Assuming it should post to the dropdown I already have?
<script>
const searchParams = new URLSearchParams(location.search);
for (const [key, value] of searchParams) {
let element = document.getElementById(key);
if (element) {
element.value = value;
}
else {
console.warn("Unknown element:", key, element);
}
}
</script>
|
|
|
|
|
Ah, no, sorry. I thought you were trying to put the values into the text inputs.
Given a select list:
<div class='dropdown-container row p-4'>
<select>
<option class='dropdown'>level-1</option>
<option class='dropdown'>level-2</option>
<option class='dropdown'>level-3</option>
<option class='dropdown'>level-4</option>
<option class='dropdown'>level-5</option>
<option class='dropdown'>level-6</option>
</select>
</div> and the URL: overheads5.html?level-1=10&level-2=20&level-3=30&level-4=40&level-5=&level-6=
then something like this should work:
const searchParams = new URLSearchParams(location.search);
const elements = document.getElementsByClassName("dropdown");
let index = 0;
for (const [key, value] of searchParams) {
let element = elements[index];
element.text = value;
index++;
} Demo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard, thankyou so much it, works. It shows as per the example 10,20,30 in the drop down.
I assume it would be difficult to show the level and value or just the level and the value somewhere else(hidden) so that the values can get used in the calculations?
I know I could do that in Excel but I'm still at the start of the learning curve here.
|
|
|
|