Cog
view release on metacpan or search on metacpan
share/js/cog.js view on Meta::CPAN
// TODO:
// - Add a url decoder/encoder
// $Cog is the Cog prototype object. You can use it anywhere to extend Cog.
$Cog = (Cog = function() {this.init()}).prototype = {
url_map: {},
setup_functions: [],
busy: false
};
$Cog.init = function() {
var funcs = this.setup_functions;
for (var i = 0, l = funcs.length; i < l; i++) {
funcs[i].apply(this);
}
};
$Cog.setup_functions.push(function() {
$('.site-navigation a._navigate')
.unbind('click')
.bind('click', this.bind('navigate'));
});
$Cog.navigate = function(elem) {
var f = $(elem).attr('href').replace(/^#/, '');
this.bind(f)();
return false;
};
$Cog.dispatch = function(path) {
var map = this.url_map;
for (var i = 0, il = map.length; i < il; i++) {
var re = map[i][0];
var regex = new RegExp('^' + re + '$');
var method = map[i][1];
var args = map[i].splice(2);
var m = path.match(regex);
if (m) {
for (var j = 0, jl = args.length; j < jl; j++) {
args[j] = args[j].replace(/^\$(\d)$/, function(x, d) { return m[Number(d)] });
}
if (typeof this[method] == 'undefined')
throw "'" + method + "' method not found";
this[method].apply(this, args);
if (path.length > 1) {
$.cookie("last_url", path, {path:'/'});
}
return;
}
}
$('div.content').jemplate('404.html');
return;
};
$Cog.redirect = function(url) {
location = url;
};
$Cog.home_page = function() {
this.redirect('/page/' + this.config.home_page_id);
};
$Cog.page_display = function(id) {
var self = this;
$.getJSON('/view/' + id + '.json', function(data) {
$('div.content').jemplate('page-display.html', data);
$.get('/view/' + id + '.html', function(data) {
$('div.page').html(data);
( run in 1.788 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )