Backpack.js is a lightweight Backbone extension for composing and structuring UI components, and was built by a couple of Airbnb Engineers.
Backpack's focus is to be a helper for storing and structuring decoupled, extensible UI components. Think of it as a roll-your-own YUI or jQuery UI, with components built with Backbone.Views. It's a micro-library that you build on as you go.
Your Backpack will come with some common UI components that you can easily extend. As you build out your app, you'll start throwing more components in your backpack. Then you just pull out the components you need when you need them.
This initial release is the result of our work abstracting components that we built for the Airbnb mobile site. We would like to open this initial release to the community to hear your thoughts and welcome contributions and ideas for its future.
Backpack is the global namespace everything gets attached too. Backpack also comes equiped with a ham radio. It extends Backbone.Events, so you have a global dispatcher/observer at your disposal.
Component is the base View which all Backpack.js components extend. It provides convenient helper methods for manipulating the component and it’s content, many of which follow a syntax similar to jQuery in that methods can be chained, or alternatively can be passed in upon initialization of the component.
Component provides the following convenience methods to all components:
render
show
hide
close
remove
before
after
append
prepend
content
setContent
parent
addClass
removeClass
css
name
slug
Tabs are a grouping of TabItems, responsible for automatically displaying the content associated with any given tab. Clicking on a TabItem automatically displays the content, and can also be extended to execute any number of given arbitrary functions.
Depending on the properties a Modal object is initialized with, they can be easily configured to provide two different experiences - Popups are notifications presented in the center of a user’s screen, and Lightboxes are notifications presented in a similar manner, with the exception that the background content becomes dim, drawing attention to the middle Modal.
Layout is a simple grid helper for component placement. Set the number of columns and gutter size and Layout will figure out the sizing of everything. No need to worry about class names or calculating widths.
It's easy to create components from existing libraries. Here's an example of how to create a Backpack component out of the Swipe.js library.
Backpack.js is still in it's early-days. We’re open-sourcing our progress thus far with the hope to continue to build Backpack.js with the help of the Backbone community.
Getting Started
git clone git@github.com:airbnb/backpack.js.git cd backpack.js && npm install
Cake Build Tools
cake compile # Compile CoffeeScript source files cake build # Creates /lib_path/Backpack-bundle.js & # /lib_path/Backpack-bundle.min.js & # /lib_path/js/*.js cake test # Opens Jasmine SpecRunner. Watches # BackpackSpec-Bundle.js for changes cake docs # Generate annotated source code # with Docco cake watch # Recompile CoffeeScript source files when # modified to Backpack-bundle.js cake watch:js # Recompile CoffeeScript source files when # modified to individual .js files
Testing
cake test.