User:K599/Desmos.js

//Author: K599 / Kelvs599

//Code based on https://dev.fandom.com/wiki/MediaWiki:YoutubePlayer/code.js

//Loading this JavaScript allows Desmos graphs to be embedded. Go to your MediaWiki:Common.js, or wherever you're loading your JS, and either copy this page's code or insert the following line: //mw.loader.load('https://meta.miraheze.org/w/index.php?title=User:K599/Desmos.js&action=raw&ctype=text/javascript');

//You embed by inserting the following code: // //The full list of parameters is as follows: // //data-id: The ID of the graph, which is found after the "calculator/" in the graph's URL. //Default width and height is 500x500.

mw.hook('wikipage.content').add(function($content) {   $content.find('.desmos:not(.loaded)').each(function { var $this = $(this), data = $this.data, uri = new mw.Uri('https://www.desmos.com/calculator/');

uri.path += String(data.id || '').trim; uri.query = { embed: null };

$this.html(           $(' ', { src: uri.toString, style: 'width: ' + (typeof data.width === 'number' ? data.width + 'px' : String(data.width || '500px').trim) + '; height: ' + (typeof data.height === 'number' ? data.height + 'px' : String(data.height || '500px').trim) + ';', frameborder: '0' })       ).addClass('loaded'); }); });