MediaWiki:Common.js

Aus Open Source Ecology - Germany
Version vom 2. Juli 2022, 12:30 Uhr von Andreas Plank (Diskussion | Beiträge) (case 'Hilfe:Ältere_Literatur_auffinden': MediaWiki:SearchTools.js)
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Gehe zu Menü → Einstellungen (Opera → Einstellungen auf dem Mac) und dann auf Datenschutz & Sicherheit → Browserdaten löschen → Gespeicherte Bilder und Dateien.
/* Das folgende JavaScript wird für alle Benutzer geladen. */
/*
 * @requires: MediaWiki:Mw-customcollapsible.js
 * @requires: MediaWiki:WikiEditor-insert-Zitat.js
 */
 
/**
 * global resource string dictionary
 *
 * $.jI18n[iso-language-cod][resourceKey], e.g.
 * $.jI18n = { 
 *   en: { CollapseBox_captionCollapse : '(show less)' },
 *   de: { CollapseBox_captionCollapse : '(weniger anzeigen)' }
 * };
 * 
 * Nomenclature proposal: if an extra plugin is used, strings can be designated by prefixing them:
 * “plugin_toolTipSomthing” otherwise just “toolTipSomthing” (global string). So it’s more clear if
 * a string is intended to be global or plugin specific.
 * @augments $
 * @type object
 */
$.jI18n = {
  de: {
    CollapseBox_captionCollapse :        ' (weniger anzeigen) ',
    CollapseBox_captionExpand :          ' (mehr...) ',
    CollapseBox_toolTipCollapse :        '(klicken um Zusatzinformationen zu verbergen)',
    CollapseBox_toolTipExpand :          '(klicken um Zusatzinformationen anzuzeigen)'
  },
  en: {
    CollapseBox_captionCollapse :        ' (show less) ',
    CollapseBox_captionExpand :          ' (more...) ',
    CollapseBox_toolTipCollapse :        '(click to hide information below)',
    CollapseBox_toolTipExpand :          '(click to show more information below)'
  }
};
/**
 * @description Get resource string (e.g. text messages, image URLs) for a given language, based on a string-key
 *  If no resource is defined in a given language for a resource key, the resource for 'en' will be returned,
 *  if this is missing as well an error message is returned “MISSING RESOURCE: ...”.
 * @augments $
 * @requires mw.config for getting global variables
 * @requires $.jI18n global language resource keys and their translated strings
 * @param {string} resourceKey key for the resource
 * @returns {String}
 */
$.resource = function (resourceKey) {
  var lang = mw.config.get('wgUserLanguage').split('-')[0]; // language: 'pt-BR', 'de-formal', etc.
  return ($.jI18n[lang] && $.jI18n[lang][resourceKey] ?
      $.jI18n[lang][resourceKey] :
      ($.jI18n.en[resourceKey]) ? $.jI18n.en[resourceKey] : 'MISSING RESOURCE: no $.jI18n.en.' + resourceKey + ' defined.');
};


/**
   @description indicates form elements created by template:Hidden
  having class indicateHiddenInputs or other fields

   structure of template:Hidden:
   div.mw-collapsible
    └ div.mw-collapsible-content.indicateHiddenInputs

   @return null|true
 */
window.markHiddenFormFields = function () {
  "use strict";
  var jDivHiddenFormTexts = $(
    // select all inputs that have definite values
      'div.mw-collapsible-content.indicateHiddenInputs * input'
    ).filter(
      function () { return this.value.length > 0 }
    )
    .add(
    // select only textarea not being empty
      'div.mw-collapsible-content.indicateHiddenInputs * textarea:not(:empty)'
    ),
    /*
    pale orange:
    hsv →  36 20 99 36 10 99  36 05 99
           #fce8ca  #fcf2e3   #fcf7f0
    pale yellow
    hsv → 50 18 100  50 10 100
          #fff7d0    #fffbe6
    */
    bgcolor =       {'background-color':'#fffbe6'},
    bgcolor_darker = {'background-color':'#fff7d0'};

// <div>
  if (jDivHiddenFormTexts.length) {
    jDivHiddenFormTexts
      .closest(".mw-collapsible")
      .css({'border-left': '2px solid #ce5c00'})
      .find(".mw-collapsible-toggle")
      .css(bgcolor_darker);
    //indicate the fields itself
    jDivHiddenFormTexts
      .css(bgcolor); //pale orange
    return true;
  } else {
    return null;
  }
// <td> implement in Template:Hidden
}; // markHiddenFormFields()

