«ميدياويكي:Common.js»: الفرق بين المراجعتين
من Sudan Memory
سطر ٢: | سطر ٢: | ||
$(function () { | $(function () { | ||
+ | function splitTrailingText(input) { | ||
+ | const regex = /^(.*?[\u0620-\u064Aa-zA-Z])([^\u0620-\u064Aa-zA-Z]*)$/; | ||
+ | const matches = input.match(regex); | ||
+ | |||
+ | if (matches && matches.length > 1) { | ||
+ | const alphabeticPart = matches[1]; | ||
+ | const nonAlphabeticPart = matches[2]; | ||
+ | return { alphabeticPart, nonAlphabeticPart }; | ||
+ | } | ||
+ | return { alphabeticPart: input, nonAlphabeticPart: '' }; | ||
+ | } | ||
+ | function parsePoem(text, vWidth) { | ||
+ | let lines = text.split('\n'); | ||
+ | let formattedLines = lines.map(line => { | ||
+ | if (line.trim() === "") { | ||
+ | // Replace empty lines with a line break | ||
+ | return '<br>'; | ||
+ | } else if (line.startsWith(' ')) { // Check for lines starting with two or more spaces | ||
+ | const { alphabeticPart, nonAlphabeticPart } = splitTrailingText(line.trim()); | ||
+ | return `<p class="vTail"><span class="vTail" style="width:${vWidth}px">${alphabeticPart}</span><span class="vTrailer">${nonAlphabeticPart}</span></p>`; | ||
+ | } else if (line.startsWith('--') && line.endsWith('--')) { // Check for lines delimited with '--' | ||
+ | return `<p class="vMid" style="width:${vWidth}px">` + line.substring(2, line.length - 2).trim() + '</p>'; | ||
+ | } else { | ||
+ | return `<p class="vHead" style="width:${0.9*vWidth}px">` + line.trim() + '</p>'; // Default to a regular paragraph for other lines | ||
+ | } | ||
+ | }); | ||
+ | return formattedLines.join(''); | ||
+ | } | ||
var toggler = document.getElementsByClassName("treeBranch"); | var toggler = document.getElementsByClassName("treeBranch"); |
مراجعة ١٣:٠٣، ١٩ فبراير ٢٠٢٤
/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */ $(function () { function splitTrailingText(input) { const regex = /^(.*?[\u0620-\u064Aa-zA-Z])([^\u0620-\u064Aa-zA-Z]*)$/; const matches = input.match(regex); if (matches && matches.length > 1) { const alphabeticPart = matches[1]; const nonAlphabeticPart = matches[2]; return { alphabeticPart, nonAlphabeticPart }; } return { alphabeticPart: input, nonAlphabeticPart: '' }; } function parsePoem(text, vWidth) { let lines = text.split('\n'); let formattedLines = lines.map(line => { if (line.trim() === "") { // Replace empty lines with a line break return '<br>'; } else if (line.startsWith(' ')) { // Check for lines starting with two or more spaces const { alphabeticPart, nonAlphabeticPart } = splitTrailingText(line.trim()); return `<p class="vTail"><span class="vTail" style="width:${vWidth}px">${alphabeticPart}</span><span class="vTrailer">${nonAlphabeticPart}</span></p>`; } else if (line.startsWith('--') && line.endsWith('--')) { // Check for lines delimited with '--' return `<p class="vMid" style="width:${vWidth}px">` + line.substring(2, line.length - 2).trim() + '</p>'; } else { return `<p class="vHead" style="width:${0.9*vWidth}px">` + line.trim() + '</p>'; // Default to a regular paragraph for other lines } }); return formattedLines.join(''); } var toggler = document.getElementsByClassName("treeBranch"); var i; for (i = 0; i < toggler.length; i++) { toggler[i].addEventListener("click", function() { this.parentElement.querySelector(".treeBranch-nested").classList.toggle("treeBranch-active"); this.classList.toggle("treeBranch-down"); }); } }());