npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wikipedia-preview

v1.10.0

Published

Shows Wikipedia article preview in a popup

Downloads

6,830

Readme

CI

Wikipedia Preview

Wikipedia Preview is a JavaScript component that allows you to provide context from Wikipedia about words or phrases on any website. It lets you show a popup card with a short summary from Wikipedia when a reader hovers over a link.

Tasks and issues are tracked on Phabricator.

Desktop | Mobile --- | --- |

Storybook: https://wikimedia.github.io/wikipedia-preview/main/storybook

Compatibility

Browsers | Versions --- | --- Chrome, Firefox, Opera, Edge | Current and previous version Internet Explorer | 11+ Safari | 5.1+ iOS | 6.1+ Android | 4.1+

Features

  • Works with any link that has an article on Wikipedia
  • Supports LTR and RTL languages
  • Works for articles with or without a lead image

Getting Started

Integrating Wikipedia Preview to your site consists of a three-step process:

  1. Loading wikipedia-preview.js (as a standalone script, WordPress plugin, or an npm dependency)
  2. Invoking wikipediaPreview.init( <options> )
  3. Annotating articles accordingly

You can read more about each step below. Once Wikipedia Preview is set up correctly, you should see the version information being logged in your JS console. You can also invoke wikipediaPreview.version() from your JS console to view version information at any time.

WordPress Plugin

A WordPress plugin providing a thin wrapper around Wikipedia Preview to simplify its integration and usage within WordPress is available on GitHub and WordPress.org.

Standalone Script

<script src="wikipedia-preview.umd.cjs"></script>
<script type="text/javascript">
  wikipediaPreview.init()
</script>

You can serve the file yourself or include it from unpkg.

NPM

$ npm install wikipedia-preview --save
const wikipediaPreview = require('wikipedia-preview')
wikipediaPreview.init()

Options of the init function

The init function accepts the following options:

Name | Type | Default | Description --- | --- | --- | --- root | string,Element,Element[] | document | Where to look for elements that should have the popup selector. Can be a selector to locate the root, a DOM Element, or an array of Elements selector | string | '[data-wikipedia-preview]' | How nodes that should have the popup are identified lang | string | 'en' | Default Wikipedia language popupContainer | DOM Element | document.body | Where to put the popup in the DOM detectLinks | Boolean | false | Allow Wikipedia hyperlinks to have the popup events | Object | {} | Custom event handlers: { onShow: <fn>, onWikiRead: <fn> } debug | Boolean | false | Shows the debug message when init() is called prefersColorScheme | string | 'detect' | Sets theme color. Allowed values are 'light', 'dark' and 'detect'. Setting it to 'light' or 'dark' will dictate theme color regardless of prefers-color-scheme; setting to 'detect' will render preview according to prefers-color-scheme.

Example (custom selector)

<p class="content">
	You can learn about <span class="wiki">Chat</span> and <span class="wiki">Chien</span> from Wikipedia.
</p>
<div class="popup-container"></div>
wikipediaPreview.init({
	root: document.querySelector('.content'),
	selector: '.wiki',
	popupContainer: '.popup-container',
	lang: 'fr'
});

Example (detect Wikipedia links)

<p class="content">
	You can learn about <a href="https://en.wikipedia.org/wiki/Chat">Chat</a> and <a href="https://en.wikipedia.org/wiki/Chien">Chien</a> from Wikipedia.
</p>
wikipediaPreview.init({
	detectLinks: true
});

Example (custom event handlers)

wikipediaPreview.init({
	events: {
		onShow: function(title, lang, type) {
			// call custom instrumentation here
		},
		onWikiRead: function(title, lang) {
			// call custom instrumentation here
		}
	}
});

Attributes

data-wikipedia-preview

To indicate that a word or expression should bring up the article preview popup, mark it with the data-wikipedia-preview attribute (or anything else as long as you're using the selector option described above).

data-wp-title

When the article title is not the same as the node's textContent property, use the data-wp-title attribute to specify the article title.

data-wp-lang

To use a language different than the language specified in the options, use the data-wp-lang attribute.

.wmf-wp-with-preview

To use the default trigger link styling:

  • Add the following link to the page header:
<link href="wikipedia-preview-link.css" rel="stylesheet">
  • Add the class wmf-wp-with-preview to the node

If you prefer to style them in a way that makes more sense for your context, simply don't include the wikipedia-preview-link.css link in the header and add your own class to the node. Both of these are valid ways:

[data-wikipedia-preview] {
	background-color: yellow;
}
.my-own-css-style {
	background-color: yellow;
}

CSS custom properties

If you wish to adjust the styling of the light/dark theme, you can override the following CSS custom properties to your liking as shown below, under the appropriate prefers-color-scheme query.

@media (prefers-color-scheme: dark) {
	.wikipediapreview {
		--wikipediapreview-primary-background-color: #202122;
		--wikipediapreview-secondary-background-color: #202122;
		--wikipediapreview-primary-color: #eaecf0;
		--wikipediapreview-filter-setting: invert(1);
	}
}

Acknowledgements/Contributors

This is heavily inspired by jquery.wikilookup and Page Previews.