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

@cogizmo/sajax-content

v0.4.1

Published

Custom element that transcludes HTML content into the current HTMLDocument.

Downloads

40

Readme

<sajax-content>

Transcludes HTML content from an external HTML resource.

Usage

Fetch the HTML document and replace itself with the HTML body contents.

<sajax-content src="path/to/external.html" auto></sajax-content>

Installation

<sajax-content> is available on NPM and may be installed as a dependency.

> npm install @cogizmo/sajax-content
  1. Place the files on your server.

  2. Install the appropriate cogizmo/Cogizmo.

    • From npm
    > npm install @cogizmo/cogizmo
    • From github
  3. Add Cogizmo to your document <head>.

    <script src="path/to/Cogizmo.js"></script>
  4. Add <sajax-content> element to your document.

    <script src="path/to/sajax-content.js"></script>
  5. Use element whereever you want to transclude html.

    <sajax-content src="path/to/external.html"></sajax-content>

Declarative API (HTML)

auto attribute

Boolean

When true, will fetch the external HTML when a valid src attribute. When false, will wait until auto attribute is true or transclude is called.

True:

<sajax-content auto></sajax-content>

False:

<sajax-content></sajax-content>

select attribute

String<CSSSelector> = "*"

Determines which elements are transcluded from the external HTML document's <body>. Valid values are any selector that can be used as an argument for HTMLElement.querySelectorAll(). The following gets all <p>s that are children of elements with class="container".

<sajax-content select=".container > p"></sajax-content>

src attribute

String - Required

URL pointing to the desired external HTML document. URLs are calculated in relation to the current document.

<sajax-content src="path/to/external.html"></sajax-content>

Imperative API (JS/ES)

element.auto

Returns Boolean - ReadOnly

When true, will fetch the external HTML when a valid src attribute. When false, will wait until auto attribute is true or transclude is called.

element.select

Returns String<CSSSelector> = "*"

Determines which elements are transcluded from the external HTML document's <body>. Valid values are any selector that can be used as an argument for HTMLElement.querySelectorAll(). The following gets all <p>s that are children of elements with class="container".

element.src

Returns String - ReadOnly

URL pointing to the desired external HTML document. URLs are calculated in relation to the current document.

element.transclude()

Gets an external HTML document from src attribute, queries the document for the elements using the select attribute, and imports them into the current HTML document.

DOM Events

<sajax-content> events try to behave as close to native DOM as possible. This means that you may cancel <sajax-content>s default behavior without having to worry about order of listeners or hierarchy. There is a single limitation to maintain defaultable and cancelable behavior. do not add an event listener to <sajax-content> events on the window/global object.

response

Fires when transclude() has retrieved a URL successfully.

Detail: The response object containing the data retrieved by the URL.

sajax-success

Fires when the transclusion process has successfully retrieved elements from an HTML document.

Detail: The NodeList query results from the external HTML document. The nodes are not yet imported.

sajax-import

Fires when the transclusion process has imported the NodeList results.

Detail: An Array containing the imported nodes.

sajax-attach

Fires when the transclusion process has attached the imported nodes from the external HTML document.

Detail: An Array containing the attached nodes.