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

jquery-externalize

v5.0.0

Published

Externalize is a jQuery plugin which unobtrusively adds external window creation to a bunch of links. It’s ridiculously small (< 1kB g’zipped).

Downloads

13

Readme

Externalize

Externalize is a jQuery plugin which unobtrusively adds external window creation to a bunch of links. It’s ridiculously small (< 1kB g’zipped).

Test Coverage Status MIT license

Why?

In the past I used XHTML 1.0 Strict which prohibited the target attribute. Whenever I had a client who wanted to open some links in a new window, I told them this, and I really did not want to switch to ugly Transitional doctypes. But most of the time they insisted on new windows, so I created a solution written in JavaScript which eventually became the one in this repository.

Now everybody uses HTML5 which is fine. You may go and use target again.

I for myself use this as a playground for writing and maintaining jQuery plugins. :-)

Install

Using npm:

npm install jquery-externalize

Using yarn:

yarn add jquery-externalize

Usage

Externalize is chainable and highly customizable (well, as customizable as it can get by now) by using these options:

  • name, sets the external window’s name (string, default: "external")
  • target, determines wether to use the target HTML attribute to support Firefox’s tab handling and Safari’s status bar info or not (boolean, default: true)
  • classes, applies CSS classes to an external link (string, default: "")
  • relation, applies a relationship to an external link (string, default: "external")
  • title, sets the text added as or appended to the title attribute to inform the user about an upcoming new window (string, default: "Opens in a new window")

Examples

The most common use case would be:

<p><a href="https://example.com/" title="example.com">Go to example site</a>

<script src="http://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
<script src="jquery.externalize.js"></script>
<script>
$('a[href*="//"]').externalize();
</script>

As a result we get a link that makes use of HTML5’s external relationship attribute and which features a descriptive title attribute in English and a plain old target attribute to open up a new window:

<p><a href="https://example.com/" rel="external" title="example.com (Opens in a new window)" target="external">Go to example site</a></p>

Another use case: Opening PDF files in a new window.

<p><a href="/download/sample.pdf">Download PDF</a>

<script src="http://code.jquery.com/jquery-3.6.0.slim.min.js"></script>
<script src="jquery.externalize.js"></script>
<script>
$('a[href$=".pdf"]').externalize({
  target: false
});
</script>

This becomes a link with an onClick event to open a new window:

<p><a href="/download/sample.pdf" rel="external" title="Opens in a new window">Download PDF</a></p>

License

MIT © Marc Görtz