peteshow 0.7.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.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/Gemfile +3 -0
- data/Gruntfile.js +96 -0
- data/README.md +28 -0
- data/dist/peteshow.css +1 -0
- data/dist/peteshow.js +1289 -0
- data/dist/peteshow.min.js +7 -0
- data/lib/assets/javascripts/peteshow.js +1289 -0
- data/lib/assets/javascripts/peteshow.min.js +7 -0
- data/lib/assets/stylesheets/peteshow.css +1 -0
- data/lib/peteshow/config.rb +9 -0
- data/lib/peteshow/engine.rb +4 -0
- data/lib/peteshow/helpers.rb +17 -0
- data/lib/peteshow/railtie.rb +18 -0
- data/lib/peteshow.rb +16 -0
- data/license.txt +20 -0
- data/package.json +43 -0
- data/peteshow.gemspec +17 -0
- data/src/css/peteshow.css +147 -0
- data/src/peteshow-core.js +240 -0
- data/src/peteshow-helpers.js +60 -0
- data/src/peteshow.js +29 -0
- data/tests/index.html +58 -0
- data/tests/suite/core.js +49 -0
- data/tests/suite/helpers.js +18 -0
- data/tests/suite/keybindings.js +13 -0
- data/vendor/faker.js +731 -0
- data/vendor/jquery.formatdatetime.js +225 -0
- data/vendor/peteshow.plugin.js +33 -0
- data/vendor/qunit/jquery.js +4 -0
- data/vendor/qunit/qunit.css +237 -0
- data/vendor/qunit/qunit.js +2288 -0
- metadata +74 -0
@@ -0,0 +1 @@
|
|
1
|
+
#peteshow{position:fixed;font-family:'Helvetica Neue',Tahoma;color:#fff;top:0;left:0;padding:0;text-align:left;z-index:9001;font-size:13px;background:#000;background:rgba(0,0,0,.85);text-shadow:none;width:60px;transition:width .2s ease}#peteshow.active{width:200px}#peteshow.active #peteshow-toggle i{right:10px;border-left:0;border-right-width:6px;border-right-style:solid;border-right-color:#fff}#peteshow.active #peteshow-toggle:before{content:'PETESHOW'}#peteshow-toggle{color:#fff;text-decoration:none;font-weight:700;display:block;padding:5px 10px;position:relative}#peteshow-toggle:before{content:'PS'}#peteshow-toggle i{border-style:dashed;display:-moz-inline-box;display:inline-block;font-size:10px;height:0;line-height:0;position:relative;vertical-align:middle;width:0;position:absolute;right:3px;border-color:transparent;border-width:5px;border-left-width:6px;border-left-style:solid;border-left-color:#fff;top:9px;margin:0}#peteshow-tools{display:none;color:#fff;transition:all 1s ease}#peteshow-tools a{text-shadow:none;display:block;color:#999;font-weight:700;text-decoration:none;text-transform:capitalize;height:1%}#peteshow-tools a:link,#peteshow-tools a:visited{display:block;color:#999;padding:5px 10px;text-decoration:none;text-transform:capitalize;height:1%}#peteshow-tools a:hover{background:#000;color:#FFF;text-decoration:none}#peteshow-tools a:active{height:1%}#peteshow-tools ul{list-style:none;padding:0;margin:0}#peteshow-tools ul li{display:block;border-top:1px dotted #666}#peteshow-tools ul li.list{padding:5px 10px 10px;font-size:12px;overflow:hidden;color:#aaa}#peteshow-tools ul li.list:hover{overflow:visible}#peteshow-tools ul li.list:before,#peteshow-tools ul li.list:after{content:" ";display:table}#peteshow-tools ul li.list:after{clear:both}#peteshow-tools ul li.list div{display:block;white-space:nowrap}#peteshow-tools ul li.list span{display:inline-block;margin-left:15px}#peteshow-tools ul li.list:before{content:'Stored:';display:block;font-size:13px;margin-bottom:3px;color:#999}#peteshow-tools ul li .inner{background:rgba(0,0,0,.9);padding:3px 5px;z-index:100;position:relative;float:left}@media (max-width:768px){#peteshow{position:absolute;width:100%;top:0}#peteshow.active{width:100%}}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Peteshow
|
2
|
+
module Helpers
|
3
|
+
def peteshow_include_tag(*args)
|
4
|
+
config = Peteshow.config
|
5
|
+
country = args.first.is_a?(String) ? args.shift : nil
|
6
|
+
|
7
|
+
return unless config.enabled == true
|
8
|
+
|
9
|
+
tags = []
|
10
|
+
tags << javascript_include_tag('peteshow.min.js', args.first)
|
11
|
+
tags << javascript_include_tag("peteshow.#{country}", args.first) if country
|
12
|
+
tags << stylesheet_link_tag('peteshow')
|
13
|
+
|
14
|
+
tags.join.html_safe
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'peteshow'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
class Peteshow::Railtie < Rails::Railtie
|
5
|
+
config.peteshow = ActiveSupport::OrderedOptions.new
|
6
|
+
|
7
|
+
initializer "peteshow.configure" do |app|
|
8
|
+
Peteshow.configure do |config|
|
9
|
+
config.enabled = app.config.peteshow[:enabled]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
initializer 'peteshow.action_controller' do
|
14
|
+
ActiveSupport.on_load :action_controller do
|
15
|
+
helper Peteshow::Helpers
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/peteshow.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'peteshow/helpers'
|
2
|
+
require 'peteshow/engine' if defined? Rails
|
3
|
+
require 'peteshow/railtie' if defined? ::Rails::Railtie
|
4
|
+
|
5
|
+
module Peteshow
|
6
|
+
autoload :Config, 'peteshow/config'
|
7
|
+
|
8
|
+
def self.config
|
9
|
+
@config ||= Config.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
yield self.config
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/license.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Pete Brousalis http://github.com/brousalis/peteshow/
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/package.json
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
{
|
2
|
+
"name": "peteshow",
|
3
|
+
"version": "0.7.5",
|
4
|
+
"description": "Plugin for filling out forms with fake data for testing purposes",
|
5
|
+
"keywords": [
|
6
|
+
"filler",
|
7
|
+
"forms",
|
8
|
+
"inputs"
|
9
|
+
],
|
10
|
+
"homepage": "http://github.com/brousalis/peteshow/",
|
11
|
+
"author": {
|
12
|
+
"name": "Pete Brousalis",
|
13
|
+
"email": "brousapg@gmail.com",
|
14
|
+
"url": "http://brousalis.com/"
|
15
|
+
},
|
16
|
+
"main": "dist/peteshow.js",
|
17
|
+
"repository": {
|
18
|
+
"type": "git",
|
19
|
+
"url": "https://github.com/brousalis/peteshow"
|
20
|
+
},
|
21
|
+
"bugs": {
|
22
|
+
"url": "https://github.com/brousalis/peteshow/issues"
|
23
|
+
},
|
24
|
+
"licenses": [
|
25
|
+
{
|
26
|
+
"type": "MIT",
|
27
|
+
"url": "https://github.com/brousalis/peteshow/blob/master/license.txt"
|
28
|
+
}
|
29
|
+
],
|
30
|
+
"dependencies": {},
|
31
|
+
"devDependencies": {
|
32
|
+
"grunt": "^0.4.0",
|
33
|
+
"grunt-contrib-watch": "^0.6.0",
|
34
|
+
"grunt-contrib-connect": "^0.7.0",
|
35
|
+
"grunt-contrib-concat": "^0.4.0",
|
36
|
+
"grunt-closure-tools": "^0.9.0",
|
37
|
+
"grunt-contrib-uglify": "^0.4.0",
|
38
|
+
"grunt-contrib-cssmin": "~0.6.1",
|
39
|
+
"grunt-contrib-copy": "~0.4.1",
|
40
|
+
"grunt-contrib-clean": "~0.4.1",
|
41
|
+
"grunt-contrib-qunit": "0.4.x"
|
42
|
+
}
|
43
|
+
}
|
data/peteshow.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
package = open('package.json').read
|
4
|
+
version = JSON.parse(package)['version']
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'peteshow'
|
8
|
+
s.version = version
|
9
|
+
s.author = 'Pete Brousalis'
|
10
|
+
s.email = 'brousapg@gmail.com'
|
11
|
+
s.summary = 'Javascript plugin for filling out forms with fake data '
|
12
|
+
s.description = 'Javascript plugin for filling out forms with fake data for testing purposes'
|
13
|
+
s.homepage = 'http://github.com/brousalis/peteshow'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($\)
|
16
|
+
s.require_paths = ['lib']
|
17
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
#peteshow {
|
2
|
+
position: fixed;
|
3
|
+
font-family: 'Helvetica Neue', 'Tahoma';
|
4
|
+
color: #fff;
|
5
|
+
top: 0;
|
6
|
+
left: 0;
|
7
|
+
padding: 0;
|
8
|
+
text-align: left;
|
9
|
+
z-index: 9001;
|
10
|
+
font-size: 13px;
|
11
|
+
background: #000;
|
12
|
+
background: rgba(0, 0, 0, 0.85);
|
13
|
+
text-shadow: none;
|
14
|
+
width: 60px;
|
15
|
+
transition: width 0.2s ease;
|
16
|
+
}
|
17
|
+
#peteshow.active {
|
18
|
+
width: 200px;
|
19
|
+
}
|
20
|
+
#peteshow.active #peteshow-toggle i {
|
21
|
+
right: 10px;
|
22
|
+
border-left: 0;
|
23
|
+
border-right-width: 6px;
|
24
|
+
border-right-style: solid;
|
25
|
+
border-right-color: #fff;
|
26
|
+
}
|
27
|
+
#peteshow.active #peteshow-toggle:before {
|
28
|
+
content: 'PETESHOW';
|
29
|
+
}
|
30
|
+
#peteshow-toggle {
|
31
|
+
color: #fff;
|
32
|
+
text-decoration: none;
|
33
|
+
font-weight: bold;
|
34
|
+
display: block;
|
35
|
+
padding: 5px 10px;
|
36
|
+
position: relative;
|
37
|
+
}
|
38
|
+
#peteshow-toggle:before {
|
39
|
+
content: 'PS';
|
40
|
+
}
|
41
|
+
#peteshow-toggle i {
|
42
|
+
border-style: dashed;
|
43
|
+
display: -moz-inline-box;
|
44
|
+
display: inline-block;
|
45
|
+
font-size: 10px;
|
46
|
+
height: 0;
|
47
|
+
line-height: 0;
|
48
|
+
position: relative;
|
49
|
+
vertical-align: middle;
|
50
|
+
width: 0;
|
51
|
+
position: absolute;
|
52
|
+
right: 3px;
|
53
|
+
border-color: transparent;
|
54
|
+
border-width: 5px;
|
55
|
+
border-left-width: 6px;
|
56
|
+
border-left-style: solid;
|
57
|
+
border-left-color: #fff;
|
58
|
+
top: 9px;
|
59
|
+
margin: 0px;
|
60
|
+
}
|
61
|
+
#peteshow-tools {
|
62
|
+
display: none;
|
63
|
+
color: #fff;
|
64
|
+
transition: all 1.0s ease;
|
65
|
+
}
|
66
|
+
#peteshow-tools a {
|
67
|
+
text-shadow: none;
|
68
|
+
display: block;
|
69
|
+
color: #999;
|
70
|
+
font-weight: bold;
|
71
|
+
text-decoration: none;
|
72
|
+
text-transform: capitalize;
|
73
|
+
height: 1%;
|
74
|
+
}
|
75
|
+
#peteshow-tools a:link, #peteshow-tools a:visited {
|
76
|
+
display: block;
|
77
|
+
color: #999;
|
78
|
+
padding: 5px 10px;
|
79
|
+
text-decoration: none;
|
80
|
+
text-transform: capitalize;
|
81
|
+
height: 1%;
|
82
|
+
}
|
83
|
+
#peteshow-tools a:hover {
|
84
|
+
background: #000;
|
85
|
+
color: #FFF;
|
86
|
+
text-decoration: none;
|
87
|
+
}
|
88
|
+
#peteshow-tools a:active {
|
89
|
+
height: 1%;
|
90
|
+
}
|
91
|
+
#peteshow-tools ul {
|
92
|
+
list-style: none;
|
93
|
+
padding: 0;
|
94
|
+
margin: 0;
|
95
|
+
}
|
96
|
+
#peteshow-tools ul li {
|
97
|
+
display: block;
|
98
|
+
border-top: 1px dotted #666;
|
99
|
+
}
|
100
|
+
#peteshow-tools ul li.list {
|
101
|
+
padding: 5px 10px 10px;
|
102
|
+
font-size: 12px;
|
103
|
+
overflow: hidden;
|
104
|
+
color: #aaa;
|
105
|
+
}
|
106
|
+
#peteshow-tools ul li.list:hover {
|
107
|
+
overflow: visible;
|
108
|
+
}
|
109
|
+
#peteshow-tools ul li.list:before, #peteshow-tools ul li.list:after {
|
110
|
+
content: " ";
|
111
|
+
display: table;
|
112
|
+
}
|
113
|
+
#peteshow-tools ul li.list:after {
|
114
|
+
clear: both;
|
115
|
+
}
|
116
|
+
#peteshow-tools ul li.list div {
|
117
|
+
display: block;
|
118
|
+
white-space: nowrap;
|
119
|
+
}
|
120
|
+
#peteshow-tools ul li.list span {
|
121
|
+
display: inline-block;
|
122
|
+
margin-left: 15px;
|
123
|
+
}
|
124
|
+
#peteshow-tools ul li.list:before {
|
125
|
+
content: 'Stored:';
|
126
|
+
display: block;
|
127
|
+
font-size: 13px;
|
128
|
+
margin-bottom: 3px;
|
129
|
+
color: #999;
|
130
|
+
}
|
131
|
+
#peteshow-tools ul li .inner {
|
132
|
+
background: rgba(0, 0, 0, 0.9);
|
133
|
+
padding: 3px 5px;
|
134
|
+
z-index: 100;
|
135
|
+
position: relative;
|
136
|
+
float: left;
|
137
|
+
}
|
138
|
+
@media (max-width: 768px) {
|
139
|
+
#peteshow {
|
140
|
+
position: absolute;
|
141
|
+
width: 100%;
|
142
|
+
top: 0;
|
143
|
+
}
|
144
|
+
#peteshow.active {
|
145
|
+
width: 100%;
|
146
|
+
}
|
147
|
+
}
|
@@ -0,0 +1,240 @@
|
|
1
|
+
+function($) {
|
2
|
+
getDefaultRules = function() {
|
3
|
+
return {
|
4
|
+
'input[type=password]' : 'password',
|
5
|
+
'input[type=text]' : Peteshow.randomLetters(8),
|
6
|
+
'input[type=email], input[name*=email]' : Peteshow.randomEmail(),
|
7
|
+
'input[name*=number], input[type=number]' : Peteshow.randomNumber(8),
|
8
|
+
'input[class*=number], input[class*=decimal]' : Peteshow.randomNumber(8),
|
9
|
+
'input[name*=date]' : Peteshow.randomDate(),
|
10
|
+
'input[name*=phone]' : Faker.PhoneNumber.phoneNumberFormat(5),
|
11
|
+
'input[name*=first_name]' : Faker.Name.firstName(),
|
12
|
+
'input[name*=last_name]' : Faker.Name.lastName(),
|
13
|
+
'input[name*=company]' : Faker.Company.companyName(),
|
14
|
+
'input[name*=line1], input[name*=street]' : Faker.Address.streetName(),
|
15
|
+
'input[name*=line2], input[name*=suite]' : Faker.Address.secondaryAddress(),
|
16
|
+
'input[name*=city]' : Faker.Address.city(),
|
17
|
+
'input[name*=zip], input[name*=postal]' : Faker.Address.zipCodeFormat(0),
|
18
|
+
'input[name*=state]' : Faker.Address.usState(),
|
19
|
+
'input[name*=job_title]' : Faker.Company.catchPhrase(),
|
20
|
+
'input[name*=intent]' : Faker.Lorem.sentence(),
|
21
|
+
'input[name*=income], input[name*=amount]' : Peteshow.randomNumber(4),
|
22
|
+
'input[name*=branch], input[name*=routing]' : '400001',
|
23
|
+
'input[name*=card_type_cd]' : '001',
|
24
|
+
'input[name*=card_number]' : '4111111111111111',
|
25
|
+
'input[name*=cvv]' : '123'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
Peteshow.init = function(options) {
|
30
|
+
_options = $.extend(true, Peteshow.defaults, options || {})
|
31
|
+
|
32
|
+
$div = $('<div/>', { id: 'peteshow' })
|
33
|
+
$toggle = $('<a/>', { id: 'peteshow-toggle', href: '#' }).append('<i/>')
|
34
|
+
$tools = $('<div/>', { id: 'peteshow-tools' })
|
35
|
+
$commands = $('<ul/>', { id: 'peteshow-commands' })
|
36
|
+
|
37
|
+
$div.append($toggle)
|
38
|
+
.append($tools.append($commands))
|
39
|
+
|
40
|
+
$('body').append($div)
|
41
|
+
|
42
|
+
Peteshow.commands()
|
43
|
+
}
|
44
|
+
|
45
|
+
Peteshow.keydown = function(e) {
|
46
|
+
var key = (typeof e.which == 'number') ? e.which : e.keyCode,
|
47
|
+
code = String.fromCharCode(e.keyCode)
|
48
|
+
|
49
|
+
if(e.ctrlKey) code = 'ctrl_'+code
|
50
|
+
if(e.altKey || (e.originalEvent && e.originalEvent.metaKey)) code = 'alt_'+code
|
51
|
+
if(e.shiftKey) code = 'shift_'+code
|
52
|
+
if($.inArray(e.keyCode, [9,16,17,18, 91, 93, 224]) != -1) return
|
53
|
+
if(e.metaKey) return
|
54
|
+
|
55
|
+
if(e.keyCode == 192) { // `
|
56
|
+
$tools.toggle()
|
57
|
+
$div.toggleClass('active')
|
58
|
+
}
|
59
|
+
|
60
|
+
var action = $("[data-command='"+code+"']"),
|
61
|
+
visible = $tools.is(':visible')
|
62
|
+
|
63
|
+
if(action.length > 0 && visible) action.click()
|
64
|
+
}
|
65
|
+
|
66
|
+
Peteshow.commands = function() {
|
67
|
+
var base = "<li><a data-command='F' href='#' id='fill-out-forms'>Fill Out Forms</a></li>"
|
68
|
+
base += "<li><a data-command='Q' href='#' id='fill-out-forms-and-submit'>Fill Out and Submit</a></li>"
|
69
|
+
base += outputLocalStorage()
|
70
|
+
base += "<li><a data-command='H' href='#' id='hide-peteshow'>Hide</a></li>"
|
71
|
+
|
72
|
+
$div.find($commands).html(_options.commands + base)
|
73
|
+
|
74
|
+
Peteshow.events()
|
75
|
+
}
|
76
|
+
|
77
|
+
Peteshow.events = function() {
|
78
|
+
var commands = [
|
79
|
+
[ $toggle, function() { $div.toggleClass('active'); $tools.toggle() } ],
|
80
|
+
[ $('#fill-out-forms'), function() { Peteshow.fillOutForms() } ],
|
81
|
+
[ $('#fill-out-forms-and-submit'), function() { Peteshow.fillOutForms(); Peteshow.submitForm() } ],
|
82
|
+
[ $('#clear-localstorage'), function() { clearLocalStorage() } ],
|
83
|
+
[ $('#hide-peteshow'), function() { $div.hide() } ]
|
84
|
+
]
|
85
|
+
|
86
|
+
$.each(commands, function() {
|
87
|
+
var command = $(this)
|
88
|
+
|
89
|
+
$(command[0]).on('click', function() {
|
90
|
+
command[1]()
|
91
|
+
return false
|
92
|
+
});
|
93
|
+
});
|
94
|
+
|
95
|
+
_options.events()
|
96
|
+
}
|
97
|
+
|
98
|
+
Peteshow.submitForm = function() {
|
99
|
+
$(_options.form).submit()
|
100
|
+
$('.simple_form').last().submit()
|
101
|
+
$('form').last().submit()
|
102
|
+
};
|
103
|
+
|
104
|
+
Peteshow.fillOutForms = function() {
|
105
|
+
// select
|
106
|
+
$('select').each(randomSelectValue)
|
107
|
+
|
108
|
+
// checkbox
|
109
|
+
$('input[type=checkbox]').prop('checked', true)
|
110
|
+
|
111
|
+
// radio button
|
112
|
+
randomRadioValue()
|
113
|
+
|
114
|
+
// force rules
|
115
|
+
$.each(_options.force, function(element,v) {
|
116
|
+
$(element)
|
117
|
+
.filter(function() { return _options.ignore.indexOf(this.id) === -1 })
|
118
|
+
.val($.isFunction(v) ? v() : v)
|
119
|
+
|
120
|
+
if(_options.blur) $(element).blur()
|
121
|
+
})
|
122
|
+
|
123
|
+
// apply rules
|
124
|
+
var rules = $.extend(true, getDefaultRules(), _options.rules || {})
|
125
|
+
reused = {},
|
126
|
+
ls = getLocalStorage(),
|
127
|
+
local = (ls != null || ls != undefined) ? ls : {}
|
128
|
+
|
129
|
+
// apply value to rule element, if visible and not in ignore list
|
130
|
+
$.each(rules, function(element,v) {
|
131
|
+
$(element).filter(':visible')
|
132
|
+
.filter(function() { return _options.ignore.indexOf(this.id) === -1 })
|
133
|
+
.val($.isFunction(v) ? v() : v)
|
134
|
+
|
135
|
+
if(_options.blur) $(element).blur()
|
136
|
+
})
|
137
|
+
|
138
|
+
// special rules
|
139
|
+
_options.special()
|
140
|
+
|
141
|
+
// reuse values
|
142
|
+
$.each(_options.reuse, function(element,v) {
|
143
|
+
var url = _options.reuse[element]
|
144
|
+
|
145
|
+
if($(element).length > 0) {
|
146
|
+
// if element isnt in localstorage, save it in localstorage
|
147
|
+
if(!(element in local))
|
148
|
+
reused[element] = $(element).val()
|
149
|
+
|
150
|
+
// if element is in localstorage and we're not on the reused url, save it in localstorage
|
151
|
+
if((element in local) && window.location.href.indexOf(url) < 0)
|
152
|
+
reused[element] = $(element).val()
|
153
|
+
}
|
154
|
+
})
|
155
|
+
|
156
|
+
// save localstorage if found rules to reuse
|
157
|
+
if(!$.isEmptyObject(reused)) {
|
158
|
+
$.extend(local, reused)
|
159
|
+
|
160
|
+
localStorage.setItem('peteshow', JSON.stringify(local))
|
161
|
+
}
|
162
|
+
|
163
|
+
// apply localstorage rule values if they exist and on the right page
|
164
|
+
if(localStorage.peteshow != undefined || localStorage.peteshow != null) {
|
165
|
+
$.each(getLocalStorage(), function(element,v) {
|
166
|
+
var url = _options.reuse[element]
|
167
|
+
|
168
|
+
if(window.location.href.indexOf(url) > -1)
|
169
|
+
$(element).val(v)
|
170
|
+
})
|
171
|
+
|
172
|
+
// reinit menu
|
173
|
+
Peteshow.commands()
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
outputLocalStorage = function() {
|
178
|
+
var base = ''
|
179
|
+
if(localStorage.peteshow != undefined || localStorage.peteshow != null) {
|
180
|
+
base += "<li class='list'>"
|
181
|
+
base += "<div class='inner'>"
|
182
|
+
$.each(getLocalStorage(), function(k,v) {
|
183
|
+
base += '<div>' + k + '<span>' + v + '</span></div>'
|
184
|
+
})
|
185
|
+
base += "</div>"
|
186
|
+
base += "</li>"
|
187
|
+
|
188
|
+
base += "<li><a data-command='R' href='#' id='clear-localstorage'>Clear stored</a></li>"
|
189
|
+
}
|
190
|
+
return base
|
191
|
+
}
|
192
|
+
|
193
|
+
getLocalStorage = function() {
|
194
|
+
return JSON.parse(localStorage.getItem('peteshow'))
|
195
|
+
}
|
196
|
+
|
197
|
+
clearLocalStorage = function() {
|
198
|
+
localStorage.removeItem('peteshow')
|
199
|
+
Peteshow.commands() // reinit menu to remove ls
|
200
|
+
}
|
201
|
+
|
202
|
+
randomSelectValue = function(i,select) {
|
203
|
+
var options = $(select).find('option'),
|
204
|
+
filters = _options.filter.toString().replace(new RegExp(',', 'g'), '|'),
|
205
|
+
regex = new RegExp('other|select'+(filters == '' ? '' : '|' + filters),'gi'),
|
206
|
+
filtered = []
|
207
|
+
|
208
|
+
$.each(options, function(e) {
|
209
|
+
var value = $(this).val()
|
210
|
+
|
211
|
+
if(value.match(regex) == null && value != '')
|
212
|
+
filtered.push(value)
|
213
|
+
});
|
214
|
+
|
215
|
+
var random = Math.floor(Math.random() * filtered.length)
|
216
|
+
|
217
|
+
$(select)
|
218
|
+
.filter(function() { return _options.ignore.indexOf(this.id) === -1 })
|
219
|
+
.val(filtered[random]).change()
|
220
|
+
}
|
221
|
+
|
222
|
+
randomRadioValue = function() {
|
223
|
+
var names = $('input:radio').map(function() {
|
224
|
+
return $(this).attr('name')
|
225
|
+
})
|
226
|
+
|
227
|
+
$.unique(names)
|
228
|
+
|
229
|
+
$.each(names, function(i, name) {
|
230
|
+
var radios = $('input:radio[name="'+name+'"]')
|
231
|
+
|
232
|
+
$(radios[Math.floor(Math.random() * radios.length)])
|
233
|
+
.filter(function() { return _options.ignore.indexOf(this.id) === -1 })
|
234
|
+
.prop('checked', true).change()
|
235
|
+
})
|
236
|
+
}
|
237
|
+
|
238
|
+
$(document).keydown(Peteshow.keydown);
|
239
|
+
|
240
|
+
}(jQuery)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
+function($) {
|
2
|
+
Peteshow.randomChars = function (length, chars) {
|
3
|
+
var string = ''
|
4
|
+
|
5
|
+
for (var i = 0; i < length; i++) {
|
6
|
+
var num = Math.floor(Math.random() * chars.length)
|
7
|
+
string += chars.substring(num, num + 1)
|
8
|
+
}
|
9
|
+
|
10
|
+
return string
|
11
|
+
}
|
12
|
+
|
13
|
+
Peteshow.randomLetters = function (length) {
|
14
|
+
return function() {
|
15
|
+
return Peteshow.randomChars(length, 'ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz')
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
Peteshow.randomNumberRange = function (min, max) {
|
20
|
+
return function() {
|
21
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
Peteshow.randomNumber = function (length, prefix) {
|
26
|
+
if(typeof prefix == 'undefined') { prefix = '' }
|
27
|
+
|
28
|
+
return function() {
|
29
|
+
return prefix + Peteshow.randomChars(1, '123456789') + Peteshow.randomChars(length-1, '0123456789')
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
Peteshow.randomDate = function(format) {
|
34
|
+
if(typeof format === 'undefined' || format === null) format = 'mm/dd/yy'
|
35
|
+
|
36
|
+
var start = new Date(1942, 1, 1),
|
37
|
+
end = new Date(1970, 1, 1)
|
38
|
+
|
39
|
+
var random = new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime())),
|
40
|
+
day = parseInt(random.getDate())
|
41
|
+
|
42
|
+
if(day % 2 == 1) {
|
43
|
+
if(day < 30) random.setTime(random.getTime() + (24 * 60 * 60 * 1000))
|
44
|
+
else random.setTime(random.getTime() - (24 * 60 * 60 * 1000))
|
45
|
+
}
|
46
|
+
|
47
|
+
return Peteshow.formatDate(format, random)
|
48
|
+
}
|
49
|
+
|
50
|
+
Peteshow.randomEmail = function() {
|
51
|
+
return function() {
|
52
|
+
return Peteshow.defaults.emailPrefix + Peteshow.randomNumber(6)() + '@' + Peteshow.defaults.emailDomain
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
Peteshow.formatDate = function(format, date, settings) {
|
57
|
+
return $.formatDateTime(format, date, settings)
|
58
|
+
}
|
59
|
+
|
60
|
+
}(jQuery)
|
data/src/peteshow.js
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
var Peteshow = {};
|
2
|
+
|
3
|
+
Peteshow.defaults = {
|
4
|
+
emailPrefix : 'test-',
|
5
|
+
emailDomain : 'example.com',
|
6
|
+
form : 'form[class*=registration], .simple_form, form',
|
7
|
+
blur : false,
|
8
|
+
|
9
|
+
rules : {},
|
10
|
+
ignore : [],
|
11
|
+
filter : [],
|
12
|
+
force : {},
|
13
|
+
reuse : {},
|
14
|
+
commands : '',
|
15
|
+
special : function(){},
|
16
|
+
events : function(){},
|
17
|
+
}
|
18
|
+
|
19
|
+
if (typeof define == 'function'){
|
20
|
+
define(function(){
|
21
|
+
return Peteshow;
|
22
|
+
});
|
23
|
+
|
24
|
+
} else if(typeof module !== 'undefined' && module.exports) {
|
25
|
+
module.exports = Peteshow;
|
26
|
+
|
27
|
+
} else {
|
28
|
+
window.Peteshow = Peteshow;
|
29
|
+
}
|