User:Readyokaygo/per book/Intensive Hebrew.js

// settings if (window.intensivehebrewSettings === undefined) window.intensivehebrewSettings = { }; if (window.intensivehebrewSettings.englishVisibility === undefined) window.intensivehebrewSettings.englishVisibility = 'default'; // 'default', 'hidden', or 'visible'; if (window.intensivehebrewSettings.hiddenSectionVisibility === undefined) window.intensivehebrewSettings.hiddenSectionVisibility = 'default'; // 'default', 'hidden', or 'visible'; // /settings

// util String.prototype.contains = function(str) { return (this.indexOf(str) >= 0); }; String.prototype.remove = function(str) { return this.replace(str, ''); }; // /util

// english visibility toggle // Adds button to toggle visibility of English translations function toggleEnglishVisibility(table, toggle) { if (table.className.contains(' intensive-hebrew-hidden-english')) { table.className = table.className.remove(' intensive-hebrew-hidden-english'); toggle.innerHTML = 'hide English'; } else { table.className += ' intensive-hebrew-hidden-english'; toggle.innerHTML = 'show English'; } } function addEnglishVisibilityToggle(table) { var toggleCell = table.insertRow(-1).insertCell(-1); toggleCell.colSpan = '6'; toggleCell.className = 'intensive-hebrew-english-visibility-toggle-cell'; var toggle = document.createElement('span'); toggle.innerHTML = 'hide English'; toggle.onclick = function { toggleEnglishVisibility(table, toggle); }; toggle.className = 'intensive-hebrew-toggle'; var openParen = document.createElement('span'); openParen.innerHTML = '(';   var closeParen = document.createElement('span');    closeParen.innerHTML = ')'; toggleCell.appendChild(openParen); toggleCell.appendChild(toggle); toggleCell.appendChild(closeParen); var hideEnglish = (intensivehebrewSettings.englishVisibility == 'hidden') || (intensivehebrewSettings.englishVisibility == 'default' && table.className.contains('intensive-hebrew-hide-english-by-default')); if (hideEnglish) toggleEnglishVisibility(table, toggle); } function addEnglishVisibilityToggles { var tables = document.getElementsByClassName('intensive-hebrew-table intensive-hebrew-translations'); for (var i = 0; i < tables.length; i++) addEnglishVisibilityToggle(tables[i]); } $(addEnglishVisibilityToggles); // /english visibility toggle

// supplementary section visibility toggle // Adds show/hide button to supplementary sections function toggleHiddenSectionVisibility(hiddenSection, toggle) { if (hiddenSection.className.contains(' intensive-hebrew-hidden')) { hiddenSection.className = hiddenSection.className.remove(' intensive-hebrew-hidden'); toggle.innerHTML = 'hide ▲'; } else { hiddenSection.className += ' intensive-hebrew-hidden'; toggle.innerHTML = 'show ▼'; } } function addHiddenSectionVisibilityToggle(hiddenSectionHeading) { var hiddenSectionId = hiddenSectionHeading.className.remove('intensive-hebrew-section-heading intensive-hebrew-hidden '); var hiddenSection = document.getElementById(hiddenSectionId); hiddenSection.className += ' intensive-hebrew-section'; var toggleContainer = document.createElement('span'); toggleContainer.className = 'intensive-hebrew-hidden-section-toggle-container'; var toggle = document.createElement('span'); toggle.innerHTML = 'hide ▲'; toggle.onclick = function { toggleHiddenSectionVisibility(hiddenSection, toggle); }; toggle.className = 'intensive-hebrew-hidden-section-toggle'; var openParen = document.createElement('span'); openParen.innerHTML = '(';   var closeParen = document.createElement('span');    closeParen.innerHTML = ') '; toggleContainer.appendChild(openParen); toggleContainer.appendChild(toggle); toggleContainer.appendChild(closeParen); hiddenSectionHeading.insertBefore(toggleContainer, hiddenSectionHeading.firstChild); var startHidden = (intensivehebrewSettings.hiddenSectionVisibility != 'hidden'); if (startHidden) toggleHiddenSectionVisibility(hiddenSection, toggle); } function addHiddenSectionVisibilityToggles { var sectionHeadings = document.getElementsByClassName('intensive-hebrew-section-heading intensive-hebrew-hidden'); for (var i = 0; i < sectionHeadings.length; i++) addHiddenSectionVisibilityToggle(sectionHeadings[i]); } $(addHiddenSectionVisibilityToggles); // /supplementary section visibility toggle