Permalink
Browse files

Adds experimental IE code.

  • Loading branch information...
1 parent 18456b0 commit 961a6e10036469010205320910a15d8d9bea7103 @asual committed Aug 20, 2012
Showing with 43 additions and 25 deletions.
  1. +10 −4 samples/express/app.js
  2. +2 −2 samples/express/views/index.html
  3. +31 −19 samples/state/index.php
View
@@ -16,6 +16,7 @@ app.get('*', function(req, res) {
var pathname = url.parse(req.url).pathname,
pageNotFound = "Page not found.",
+ state = '',
selected = {
title: pageNotFound,
content: pageNotFound,
@@ -30,14 +31,19 @@ app.get('*', function(req, res) {
}
}
- if (req.isXMLHttpRequest && req.accepts('application/json')) {
- res.send(selected, selected.status);
- } else {
+ if (req.isXMLHttpRequest && req.accepts('application/json')) {
+ res.send(selected, selected.status);
+ // Experimental patch for IE
+ // } else if (/MSIE\s(?!10)/i.test(req.headers['user-agent']) && pathname != '/') {
+ // res.writeHead(302, { 'Location': state + '/#' + pathname });
+ // res.end();
+ } else {
res.render(path.dirname(__filename) + '/views/index.html', {
layout: false,
locals: {
data: data,
- selected: selected
+ selected: selected,
+ state: state
}
}, function(err, content) {
res.send(content, selected.status);
@@ -19,7 +19,7 @@
$('.page').show();
};
- $.address.state('/').init(function(event) {
+ $.address.state('<%= state %>').init(function(event) {
// Initializes the plugin
$('.nav a').address();
@@ -66,7 +66,7 @@
<h1>jQuery Address Express</h1>
<ul class="nav">
<% for (var key in data) { %>
- <li><a href="<%= data[key].href %>"<%- selected == data[key] ? ' class="selected"' : '' %>><%= data[key].title %></a></li>
+ <li><a href="<%= state %><%= data[key].href %>"<%- selected == data[key] ? ' class="selected"' : '' %>><%= data[key].title %></a></li>
<% } %>
</ul>
<div class="content"><%- selected.content %></div>
View
@@ -1,4 +1,20 @@
<?php
+
+ class Address {
+
+ static function state() {
+
+ // Returns the base state
+ return substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
+ }
+
+ static function value() {
+
+ // Returns the state value
+ return str_replace(Address::state(), '', $_SERVER['REQUEST_URI']);
+ }
+
+ }
class Data {
@@ -9,19 +25,7 @@ function Data($file) {
$this->doc->load($file);
$this->xp = new DOMXPath($this->doc);
$this->nodes = $this->xp->query('/data/page');
- $this->node = $this->xp->query('/data/page[@href="' . $this->value() . '"]')->item(0);
- }
-
- function state() {
-
- // Returns the base state
- return substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
- }
-
- function value() {
-
- // Returns the state value
- return str_replace($this->state(), '', $_SERVER['REQUEST_URI']);
+ $this->node = $this->xp->query('/data/page[@href="' . Address::value() . '"]')->item(0);
}
function nav() {
@@ -31,8 +35,8 @@ function nav() {
foreach ($this->nodes as $node) {
$href = $node->getAttribute('href');
$title = $node->getAttribute('title');
- $str .= '<li><a href="' . $this->state() . $href . '"'
- . ($this->value() == $href ? ' class="selected"' : '') . '>' . $title . '</a></li>';
+ $str .= '<li><a href="' . Address::state() . $href . '"'
+ . (Address::value() == $href ? ' class="selected"' : '') . '>' . $title . '</a></li>';
}
return trim($str);
}
@@ -57,13 +61,21 @@ function title(){
// Prepares the title
foreach($this->nodes as $node){
- $href=$node->getAttribute('href');
- $title=$node->getAttribute('title');
- $str.=($this->value()==$href?$title:'');
+ $href = $node->getAttribute('href');
+ $title = $node->getAttribute('title');
+ $str .= Address::value() == $href ? $title : '';
}
return trim($str);
}
}
+
+ // Experimental patch for IE
+ // if (preg_match('/MSIE\s(?!10)/i', $_SERVER['HTTP_USER_AGENT']) &&
+ // $_SERVER[ 'HTTP_X_REQUESTED_WITH' ] != 'XMLHttpRequest' &&
+ // Address::value() != '/') {
+ // header('Location: ' . Address::state() . '/#' . Address::value());
+ // exit();
+ // }
$data = new Data('data.xml');
@@ -89,7 +101,7 @@ function title(){
$.address.title(/>([^<]*)<\/title/.exec(data)[1]);
};
- $.address.state('<?php echo($data->state()); ?>').init(function() {
+ $.address.state('<?php echo(Address::state()); ?>').init(function() {
// Initializes the plugin
$('.nav a').address();

0 comments on commit 961a6e1

Please sign in to comment.