Browse files

Better rewrites

  • Loading branch information...
1 parent 686c90a commit d023a0f2380eda0669a50f43f529f147c47930b3 @quirkey committed Mar 21, 2011
Showing with 80 additions and 2 deletions.
  1. +19 −0 css/screen.css
  2. +1 −0 index.html
  3. +28 −1 js/app.js
  4. +28 −1 js/default.js
  5. +4 −0 rewrites.js
View
19 css/screen.css
@@ -3,3 +3,22 @@ body {
color: #333;
margin: 10px;
}
+
+em {
+ color: #CCC;
+}
+
+#info {
+ margin: 10px;
+ padding: 10px;
+ border: 1px solid #CCC;
+ font-weight: bold;
+}
+
+.warning {
+ background: red;
+ color: #FFF;
+}
+.success {
+ color: green;
+}
View
1 index.html
@@ -7,6 +7,7 @@
</head>
<body>
<div id="container">
+ <div id="info" class="warning"></div>
<p>
<a href="/pushstate/_design/pushstate/_rewrite/push/one">one</a>
|
View
29 js/app.js
@@ -3,8 +3,14 @@
var app = $.sammy('#container', function() {
this.use('Couch');
+ var clicked = false;
this.before(function() {
- $('#log').append('<li>' + this.path + '</li>');
+ var log = this.path;
+ if (clicked) {
+ log += "<em> clicked " + clicked.attr('href') + '</em>';
+ clicked = false;
+ }
+ $('#log').append('<li>' + log + '</li>');
});
this.get(/\/$/, function() {
@@ -14,6 +20,27 @@
this.get('/push/:push_id', function(ctx) {
$('#at').text(this.params.push_id);
});
+
+ this.bind('run', function() {
+ $('a').click(function() {
+ clicked = $(this);
+ });
+
+ var info = "Your browser <strong>" + navigator.userAgent + "<strong> ";
+ var support = false;
+ if (this.app._location_proxy.has_history) {
+ info += " supports HTML5 History";
+ $('#info').addClass('success').removeClass('warning');
+ } else {
+ info += " does not support HTML5 History";
+ }
+ $('#info').html(info);
+
+ $(window).bind('popstate hashchange', function(e) {
+ $('#log').append('<li><em>window event ' + e.type + '</em></li>');
+ });
+ });
+
});
$(function() {
View
29 js/default.js
@@ -9106,8 +9106,14 @@ window.jQuery = window.$ = jQuery;
var app = $.sammy('#container', function() {
this.use('Couch');
+ var clicked = false;
this.before(function() {
- $('#log').append('<li>' + this.path + '</li>');
+ var log = this.path;
+ if (clicked) {
+ log += "<em> clicked " + clicked.attr('href') + '</em>';
+ clicked = false;
+ }
+ $('#log').append('<li>' + log + '</li>');
});
this.get(/\/$/, function() {
@@ -9117,6 +9123,27 @@ window.jQuery = window.$ = jQuery;
this.get('/push/:push_id', function(ctx) {
$('#at').text(this.params.push_id);
});
+
+ this.bind('run', function() {
+ $('a').click(function() {
+ clicked = $(this);
+ });
+
+ var info = "Your browser <strong>" + navigator.userAgent + "<strong> ";
+ var support = false;
+ if (this.app._location_proxy.has_history) {
+ info += " supports HTML5 History";
+ $('#info').addClass('success').removeClass('warning');
+ } else {
+ info += " does not support HTML5 History";
+ }
+ $('#info').html(info);
+
+ $(window).bind('popstate hashchange', function(e) {
+ $('#log').append('<li><em>window event ' + e.type + '</em></li>');
+ });
+ });
+
});
$(function() {
View
4 rewrites.js
@@ -11,6 +11,10 @@
"to": "js/:file"
},
{
+ "from": "*/css/:file",
+ "to": "css/:file"
+ },
+ {
"from": "/push/*",
"to": "index.html"
},

0 comments on commit d023a0f

Please sign in to comment.