Skip to content

Instantly share code, notes, and snippets.

@danijeel danijeel/index.php
Last active Aug 29, 2015

Embed
What would you like to do?
List all project, press enter, voliá!
<?php
foreach (new DirectoryIterator('.') as $fileInfo) {
if($fileInfo->isDot()) continue;
if($fileInfo->isDir()) $folders[] = $fileInfo->getFilename();
if($fileInfo->isFile() && $fileInfo->getExtension() == 'php') {
if (!in_array($fileInfo->getFilename(), array('index.php', 'error.php', '404.php'))) {
$files[] = $fileInfo->getFilename();
}
}
}
?>
<!doctype html>
<html lang="sv">
<head>
<link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<meta charset="utf-8">
<style>
body{
background: hsl(156, 24%, 50%);
color: white;
font-family: 'Varela Round', sans-serif;
}
#search {
width: 100%;
height: 30px;
padding: 20px;
font-size: 20px;
}
ol{
list-style-type: none;
}
a{
color:white;
text-decoration: none;
}
a:active {
outline: 5px solid red;
}
a:hover{
}
.searchbox{
margin-top: 100px !important;
width: 900px;
margin: 0 auto;
}
.container{
width: 900px;
margin: 0 auto;
}
ol{
width:760px;
margin-bottom:20px;
overflow:hidden;
}
li{
line-height:1.5em;
float:left;
display:inline;
}
#six li { width:16.666%; }
#quad li { width:25%; }
#double li { width:50%;}
#triple li { width:33.333%; }
.highlighted{
background: hsla(59, 95%, 69%, 0.30);
font-weight: bold;
color: #00663A;
}
::-webkit-input-placeholder {
}
:-moz-placeholder { /* Firefox 18- */
}
::-moz-placeholder { /* Firefox 19+ */
}
:-ms-input-placeholder {
}
.files{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: auto;
background: darkslategray;
}
a:hover{
color: red;
}
</style>
<title>Root</title>
</head>
<body ng-app>
<div ng-init="projects = <?php echo htmlspecialchars(json_encode($folders)); ?>">
</div>
<div class="ctrl" ng-controller="Magic">
<div class="searchbox">
<input ng-keyup="keyPress($event.keyCode)" type="text" id="search" ng-model="searchText" autofocus placeholder="{{projects.length}} projekt..">
</div>
<div class="container">
<p> {{filtered.length}}</p>
<ol id="quad">
<li ng-repeat="project in filtered = (projects | filter:searchText) ">
<a href="{{project}}">{{project}}</a>
</li>
</ol>
</div>
<div class="files">
<ol>
<?php foreach ($files as $file): ?>
<a href="<?=$file?>"><?=$file?></a>
<?php endforeach ?>
</ol>
</div>
<div class="container timecalculator">
<input type="time" id="start" ng-model="start">
<input type="number" ng-model="break" placeholder="minuter..">
<input type="time" ng-model="end">
{{ workday() }}
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script type="text/javascript">
function Magic($scope){
$scope.keyPress = function(keyCode){
var parentElement = document.getElementById("quad");
//parentElement.firstElementChild.classList.add("highlighted");
if(keyCode == 13){
window.location = parentElement.firstElementChild.firstElementChild.href;
}
}
$scope.workday = function() {
var start = { hours: null, minutes: null },
end = { hours: null, minutes: null },
diff = {
hh: null,
mm: null,
hoursToMinutes: function(minutes) {
if (parseInt(minutes) <= 0) { return; }
function leftPad(number) {
return ((number < 10 && number >= 0) ? '0' : '') + number;
}
var hours = leftPad(Math.floor(Math.abs(minutes) / 60)),
minutes = leftPad(Math.abs(minutes) % 60);
return {
"hours": parseInt(hours),
"minutes": parseInt(minutes)
};
},
calculateDiff: function() {
var startDate = new Date,
endDate = new Date, totalhours, returnString;
startDate.setHours(start.hours);
startDate.setMinutes(start.minutes);
endDate.setHours(end.hours);
endDate.setMinutes(end.minutes);
totalhours = endDate - startDate;
diff.msec = totalhours;
diff.hh = Math.floor(diff.msec / 1000 / 60 / 60);
diff.msec -= diff.hh * 1000 * 60 * 60;
diff.mm = Math.floor(diff.msec / 1000 / 60);
returnString = diff.hh + " timmar";
if(diff.mm > 0) {
returnString += " och " +diff.mm + " minuter";
}
if($scope.break) {
var total_minutes = diff.mm + (diff.hh *60) - $scope.break,
diff_minutes = diff.hoursToMinutes(total_minutes);
returnString = diff_minutes.hours + " timmar";
if(diff_minutes.minutes > 0) {
returnString += " och " + diff_minutes.minutes + " minuter";
}
}
return returnString;
}
};
if($scope.start) {
start.hours = $scope.start.split(":")[0];
start.minutes = $scope.start.split(":")[1];
}
if ($scope.end) {
end.hours = $scope.end.split(":")[0];
end.minutes = $scope.end.split(":")[1];
return diff.calculateDiff();
}
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.