Permalink
Browse files

Remove dependencies on Zepto and Routie, replaced with Yokuto and Ruto.

  • Loading branch information...
cheeaun committed Aug 8, 2013
1 parent aa4b123 commit e6b53a00034f62280c881ecc08ee9e37fc08bc8e
Showing with 308 additions and 1,310 deletions.
  1. +0 −2 Gruntfile.js
  2. +0 −201 assets/js/routie.js
  3. +104 −0 assets/js/ruto.js
  4. +160 −0 assets/js/yokuto.js
  5. +0 −248 assets/js/zepto/event.js
  6. +0 −792 assets/js/zepto/zepto.js
  7. +32 −26 index.html
  8. +11 −40 js/scripts.js
  9. +1 −1 js/scripts.js.map
@@ -15,8 +15,6 @@ module.exports = function(grunt) {
},
files: {
'js/scripts.js': [
'assets/js/zepto/zepto.js',
'assets/js/zepto/event.js',
'assets/js/*.js'
]
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,104 @@
/*!
* ruto.js, yet another simple hash router
*
* Copyright 2012, Lim Chee Aun (http://cheeaun.com/)
* Licensed under the MIT license.
* http://cheeaun.mit-license.org/
*/

(function(w){
var routes = [],
noop = function(){},
options = {
defaultPath: '/',
before: noop,
on: noop,
notfound: noop
};

var ruto = {
current: null,
previous: null,
config: function(opts){
for (var o in opts){
if (opts.hasOwnProperty(o)) options[o] = opts[o];
}
return ruto;
},
add: function(path, name, fn){
if (path && name){
if (typeof name == 'function'){
fn = name;
name = null;
}
routes.push({
path: path,
name: name,
fn: fn || function(){}
});
}
return ruto;
},
go: function(path){
location.hash = path;
return ruto;
},
back: function(path){
// Only 1-step back
if (ruto.previous){
history.back();
ruto.previous = null;
} else if (path){ // Fallback if can't go back
location.hash = path;
}
return ruto;
}
};

var hashchange = function(){
var hash = location.hash.slice(1),
found = false,
current = ruto.current;

if (!hash) hash = options.defaultPath;

if (current && current != ruto.previous){
ruto.previous = current;
}
ruto.current = hash;

for (var i=0, l=routes.length; i<l && !found; i++){
var route = routes[i],
path = route.path,
name = route.name,
fn = route.fn;
if (typeof path == 'string'){
if (path.toLowerCase() == hash.toLowerCase()){
options.before.call(ruto, path, name);
fn.call(ruto);
options.on.call(ruto, path, name);
found = true;
}
} else { // regexp
var matches = hash.match(path);
if (matches){
options.before.call(ruto, path, name, matches);
fn.apply(ruto, matches);
options.on.call(ruto, path, name, matches);
found = true;
}
}
}

if (!found) options.notfound.call(ruto);

return ruto;
};
ruto.init = function(path){
w.addEventListener('hashchange', hashchange);
return hashchange();
};
ruto.reload = hashchange;

w.ruto = ruto;
})(window);
Oops, something went wrong.

0 comments on commit e6b53a0

Please sign in to comment.