Hashview v2.5

Dynamic view loading based on hash changes for mootools 1.4.x Works with mustache.js by janl.

Now with support for IE6 / IE 7.



Details

Author
Stéphane P. Péricat
Current version
v2.5
GitHub
stephanepericat/Hashview
Downloads
3930
Category
Utilities
Tags
Report
GitHub Issues

Releases


Dependencies

  • _self_/_current_: Core

How to use

1 - Create an HTML file, and add some mustache logic in it, such as this:

<!DOCTYPE html>
<html>
    <head>
        <title>Hashview</title>
        <link href="demo.css" type="text/css" rel="stylesheet" />
        <script type="text/javascript" src="./js/mootools-core-1.4.1.js"></script>
        <script type="text/javascript" src="./js/mustache.js"></script>
        <script type="text/javascript" src="./Source/hashview.js"></script>
    </head>
    <body>
        <div id="menu">
            <a href="./">home</a>
            <a href="./#about">about</a>
            <a href="./#contact">contact</a>
        </div>
        <div id="contents">
            {{#home}}
            <p>this is {{pageTitle}}</p>
            {{/home}}
            {{#about}}
            <p>all about {{who}}</p>
            {{/about}}
            {{#contact}}
            <p>my name is {{who}}</p>
            {{/contact}}
            {{#notfound}}
            <p>{{message}}</p>
            {{/notfound}}
        </div>
        <p id="footer">Powered by Hashview</p>
    </body>
</html>

2 - Then, define your hash routing with javascript:

window.addEvent('domready', function() {
    new Hashview({
        'wrapper': 'contents', //where the template blocks are
        'nav': 'menu',
        'views': {
            '/': ['home', {pageTitle: 'home'}], 
            '#about': ['about', {who: 'me me me'}],
            '#contact': ['contact', {who: 'Stephane'}],
            '#notfound': ['notfound', {message: 'Sorry, the page you requested could not be found.'}]
        }
    });
});

Default routes

- '/' : the route for the home page
- '#notfound': to throw a 404 page

License

The MIT License (MIT) Copyright (c) 2012 Stephane P. Pericat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Current Tested Compatibility

- IE 6+
- Chrome 6+
- Safari 5+
- Firefox 3.6+
- Opera 10.6+

Discuss

A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.

Found a bug in this plugin? Please report it this repository's Github Issues.

blog comments powered by Disqus