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

savvior

v0.6.1

Published

A Javascript multicolumn layout tool alternative to Masonry or Salvattore.

Downloads

945

Readme

Savvior

Build Status Code Climate Test Coverage

A Javascript solution for multicolumn layouts, an alternative to Salvattore or Masonry, without CSS driven configuration or absolute CSS positioning. A large part of the code is heavily inspired by the excellent Salvattore, however it fixes many of its quirks.

Features

  • Requirements: Savvior depends on on window.matchMedia and enquire.js.
  • Integrates easily: No automatic execution, init the script when YOU think it should happen. For further integration, custom events are dispatched after initialisation or redrawing the layout.
  • Sensible configuration: CSS-driven configuration can make parsing CSS on a CDN troublesome, just pass the element selector instead and a single config object to init() and it's done.
  • Lightweight: ~2.5 kB minified and gzipped
  • Wide browser support: most modern devices/browsers and IE9+

Installation

Install it via npm for your Browserify-based project

npm install savvior

Install it via Bower

bower install savvior

Or just grab the latest release from the Releases page

Usage

Please refer to the Examples for detailed usage information.

Add some CSS

Add some CSS to support the layout when multiple columns are created, e.g

.column { float: left; }
.size-1of2 { width: 50%; }
.size-1of3 { width: 33.33333%; }
.size-1of4 { width: 25%; }

These CSS classes will be added to your columns by default. If you need another classes, you can specify them in options as described in next sections.

Load the JavaScript

CommonJS

In your Browserify projects you can require the module as usual:

var savvior = require('savvior');

using AMD/Require.js

In your configuration:

// Configure paths
requirejs.config({
  paths: {
    enquire: 'path/to/enquire',
    savvior: 'path/to/savvior'
  }
});
```

Then in your project:

```js
require(['savvior', 'domReady!'], function(savvior) {
  // Initialise savvior here.
  //
  // Enquire is a dependency of savvior which should already be loaded by Require
  // You will need to load your own polyfills though.
});

Using a plain script tag

Just add these before your </body>.

<!--[if IE 9]>
<script src="/path/to/media-match.js"></script>
<![endif]-->
<script src="/path/to/enquire.min.js"></script>
<script src="/path/to/savvior.min.js"></script>

Initialise

  savvior.init("#myGrid", {
    "screen and (max-width: 20em)": { columns: 2 },
    "screen and (min-width: 20em) and (max-width: 40em)": { columns: 3 },
    "screen and (min-width: 40em)": { columns: 4 },
  });

Grid items can be excluded by using filter in the options. This takes a string consumable by document.querySelectorAll(). This is processed in each mediaMatch breakpoint, examples:

  savvior.init("#myGrid", {
    "screen and (max-width: 20em)": {
      columns: 2,
      filter: '#excludeme'
    },
    "screen and (min-width: 20em) and (max-width: 40em)": {
      columns: 3,
      filter: '#excludeme, .filter-these-as-well'
    },
    "screen and (min-width: 40em)": { columns: 4 },
  });

Also, you can specify which CSS classes will be applied to columns on each media query, examples:

  savvior.init("#myGrid", {
    "screen and (max-width: 20em)": {
      columns: 2,
      columnClasses: 'mobile-columns mobile-columns-one-half' // as a string
    },
    "screen and (min-width: 20em) and (max-width: 40em)": {
      columns: 3,
      columnClasses: ['tablet-columns', 'tablet-columns-1-3'] // as an array
    },
    "screen and (min-width: 40em)": { columns: 4 }, // default classes "column size-1of4"
  });

Get status

  savvior.ready();
  // returns ["#myGrid"]
  savvior.ready("#myGrid");
  // returns true

Destroy

  // destroy all instances
  savvior.destroy();
  // destroy specific instances
  savvior.destroy(["#myGrid", "#anotherGrid"]);

Add elements to a grid

  // Set some options, defaults are:
  var options = {
    method: 'append' // One of 'append', or 'prepend'.
    clone: false // Whether to clone elements or move them.
  };
  var someItems = document.querySelectorAll('.new-items');
  savvior.addItems('#myGrid', someItems, options, function (grid) {
    // All done by now.
    console.log(grid);
  });

History of changes

See CHANGELOG

Contributing

If you find an bug or a problem please open an issue.

This project uses Grunt for running the builds and tests. The module uses an UMD wrapper to retain compatibility with CommonJS and AMD module formats. Tests are run via Jasmine in PhantomJS.

Install the development environment

To install the development dependencies, make sure you have nodejs installed, then:

  1. Install grunt-cli with npm i grunt-cli -g
  2. Install development dependencies with npm i
  3. Build the project by running grunt

Pull requests for new features or bug fixes are most welcome, just make sure it conforms the current coding style of the project.

Development

Project led and maintained by Attila Beregszaszi

Development sponsored by Dennis Publishing and Front Seed Labs