Site News
Warning: This wiki contains spoilers. Read at your own risk!

Social media: If you would like, please join our Discord server, and/or follow us on Twitter (X) or Tumblr!

MediaWiki:Common.js: Difference between revisions

From Fire Emblem Wiki, your source on Fire Emblem information. By fans, for fans.
mNo edit summary
m (test)
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
importScript('MediaWiki:Tabs.js');
mw.loader.load( '/w/index.php?title=MediaWiki:Tabs.js&action=raw&ctype=text/javascript' );


// --------------------------------------------------------
// --------------------------------------------------------
// Test if an element has a certain class
// Test if an element has a certain class
// Description: Uses regular expressions and caching for better performance.
// Description: Uses regular expressions and caching for better performance.
// Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
// --------------------------------------------------------
// --------------------------------------------------------
   
   
Line 14: Line 13:
         };
         };
})();
})();
// --------------------------------------------------------
// addPurge
// adds a "purge" tab (after "watch")
// --------------------------------------------------------
jQuery(function ($) {
    if (wgAction != 'edit' && wgCanonicalNamespace != 'Special' && wgAction != 'history' && wgAction != 'delete' && wgAction != 'watch' && wgAction
    != 'unwatch' && wgAction != 'protect' && wgAction != 'markpatrolled' && wgAction != 'rollback' && document.URL.indexOf('diff=') <= 0
    && document.URL.indexOf('oldid=') <=0)
    { var hist; var url;
    if (!(hist = document.getElementById('ca-history') )) return;
    if (!(url = hist.getElementsByTagName('a')[0] )) return;
    if (!(url = url.href )) return;
    addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'),
                  'purge', 'ca-purge', 'Purge server cache for this page', '0');
}
});
//




Line 43: Line 23:
   if (document.getElementById('p-tb') && NSWithoutSubpages.indexOf(wgNamespaceNumber) == -1)
   if (document.getElementById('p-tb') && NSWithoutSubpages.indexOf(wgNamespaceNumber) == -1)
     {
     {
     var linkSubpages = '/Special:PrefixIndex/' + wgPageName + '/';
     var linkSubpages = '/wiki/Special:PrefixIndex/' + wgPageName + '/';
     addPortletLink('p-tb', linkSubpages, 'Subpages', 't-subpages', 'Subpages of this page');
     mw.util.addPortletLink('p-tb', linkSubpages, 'Subpages', 't-subpages', 'Subpages of this page');
     }
     }
});
});
//
//




Line 103: Line 81:
   return node;
   return node;
}
}
/**
* Name:        StrawpollIntegrator
* Author:      Fujimaru-kun
* Description: Allows intergration with Strawpoll polls
*/
mw.hook('wikipage.content').add(function($content) {
    if (!$content) {
        return;
    }
    $content.find('.strawpoll').each(function() {
        var $this = $(this),
            id = $this.attr('data-poll-id'),
            css = {
                width: 'inherit',
                height: 'inherit',
                border: 0
            };
        $this.html(
            $('<iframe>', {
                src: 'https://www.strawpoll.me/embed_1/' + id,
                css: css
            })
        );
    });
});

Latest revision as of 17:00, 21 July 2021

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.load( '/w/index.php?title=MediaWiki:Tabs.js&action=raw&ctype=text/javascript' );

// --------------------------------------------------------
// Test if an element has a certain class
// Description: Uses regular expressions and caching for better performance.
// --------------------------------------------------------
 
var hasClass = (function () {
        var reCache = {};
        return function (element, className) {
                return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
        };
})();


// --------------------------------------------------------
// addSubpages
// adds a 'subpages' link to the toolbox bar (excludes File, MediaWiki and Category namespaces)
// --------------------------------------------------------
jQuery(function ($) {
  var NSWithoutSubpages = new Array(-1, 6, 8, 14);
  if (document.getElementById('p-tb') && NSWithoutSubpages.indexOf(wgNamespaceNumber) == -1)
    {
    var linkSubpages = '/wiki/Special:PrefixIndex/' + wgPageName + '/';
    mw.util.addPortletLink('p-tb', linkSubpages, 'Subpages', 't-subpages', 'Subpages of this page');
    }
});
//


/*gotten from http://grifkuba.org/MotherEarthBoundWiki/index.php?title=MediaWiki:Common.js on 11/1/2010*/
/*
=== DOM creation ===
<pre>*/
/**
 * Create a new DOM node for the current document.
 *    Basic usage:  var mySpan = newNode('span', "Hello World!")
 *    Supports attributes and event handlers*: var mySpan = newNode('span', {style:"color: red", focus: function(){alert(this)}, id:"hello"}, "World, Hello!")
 *    Also allows nesting to create trees: var myPar = newNode('p', newNode('b',{style:"color: blue"},"Hello"), mySpan)
 *
 * *event handlers, there are some issues with IE6 not registering event handlers on some nodes that are not yet attached to the DOM,
 * it may be safer to add event handlers later manually.
**/
function newNode(tagname){

  var node = document.createElement(tagname);
  
  for( var i=1;i<arguments.length;i++ ){
    
    if(typeof arguments[i] == 'string'){ //Text
      node.appendChild( document.createTextNode(arguments[i]) );
      
    }else if(typeof arguments[i] == 'object'){ 
      
      if(arguments[i].nodeName){ //If it is a DOM Node
        node.appendChild(arguments[i]);
        
      }else{ //Attributes (hopefully)
        for(var j in arguments[i]){
          if(j == 'class'){ //Classname different because...
            node.className = arguments[i][j];
            
          }else if(j == 'style'){ //Style is special
            node.style.cssText = arguments[i][j];
            
          }else if(typeof arguments[i][j] == 'function'){ //Basic event handlers
            try{ node.addEventListener(j,arguments[i][j],false); //W3C
            }catch(e){try{ node.attachEvent('on'+j,arguments[i][j],"Language"); //MSIE
            }catch(e){ node['on'+j]=arguments[i][j]; }}; //Legacy
          
          }else{
            node.setAttribute(j,arguments[i][j]); //Normal attributes

          }
        }
      }
    }
  }
  
  return node;
}

/**
 * Name:        StrawpollIntegrator
 * Author:      Fujimaru-kun
 * Description: Allows intergration with Strawpoll polls
 */
 
mw.hook('wikipage.content').add(function($content) {
    if (!$content) {
        return;
    }
    $content.find('.strawpoll').each(function() {
        var $this = $(this),
            id = $this.attr('data-poll-id'),
            css = {
                width: 'inherit',
                height: 'inherit',
                border: 0
            };
        $this.html(
            $('<iframe>', {
                src: 'https://www.strawpoll.me/embed_1/' + id,
                css: css
            })
        );
    });
});