/**
 * @description create jQuery UI Tabs on CSS class="use-jquery-ui-tabs"
 *
 * @requires https://www.mediawiki.org/wiki/Extension:Semantic_Forms
 * @requires jQuery-UI mw.loader.using( 'jquery.ui.tabs', function () {});
 * @returns {undefined}
 */
window.initUiTabsInForms = function () {
  console.log('initUiTabsInForms');
  var use_jquery_ui_tabs= $('.use-jquery-ui-tabs');
  var use_jquery_ui_tabs_vertical= $('.use-jquery-ui-tabs-vertical');
  if (use_jquery_ui_tabs.length || use_jquery_ui_tabs_vertical.length) {
    mw.loader.using( 'jquery.ui.tabs', function () {
      var use_jquery_ui_tabs= $('.use-jquery-ui-tabs');// Google Chrome Fix
      var use_jquery_ui_tabs_vertical= $('.use-jquery-ui-tabs-vertical');// Google Chrome Fix
      console.log('initUiTabsInForms mw.loader.using');
      if ($('.use-jquery-ui-tabs').length) {
        $('.use-jquery-ui-tabs').tabs({event: 'mouseover', show: { duration: 800 }, hide: { duration: 800 } });
        console.log('initUiTabsInForms tabs');
      }
      if (use_jquery_ui_tabs_vertical.length) {
        use_jquery_ui_tabs_vertical.tabs({event: 'mouseover', show: { duration: 800 }, hide: { duration: 800 } }).addClass( 'ui-tabs-vertical ui-helper-clearfix' );
        use_jquery_ui_tabs_vertical.find( 'li' ).removeClass( 'ui-corner-top' ).addClass( 'ui-corner-left' );
        console.log('initUiTabsInForms tabs_vertical');
      }
    });
  }
};

///////////////////////
// Load scripts page specific:
switch (mw.config.get( 'wgPageName' )) { // Minimize the pages on which the code will be loaded
  case 'Hilfe:Gemeinfreie_Patente_(Public_Domain)':
  case 'Hilfe:Ältere_Literatur_auffinden':
  case 'Benutzer:Andreas_Plank/Hilfe_–_Gemeinfreie_Patente_(Public_Domain)':
  case 'Benutzer:Andreas_Plank/Verlorene_Wörter_wiederfinden':
  case 'Benutzer:Andreas_Plank/Sandkasten':
  case 'Benutzer:Andreas_Plank/Sandkasten2':
  case 'Benutzer:Andreas_Plank/Testen':
    mw.loader.load( mw.config.get('wgScriptPath') + '/index.php?title=MediaWiki:SearchTools.js&action=raw&ctype=text/javascript' );
  break;
};
///////////////////////

// click-text modifications for mw-customcollapsible triggering from outside of mw-collapsible
mw.loader.load( mw.config.get('wgScriptPath') + '/index.php?title=MediaWiki:Mw-customcollapsible.js&action=raw&ctype=text/javascript' );

switch (mw.config.get('wgAction')) {
  case 'edit':
  case 'submit':
    // Wizard to insert template:Zitat
    mw.loader.load( mw.config.get('wgScriptPath') + '/index.php?title=MediaWiki:WikiEditor-insert-Zitat.js&action=raw&ctype=text/javascript' );
  break;
}
jQuery(document).ready(function($) {
  if(mw.config.get( 'wgAction' )==='formedit'
  || mw.config.get( 'wgCanonicalSpecialPageName' )==='FormEdit'){
    markHiddenFormFields();
    initUiTabsInForms();
  }
});