Skip to content

michaelpapworth/jQuery.navigate

Repository files navigation

jQuery.navigate

An abstraction on site navigation wrapped up in a jQuery plugin. When using website analytics, window.location is not sufficient due to the referer not being passed on the request. The plugin resolves this and allows for both aliased and parametrised URLs. I also provide an API helper method, which enables quick and simple ReSTful URL building capability.

Build Status

The Setup

$(document).ready(function() {
	$.navigateSetup({
		api : '/api/',
		endpoints : {
			'home' : '/michaelpapworth',
			'myAwesomePlugin' : '/{user}/{repo}'
		}
	});
});

Usage

The examples below are based on the setup above, let's assume the root of the site is http://github.com.

How to navigate to the preconfigured endpoints?

// Address bar will read http://github.com/michaelpapworth
$.navigate('to', 'home');

// Address bar will read http://github.com/michaelpapworth/jQuery.navigate
$.navigate('to', 'myAwesomePlugin', { user : 'michaelpapworth', repo : 'jQuery.navigate' });

Want to navigate to a specific URL?

$.navigate('goTo', 'http://github.com/michaelpapworth/jQuery.navigate');	

What about your API?

$.ajax({ type : 'GET', url : $.navigate('api', 'resource', 123) })
	.done(function(data) {
		console.log('This data came from "http://github.com/api/resource/123"');
	});

I just want the URL?

// Just use the endpoints to build the URL for me
var homepageUrl = $.navigate('url', 'home');	

Want to roll your own or contribute?

  1. Fork this repository and create a new branch if you intend to contribute your work.
  2. Clone the branch to your computer.
  3. In the console cd jQuery.navigate && npm run-script build.
  4. Enable the build as you save your work npm start.

About

An abstraction on site navigation wrapped up in a jQuery plugin

Resources

License

Stars

Watchers

Forks

Packages

No packages published