• Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Backbone view management and transitions

Backbone.ViewKit

Backbone.ViewKit is a Backbone plugin for managing views and view transitions, geared primarily toward mobile applications.

Note: This is very much still an experiment/work in progress. It has only been developed/tested in Chrome and Safari (desktop and iOS) at this point.

Demo

A demo (of the included example) is available here: http://fiddle.jshell.net/scttnlsn/xQxRY/show/. You can view/edit the code here: http://jsfiddle.net/scttnlsn/xQxRY/.

Backbone.ViewKit.ViewPort

A ViewPort is a Backbone.View responsible for rendering other views inside of it (one at a time) and serves as a base class for other Backbone.ViewKit classes. To build custom ViewPorts, override the getView method and return a Backbone.View. The returned view will be displayed inside the ViewPort when the ViewPort is rendered. ViewPorts can also optionally transition between views (see Backbone.ViewKit.Transition).

var foo = new Backbone.View({ el: $('<div>foo</div>') });
var bar = new Backbone.View({ el: $('<div>bar</div>') });
var baz = new Backbone.View({ el: $('<div>baz</div>') });

var CycleView = Backbone.ViewKit.ViewPort.extend({

    initialize: function() {
        this.index = 0;
        this.views = [foo, bar, baz];
    },

    getView: function() {
        var view = this.views[this.index];
        this.index = (this.index + 1) % this.views.length;
        return view;
    }

});

var cycle = new CycleView();
cycle.render(); // renders 'foo'
cycle.render(); // renders 'bar'
cycle.render(); // renders 'baz'
cycle.render(); // renders 'foo'

getView()

Returns the currently "active" view to be rendered in the view port.

render([transition])

Render the view returned from getView in the view port, optionally using the given transition. Emits an inview event on the view entering the viewport and an outview on the view exiting the viewport.

Backbone.ViewKit.ViewSelector

A ViewSelector is a ViewPort that manages an ordered set of views which can be selected and rendered one at a time.

var viewSelector = new Backbone.ViewKit.ViewSelector({ views: [foo, bar, baz] });

viewSelector.selectView(0); // renders 'foo'
viewSelector.selectView(1); // renders 'bar'
viewSelector.selectView(2); // renders 'baz'
viewSelector.selectView(3); // throws error

Views that are managed by the selector will be able to access the selector via this.viewSelector.

new Backbone.ViewKit.ViewSelector([options])

When creating a new view selector, optionally initialize it with an array of views and/or a default transition.

new Backbone.ViewKit.ViewSelector({
    views: [foo, bar, baz],
    transition: new Backbone.ViewKit.Transitions.Fade()
});

setViews(views)

Set the views that the selector will manage. This replaces all existing views with those given and clears the previously selected index.

viewSelector.setViews([foo, bar, baz]);

selectView(index, [transition])

Select the view at the given index and render it in the view port. Optionally specify a transition. Throws an error if the index is out of bounds. Emits a selected event passing the selected view and the index respectively.

Backbone.ViewKit.ViewStack

A ViewStack is a ViewPort that manages a stack of views. New views can be displayed by pushing them on to the stack and one can revert to previously displayed views by popping the stack.

var viewStack = new Backbone.ViewKit.ViewStack();

viewStack.pushView(foo); // renders 'foo'
viewStack.pushView(bar); // renders 'bar'
viewStack.popView(); // renders 'foo'
viewStack.pushView(bar); // renders 'bar'
viewStack.replaceView(baz); // renders 'baz'
viewStack.popView(); // renders 'foo'

Views that are pushed onto the stack will be able to access the stack via this.viewStack.

new Backbone.ViewKit.ViewStack([options])

When creating a new view stack, optionally specify any default transitions.

new Backbone.ViewKit.ViewStack({
    transitions: {
        push: new Backbone.ViewKit.Transitions.Slide(),
        pop: new Backbone.ViewKit.Transitions.Slide({ reverse: true })
    }
});

pushView(view, [transition])

Push the given view onto the stack and render it in the view port. Optionally specify a transition. Emits a pushed event passing the pushed view.

popView([transition])

Pop the current view off the top of the stack and render the previous view in the view port. Returns the popped view. Optionally specify a transition. Emits a popped event passing the popped view.

replaceView(view, [transition])

Replace the current view with the given view. This effectively pops the stack and pushes the given view as a single operation. Returns the replaced view. Optionally specify a transition. Throws an error if there is no view to replace. Emits a popped event (see above), pushed event (see above), and replaced event passing the pushed view and the popped view respectively.

Backbone.ViewKit.Transition

A Transition is responsible for handling the change between views returned by a ViewPort's getView method using CSS transitions. There are a number of method "hooks" that can be overridden to implement custom transitions- check out the source of the transitions bundled with Backbone.ViewKit for more details.

