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

@kiralt/bjax

v2.0.0-alpha.3

Published

Ajax link system for modern website. Convert any link in your page to ajax link.

Downloads

13

Readme

Welcome to Bjax 2.0

Ajax link system for modern website. Convert any link in your page to ajax link.

New V2 version on pure VanilaJS, lightweight and super fast!

Install

NPM

npm install @kiralt/bjax

Browser

<script src="https://unpkg.com/@kiralt/bjax/dist/bjax.full.js"></script>

In browser build, all funtions will be exported on window.Bjax.

Usage

Binding links

You can convert all links to Bjax links using bindLinks with a selector.

bindLinks('a')

Or you can bind on data-bjax selector.

bindLinks('[data-bjax]')

Loading part of a page

You can specify source and target using data attributes:

<a href="/" data-bjax data-source="#source" data-target="#target">My link</a>

Or you can specify that information when binding:

bindLinks('data-bjax', {
    source: '#source',
    target: '#target'
})

Also, you can use data-selector attribute or selector parameter to specify both target & source with one parameter.

Manually loading

You can load link manually using loadLink function.

loadLink('https://my.page/second-page', {
    target: '#part'
})

This will download whole page and insert it into element with part ID.

Bind manually

Using liveBind and loadLink you can customize bindings as much as you wish.

liveBind('[data-bjax]', 'click', function(event, element) {
    event.preventDefault()
    if (element instanceof HTMLAnchorElement) {
        loadLink(element.href, {
            selector: '#container'
        })
    }
})

Functions

loadLink(url, [options])

Downloads page from url and updates current page using downloaded HTML.

loadLink('https://my.page/second-page')

Options:

  • target - DOM selector where should be inserted downloaded page HTML (default is body).
  • source - DOM selected which indicates which part from downloaded page should be extracted (default is body).
  • selector - Overwrites both target and source (default: undefined).
  • shouldUpdateUrl - indicates if the url should be updated using url parameter using pushState (default is true).
  • loader - custom loader instance (default is empty loader - {}).
  • successCallback - callback which is called if the function finished the work without an error.
  • errorCallback - Callback which is called if the function had an error and failed to finish.

bindLinks(selector, [options])

Binds loadLink funtion on given selector using liveBind.

bindLinks('a[data-bjax]')

Supports all loadLink options.

Additional options:

  • url - target page URL, default is undefined and urlAttribute parameter is used.
  • urlAttribute - url parameter value, which is taken from clicked element (default is href).
  • targetAttribute - target parameter value, which is taken from clicked element (default is data-target).
  • sourceAttribute - source parameter value, which is taken from clicked element (default is data-source).
  • selectorAttribute - selector parameter value, which is taken from clicked element (default is data-selector).

liveBind(target, eventName, callback)

Listens eventName events on window object. Because it binds on window object, you can change inner DOM and it won't effect this bind at all.