Really easy, CSS-based, location-driven display control for your elements.
npm install vista#### Vista uses generated CSS to provide declarative, URL-driven control of when (or how) any elements in your page are displayed, right from your HTML.
`` Foo Barhtml`
Show Foo And Hide Bar
Hide Foo And Show Bar
In a typical webapp, the URL loads a different page of HTML elements. But in a single page webapp, all elements live in the same page but only some are displayed at any one time. Vista makes it easy, even necessary, to keep that meaningful relationship between the URL and the elements that are displayed. After all, if you use the URL to control element display, you can't forget to update the URL. This means you always support the back button, deep linking, and bookmarks.
Vista lets you manage element display in a way that is simple, declarative, decoupled, and fast. Just add a vista="url-section-here" attribute to your element, and it will only be displayed when the URL has a section like that. Nothing else needed. If you want more complex URL tests, Vista lets you declare those in markup too. There's no manual display toggling, nor custom CSS, nor extra JavaScript to write. Vista works with frameworks or on its own. It has no dependencies, no known conflicts, and few constraints.
Try it out. In many cases, dynamic element display (unlike dynamic element content) is better managed in markup (which is display code, after all), without tight JavaScript coupling to routers, controllers, or renderers. With Vista, it's only between the URL and your
Download the [production version][min] or the [development version][max]. 
[NPM][npm]: npm install vista
[min]: https://raw.github.com/esha/vista/master/dist/vista.min.js
[max]: https://raw.github.com/esha/vista/master/dist/vista.js
[npm]: https://npmjs.org/package/vista
"Views" with Vista are defined by a name and a "test" for the current URL (optionally, a display style too). In many cases, that name and the test can be the same value, as in the quick example above. In other cases, you'll want a more complex URL test and need a simpler logical name.
#### Declarative Definition (best way):
Basic version (element is visible under a URL like 'http://example.com/simple.html'):
`html`...
Named test (visible under a URL like 'http://example.com?test_this=true'):
`html`...
Add a 2nd named, regexp test and a custom style:
`html`...
...
As you can see, multiple definitions can share the same element, as long as they are space-delimited.
It may be helpful to know that in the common case, where no custom display style is specified, the default style used is initial (with block as fallback for browsers that need it).
Also, note that definitions never need to be declared next to the elements they are controlling.
Your definitions can be placed anywhere. The
element is recommended.#### Programmatic Definition (if you really must):
The provided API is
Vista.define(name[, test[, style]]). Here are some examples:`javascript
// simple view, where the name and URL test value are the same
Vista.define('reports');// view with full RegExp to test if URL's full hash equals a chart
Vista.define('hasChart', /#(pie|bar)$/);
// view with a custom test function to which the URL is passed and an alternate style
Vista.define('special', function(url) {
// return a truthy value to pass the test or falsey to fail
return url.indexOf('special') > 0 || localStorage.getItem('special');
}, 'inline-block');
`Of course, only the last one actually must be done with JavaScript. Functions may not be defined as tests via markup at this time, though they may be supported (via reference) eventually.
Please note that when you define new tests programmatically, they are not automatically applied until the next time the location is updated. To force an immediate re-evaluation of all tests, call
Vista.update().$3
To show an element only when a test passes: