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

xrayhtml

v2.3.0

Published

A plugin to easily show examples of components with the markup to use them.

Downloads

31

Readme

X-rayHTML

Filament Group

A little something to help build documentation pages.

Instead of dropping in a block of markup to render as a demo, then copying and pasting it into a pre/code block, then escaping it—then going back and updating both the rendered code and the escaped code should something change: now you just wrap the code you’re rendering in a div and it generates a copy/pastable source snippet. Credit to @ugomobi for the original idea, which is in use on the jQuery Mobile docs.

Dependencies

  1. jQuery or Shoestring (./libs)
  2. prism.js (./libs) (Optional)

Install

This plugin is available on npm as xrayhtml.

npm install xrayhtml

Demos

Here’s the plugin in action.

The second set of demos are using the plugin’s “create” event (create.xrayhtml by default, but configurable) to bolt on Prism.js syntax highlighting.

Getting Started

Download the production version or the development version, and the structural CSS.

In your page:

<script src="jquery.js"></script>
<script src="X-rayHTML.min.js"></script>

and

<link href="X-rayHTML.css" rel="stylesheet">

There are some config options up at the top of X-rayHTML.js:

 var pluginName = "xrayhtml",
        o = {
        text: {
            open: "View Source",
            close: "View Demo"
        },
        classes: {
            button: "btn btn-small",
            open: "view-source",
            sourcepanel: "source-panel"
        },
        initSelector: "[data-" + pluginName + "]",
        defaultReveal: "inline"
    }

By default, functionality is hooked to the xrayhtml data attribute.

flip as the value of the data-xrayhtml attribute will gives you a snazzy flip-to-reveal animation (browsers without support for 3D tranforms will simply show/hide the code snippet).

Leaving data-xrayhtml valueless or giving it a value of inline gives you—predictably enough—code snippets that are visible inline with the rendered code.

A pre/code block gets dropped into place, so whitespace inside of the element with that attribute counts the same way. For example, to avoid a bunch of extra whitespace at the start/end of your snippet:

<div data-xrayhtml><aside>
	<blockquote>
		<p>It is the unofficial force—the Baker Street irregulars.</p>
	</blockquote>
	<address>Sherlock Holmes</address>
	<cite>Sign of Four</cite>
</aside></div>

iframe support

You can load your examples into an iframe using the data-xrayhtml-iframe attribute. This is useful for examples that have media queries which depend on the viewport width and which may be in pages where the examples are not full width (e.g. when you have documentation navigation on the left).

<div data-xrayhtml data-xrayhtml-iframe="/xray.html">
  ...

Critically, the value of the attribute should point to a URL which serves a document that includes all of the necessary assets to handle the example properly.

That document must also include the xrayhtml-iframe.js found in the dist directory. The JS will listen for messages from the xrayhtml.js in the parent page to so that it can communicate dimensions for the iframe during initial load and also during resize events.

Following the example above, you might include the following in /xray.html

<!doctype html>
<html lang="en">
	<head>
		<!-- other assets to support code snippets go here -->
		<script src="xrayhtml-iframe.js"></script>
	</head>
	<body>
	</body>
</html>