Difference between revisions of "MediaWiki:Gadget-HeadingLink.js"

From FloraWiki - das Wiki zur Schweizer Flora
Jump to: navigation, search
(Die Seite wurde neu angelegt: „// <syntaxhighlight lang="javascript"> /** * This JavaScript will be loaded only for some pages, see MediaWiki:Common.js * This program is free software; y…“)
 
m
Line 10: Line 10:
 
  * Author: A. Plank
 
  * Author: A. Plank
 
  * @description add a link of the section while hovering it  
 
  * @description add a link of the section while hovering it  
  * @requires jqueryEscapeId()
+
  * @requires $.jqueryEscapeId()
 
  * @requires $.jI18n
 
  * @requires $.jI18n
 
  * @requires $.resource()
 
  * @requires $.resource()
Line 16: Line 16:
 
/*jslint sloppy: true, indent: 2, white: true */
 
/*jslint sloppy: true, indent: 2, white: true */
 
/*global clearInterval: false, clearTimeout: false, document: false, event: false, frames: false, history: false, Image: false, location: false, name: false, navigator: false, Option: false, parent: false, screen: false, setInterval: false, setTimeout: false, window: false, XMLHttpRequest: false, $: false, mw: false */
 
/*global clearInterval: false, clearTimeout: false, document: false, event: false, frames: false, history: false, Image: false, location: false, name: false, navigator: false, Option: false, parent: false, screen: false, setInterval: false, setTimeout: false, window: false, XMLHttpRequest: false, $: false, mw: false */
switch (mw.config.get( 'wgNamespaceNumber' )) {
+
 
  case  0: // main namespace
+
(function () {
  case  1: // discussion namespace
+
  function init_HeadingLink () {
  case  2: // user namespace
+
    switch (mw.config.get( 'wgNamespaceNumber' )) {
  case 10: // template namespace
+
      case  0: // main namespace
  case 12: // help namespace
+
      case  1: // discussion namespace
  case 200: // portal namespace
+
      case  2: // user namespace
    if ($('h1,h2,h3,h4').length) {
+
      case 10: // template namespace
      $('h1,h2,h3,h4').mouseenter(function () {
+
      case 12: // help namespace
        hrefID = $(this).find('.mw-headline').attr('id'); hrefID = hrefID === 'undefined' ? false : hrefID;
+
      case 200: // portal namespace
        hasCurRevisionId = (mw.config.get( 'wgCurRevisionId') ? true : false);
+
        if ($('h1,h2,h3,h4').length) {
        tmpArtilePath   = (mw.config.get( 'wgServer') +  
+
          $('h1,h2,h3,h4').mouseenter(function () {
            mw.config.get( 'wgArticlePath').replace(/\$1/, mw.config.get( 'wgPageName')));
+
            var hrefID = $(this).find('.mw-headline').attr('id') === undefined ? false : $(this).find('.mw-headline').attr('id'),
        msgBoxHeadinglink = '<div id=linkmsg_' + hrefID + ' style=display:none class=js-messagebox >' +  
+
              hasCurRevisionId = (mw.config.get( 'wgCurRevisionId') ? true : false),
          ( $.jI18n.en.toolTipHeadingLinkHelp ? $.resource('toolTipHeadingLinkHelp') : '(1) Normal link to this head line or (2) the permanent link with version number:' ) +
+
              tmpArtilePath = (mw.config.get( 'wgServer') +  
          '<ol>' +  
+
                mw.config.get( 'wgArticlePath').replace(/\$1/, mw.config.get( 'wgPageName')));
            '<li>' + tmpArtilePath + ( hrefID ? '#' + hrefID : '' ) + '</li>' +
+
            if (hrefID) {
            ( hasCurRevisionId ? '<li>' + tmpArtilePath + '?oldid=' + mw.config.get('wgCurRevisionId') + ( hrefID ? '#' + hrefID : '' ) + '</li>' : '')  +
+
              msgBoxHeadinglink = '<div id=linkmsg_' + hrefID + ' style=display:none class=js-messagebox >' +  
          '</ol></div>';
+
                ( $.jI18n.en.HeadingLink_toolTipHeadingLinkHelp ? $.resource('HeadingLink_toolTipHeadingLinkHelp') : '(1) Normal link to this head line or (2) the permanent link with version number:' ) +
      $(this).append(' '
+
                '<ol>' +  
        + '<span ' +
+
                  '<li>' + tmpArtilePath + ( hrefID ? '#' + hrefID : '' ) + '</li>' +
          ' class="headinglink" ' +  
+
                  ( hasCurRevisionId ? '<li>' + tmpArtilePath + '?oldid=' + mw.config.get('wgCurRevisionId') + ( hrefID ? '#' + hrefID : '' ) + '</li>' : '')  +
          ' onclick="' +
+
                '</ol></div>';
            '$(this).parent().before( msgBoxHeadinglink );' +  
+
              if ( $(this).find('.headinglink').length === 0 ) {
            '$(jqueryEscapeId(\'#linkmsg_' + hrefID + '\'))' +  
+
                $(this).append(' '
              '.slideDown(\'slow\', function() {$(this).addClass(\'is-shown\');} )' +  
+
                + '<span ' +
              '.mouseleave (function () {if($(this).hasClass(\'is-shown\')) {$(this).slideUp(\'slow\', function () {$(this).remove();return false;});return false;} });' +  
+
                  ' class="headinglink noprint" ' +  
            '"' +
+
                  ' onclick="' +
          ' style="color:#CCCCCC; margin-left:0.2em;" ' +  
+
                    '$(this).parent().before( msgBoxHeadinglink );' +  
          ' title="' + ( $.jI18n.en.toolTipHeadingLink ? $.resource('toolTipHeadingLink') : 'Click to get a (permanent) link of this headline' ) + '" ' +  
+
                    '$($.jqueryEscapeId(\'#linkmsg_' + hrefID + '\'))' +  
          ' >'
+
                      '.slideDown(\'slow\', function() {$(this).addClass(\'is-shown\');} )' +  
        +  '<img src="http://species-id.net/o/media/f/f9/Button-sprite_link-pale.png"  style="vertical-align:middle;" width="16" height="16">'  
+
                      '.mouseleave (function () {if($(this).hasClass(\'is-shown\')) {$(this).slideUp(\'slow\', function () {$(this).remove();return false;});return false;} });' +  
        + '</span>');
+
                    '"' +
      }).mouseleave(function () {
+
                  ' style="color:#CCCCCC;position:absolute;left:-22px;margin-left: 0.2em;cursor: pointer;" ' +  
        $(this).find('span.headinglink').remove();
+
                  ' title="' + ( $.jI18n.en.HeadingLink_toolTipHeadingLink ? $.resource('HeadingLink_toolTipHeadingLink') : 'Click to get a (permanent) link of this headline' ) + '" ' +  
      });
+
                  ' >'
 +
                +  '<img src="http://species-id.net/o/media/f/f9/Button-sprite_link-pale.png"  style="vertical-align:middle;" width="16" height="16">'  
 +
                + '</span>');
 +
              }
 +
            }// if hrefID
 +
          })// mouseenter
 +
          .mouseleave(function () {
 +
            var $this=$(this);
 +
            $this.find('span.headinglink').fadeOut(3000);
 +
            setTimeout(function(){
 +
              $this.find('span.headinglink').remove();
 +
            }, 3500);
 +
          });
 +
        }
 +
        break;
 
     }
 
     }
    break;
+
  }// init_HeadingLink
}
+
  jQuery(document).ready(init_HeadingLink);
 +
})();
 
// </syntaxhighlight>
 
// </syntaxhighlight>

Revision as of 05:53, 29 April 2016

// <syntaxhighlight lang="javascript">
/**  
 * This JavaScript will be loaded only for some pages, see MediaWiki:Common.js
 * This program is free software; you can redistribute it and/or modify it under the terms of 
 * the EUPL v.1.1 or (at your option) the GNU General Public License as published by the Free 
 * Software Foundation; either GPL v.3 or (at your option) any later version. This program is  
 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the  
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General  
 * Public License (http://www.gnu.org/licenses/) for more details.  
 * Author: A. Plank
 * @description add a link of the section while hovering it 
 * @requires $.jqueryEscapeId()
 * @requires $.jI18n
 * @requires $.resource()
 */
/*jslint sloppy: true, indent: 2, white: true */
/*global clearInterval: false, clearTimeout: false, document: false, event: false, frames: false, history: false, Image: false, location: false, name: false, navigator: false, Option: false, parent: false, screen: false, setInterval: false, setTimeout: false, window: false, XMLHttpRequest: false, $: false, mw: false */

(function () {
  function init_HeadingLink () {
    switch (mw.config.get( 'wgNamespaceNumber' )) {
      case  0: // main namespace
      case  1: // discussion namespace
      case  2: // user namespace
      case 10: // template namespace
      case 12: // help namespace
      case 200: // portal namespace
        if ($('h1,h2,h3,h4').length) {
          $('h1,h2,h3,h4').mouseenter(function () {
            var hrefID = $(this).find('.mw-headline').attr('id') === undefined ? false : $(this).find('.mw-headline').attr('id'),
              hasCurRevisionId = (mw.config.get( 'wgCurRevisionId') ? true : false),
              tmpArtilePath = (mw.config.get( 'wgServer') + 
                mw.config.get( 'wgArticlePath').replace(/\$1/, mw.config.get( 'wgPageName')));
            if (hrefID) {
              msgBoxHeadinglink = '<div id=linkmsg_' + hrefID + ' style=display:none class=js-messagebox >' + 
                ( $.jI18n.en.HeadingLink_toolTipHeadingLinkHelp ? $.resource('HeadingLink_toolTipHeadingLinkHelp') : '(1) Normal link to this head line or (2) the permanent link with version number:' ) +
                '<ol>' + 
                  '<li>' + tmpArtilePath + ( hrefID ? '#' + hrefID : '' ) + '</li>' +
                  ( hasCurRevisionId ? '<li>' + tmpArtilePath + '?oldid=' + mw.config.get('wgCurRevisionId') + ( hrefID ? '#' + hrefID : '' ) + '</li>' : '')  +
                '</ol></div>';
              if ( $(this).find('.headinglink').length === 0 ) {
                $(this).append(' '
                 + '<span ' +
                   ' class="headinglink noprint" ' + 
                   ' onclick="' +
                     '$(this).parent().before( msgBoxHeadinglink );' + 
                     '$($.jqueryEscapeId(\'#linkmsg_' + hrefID + '\'))' + 
                       '.slideDown(\'slow\', function() {$(this).addClass(\'is-shown\');} )' + 
                       '.mouseleave (function () {if($(this).hasClass(\'is-shown\')) {$(this).slideUp(\'slow\', function () {$(this).remove();return false;});return false;} });' + 
                     '"' +
                   ' style="color:#CCCCCC;position:absolute;left:-22px;margin-left: 0.2em;cursor: pointer;" ' + 
                   ' title="' + ( $.jI18n.en.HeadingLink_toolTipHeadingLink ? $.resource('HeadingLink_toolTipHeadingLink') : 'Click to get a (permanent) link of this headline' ) + '" ' + 
                   ' >'
                 +  '<img src="http://species-id.net/o/media/f/f9/Button-sprite_link-pale.png"  style="vertical-align:middle;" width="16" height="16">' 
                 + '</span>');
              }
            }// if hrefID
          })// mouseenter
          .mouseleave(function () {
            var $this=$(this);
            $this.find('span.headinglink').fadeOut(3000);
            setTimeout(function(){ 
              $this.find('span.headinglink').remove();
            }, 3500);
          });
        }
        break;
    }
  }// init_HeadingLink
  jQuery(document).ready(init_HeadingLink);
})();
// </syntaxhighlight>