User:Sohom Datta/openseadragon minimap.js

From Wikisource
Jump to navigation Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Cmd-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (Cmd-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences

For details and instructions about other browsers, see Wikipedia:Bypass your cache.

// Demo script for changes to the ProofreadPage Openseadragon API in {{gerrit|852322}}
(function(){
	// We have our Openseadragon object here, so we can go ahead and hook into it's API
	function initialize( openseadragon ) {
		// Our objective is to add a minimap for Openseadragon
		// Based on the documentation at https://openseadragon.github.io/docs/OpenSeadragon.html#.Options
		// We effectively need to set showNavigator: true in the options.
		// We use the 'prp-osd-before-creation' hook to modify the parameters that will
		// be used to initialize Openseadragon.
		openseadragon.on( 'prp-osd-before-creation', function ( osdParams ) {
			osdParams['showNavigator'] = true;
		} );
		// In case Openseadragon has already been initialized, force it
		// to initialize again
		openseadragon.forceInitialize();
	}
	
	// We make sure that we are loading after 'ext.proofreadpage.page.edit'
	// (which initializes Openseadragon)
	mw.loader.using(['ext.proofreadpage.page.edit'], function () {
		if ( mw.proofreadpage.openseadragon ) {
			// We have already initialized Openseadragon here
			initialize( mw.proofreadpage.openseadragon );
		} else {
			// Alternatively wait for the 'ext.proofreadpage.osd-controller-available' hook to be fired
			// and then initialize our script
			mw.hook( 'ext.proofreadpage.osd-controller-available', function () {
				initialize( mw.proofreadpage.openseadragon );
			} );
		}
	});
})();