Savvior
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
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 = ;
using AMD/Require.js
In your configuration:
// Configure pathsrequirejs;``` Then in your project: ```js;
Using a plain script tag
Just add these before your </body>
.
<!--[if IE 9]><script src="/path/to/media-match.js"></script><![endif]-->
Initialise
savvior;
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;
Also, you can specify which CSS classes will be applied to columns on each media query, examples:
savvior;
Get status
savvior; // returns ["#myGrid"] savvior; // returns true
Destroy
// destroy all instances savvior; // destroy specific instances savvior;
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; savvior;
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:
- Install grunt-cli with
npm i grunt-cli -g
- Install development dependencies with
npm i
- 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