forked from andris9/jStorage
/
test.html
130 lines (116 loc) · 4.03 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html>
<head>
<title>jStorage - simple JavaScript plugin to store data locally</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
body{font-family: Sans-serif;font-size: 13px;color: #333;}
table{border-left: 1px solid #CDEB8B;border-top: 1px solid #CDEB8B;}
h1{padding-top: 50px;font-size: 26px;font-weight: bold; border-bottom: 3px solid #CDEB8B;}
td{padding: 3px;border-right: 1px solid #CDEB8B;border-bottom: 1px solid #CDEB8B;}
thead{background: #006E2E;color: white;}
.container{width: 700px;margin: 10px auto;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
<script src="jstorage.js"></script>
<script>
JSOTRAGE_TEST = {
/**
* insert_value
* takes data from form fields and stores it with jStorage
* @return
*/
insert_value: function(){
var row = new Element("tr"),
key = $('key').value,
val = $('val').value;
if(!key){
alert("KEY NEEDS TO BE SET!");
$('key').focus();
return;
}
$.jStorage.set(key, val);
$('key').value = "";
$('val').value = "";
this.reDraw();
},
/**
* get_value
* alerts a value from jStorage with a key from a form field
* @return
*/
get_value: function(){
var value = $.jStorage.get($F("key2"));
alert(value);
$('key2').value = "";
},
/**
* flush_values
* clears all data
* @return
*/
flush_values: function(){
$.jStorage.flush();
this.reDraw();
},
/**
* reDraw
* fills table with data from jStorage
* @return
*/
reDraw: function(){
var row, del, indx=$.jStorage.index();
$$("tr[class~=rida]").each(function(c){c.remove();});
for(var i=0; i<indx.length; i++){
row = new Element("tr",{className:"rida"});
row.insert(new Element("td").update(indx[i]));
row.insert(new Element("td").update($.jStorage.get(indx[i])));
del = new Element("a",{href:"javascript:void(0)"}).update("DEL");
(function(i){
del.observe("click", function(){
$.jStorage.deleteKey(i);
this.reDraw();
});
}).call(this,indx[i])
row.insert(new Element("td").insert(del));
$("tulemused").insert(row);
}
}
}
</script>
</head>
<body>
<div class="container">
<h1>jStorage - store data locally with JavaScript</h1>
<p><strong><a href="http://www.jstorage.info">jStorage</a></strong> is a simple wrapper plugin for Prototype, MooTools and jQuery to cache data on browser side.</p>
<p>Add some values and refresh the page - if your browser supports storing local data, then the values should survive the page refresh.</p>
<table cellspacing="0" cellpadding="0" style="width: 100%">
<thead>
<tr><td width="120">KEY</td><td>VALUE</td><td width="50"> </td></tr>
</thead>
<tbody id="tulemused"></tbody>
<tfoot>
<tr>
<td><input type="text" id="key" name="key" value="" style="width: 110px;" /></td>
<td><input type="text" id="val" name="val" value="" style="width: 98%" /></td>
<td><a href="javascript:JSOTRAGE_TEST.insert_value()">ADD</a></td>
</tr>
<tr>
<td><input type="text" id="key2" name="key2" value="" style="width: 110px;" /></td>
<td>Clicking "GET" alerts the value for provided key with the method <em>$.jStorage.get(key)</em></td>
<td><a href="javascript:JSOTRAGE_TEST.get_value()">GET</a></td>
</tr>
<tr>
<td> </td>
<td>Clear all saved data</td>
<td><a href="javascript:JSOTRAGE_TEST.flush_values()">FLUSH</a></td>
</tr>
</tfoot>
</table>
<p>© 2010 Andris Reinman, <a href="mailto:andris.reinman@gmail.com">andris.reinman@gmail.com</a><br /><a href="http://www.jstorage.info">jStorage</a> is licensed under <a href="http://www.jstorage.info/static/license.txt">MIT-styled license</a>, so basically you can do whatever you want to do with it.</p>
<script>
// Fill the table with previously saved data
JSOTRAGE_TEST.reDraw();
</script>
</body>
</html>