Skip to content

Instantly share code, notes, and snippets.

@laukstein
Forked from 140bytes/LICENSE.txt
Created November 29, 2011 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laukstein/1403670 to your computer and use it in GitHub Desktop.
Save laukstein/1403670 to your computer and use it in GitHub Desktop.
Ajax SEO snippet in 140 bytes
var nav=$('a');
$.address.crawlable(1).state('/ajax-seo').init(function(){
nav.address();
}).change(function(e){
var content=$('#content'),
timer=window.setTimeout(function(){
content.html('Loading seems to be taking a while.');
},3800),clearTimeout=window.clearTimeout(timer);
$.ajax({
type:'GET',
url:'api'+(e.path.length!=1 ? '/'+encodeURIComponent(e.path.toLowerCase().substr(1)) : ''),
dataType:'json',
cache:true,
beforeSend:function(){
document.title='Loading...';
content.fadeTo(200,0.33);
},
success:function(data,textStatus,jqXHR){
clearTimeout;
nav.each(function(){
if($(this).attr('href')==(($.address.state()+decodeURI(e.path)).replace(/\/\//,'/'))){
$(this).addClass('selected').focus();
}else{
$(this).removeAttr('class');
}
});
document.title=data.title+' - Ajax SEO';
content.fadeTo(20,1).removeAttr('style').html(data.content);
if($.browser.msie){content.removeAttr('filter');}
},
error:function(jqXHR,textStatus,errorThrown){
clearTimeout;
nav.each(function(){
$(this).removeAttr('class');
});
document.title='404 Page not found';
content.fadeTo(20,1).removeAttr('style').html('<h1>404 Page not found</h1>\r<p>Sorry, this page cannot be found.</p>\r');
if($.browser.msie){content.removeAttr('filter');}
}
});
});
GPL and MIT LICENSE
{
"name": "Ajax SEO",
"description": "Ajax SEO maximized performance - speed, accessibility, user-friendly",
"keywords": [
"ajax",
"seo",
"jquery",
"json"
]
}
<!DOCTYPE html>
<title>Ajax SEO</title>
<a class=selected href="/ajax-seo/">Home</a>
<a href="/ajax-seo/about">About</a>
<a href="/ajax-seo/contact" title="Contact us">Contact</a>
<script src=//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js></script>
<script src=https://raw.github.com/laukstein/ajax-seo/master/images/jquery.address.js></script>
<span id=content></span>
@tsaniel
Copy link

tsaniel commented Nov 29, 2011

I wonder how will it be fitted into 140bytes.

@laukstein
Copy link
Author

I just though maybe it might have some improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment