User:MonkeysHK/common.js

mw.loader.using(['mediawiki.util', 'mediawiki.api'], function {

var that; var partialLoadTool = window.partialLoadTool = Object.assign(this, {		api: new mw.Api,		parsePage: function(pagename) {			return that.api.post({ action: "parse", contentmodel: "wikitext", page: pagename, formatversion: 2, });		},		buttonclick: function(event) {			event.preventDefault;			var $this = $(this);			var button = $this.parent;			$this.text('Loading...');			that.parsePage($this.attr("data-page"))			.done(function(d) { var out = $(" ", {					class: "partialLoaded",					html: d.parse.text,				}); button.after(out); button.remove; })			.catch(console.warn);		},		tabclick: function(event) {			event.preventDefault;			var $this = $(this);			that.parsePage($this.attr("data-page"))			.done(function(d) { $this.parents(".partialLoad-tabber").find(".partialLoad-frame").html(d.parse.text); })			.catch(console.warn);		},		makeButton: function(pagename) {			var button = $(' ', { class: "page-header__actions", style: "text-align: center; width: 100%; clear: both; display: block;", html: $('', {					class: "wds-button wds-is-text page-header__action-button has-label",					href: "/wiki/" + pagename,					html: "Load This Part Of Content",					"data-page": pagename,					click: that.buttonclick,				}), });			return button;		},		main: function {			$(".partialLoad-settings").each(function { var el = $(this); var data = JSON.parse(el.attr("data-tabs")); if (!data.tabs.length) return; if (data.tabs.length == 1) { el.after(that.makeButton(data.tabs[0].pagename)); el.remove; }				else { var tabLabels = $("", {						html: data.tabs.map(function(tab) { return $("", {								html: $("", { href: "/wiki/" + tab.pagename, text: tab.caption, "data-page": tab.pagename, "data-cache": tab.cache, "class": "partialLoad-labs__label", click: that.tabclick, }),								"class": "partialLoad-tabs__tab",							}); }),						"class": "partialLoad-tabs",					}); var tabFrame = $(" ", {						"class": "partialLoad-frame",					}); el.after($(" ", { html: [ tabLabels, tabFrame, ],						"class": "partialLoad-tabber", }));					el.remove; }			});		},	});

that = partialLoadTool; this.main; });