«ميدياويكي:Common.js»: الفرق بين المراجعتين
من Sudan Memory
سطر ٣١: | سطر ٣١: | ||
} | } | ||
− | + | document.addEventListener('DOMContentLoaded', function() { | |
− | + | ||
var poems = document.querySelectorAll('.poem'); // Find all div elements with the class 'poem' | var poems = document.querySelectorAll('.poem'); // Find all div elements with the class 'poem' | ||
poems.forEach(function(poem) { // Loop through each poem element and format it | poems.forEach(function(poem) { // Loop through each poem element and format it | ||
سطر ٣٨: | سطر ٣٧: | ||
poem.innerHTML = parsePoem(poem.innerText, vWidth); | poem.innerHTML = parsePoem(poem.innerText, vWidth); | ||
}); | }); | ||
+ | }); | ||
+ | |||
+ | $(function () { | ||
var toggler = document.getElementsByClassName("treeBranch"); | var toggler = document.getElementsByClassName("treeBranch"); |
مراجعة ١٢:٥١، ١٩ فبراير ٢٠٢٤
/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */ 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(''); } document.addEventListener('DOMContentLoaded', function() { var poems = document.querySelectorAll('.poem'); // Find all div elements with the class 'poem' poems.forEach(function(poem) { // Loop through each poem element and format it var vWidth = poem.getAttribute('vWidth') || 350; // Verse width, default is for quads poem.innerHTML = parsePoem(poem.innerText, vWidth); }); }); $(function () { 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"); }); } }());