Difference between revisions of "MediaWiki:Common.js"

From FloraWiki - das Wiki zur Schweizer Flora
Jump to: navigation, search
(+$:resourc)
 
m (importScript("MediaWiki:Mw-customcollapsible.js");)
Line 67: Line 67:
 
       $.jI18n[lang][resourceKey] :
 
       $.jI18n[lang][resourceKey] :
 
       ($.jI18n.en[resourceKey]) ? $.jI18n.en[resourceKey] : "MISSING RESOURCE: no $.jI18n.en." + resourceKey + " defined.");
 
       ($.jI18n.en[resourceKey]) ? $.jI18n.en[resourceKey] : "MISSING RESOURCE: no $.jI18n.en." + resourceKey + " defined.");
  };
+
};
 +
 
 +
// click-text modifications for mw-customcollapsible triggering from outside of mw-collapsible
 +
importScript("MediaWiki:Mw-customcollapsible.js");

Revision as of 18:14, 19 January 2015

/*
 * @requires: MediaWiki:Mw-customcollapsible.js
*/

/*global jQuery, document, screen, window, location, navigator, unescape, Image, clearTimeout, addOnloadHook, importScript, setTimeout, appendCSS, mw */ 
/* = settings for JSLint */
/* should go into mw.config: wgPageName, wgServer, wgScript, wgAction, wgCanonicalNamespace */
"use strict"; // set ECMAScript 5 Strict Mode

/**
 * @description: helper function to escape jQuery IDs
 * @param {string} myid HTML ID
 * @returns {@exp;myid@call;replace|String}
 */ 
function jqueryEscapeId(myid) {
  if(myid.substr(0, 1) === "#"){
    return myid.replace(/(:|\.)/g,'\\$1');
  } else {
    return '#' + myid.replace(/(:|\.)/g,'\\$1');
  }
}

/**
 * @namespace resource string dictionary
 * 
 * Note: Commons uses collapse/expand ▲/▼, but this looks better in strict box
 * layouts that in the free-wrapping key statements
 * 
 * Nomenclature proposal: if an extra plugin is used, strings can be designated as
 * “plugin_toolTipSomthing” otherwise just “toolTipSomthing” (global string). So it’s more clear if
 * somebody wants to deactivate a plugin and remove strings from the resource dictionary.
 * @augments $
 * @type object
 */
$.jI18n = {
  en: {
    captionCollapse :        " (show less) ",
    captionExpand :          " (more...) ",
    toolTipCollapse :        "(click to hide information below)",
    toolTipExpand :          "(click to show more information below)",
  },
  de: {
    captionCollapse :        " (weniger anzeigen) ",
    captionExpand :          " (mehr...) ",
    toolTipCollapse :        "(klicken um Zusatzinformationen zu verbergen)",
    toolTipExpand :          "(klicken um Zusatzinformationen anzuzeigen)",
  },
  it: {
    captionCollapse :        " (mostra di meno) ",
    captionExpand :          " (più...) ",
  }
};


/**
 * @description Get resource string (text, 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.
 * @augments $
 * @requires mw.config for getting global variables
 * @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.");
 };

// click-text modifications for mw-customcollapsible triggering from outside of mw-collapsible
importScript("MediaWiki:Mw-customcollapsible.js");