MediaWiki:BandcampLazyloader.js

/** * Name:       Bandcamp * Description: Adds wrappers around Bandcamp widgets that when *             clicked load the widget. Useful for soundtrack *             listing pages with a lot of Bandcamp widgets. * Author:     KockaAdmiralac <1405223@gmail.com> * Version:    v1.0 */ (function {   var Bandcamp = {        properties: {            bool: ['tracklist', 'minimal', 'transparent'],            hex: ['linkcol', 'bgcol'],            size: ['size', 'artwork'],            id: ['track', 'album']        },        init: function($content) {            $content.find('.Bandcamp').each($.proxy(this.setup, this));        },        setup: function(_, el) {            var $el = $(el);            $el.html(' ');            $el.find('svg').click($.proxy(this.load, this));        },        load: function(e) {            var $el = $(e.target).closest('.Bandcamp'),                data = $el.data, url = 'https://bandcamp.com/EmbeddedPlayer'; $.each(this.properties, $.proxy(function(k, v) { v.forEach(function(el) {                   if (data[el]) {                        url += '/' + el + '=' + this[k + 'Process'](data[el]);                    }                }, this); }, this)); $el.html(               $(' ', { src: url }).on('load', function { $el.find('img').remove; })           );            $el.append(                $(' ', { src: mw.config.get('stylepath') + '/common/images/ajax.gif' })           );            $el.addClass('loaded'); },       boolProcess: function(val) { return String(Boolean(val)); },       hexProcess: function(val) { return (/^(?:[0-9a-f]{3}|[0-9a-f]{6})$/i).test(val) ? val : '000000'; },       sizeProcess: function(val) { return ['small', 'big', 'large', 'none'].indexOf(val) === -1 ? 'small' : val; },       idProcess: function(val) { return Math.round(Number(val)); }   };    mw.hook('wikipage.content').add($.proxy(Bandcamp.init, Bandcamp)); });