MediaWiki:Bestiary/Code.js

// /*jslint devel: true, browser: true, white: true, indent: 2, plusplus: true, bitwise: true*/ /*global $, wgUserName, mw */ $(window).load(function {   //__NOWYSIWYG__    /*General*/    'use strict';    (function { var get_creature_name_from_img_src = function (src) { var tokens, imgnamecomponents, name; tokens = src.split(/\//); /*            * All image links follow a similar pattern: tokens[7] contains image name. * Assumption: there are no slashes in the image name. * Assumption: there is only one extension separator (.) in the image name. * Example: Ancient_Amulet.gif */           imgnamecomponents = (tokens[7] || "").split("."); /* First element of the components corresponds to the image file, without the extension. */           name = decodeURIComponent(imgnamecomponents[0].replace(/_/g, ' ').toLowerCase); console.log(name); return name; },       bestiary_get_link_for_name = function(creature) { /* Filter out every image that doesn't match. We should be left with a jQuery object containing one element. * If we aren't, just get the first one anyway. */       /* Wikia's Lazy Loading functionality requires us to check data-src. If data-src doesn't exist, it may have already been processed, so        use the src as a fallback. This solves a rare issue of (usually a single) image not loading correctly. */        var $creature = $('#bestiary_list_img img').filter(function {             var $this = $(this), dataSrc;             dataSrc = $this.attr('data-src') || $this.attr('src');             if(dataSrc !== null) {                 return (get_creature_name_from_img_src(dataSrc) === creature.toLowerCase);                 }                }).first; return $creature.attr('data-src') || $creature.attr('src'); };   $('#bestiary_creature_img').html(        ''        ); });