Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Update to Storage Page #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
logs/*
logs/*
15 changes: 13 additions & 2 deletions demos/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
</article>
<script>

function getVals(){
getStorage('session');
getStorage('local');
}

function getStorage(type) {
var storage = window[type + 'Storage'],
delta = 0,
Expand All @@ -49,17 +54,23 @@
document.querySelector('#previous').appendChild(li);
}

getStorage('session');
getStorage('local');
function updateList(){
document.querySelector('#previous').innerHTML = '';
getVals();
}

getVals();

addEvent(document.querySelector('#session'), 'keyup', function () {
sessionStorage.setItem('value', this.value);
sessionStorage.setItem('timestamp', (new Date()).getTime());
updateList();
});

addEvent(document.querySelector('#local'), 'keyup', function () {
localStorage.setItem('value', this.value);
localStorage.setItem('timestamp', (new Date()).getTime());
updateList();
});

addEvent(document.querySelector('#clear'), 'click', function () {
Expand Down
40 changes: 25 additions & 15 deletions page.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
<?php
$request = preg_replace('/[^0-9a-z-_]/', '', preg_replace('/^\//', '', preg_replace('/\/$/', '', preg_replace('/\?.*$/', '', $_SERVER['REQUEST_URI']))));
if (file_exists('demos/' . $request . '.html')) {
$file = file_get_contents('demos/' . $request . '.html');
preg_match('/<title>(.*)<\/title>/', $file, $matches);
$file = preg_replace('/<title>(.*?)<\/title>/', '', $file);
$title = $matches[1];
// $request = preg_replace('/[^0-9a-z-_]/', '', preg_replace('/^\//', '', preg_replace('/\/$/', '', preg_replace('/\?.*$/', '', $_SERVER['REQUEST_URI']))));

$manifest = '';
if ($request == 'offlineapp') { // specific change to support <html manifest=xyz>
$manifest = ' manifest="html5demo.appcache"';
// Above method caused issues when repo is in a subfolder.
// Replaced with "end" function below.
// Added simple if-else

if($request= end((explode('/', $_SERVER['REQUEST_URI']))))
{
if (file_exists('demos/' . $request . '.html')) {
$file = file_get_contents('demos/' . $request . '.html');
preg_match('/<title>(.*)<\/title>/', $file, $matches);
$file = preg_replace('/<title>(.*?)<\/title>/', '', $file);
$title = $matches[1];

$manifest = '';
if ($request == 'offlineapp') { // specific change to support <html manifest=xyz>
$manifest = ' manifest="html5demo.appcache"';
}

include('includes/header.php');
echo $file;
include('includes/footer.php');
} else {
header("HTTP/1.0 404 Not Found");
echo 'File not found';
}

include('includes/header.php');
echo $file;
include('includes/footer.php');
} else {
header("HTTP/1.0 404 Not Found");
echo 'File not found';
echo "Invalid Request";
}

?>