«ميدياويكي:Common.js»: الفرق بين المراجعتين
من Sudan Memory
سطر ٣٨: | سطر ٣٨: | ||
var vWidth = poem.getAttribute('data-vWidth') || 350; // Verse width, default is for quads | var vWidth = poem.getAttribute('data-vWidth') || 350; // Verse width, default is for quads | ||
poem.innerHTML = parsePoem(poem.innerText, vWidth); | poem.innerHTML = parsePoem(poem.innerText, vWidth); | ||
+ | poem.classList.remove('poem'); | ||
}); | }); | ||
مراجعة ١٥:١٣، ١٩ فبراير ٢٠٢٤
/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */ function splitTrailingText(input) { var regex = /^(.*?[\u0620-\u064Aa-zA-Z])([^\u0620-\u064Aa-zA-Z]*)$/; var matches = input.match(regex); if (matches && matches.length > 1) { var alphabeticPart = matches[1]; var nonAlphabeticPart = matches[2]; return { alphabeticPart: alphabeticPart, nonAlphabeticPart: nonAlphabeticPart }; } return { alphabeticPart: input, nonAlphabeticPart: '' }; } function parsePoem(text, vWidth) { var lines = text.split('\n'); var formattedLines = lines.map(function(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 var result = splitTrailingText(line.trim()); var alphabeticPart = result.alphabeticPart; var nonAlphabeticPart = result.nonAlphabeticPart; 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(''); } $(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('data-vWidth') || 350; // Verse width, default is for quads poem.innerHTML = parsePoem(poem.innerText, vWidth); poem.classList.remove('poem'); }); 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"); }); } }());