peteshow 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gruntfile.js +1 -0
- data/README.md +82 -5
- data/dist/peteshow.js +171 -141
- data/dist/peteshow.min.js +2 -2
- data/lib/assets/javascripts/peteshow.js +171 -141
- data/lib/assets/javascripts/peteshow.min.js +2 -2
- data/package.json +1 -1
- data/src/peteshow-core.js +90 -132
- data/src/peteshow-helpers.js +1 -1
- data/src/peteshow-storage.js +69 -0
- data/src/peteshow.js +10 -8
- data/tests/index.html +3 -3
- data/tests/playground.html +2 -1
- data/tests/suite/cookies.js +2 -2
- data/tests/suite/core.js +11 -2
- data/tests/suite/localstorage.js +3 -1
- metadata +3 -3
- data/tests/suite/helpers.js +0 -29
data/package.json
CHANGED
data/src/peteshow-core.js
CHANGED
@@ -47,28 +47,9 @@
|
|
47
47
|
|
48
48
|
$('body').append($div)
|
49
49
|
|
50
|
-
initCommands()
|
51
|
-
}
|
52
|
-
|
53
|
-
Peteshow.destroy = function() {
|
54
|
-
Peteshow.hide()
|
55
|
-
$div.remove();
|
56
|
-
}
|
57
|
-
|
58
|
-
Peteshow.hide = function() {
|
59
|
-
$div.hide()
|
60
|
-
$div.removeClass('active')
|
61
|
-
}
|
62
|
-
|
63
|
-
Peteshow.toggle = function() {
|
64
|
-
$tools.toggle()
|
65
|
-
$div.toggleClass('active')
|
66
|
-
}
|
50
|
+
Peteshow.initCommands()
|
67
51
|
|
68
|
-
|
69
|
-
$div.show()
|
70
|
-
$tools.show()
|
71
|
-
if(!$div.hasClass('active')) $div.addClass('active')
|
52
|
+
Peteshow.storage.init(_options)
|
72
53
|
}
|
73
54
|
|
74
55
|
handleKeypress = function(e) {
|
@@ -82,7 +63,7 @@
|
|
82
63
|
if($.inArray(e.keyCode, [9,16,17,18, 91, 93, 224]) != -1) return
|
83
64
|
if(e.metaKey) return
|
84
65
|
|
85
|
-
if(e.keyCode == 192) //
|
66
|
+
if(e.keyCode == 192) // backtick
|
86
67
|
Peteshow.toggle()
|
87
68
|
|
88
69
|
var action = $("[data-command='"+code+"']"),
|
@@ -92,72 +73,57 @@
|
|
92
73
|
action.click()
|
93
74
|
}
|
94
75
|
|
95
|
-
initCommands = function() {
|
76
|
+
Peteshow.initCommands = function() {
|
96
77
|
var base = "<li><a data-command='F' href='#' id='fill-out-forms'>Fill Out Forms</a></li>"
|
97
78
|
base += "<li><a data-command='Q' href='#' id='fill-out-forms-and-submit'>Fill Out and Submit</a></li>"
|
98
|
-
base +=
|
79
|
+
base += Peteshow.storage.output()
|
99
80
|
base += "<li><a data-command='H' href='#' id='hide-peteshow'>Hide</a></li>"
|
100
81
|
|
101
|
-
$
|
102
|
-
|
103
|
-
bindEvents()
|
104
|
-
}
|
82
|
+
$commands.html(_options.commands + base)
|
105
83
|
|
106
|
-
|
84
|
+
// bind events
|
107
85
|
var commands = [
|
108
|
-
[ $toggle,
|
109
|
-
[ $('#fill-out-forms'),
|
110
|
-
[ $('#fill-out-forms-and-submit'),
|
111
|
-
[ $('#clear'),
|
112
|
-
[ $('#hide-peteshow'),
|
86
|
+
[ $toggle, Peteshow.toggle ],
|
87
|
+
[ $('#fill-out-forms'), Peteshow.fillOutForms ],
|
88
|
+
[ $('#fill-out-forms-and-submit'), Peteshow.fillOutFormsAndSubmit ],
|
89
|
+
[ $('#clear'), Peteshow.storage.clear ],
|
90
|
+
[ $('#hide-peteshow'), Peteshow.hide ]
|
113
91
|
]
|
114
92
|
|
115
93
|
$.each(commands, function() {
|
116
94
|
var command = $(this)
|
117
95
|
$(command[0]).on('click', function() {
|
118
|
-
command[1]()
|
119
|
-
|
120
|
-
|
121
|
-
});
|
96
|
+
command[1](); return false
|
97
|
+
})
|
98
|
+
})
|
122
99
|
|
123
100
|
_options.events()
|
124
101
|
}
|
125
102
|
|
126
|
-
Peteshow.submitForm = function() {
|
127
|
-
$(_options.form).submit()
|
128
|
-
$('form[name*=registration], .simple_form').submit()
|
129
|
-
$('form').last().submit()
|
130
|
-
};
|
131
|
-
|
132
103
|
Peteshow.fillOutForms = function() {
|
133
|
-
|
134
|
-
|
104
|
+
var rules = $.extend(true, getDefaultRules(), _options.rules || {})
|
105
|
+
|
106
|
+
$('input:checkbox').filterFields().prop('checked', true)
|
135
107
|
|
136
|
-
|
137
|
-
randomRadioValue()
|
108
|
+
$('input:radio').each(randomRadioValue)
|
138
109
|
|
139
|
-
// select
|
140
110
|
$('select').each(randomSelectValue)
|
141
111
|
|
142
|
-
// force rules
|
112
|
+
// force rules (for hidden fields)
|
143
113
|
$.each(_options.force, function(element,v) {
|
144
114
|
$(element)
|
145
|
-
.
|
115
|
+
.filterFields()
|
146
116
|
.val($.isFunction(v) ? v() : v)
|
147
117
|
|
148
118
|
if(_options.blur) $(element).blur()
|
149
119
|
})
|
150
120
|
|
151
|
-
//
|
152
|
-
var rules = $.extend(true, getDefaultRules(), _options.rules || {})
|
153
|
-
reused = {},
|
154
|
-
saved = Peteshow.getSavedFields()
|
155
|
-
|
156
|
-
// apply value to rule element, if visible and not in ignore list
|
121
|
+
// fill out fields with rules
|
157
122
|
$.each(rules, function(element,v) {
|
158
|
-
$(element)
|
159
|
-
|
160
|
-
|
123
|
+
$(element)
|
124
|
+
.filter(':visible')
|
125
|
+
.filterFields()
|
126
|
+
.val($.isFunction(v) ? v() : v)
|
161
127
|
|
162
128
|
if(_options.blur) $(element).blur()
|
163
129
|
})
|
@@ -165,15 +131,24 @@
|
|
165
131
|
// special rules
|
166
132
|
_options.special()
|
167
133
|
|
168
|
-
//
|
134
|
+
// localstorage functionality
|
135
|
+
reuseLocalStorage()
|
136
|
+
}
|
137
|
+
|
138
|
+
reuseLocalStorage = function() {
|
139
|
+
var reused = {},
|
140
|
+
saved = Peteshow.storage.get()
|
141
|
+
|
169
142
|
$.each(_options.reuse, function(element,v) {
|
170
143
|
var url = _options.reuse[element]
|
171
144
|
|
145
|
+
// exists on page
|
172
146
|
if($(element).length > 0) {
|
173
|
-
//
|
174
|
-
if(!(element in saved))
|
147
|
+
// element isnt in saved, save it
|
148
|
+
if(!(element in saved))
|
149
|
+
reused[element] = $(element).val()
|
175
150
|
|
176
|
-
//
|
151
|
+
// element is saved and we're not on the reused url, save it
|
177
152
|
if((element in saved) && window.location.href.indexOf(url) < 0)
|
178
153
|
reused[element] = $(element).val()
|
179
154
|
}
|
@@ -182,79 +157,22 @@
|
|
182
157
|
// save if found rules to reuse
|
183
158
|
if(!$.isEmptyObject(reused)) {
|
184
159
|
$.extend(saved, reused)
|
185
|
-
Peteshow.
|
160
|
+
Peteshow.storage.set(saved)
|
186
161
|
}
|
187
162
|
|
188
163
|
// apply saved rule values if they exist and on the right page
|
189
164
|
if(savedFieldsExist()) {
|
190
|
-
$.each(Peteshow.
|
165
|
+
$.each(Peteshow.storage.get(), function(element,v) {
|
191
166
|
var url = _options.reuse[element]
|
192
167
|
if(window.location.href.indexOf(url) > -1) $(element).val(v)
|
193
168
|
})
|
194
|
-
// reinit menu
|
195
|
-
initCommands()
|
196
|
-
}
|
197
|
-
}
|
198
|
-
|
199
|
-
outputSavedFields = function() {
|
200
|
-
var base = ''
|
201
169
|
|
202
|
-
|
203
|
-
|
204
|
-
base += "<div class='inner'>"
|
205
|
-
$.each(Peteshow.getSavedFields(), function(k,v) {
|
206
|
-
base += '<div>' + k + '<span>' + v + '</span></div>'
|
207
|
-
})
|
208
|
-
base += "</div>"
|
209
|
-
base += "</li>"
|
210
|
-
base += "<li><a data-command='R' href='#' id='clear'>Clear stored</a></li>"
|
170
|
+
// redraw menu
|
171
|
+
Peteshow.initCommands()
|
211
172
|
}
|
212
|
-
|
213
|
-
return base
|
214
|
-
}
|
215
|
-
|
216
|
-
savedFieldsExist = function() {
|
217
|
-
var saved = _options.cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
|
218
|
-
return saved != undefined || saved != null
|
219
|
-
}
|
220
|
-
|
221
|
-
Peteshow.setSavedFields = function(data) {
|
222
|
-
_options.cookies ? $.cookie('peteshow', data, {domain: getDomain()}) : localStorage.setItem('peteshow', data)
|
223
173
|
}
|
224
174
|
|
225
|
-
|
226
|
-
var saved = _options.cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
|
227
|
-
return (saved != undefined || saved != null) ? JSON.parse(saved) : {}
|
228
|
-
}
|
229
|
-
|
230
|
-
getDomain = function() {
|
231
|
-
// http://rossscrivener.co.uk/blog/javascript-get-domain-exclude-subdomain
|
232
|
-
var i=0, domain=document.domain, p=domain.split('.'), s='_gd'+(new Date()).getTime();
|
233
|
-
while(i<(p.length-1) && document.cookie.indexOf(s+'='+s)==-1){
|
234
|
-
domain = p.slice(-1-(++i)).join('.');
|
235
|
-
document.cookie = s+"="+s+";domain="+domain+";";
|
236
|
-
}
|
237
|
-
document.cookie = s+"=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain="+domain+";";
|
238
|
-
return domain;
|
239
|
-
}
|
240
|
-
|
241
|
-
Peteshow.clearSaved = function() {
|
242
|
-
Peteshow.clearLocalStorage()
|
243
|
-
Peteshow.clearCookies()
|
244
|
-
initCommands()
|
245
|
-
}
|
246
|
-
|
247
|
-
Peteshow.clearLocalStorage = function() {
|
248
|
-
localStorage.removeItem('peteshow')
|
249
|
-
initCommands()
|
250
|
-
}
|
251
|
-
|
252
|
-
Peteshow.clearCookies = function() {
|
253
|
-
$.removeCookie('peteshow', {domain: getDomain()})
|
254
|
-
initCommands()
|
255
|
-
}
|
256
|
-
|
257
|
-
randomSelectValue = function(i,select) {
|
175
|
+
randomSelectValue = function(i, select) {
|
258
176
|
var options = $(select).find('option'),
|
259
177
|
filters = _options.filter.toString().replace(new RegExp(',', 'g'), '|'),
|
260
178
|
regex = new RegExp('other|select'+(filters == '' ? '' : '|' + filters),'gi'),
|
@@ -265,18 +183,18 @@
|
|
265
183
|
|
266
184
|
if(value.match(regex) == null && value != '')
|
267
185
|
filtered.push(value)
|
268
|
-
})
|
186
|
+
})
|
269
187
|
|
270
188
|
var random = Math.floor(Math.random() * filtered.length)
|
271
189
|
|
272
190
|
$(select)
|
273
|
-
.
|
191
|
+
.filterFields()
|
274
192
|
.val(filtered[random])
|
275
193
|
.change()
|
276
194
|
}
|
277
195
|
|
278
|
-
randomRadioValue = function() {
|
279
|
-
var names = $(
|
196
|
+
randomRadioValue = function(i, radios) {
|
197
|
+
var names = $(radios).map(function() {
|
280
198
|
return $(this).attr('name')
|
281
199
|
})
|
282
200
|
|
@@ -286,12 +204,52 @@
|
|
286
204
|
var radios = $('input:radio[name="'+name+'"]')
|
287
205
|
|
288
206
|
$(radios[Math.floor(Math.random() * radios.length)])
|
289
|
-
.
|
207
|
+
.filterFields()
|
290
208
|
.prop('checked', true)
|
291
209
|
.change()
|
292
210
|
})
|
293
211
|
}
|
294
212
|
|
295
|
-
|
213
|
+
$.fn.filterFields = function() {
|
214
|
+
return this.filter(function() {
|
215
|
+
return _options.ignore.indexOf(this.name) === -1
|
216
|
+
})
|
217
|
+
}
|
218
|
+
|
219
|
+
Peteshow.submitForm = function() {
|
220
|
+
$(_options.form).submit()
|
221
|
+
$('form[name*=registration], .simple_form').submit()
|
222
|
+
$('form').last().submit()
|
223
|
+
}
|
224
|
+
|
225
|
+
Peteshow.fillOutFormsAndSubmit = function() {
|
226
|
+
Peteshow.fillOutForms()
|
227
|
+
Peteshow.submitForm()
|
228
|
+
}
|
229
|
+
|
230
|
+
Peteshow.destroy = function() {
|
231
|
+
Peteshow.hide()
|
232
|
+
$div.remove()
|
233
|
+
}
|
234
|
+
|
235
|
+
Peteshow.hide = function() {
|
236
|
+
$div.hide()
|
237
|
+
$div.removeClass('active')
|
238
|
+
}
|
239
|
+
|
240
|
+
Peteshow.toggle = function() {
|
241
|
+
$tools.toggle()
|
242
|
+
$div.toggleClass('active')
|
243
|
+
}
|
244
|
+
|
245
|
+
Peteshow.show = function() {
|
246
|
+
$div.show()
|
247
|
+
$tools.show()
|
248
|
+
|
249
|
+
if(!$div.hasClass('active'))
|
250
|
+
$div.addClass('active')
|
251
|
+
}
|
252
|
+
|
253
|
+
$(document).keydown(handleKeypress)
|
296
254
|
}(jQuery)
|
297
255
|
|
data/src/peteshow-helpers.js
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
+function($) {
|
2
|
+
var cookies = false
|
3
|
+
|
4
|
+
Peteshow.storage.init = function(options) {
|
5
|
+
cookies = options.cookies
|
6
|
+
}
|
7
|
+
|
8
|
+
Peteshow.storage.set = function(data) {
|
9
|
+
data = JSON.stringify(data)
|
10
|
+
|
11
|
+
if(cookies) $.cookie('peteshow', data, {domain: getDomain()})
|
12
|
+
else localStorage.setItem('peteshow', data)
|
13
|
+
}
|
14
|
+
|
15
|
+
Peteshow.storage.get = function() {
|
16
|
+
var saved = cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
|
17
|
+
return (saved != undefined || saved != null) ? JSON.parse(saved) : {}
|
18
|
+
}
|
19
|
+
|
20
|
+
Peteshow.storage.output = function() {
|
21
|
+
var base = ''
|
22
|
+
|
23
|
+
if(savedFieldsExist()) {
|
24
|
+
base += "<li class='list'>"
|
25
|
+
base += "<div class='inner'>"
|
26
|
+
$.each(Peteshow.storage.get(), function(k,v) {
|
27
|
+
base += '<div>' + k + '<span>' + v + '</span></div>'
|
28
|
+
})
|
29
|
+
base += "</div>"
|
30
|
+
base += "</li>"
|
31
|
+
base += "<li><a data-command='R' href='#' id='clear'>Clear stored</a></li>"
|
32
|
+
}
|
33
|
+
|
34
|
+
return base
|
35
|
+
}
|
36
|
+
|
37
|
+
Peteshow.storage.clear = function() {
|
38
|
+
clearLocalStorage()
|
39
|
+
clearCookies()
|
40
|
+
Peteshow.initCommands()
|
41
|
+
}
|
42
|
+
|
43
|
+
savedFieldsExist = function() {
|
44
|
+
var saved = cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
|
45
|
+
return (saved != undefined || saved != null)
|
46
|
+
}
|
47
|
+
|
48
|
+
getDomain = function() {
|
49
|
+
// http://rossscrivener.co.uk/blog/javascript-get-domain-exclude-subdomain
|
50
|
+
var i=0, domain=document.domain, p=domain.split('.'), s='_gd'+(new Date()).getTime()
|
51
|
+
while(i<(p.length-1) && document.cookie.indexOf(s+'='+s)==-1){
|
52
|
+
domain = p.slice(-1-(++i)).join('.')
|
53
|
+
document.cookie = s+"="+s+";domain="+domain+";"
|
54
|
+
}
|
55
|
+
document.cookie = s+"=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain="+domain+";"
|
56
|
+
return domain == 'localhost' ? '' : domain
|
57
|
+
}
|
58
|
+
|
59
|
+
clearLocalStorage = function() {
|
60
|
+
localStorage.removeItem('peteshow')
|
61
|
+
Peteshow.initCommands()
|
62
|
+
}
|
63
|
+
|
64
|
+
clearCookies = function() {
|
65
|
+
$.removeCookie('peteshow', {domain: getDomain()})
|
66
|
+
Peteshow.initCommands()
|
67
|
+
}
|
68
|
+
|
69
|
+
}(jQuery)
|
data/src/peteshow.js
CHANGED
@@ -7,14 +7,16 @@ Peteshow.defaults = {
|
|
7
7
|
blur : false,
|
8
8
|
cookies : false,
|
9
9
|
|
10
|
-
rules
|
11
|
-
ignore
|
12
|
-
filter
|
13
|
-
force
|
14
|
-
reuse
|
15
|
-
commands
|
16
|
-
special
|
17
|
-
events
|
10
|
+
rules : {},
|
11
|
+
ignore : [],
|
12
|
+
filter : [],
|
13
|
+
force : {},
|
14
|
+
reuse : {},
|
15
|
+
commands : '',
|
16
|
+
special : function(){},
|
17
|
+
events : function(){},
|
18
18
|
}
|
19
19
|
|
20
|
+
Peteshow.storage = {};
|
21
|
+
|
20
22
|
window.Peteshow = Peteshow;
|
data/tests/index.html
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
<input name='date ' type='date' >
|
19
19
|
<input name='decimal' type='text' >
|
20
20
|
<input name='number' type='text' >
|
21
|
-
<input name='phone' type='text' />
|
21
|
+
<input name='phone' type='text' id='phone-number' />
|
22
22
|
<input name='tel' type='tel' >
|
23
23
|
<input name='first_name' type='text /'>
|
24
24
|
<input name='middle_name' type='text /'>
|
@@ -50,11 +50,11 @@
|
|
50
50
|
<script src='../vendor/jquery.cookie.js'></script>
|
51
51
|
|
52
52
|
<script src='../src/peteshow.js'></script>
|
53
|
-
<script src='../src/peteshow-core.js'></script>
|
54
53
|
<script src='../src/peteshow-helpers.js'></script>
|
54
|
+
<script src='../src/peteshow-storage.js'></script>
|
55
|
+
<script src='../src/peteshow-core.js'></script>
|
55
56
|
|
56
57
|
<script src='./suite/core.js'></script>
|
57
|
-
<script src='./suite/helpers.js'></script>
|
58
58
|
<script src='./suite/keybindings.js'></script>
|
59
59
|
<script src='./suite/options.js'></script>
|
60
60
|
<script src='./suite/localstorage.js'></script>
|