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), $parent = $this.parents(".partialLoad-tabber"), $parenttab = $this.parents(".partialLoad-tabs__tab");			that.parsePage($this.attr("data-page"))			.done(function(d) { $parent.find(".selected").removeClass("selected"); $parenttab.addClass("selected"); $parent.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: $('', {					href: "/wiki/" + pagename,					html: "Load This Part Of Content",					"data-page": pagename,					click: that.buttonclick,					class: "wds-button wds-is-text page-header__action-button has-label",				}), });			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 = $(" ", {						class: "partialLoad-tabs__wrapper",						html: $("", { class: "partialLoad-tabs", html: data.tabs.map(function(tab) {								return $("", { class: "partialLoad-tabs__tab", html: $(" ", {										html: $("", { href: "/wiki/" + tab.pagename, text: tab.caption, "data-page": tab.pagename, "data-cache": tab.cache, click: that.tabclick, }),										class: "partialLoad-tabs__label",									}), });							}),						}),					});					var tabFrame = $(" ", {						class: "partialLoad-frame",					}); el.after($(" ", { class: "partialLoad-tabber", html: [ tabLabels, tabFrame, ],					}));					el.remove; var activeTabIndex = parseInt(data.activeTabIndex); if (isNaN(activeTabIndex) || activeTabIndex > data.tabs.length || activeTabIndex < 1) { console.warn("[PartialLoad/Tabview] One or more tabbers have invalid active tab index. It will be changed to first tab."); activeTabIndex = 0; }					else activeTabIndex--; tabLabels.find(".partialLoad-tabs__tab").eq(activeTabIndex).find("a").eq(0).trigger("click"); }			});		},	});

that = partialLoadTool; this.main; });