forked from yckart/jquery.storage.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (145 loc) · 6.15 KB
/
index.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width'>
<link href='http://fonts.googleapis.com/css?family=Numans' rel='stylesheet'>
<style>
html,body{height:100%; margin:0; padding:0}
body {
font-family: 'Numans', sans-serif;
text-align: center;
background: whiteSmoke;
background: -moz-radial-gradient(center, ellipse cover, white 0%, #f6f6f6 47%, #ededed 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, white), color-stop(47%, #f6f6f6), color-stop(100%, #ededed));
background: -webkit-radial-gradient(center, ellipse cover, white 0%, #f6f6f6 47%, #ededed 100%);
background: -o-radial-gradient(center, ellipse cover, white 0%, #f6f6f6 47%, #ededed 100%);
background: -ms-radial-gradient(center, ellipse cover, white 0%, #f6f6f6 47%, #ededed 100%);
background: radial-gradient(ellipse at center, white 0%, #f6f6f6 47%, #ededed 100%);
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100, finishopacity=90, style=2);
}
hr{
border: 0;
border-top: 1px solid #ccc;
border-bottom: 1px solid #fff;
box-shadow: 3px 3px 20px 5px #eee;
}
.example {width:600px; margin: 60px auto 0}
.example div {text-align:left; margin: 20px}
.local {}
.local input {background: transparent; border:none; border-bottom: 1px dotted #aaa}
.local input, .local pre { font-family:courier, 'courier new', mono-space; }
.session {}
#box {
float:left;
width: 128px;
height: 128px;
background: rgb(0, 170, 238)
}
.session input {display:block}
</style>
<title>jquery.ga.js | Google analytics implementation for jQuery.</title>
</head>
<body>
<h1>jQuery Storage</h1>
<div class="example local">
<h2>localStorage</h2>
<hr>
<div class="set">
<code>$.localStorage('</code><input type="text" class="key" placeholder="Enter a key..."><code>', '</code> <input type="text" class="value" placeholder="Enter a value..."> <code>');</code>
<!-- <button>Set item</button> -->
</div>
<div class="get">
<code>$.localStorage('</code><input type="text" placeholder="Enter an item..."><code>'); <span class="result"></span></code>
<!-- <button>Get item</button> -->
</div>
<div class="remove">
<code>$.localStorage('</code><input type="text" placeholder="Enter an item..."><code>', null);</code>
<button>Remove item</button>
</div>
</div>
<div class="example session">
<h2>sessionStorage</h2>
<hr>
<div>
<div id="box"></div>
<label for="r">Red</label>
<input type="range" value="100" min="0" max="255" step="1" id="r" />
<label for="g">Green</label>
<input type="range" value="100" min="0" max="255" step="1" id="g" />
<label for="b">Blue</label>
<input type="range" value="100" min="0" max="255" step="1" id="b" />
<button>Reset</button>
</div>
<hr>
<i>- No documentation yet -</i>
<!-- <a href="">yckart.com</a> -->
</div>
<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
<script src='jquery.storage.js'></script>
<script>
/* localStorage
================= */
var local = $('.local'),
set = $('.set'),
get = $('.get'),
del = $('.remove');
set.find('input').keyup(function(){
$.localStorage( set.find('.key').val(), set.find('.value').val() );
get.find('input').val( set.find('.key').val() );
get.find('.result').text( '// ' + $.localStorage( set.find('.key').val() ) )
});
get.find('.result').text( '// ' + $.localStorage( set.find('.key').val() ) )
get.find('input').keyup(function(){
get.find('.result').text( '// ' + $.localStorage( get.find('input').val() ) )
});
del.find('button').click(function(){
var val = $.localStorage(del.find('input').val(), null);
});
var resizeInput = function() {
var self = $(this),
newWidth = self.val().length,
minWidth = self.attr('placeholder').length;
self.attr('size', newWidth > minWidth ? newWidth : minWidth);
};
$('input[type="text"]').on('keydown keyup', resizeInput).each(resizeInput);
/* sessionStorage
================= */
var session = $('.session');
var boxRGB = $.data(this, 'rgb', $('#box').css('backgroundColor').match(/\d+/g)),
RGB = $.sessionStorage('rgb') || boxRGB;
$('#box').css({
backgroundColor: 'rgb(' + RGB[0] + ',' + RGB[1] + ',' + RGB[2] + ')'
});
session.find('input').each(function(i){
$(this).val(RGB[i]);
});
session.find('input').on('change keyup', function(){
$.sessionStorage('rgb', [
$('#r').val(),
$('#g').val(),
$('#b').val()
]);
RGB = $.sessionStorage('rgb');
$('#box').css({
backgroundColor: 'rgb(' + RGB[0] + ',' + RGB[1] + ',' + RGB[2] + ')'
});
});
session.find('button').click(function(){
$.sessionStorage('rgb', null);
$('#box').css({
backgroundColor: 'rgb(' + boxRGB[0] + ',' + boxRGB[1] + ',' + boxRGB[2] + ')'
});
session.find('input').each(function(i){
$(this).val(boxRGB[i]);
});
});
// Allow only rgb values as input
session.find('input').keyup(function (e) {
var v = this.value,
s = v.slice(0,-1);
this.value = v.charAt(0) > 2 ? s : v.charAt(0) > 1 && v.charAt(1) > 5 ? s : v > 255 ? s : v.replace(/\D/g,''); // /[^0-9\.]/g
});
</script>
</body>
</html>