Backbone.ViewKit.Transitions.Slide

Slide (right to left by default) between views. Accepts various optional parameters:

new Backbone.ViewKit.Transitions.Slide({
    reverse: false, // right to left
    duration: 0.4, // seconds
    easing: 'ease-out',
    delay: 0 // seconds
});

Backbone.ViewKit.Transitions.Fade

Crossfade between views. Accepts various optional parameters:

new Backbone.ViewKit.Transitions.Fade({
    duration: 0.4, // seconds
    easing: 'ease-out',
    delay: 0 // seconds
});

More Repositories

1

dandelion

Incremental Git repository deployment.
Ruby
737
star
2

backbone.io

Backbone.js sync via Socket.IO
540
star
3

data.io

Bidirectional data syncing via Socket.IO
JavaScript
387
star
4

mubsub

Pub/sub for Node.js and MongoDB
JavaScript
310
star
5

monq

MongoDB-backed job queue for Node.js
JavaScript
185
star
6

queued

Simple HTTP-based queue server
Go
132
star
7

syphon

Immutable architecture for React/Flux applications
JavaScript
76
star
8

mongoose-acl

Mongoose ACL
JavaScript
61
star
9

jot

A mobile web app for your plain text notes
Clojure
34
star
10

bms

Battery management system for 4-series li-ion packs
C
34
star
11

cell-monitor

Battery cell monitor and balancer
C++
29
star
12

tree.js

JavaScript library for creating and manipulating hierarchical tree structures.
JavaScript
24
star
13

redblack.js

Red-black tree for Node.js and the browser
JavaScript
19
star
14

avr-twi

Nonblocking TWI/I2C master driver for Atmel AVR
C
18
star
15

cmcm

Cooperative multitasking for ARM Cortex-M microcontrollers
C
11
star
16

nettle

On-the-fly processing framework for Node.js and MongoDB
JavaScript
10
star
17

manacle.js

Lightweight ACL for Node.js and the browser
JavaScript
9
star
18

ina219

INA219 current/power monitor driver for Rust
Rust
5
star
19

pagoda

Reusable function stacks for Node.js and the browser
JavaScript
5
star
20

mongoose-denormalize

Bidirectional denormalization for your Mongoose models
JavaScript
5
star
21

emt

Express/Mongoose Toolkit
JavaScript
4
star
22

pack-monitor

Battery pack monitor
C++
4
star
23

blobstore

Content addressable blob store
Rust
4
star
24

cnc-tools

CNC tools for working with Gcode and Grbl
Python
3
star
25

require-hbt

An AMD loader plugin for Handlebars templates
JavaScript
3
star
26

broadcastd

Simple HTTP-based pubsub server
Go
3
star
27

modbus.cr

Modbus client library for Crystal
Crystal
2
star
28

gpio-socket

GPIO control via WebSocket
Clojure
2
star
29

stm32l0

Minimal development environment for STM32L0 using libopencm3
C
2
star
30

normal

Normalize nested data according to a relationship schema
Clojure
2
star
31

celeriac

State management for ClojureScript applications
Clojure
2
star
32

scthing

SuperCollider control interface for embedded devices
Rust
2
star
33

weedb

A wee database for Node.js built with LevelDB
JavaScript
2
star
34

routemachine

Stateful client-side router
JavaScript
2
star
35

node-queued

Queued client for Node.js
JavaScript
2
star
36

daffy

A minimal Scheme interpreter written in Python.
Python
2
star
37

splitd

Splits newline-separated HTTP response body into multiple HTTP requests
Go
2
star
38

peerpipe

An auto-discoverable, encrypted network pipe for P2P data transfer
Rust
1
star
39

raisin

A Python library for storing, retrieving and indexing JSON objects in MySQL.
Python
1
star
40

queued-ruby

Queued client for Ruby
Ruby
1
star
41

kite

Another lightweight Python web framework.
Python
1
star
42

terrain

Opinionated toolkit for building CRUD APIs with Rails
Ruby
1
star
43

earle

A URL pattern parser for Django.
Python
1
star
44

pytest-trace

Save OpenTelemetry spans generated during testing
Python
1
star
45

cello

An append-only B+ tree with multiversion concurrency control.
Scala
1
star
46

decibel

Networked audio player services
JavaScript
1
star
47

emacs.d

My Emacs config
Emacs Lisp
1
star
48

rfm69-gateway

RFM69 Linux gateway
C
1
star
49

webaudio

Experiments with the Web Audio API
JavaScript
1
star
50

pgque

PostgreSQL job queue extension using advisory locks
PLpgSQL
1
star