User:Jon Harald Søby/ordbokIframe.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
(function () {
	"use strict";

	if (mw.config.get( 'wgNamespaceNumber' ) !== 146) {
		return;
	}

	mw.hook("wikibase.entityPage.entityLoaded").add( function ( e ) {
		var language = e.language;
		if ( language === 'Q25167' || language === 'Q25164' ) {
			mw.loader.load( '//www.wikidata.org/w/index.php?title=User:Jon_Harald_Søby/ordbokIframe.css&action=raw&ctype=text/css', 'text/css' );
			var lemma,
				$placeholder = $( "<div />" )
					.css( { width: '100%', height: '80vh', padding: '35vh 0', 'text-align': 'center', 'box-sizing': 'border-box' } )
					.addClass( 'oo-ui-pendingElement-pending' )
					.text( 'Hover me!' ),
				$iframe = $( "<iframe />"),
				src = 'https://ordbokene.no/bm/search?q=';
			if ( language === 'Q25164' ) {
				lemma = e.lemmas.nn.value;
				src = 'https://ordbokene.no/nn/search?q=';
			} else {
				lemma = e.lemmas.nb.value;
			}
			$iframe.attr( 'allow', 'clipboard-read; clipboard-write' );
			$iframe.attr( 'src', src + lemma );
			$iframe.on( 'load', function() {
				$( 'body' ).focus();
			});
			$( '.wikibase-entityview-side' ).html( $placeholder );
			$placeholder.on( 'mouseover', function() {
				$placeholder.replaceWith( $iframe );
			} );
		}
	});
})();