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

dorsal

v0.6.5

Published

HTML UI bootstrap and automation using CSS directives

Downloads

6,292

Readme

Dorsal

Build Status NPM version Code Climate

What is it?

TL;DR: An HTML decorator library.

Want to use JavaScript without writing it? Want your team to be able to use your BackboneJS or JavaScript components without manually initializing them? Well you and your team should use Dorsal!

Dorsal swims around your DOM in search of HTML that's hungry for delicious, delicious JavaScript. Dorsal scoops up those DOM elements and wires them up just by applying one class to your HTML. We were inspired by the directives system in Angular and wanted to bring something similar to our frontend stack here at Eventbrite.

Dorsal is platform agnostic, has no dependencies, and has been tested to work with IE8+, Firefox, Safari, and Chrome.

Setup

Dorsal is compatible with AMD, CommonJS, and namespaces.

  • CommonJS/Node: require('dorsal')
  • AMD: require('node_modules/dorsal/dist/dorsal')
  • Namespaces: window.Dorsal after adding src/dorsal.js as a script

Installation is easiest using npm: npm install dorsal --save

API

Register a plugin

The following is an example of a plugin and its usage. We define a Dorsal plugin named hello-world. Once wire is called Dorsal will query for .js-d-hello-world in the DOM and all occurances will be initialized.

<div class='js-d-hello-world'></div>

<script>
    Dorsal.registerPlugin('hello-world', {
        create: function(options) {
            console.log(this === options.el); // true
            options.el.innerHTML = 'Hello World';
            
            return options.el;
        },
        destory: function(options) {
            options.instance.innerHTML = '';
        }
    });

    Dorsal.wire()
</script>

Wiring

You don't need to wire your whole page. Dorsal.wire() accepts an element as an optional argument. If no element is provided it will use document as the parent and find all occurances within it.

<div class='js-d-other-plugin'></div>

<div class='some-arbitrary-parent-selector'>
    <div class='js-d-hello-world'></div>
    <div class='js-d-hello-world'></div>
    <div class='js-d-hello-world'></div>
</div>

<script>
    // if using jquery
    Dorsal.wire($('.js-d-other-plugin').get(0));
    Dorsal.wire($('.some-arbitrary-parent-selector').get(0));
</script>

Unwiring/Rewiring

Sometimes you'll want to rewire something if it changes dynamically and your plugin can't account for that. In that case, you should use rewire.

<div class='js-lorem-1 js-d-lorem' data-xd-wired="lorem">Lorem yay</div>

<div class='js-lorem-2 js-d-lorem' data-xd-wired="lorem">Lorem yay</div>

<script>
    // disable the first lorem
    Dorsal.unwire($('.js-lorem-1').get(0), 'lorem');

    // change the type of the second lorem to bacon
    $('.js-lorem-2').data('d-type', 'bacon');
    // replaces lorem ipsum with bacon ipsum
    Dorsal.rewire($('.js-lorem-2').get(0), 'lorem');
</script>

Deferred Promises

Dorsal plugins run asynchronously, preventing too much blocking on the page. To more easily determine when it completes, Dorsal returns a jQuery compatible deferred promise from the Dorsal.wire() and Dorsal.rewire() functions. Every plugin that runs will trigger a progress notification, providing the plugin's return value to all registered progress handlers. The promise will resolve once all plugins have been processed, triggering the done handlers.

<script>
    Dorsal.wire()
        .progress(function(pluginName, pluginResponse, dorsal) {
            alert('Plugin "' + pluginName + '" completed!');
        })
        .done(function(dorsal) {
            alert('Dorsal completed!');
        });
</script>

Arguments and Data Attributes

Sometimes you will want to pass options to your selectors. In such cases you can use data attributes.

<div
    class='js-d-hello-world'
    data-d-non-standard-hello-variant='bacon'
    data-d-prefix='Ohhhh, '
></div>

<script>
    Dorsal.registerPlugin('hello-world', {
        create: function(options) {
            console.log(options.data.nonStandardHelloVariant); // bacon

            var helloMap = [
                    bacon: 'Bacon world',
                    default: 'Hello world'
                ],
                variant = options.nonStandardHelloVariant || 'default',
                prefix = options.data.prefix || '';

            options.el.innerHTML = prefix + helloMap[variant];
            return el;
        },
        destroy: function(options) {
            options.instance.innerHTML = '';
        }
    });

    Dorsal.wire()
</script>

Examples

See it in action by opening examples/lorem.html. This use case automatically inserts Lorem ipsum wherever a .js-d-lorem class is used.

License

Copyright 2014 Eventbrite

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

See LICENSE.md.