跳至内容

MediaWiki:Perbook/French.js

来自维基文库,开放的世界中开放的书籍
注意:保存后,更改可能不会立即生效。点击此处了解如何绕过浏览器的缓存。
  • Mozilla / Firefox / Safari:点击重新加载时按住Shift键,或按Ctrl-Shift-R(苹果 Mac 上为Cmd-Shift-R);
  • Internet Explorer:点击刷新时按住Ctrl键,或按Ctrl-F5
  • Konqueror:只需点击重新加载按钮或按F5
  • Opera用户可能需要在工具→首选项中完全清除其缓存。
// settings
if (window.frenchSettings === undefined) window.frenchSettings = { };
if (window.frenchSettings.englishVisibility === undefined) window.frenchSettings.englishVisibility = 'default'; // 'default', 'hidden', or 'visible';
if (window.frenchSettings.hiddenSectionVisibility === undefined) window.frenchSettings.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(' french-hidden-english')) {
        table.className = table.className.remove(' french-hidden-english');
        toggle.innerHTML = 'hide English';
    } else {
        table.className += ' french-hidden-english';
        toggle.innerHTML = 'show English';
    }
}
 
function addEnglishVisibilityToggle(table) {
    var toggleCell = table.insertRow(-1).insertCell(-1);
    toggleCell.colSpan = '6';
    toggleCell.className = 'french-english-visibility-toggle-cell';
 
    var toggle = document.createElement('span');
    toggle.innerHTML = 'hide English';
    toggle.onclick = function() { toggleEnglishVisibility(table, toggle); };
    toggle.className = 'french-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 = (frenchSettings.englishVisibility == 'hidden') || (frenchSettings.englishVisibility == 'default' && table.className.contains('french-hide-english-by-default'));
    if (hideEnglish) toggleEnglishVisibility(table, toggle);
}
 
function addEnglishVisibilityToggles() {
    var tables = document.getElementsByClassName('french-table french-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(' french-hidden')) {
        hiddenSection.className = hiddenSection.className.remove(' french-hidden');
        toggle.innerHTML = 'hide ▲';
    } else {
        hiddenSection.className += ' french-hidden';
        toggle.innerHTML = 'show ▼';
    }
}
 
function addHiddenSectionVisibilityToggle(hiddenSectionHeading) {
    var hiddenSectionId = hiddenSectionHeading.className.remove('french-section-heading french-hidden ');
    var hiddenSection = document.getElementById(hiddenSectionId);
    hiddenSection.className += ' french-section';
    
    var toggleContainer = document.createElement('span');
    toggleContainer.className = 'french-hidden-section-toggle-container';
    
    var toggle = document.createElement('span');
    toggle.innerHTML = 'hide ▲';
    toggle.onclick = function() { toggleHiddenSectionVisibility(hiddenSection, toggle); };
    toggle.className = 'french-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 = (frenchSettings.hiddenSectionVisibility != 'hidden');
    if (startHidden) toggleHiddenSectionVisibility(hiddenSection, toggle);
}
 
function addHiddenSectionVisibilityToggles() {
    var sectionHeadings = document.getElementsByClassName('french-section-heading french-hidden');
    for (var i = 0; i < sectionHeadings.length; i++)
        addHiddenSectionVisibilityToggle(sectionHeadings[i]);
}
 
$(addHiddenSectionVisibilityToggles);
// /supplementary section visibility toggle
华夏公益教科书