Jump to content

User:Shyamal/common.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Shyamal (talk | contribs) at 16:01, 10 December 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
importScript('User:Ucucha/HarvErrors.js');
/*importScript('User:William Avery/taxoboxalyzer.js');*/
/* importScript( 'meta:User:SuperHamster/view-it.js' ); */
importScript('User:Jts1882/taxonomybrowser2.js');
importScript('User:Harej/citation-watchlist.js');
importScript('User:NKohli_(WMF)/megawatch.js');

// Add a "Codex Widgets" portlet to the main menu
mw.util.addPortlet( 'p-codex', 'Codex Widgets', '#p-interaction' );
const dialogTrigger = mw.util.addPortletLink( 'p-codex', '#', 'Example Dialog Widget', 'p-codex-dialog' );

mw.loader.using( '@wikimedia/codex' ).then( function( require ) {
	const Vue = require( 'vue' );
	const Codex = require( '@wikimedia/codex' );
	const mountPoint = document.body.appendChild( document.createElement( 'div' ) );
	
	Vue.createMwApp( {
		data: function() {
			return {
				showDialog: false,
				count: 0,
				codexLink: 'https://doc.wikimedia.org/codex/latest/'
			};
		},
		template: `
			<cdx-dialog v-model:open="showDialog"
				title="Hello from Codex"
				close-button-label="Close"
				:default-action="defaultAction"
				@default="open = false"
			>
				<p>This Dialog component comes from Codex, the new design system for Wikimedia.</p>
				<p>To learn more about Codex, check out the documentation <a :href="codexLink" target="_blank">here.</a></p>
				<hr />
				<p>Click these buttons to update the reactive count value:</p>
				<p>Count: {{ count }}</p>
				<p>
					<cdx-button action="destructive" @click="decrement">Decrease</cdx-button>
					<cdx-button action="progressive" @click="increment">Increase</cdx-button>
				</p>
			</cdx-dialog>
		`,
		methods: {
			openDialog () {
				this.showDialog = true;
			},
			increment() {
				this.count++;
			},
			decrement() {
				this.count--;
			}
		},
		mounted() {
			dialogTrigger.addEventListener( 'click', this.openDialog );
		},
		unMounted() {
			dialogTrigger.removeEventListener( this.openDialog );
		}
	} )
	.component( 'cdx-button', Codex.CdxButton )
	.component( 'cdx-dialog', Codex.CdxDialog )
	.mount( mountPoint );
} );