Skip to content

Commit

Permalink
Implement better URI class/ID on body tag, closes #242
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Oct 5, 2015
1 parent 17608b0 commit ed5fa13
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/Dispatcher/PageDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,35 @@ public function setContentUri($uri, ResponseContent $content) {
if(strrpos($uri, "/") === strlen($uri) - 1) {
$uri .= "index";
}

$body = $content->querySelector("body");
$uri = trim($uri, "/");
$uriPartTotal = "";
foreach (explode("/", $uri) as $uriPart) {
$body->classList->add($uriPart);
if($uriPartTotal) {
$body->classList->add($uriPartTotal);
$classArray = [];

foreach(explode("/", $uri) as $uriPart) {
$newClass = "";

foreach($classArray as $c) {
if(strlen($newClass) > 0) {
$newClass .= "_";
}
$newClass .= $c;
}
$uriPartTotal .= $uriPartTotal ? "_$uriPart" : $uriPart;

if(strlen($newClass) > 0) {
$newClass .= "_";
}

$classArray []= $newClass . $uriPart;
}

foreach($classArray as $c) {
$body->classList->add("dir--" . $c);
}

$uri = str_replace("/", "_", $uri);
$idUri = $uri;
$content->querySelector("body")->id = $idUri;
$body->id = "uri--" . $uri;

}

}#
}#

0 comments on commit ed5fa13

Please sign in to comment.