Skip to content

Commit

Permalink
Merge pull request #1 from sainivikas/slave
Browse files Browse the repository at this point in the history
Slave
  • Loading branch information
sainivikas committed Mar 2, 2016
2 parents 0eb397d + c81923a commit 25af0cd
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 1 deletion.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# Info-Reader
This is the UI version of Info Reader
This is the simple UI version of Info Reader.
Currently show only all content of info format file.

How to Operate:
================
Open home.html file
Press O for open a file, page will automatically redirect after choose a info format file
and give error if format of file is not info.
The new page will show the content of file.
Press B for go back on home.html.




Issue:
=======
Not fully keyboard-centric for Firefox currently.
Will fix in later release.
3 changes: 3 additions & 0 deletions css/show.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1,h2,h3 {
text-align:center;
}
52 changes: 52 additions & 0 deletions js/reader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function key_pressed(key)
{
var key_ascii;
if(window.event) // For IE
{
key_ascii = key.keyCode;
}
else if(key.which) // For other browsers
{
key_ascii = key.which;
}
if(key_ascii == 111)
open_file();
}

function open_file()
{
var input_id = document.getElementById("info_file");
input_id.click();
}

function changeContent(evt)
{
var file_obj = document.getElementById("info_file").files[0];
var file_name = file_obj.name;
var ext_obj = file_name.split('.'), extension;
var i;
for(i in ext_obj)
extension = ext_obj[i];
// check file extension is info or not
if(extension == 'info')
{
if (file_obj)
{
var reader = new FileReader();
reader.onload = function(e)
{
contents = e.target.result;
localStorage.setItem('contents', contents);
localStorage.setItem('file_name', file_name);
document.getElementById("home_form").submit();
}
reader.readAsText(file_obj);
}
else
{
alert("Sorry,Failed to load file,Try Again");
}
}
else
alert("Wrong file format,Please open files of info format only");
}
35 changes: 35 additions & 0 deletions js/writter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function write()
{
lines = localStorage.getItem('contents');
file_name = localStorage.getItem('file_name');
var length = lines.length;
var content = "";
for(i=0;i<length;i++)
{
if(lines.charAt(i) == '\n')
content = content + '<br>';
else
content = content + lines.charAt(i);
}
document.getElementById("file_name").innerHTML = 'Contents of ' + file_name;
document.getElementById("file_content").innerHTML = content;
}


function key_pressed(key)
{
var key_ascii;
if(window.event) // For IE
{
key_ascii = key.keyCode;
}
else if(key.which) // For other browsers
{
key_ascii = key.which;
}
if(key_ascii == 98)
window.open("home.html","_self");

}


22 changes: 22 additions & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title> Info File Reader </title>
<script src="../js/reader.js"></script>
<link rel="stylesheet" type="text/css" href="../css/show.css">
</head>
<body onkeypress="key_pressed(event)">
<h1>Welcome to Info Reader</h1>
<hr/>
<br>
<h2>Press O for open a file</h2>
<br>
<br>
<br>
<center>
<form id="home_form" action="show.html">
<input type="file" id="info_file" onchange="changeContent()" />
</form>
</center>
</body>
</html>
18 changes: 18 additions & 0 deletions templates/show.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Info File Reader</title>
<script src="../js/writter.js"></script>
<link rel="stylesheet" type="text/css" href="../css/show.css">
<link rel="stylesheet" type="text/css" href="../css/pagediv.css">
</head>
<body onload="write()" onkeypress="key_pressed(event)">

<h1>Press B For Go Back</h1>
<hr/>
<h2 id="file_name"></h2>
<hr/>
<h3 id="file_content"></h3>

</body>
</html>

0 comments on commit 25af0cd

Please sign in to comment.