MediaWiki:ArticlePreview/code.3.js

(function($, mw, config){   function ArticlePreview{        this._hooks(['dev.i18n', 'dev.colors', 'dev.wds'])            .add($.proxy(this.setup, this));    }    ArticlePreview.prototype.setup = function(i18no, colors, wds){        this.i18no = i18no;        this.i18n = null;        this.colors = colors;        this.wds = wds;        this.version = '2.4.0';        this.articlePath = mw.config.get('wgArticlePath');        this.pageName = mw.config.get('wgPageName');        this.groups = mw.config.get('wgUserGroups');        this.siteURL = mw.config.get('wgServer');        this.patterns = {};        this.patterns.wikiURL = /https?:\/\/(.+)\.(?:wikia|fandom)\.com/g;        this.patterns.longURL = /^https?:\/\/(.+)\.(?:wikia|fandom)\.com\/(?:(.*))/g;        this.patterns.shortURL = /\/(?:wiki\/|(?:index\.php&title\=))(.*)/g;        this.patterns.urlParam1 = /(.*)[?&](?:[a-z0-9])=(.*)/g;        this.patterns.urlParam2 = /[?&](?:[a-z0-9])=(.*)/g; this.patterns.dataImage = /data:image\/(?:.*)/g; this.currentSiteName = this.patterns.wikiURL.exec(this.siteURL)[1]; this.selectors = ['#WikiaRail .rail-module', '.mw-content-text']; this.geti18n; };   ArticlePreview.prototype.geti18n = function{ $.when(this.i18no.loadMessages('ArticlePreview')).done(function(i18n){           this.i18n = i18n;        }); };   ArticlePreview.prototype.getLinks = function(exceptions){ this.links = this.selectors.map(function(selector){           return selector + ' a';        }); var $links = $(this.links.join(', ')); if (Array.isArray(exceptions)){ return $links.filter(function(index){               return !($(this).is(exceptions.join(', ')));            }); } else return $links; };   ArticlePreview.prototype.isCurrentSite = function(url){ var siteName = this.patterns.longURL.exec(url)[1]; return (sitename === this.currentSiteName); };   ArticlePreview.prototype.isLong = function(url){ return this.patterns.longLink.test(url); };   ArticlePreview.prototype.isShort = function(url){ var end = this.patterns.shortLink.exec(url)[1], isParam = this.patterns.urlParam1.test(end); return (this.patterns.shortLink.test(url)) && !(isParam); };   ArticlePreview.prototype.shorten = function(url){ var result; if (this.isLong(url)){ result = '/' + this.patterns.longURL.exec(url)[1]; } else { result = url; }       return result; };   ArticlePreview.prototype.lengthen = function(url){ var result; if (this.isShort(url)){ result = this.siteURL + url; } else { result = url; }       return result; }; }(jQuery, mediaWiki, $.extend(this.ArticlePreview, {})));