peteshow 0.7.9 → 0.8.0

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 CHANGED
@@ -17,7 +17,8 @@ module.exports = function(grunt) {
17
17
  meta: {
18
18
  depFiles : [
19
19
  'vendor/faker.js',
20
- 'vendor/jquery.formatdatetime.js'
20
+ 'vendor/jquery.formatdatetime.js',
21
+ 'vendor/jquery.cookie.js'
21
22
  ],
22
23
 
23
24
  srcFiles : [
@@ -78,7 +79,7 @@ module.exports = function(grunt) {
78
79
  },
79
80
 
80
81
  qunit: {
81
- all: ['tests/*.html']
82
+ all: ['tests/index.html']
82
83
  }
83
84
  });
84
85
 
data/README.md CHANGED
@@ -25,4 +25,6 @@ Also specific pages for frameworks:
25
25
 
26
26
  Developed by [Pete Brousalis](http://twitter.com/brousalis) in his spare time for use at [Enova](http://www.enova.com/) in Chicago, IL.
27
27
 
28
- Special thanks to Matthew Bergman & Marak Squires for [Faker.js](http://github.com/marak/Faker.js/), and Adam Gschwender for [jquery.formatDateTime](https://github.com/agschwender/jquery.formatDateTime), both included with Peteshow.
28
+ Special thanks to Matthew Bergman & Marak Squires for [Faker.js](http://github.com/marak/Faker.js/), Adam Gschwender for [jquery.formatDateTime](https://github.com/agschwender/jquery.formatDateTime), Klaus Hartl for [jquery.cookie](https://github.com/carhartl/jquery-cookie), all used by Peteshow.
29
+
30
+ And to Donnie Hall for creating the original `Peepshow`, which I rewrote and rebranded.
data/dist/peteshow.js CHANGED
@@ -956,6 +956,124 @@ else {
956
956
 
957
957
  }));
958
958
 
959
+ /*!
960
+ * jQuery Cookie Plugin v1.4.1
961
+ * https://github.com/carhartl/jquery-cookie
962
+ *
963
+ * Copyright 2006, 2014 Klaus Hartl
964
+ * Released under the MIT license
965
+ */
966
+ (function (factory) {
967
+ if (typeof define === 'function' && define.amd) {
968
+ // AMD
969
+ define(['jquery'], factory);
970
+ } else if (typeof exports === 'object') {
971
+ // CommonJS
972
+ factory(require('jquery'));
973
+ } else {
974
+ // Browser globals
975
+ factory(jQuery);
976
+ }
977
+ }(function ($) {
978
+
979
+ var pluses = /\+/g;
980
+
981
+ function encode(s) {
982
+ return config.raw ? s : encodeURIComponent(s);
983
+ }
984
+
985
+ function decode(s) {
986
+ return config.raw ? s : decodeURIComponent(s);
987
+ }
988
+
989
+ function stringifyCookieValue(value) {
990
+ return encode(config.json ? JSON.stringify(value) : String(value));
991
+ }
992
+
993
+ function parseCookieValue(s) {
994
+ if (s.indexOf('"') === 0) {
995
+ // This is a quoted cookie as according to RFC2068, unescape...
996
+ s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
997
+ }
998
+
999
+ try {
1000
+ // Replace server-side written pluses with spaces.
1001
+ // If we can't decode the cookie, ignore it, it's unusable.
1002
+ // If we can't parse the cookie, ignore it, it's unusable.
1003
+ s = decodeURIComponent(s.replace(pluses, ' '));
1004
+ return config.json ? JSON.parse(s) : s;
1005
+ } catch(e) {}
1006
+ }
1007
+
1008
+ function read(s, converter) {
1009
+ var value = config.raw ? s : parseCookieValue(s);
1010
+ return $.isFunction(converter) ? converter(value) : value;
1011
+ }
1012
+
1013
+ var config = $.cookie = function (key, value, options) {
1014
+
1015
+ // Write
1016
+
1017
+ if (arguments.length > 1 && !$.isFunction(value)) {
1018
+ options = $.extend({}, config.defaults, options);
1019
+
1020
+ if (typeof options.expires === 'number') {
1021
+ var days = options.expires, t = options.expires = new Date();
1022
+ t.setTime(+t + days * 864e+5);
1023
+ }
1024
+
1025
+ return (document.cookie = [
1026
+ encode(key), '=', stringifyCookieValue(value),
1027
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
1028
+ options.path ? '; path=' + options.path : '',
1029
+ options.domain ? '; domain=' + options.domain : '',
1030
+ options.secure ? '; secure' : ''
1031
+ ].join(''));
1032
+ }
1033
+
1034
+ // Read
1035
+
1036
+ var result = key ? undefined : {};
1037
+
1038
+ // To prevent the for loop in the first place assign an empty array
1039
+ // in case there are no cookies at all. Also prevents odd result when
1040
+ // calling $.cookie().
1041
+ var cookies = document.cookie ? document.cookie.split('; ') : [];
1042
+
1043
+ for (var i = 0, l = cookies.length; i < l; i++) {
1044
+ var parts = cookies[i].split('=');
1045
+ var name = decode(parts.shift());
1046
+ var cookie = parts.join('=');
1047
+
1048
+ if (key && key === name) {
1049
+ // If second argument (value) is a function it's a converter...
1050
+ result = read(cookie, value);
1051
+ break;
1052
+ }
1053
+
1054
+ // Prevent storing a cookie that we couldn't decode.
1055
+ if (!key && (cookie = read(cookie)) !== undefined) {
1056
+ result[name] = cookie;
1057
+ }
1058
+ }
1059
+
1060
+ return result;
1061
+ };
1062
+
1063
+ config.defaults = {};
1064
+
1065
+ $.removeCookie = function (key, options) {
1066
+ if ($.cookie(key) === undefined) {
1067
+ return false;
1068
+ }
1069
+
1070
+ // Must not alter options, thus extending a fresh object...
1071
+ $.cookie(key, '', $.extend({}, options, { expires: -1 }));
1072
+ return !$.cookie(key);
1073
+ };
1074
+
1075
+ }));
1076
+
959
1077
  var Peteshow = {};
960
1078
 
961
1079
  Peteshow.defaults = {
@@ -963,6 +1081,7 @@ Peteshow.defaults = {
963
1081
  emailDomain : 'example.com',
964
1082
  form : '',
965
1083
  blur : false,
1084
+ cookies : false,
966
1085
 
967
1086
  rules : {},
968
1087
  ignore : [],
@@ -974,17 +1093,7 @@ Peteshow.defaults = {
974
1093
  events : function(){},
975
1094
  }
976
1095
 
977
- if (typeof define == 'function'){
978
- define(function(){
979
- return Peteshow;
980
- });
981
-
982
- } else if(typeof module !== 'undefined' && module.exports) {
983
- module.exports = Peteshow;
984
-
985
- } else {
986
- window.Peteshow = Peteshow;
987
- }
1096
+ window.Peteshow = Peteshow;
988
1097
 
989
1098
  +function($) {
990
1099
  Peteshow.randomChars = function (length, chars) {
@@ -1050,28 +1159,36 @@ if (typeof define == 'function'){
1050
1159
  +function($) {
1051
1160
  getDefaultRules = function() {
1052
1161
  return {
1053
- 'input[type=password]' : 'password',
1054
- 'input[type=text]' : Peteshow.randomLetters(8),
1055
- 'input[type=email], input[name*=email]' : Peteshow.randomEmail(),
1056
- 'input[name*=number], input[type=number]' : Peteshow.randomNumber(8),
1057
- 'input[class*=number], input[class*=decimal]' : Peteshow.randomNumber(8),
1058
- 'input[type=date]' : Peteshow.randomDate(),
1059
- 'input[name*=phone]' : Faker.PhoneNumber.phoneNumberFormat(5),
1060
- 'input[name*=first_name]' : Faker.Name.firstName(),
1061
- 'input[name*=last_name]' : Faker.Name.lastName(),
1062
- 'input[name*=company]' : Faker.Company.companyName(),
1063
- 'input[name*=line1], input[name*=street]' : Faker.Address.streetName(),
1064
- 'input[name*=line2], input[name*=suite]' : Faker.Address.secondaryAddress(),
1065
- 'input[name*=city]' : Faker.Address.city(),
1066
- 'input[name*=zip], input[name*=postal]' : Faker.Address.zipCodeFormat(0),
1067
- 'input[name*=state]' : Faker.Address.usState(),
1068
- 'input[name*=job_title]' : Faker.Company.catchPhrase(),
1069
- 'input[name*=intent]' : Faker.Lorem.sentence(),
1070
- 'input[name*=income], input[name*=amount]' : Peteshow.randomNumber(4),
1071
- 'input[name*=branch], input[name*=routing]' : '400001',
1072
- 'input[name*=card_type_cd]' : '001',
1073
- 'input[name*=card_number]' : '4111111111111111',
1074
- 'input[name*=cvv]' : '123'
1162
+ 'input[type=password]' : 'password',
1163
+ 'input[type=text]' : Peteshow.randomLetters(8),
1164
+ 'input[type=email]' : Peteshow.randomEmail(),
1165
+ 'input[type=number]' : Peteshow.randomNumber(8),
1166
+ 'input[type=date]' : Peteshow.randomDate(),
1167
+ 'input[name*=email]' : Peteshow.randomEmail(),
1168
+ 'input[name*=number]' : Peteshow.randomNumber(8),
1169
+ 'input[class*=number]' : Peteshow.randomNumber(8),
1170
+ 'input[class*=decimal]' : Peteshow.randomNumber(8),
1171
+ 'input[name*=phone]' : Faker.PhoneNumber.phoneNumberFormat(5),
1172
+ 'input[name*=first_name]' : Faker.Name.firstName(),
1173
+ 'input[name*=last_name]' : Faker.Name.lastName(),
1174
+ 'input[name*=company]' : Faker.Company.companyName(),
1175
+ 'input[name*=line1]' : Faker.Address.streetName(),
1176
+ 'input[name*=street]' : Faker.Address.streetName(),
1177
+ 'input[name*=suite]' : Faker.Address.secondaryAddress(),
1178
+ 'input[name*=line2]' : Faker.Address.secondaryAddress(),
1179
+ 'input[name*=city]' : Faker.Address.city(),
1180
+ 'input[name*=zip]' : Faker.Address.zipCodeFormat(0),
1181
+ 'input[name*=postal]' : Faker.Address.zipCodeFormat(0),
1182
+ 'input[name*=state]' : Faker.Address.usState(),
1183
+ 'input[name*=job_title]' : Faker.Company.catchPhrase(),
1184
+ 'input[name*=intent]' : Faker.Lorem.sentence(),
1185
+ 'input[name*=income]' : Peteshow.randomNumber(4),
1186
+ 'input[name*=amount]' : Peteshow.randomNumber(4),
1187
+ 'input[name*=branch]' : '400001',
1188
+ 'input[name*=routing]' : '400001',
1189
+ 'input[name*=card_type_cd]' : '001',
1190
+ 'input[name*=card_number]' : '4111111111111111',
1191
+ 'input[name*=cvv]' : '123'
1075
1192
  }
1076
1193
  }
1077
1194
 
@@ -1116,26 +1233,27 @@ if (typeof define == 'function'){
1116
1233
  var key = (typeof e.which == 'number') ? e.which : e.keyCode,
1117
1234
  code = String.fromCharCode(e.keyCode)
1118
1235
 
1236
+ // modifier keys
1119
1237
  if(e.ctrlKey) code = 'ctrl_'+code
1120
1238
  if(e.altKey || (e.originalEvent && e.originalEvent.metaKey)) code = 'alt_'+code
1121
1239
  if(e.shiftKey) code = 'shift_'+code
1122
1240
  if($.inArray(e.keyCode, [9,16,17,18, 91, 93, 224]) != -1) return
1123
1241
  if(e.metaKey) return
1124
1242
 
1125
- if(e.keyCode == 192) { // `
1243
+ if(e.keyCode == 192) // `
1126
1244
  Peteshow.toggle()
1127
- }
1128
1245
 
1129
1246
  var action = $("[data-command='"+code+"']"),
1130
1247
  visible = $tools.is(':visible')
1131
1248
 
1132
- if(action.length > 0 && visible) action.click()
1249
+ if(action.length > 0 && visible)
1250
+ action.click()
1133
1251
  }
1134
1252
 
1135
1253
  initCommands = function() {
1136
1254
  var base = "<li><a data-command='F' href='#' id='fill-out-forms'>Fill Out Forms</a></li>"
1137
1255
  base += "<li><a data-command='Q' href='#' id='fill-out-forms-and-submit'>Fill Out and Submit</a></li>"
1138
- base += outputLocalStorage()
1256
+ base += outputSavedFields()
1139
1257
  base += "<li><a data-command='H' href='#' id='hide-peteshow'>Hide</a></li>"
1140
1258
 
1141
1259
  $div.find($commands).html(_options.commands + base)
@@ -1148,13 +1266,12 @@ if (typeof define == 'function'){
1148
1266
  [ $toggle, function() { Peteshow.toggle() } ],
1149
1267
  [ $('#fill-out-forms'), function() { Peteshow.fillOutForms() } ],
1150
1268
  [ $('#fill-out-forms-and-submit'), function() { Peteshow.fillOutForms(); Peteshow.submitForm() } ],
1151
- [ $('#clear-localstorage'), function() { Peteshow.clearLocalStorage() } ],
1269
+ [ $('#clear'), function() { Peteshow.clearSaved(); } ],
1152
1270
  [ $('#hide-peteshow'), function() { Peteshow.hide() } ]
1153
1271
  ]
1154
1272
 
1155
1273
  $.each(commands, function() {
1156
1274
  var command = $(this)
1157
-
1158
1275
  $(command[0]).on('click', function() {
1159
1276
  command[1]()
1160
1277
  return false
@@ -1190,10 +1307,9 @@ if (typeof define == 'function'){
1190
1307
  })
1191
1308
 
1192
1309
  // apply rules
1193
- var rules = $.extend(true, getDefaultRules(), _options.rules || {})
1194
- reused = {},
1195
- ls = Peteshow.getLocalStorage(),
1196
- local = (ls != null || ls != undefined) ? ls : {}
1310
+ var rules = $.extend(true, getDefaultRules(), _options.rules || {})
1311
+ reused = {},
1312
+ saved = Peteshow.getSavedFields()
1197
1313
 
1198
1314
  // apply value to rule element, if visible and not in ignore list
1199
1315
  $.each(rules, function(element,v) {
@@ -1212,55 +1328,67 @@ if (typeof define == 'function'){
1212
1328
  var url = _options.reuse[element]
1213
1329
 
1214
1330
  if($(element).length > 0) {
1215
- // if element isnt in localstorage, save it in localstorage
1216
- if(!(element in local))
1217
- reused[element] = $(element).val()
1331
+ // if element isnt in saved, save it
1332
+ if(!(element in saved)) reused[element] = $(element).val()
1218
1333
 
1219
- // if element is in localstorage and we're not on the reused url, save it in localstorage
1220
- if((element in local) && window.location.href.indexOf(url) < 0)
1334
+ // if element is saved and we're not on the reused url, save it
1335
+ if((element in saved) && window.location.href.indexOf(url) < 0)
1221
1336
  reused[element] = $(element).val()
1222
1337
  }
1223
1338
  })
1224
1339
 
1225
- // save localstorage if found rules to reuse
1340
+ // save if found rules to reuse
1226
1341
  if(!$.isEmptyObject(reused)) {
1227
- $.extend(local, reused)
1228
-
1229
- localStorage.setItem('peteshow', JSON.stringify(local))
1342
+ $.extend(saved, reused)
1343
+ Peteshow.setSavedFields(JSON.stringify(saved))
1230
1344
  }
1231
1345
 
1232
- // apply localstorage rule values if they exist and on the right page
1233
- if(localStorage.peteshow != undefined || localStorage.peteshow != null) {
1234
- $.each(Peteshow.getLocalStorage(), function(element,v) {
1346
+ // apply saved rule values if they exist and on the right page
1347
+ if(savedFieldsExist()) {
1348
+ $.each(Peteshow.getSavedFields(), function(element,v) {
1235
1349
  var url = _options.reuse[element]
1236
-
1237
- if(window.location.href.indexOf(url) > -1)
1238
- $(element).val(v)
1350
+ if(window.location.href.indexOf(url) > -1) $(element).val(v)
1239
1351
  })
1240
-
1241
1352
  // reinit menu
1242
1353
  initCommands()
1243
1354
  }
1244
1355
  }
1245
1356
 
1246
- outputLocalStorage = function() {
1357
+ outputSavedFields = function() {
1247
1358
  var base = ''
1248
- if(localStorage.peteshow != undefined || localStorage.peteshow != null) {
1359
+
1360
+ if(savedFieldsExist()) {
1249
1361
  base += "<li class='list'>"
1250
1362
  base += "<div class='inner'>"
1251
- $.each(Peteshow.getLocalStorage(), function(k,v) {
1363
+ $.each(Peteshow.getSavedFields(), function(k,v) {
1252
1364
  base += '<div>' + k + '<span>' + v + '</span></div>'
1253
1365
  })
1254
1366
  base += "</div>"
1255
1367
  base += "</li>"
1256
-
1257
- base += "<li><a data-command='R' href='#' id='clear-localstorage'>Clear stored</a></li>"
1368
+ base += "<li><a data-command='R' href='#' id='clear'>Clear stored</a></li>"
1258
1369
  }
1370
+
1259
1371
  return base
1260
1372
  }
1261
1373
 
1262
- Peteshow.getLocalStorage = function() {
1263
- return JSON.parse(localStorage.getItem('peteshow'))
1374
+ savedFieldsExist = function() {
1375
+ var saved = _options.cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
1376
+ return (saved != undefined || saved != null)
1377
+ }
1378
+
1379
+ Peteshow.setSavedFields = function(data) {
1380
+ _options.cookies ? $.cookie('peteshow', data) : localStorage.setItem('peteshow', data)
1381
+ }
1382
+
1383
+ Peteshow.getSavedFields = function() {
1384
+ var saved = _options.cookies ? $.cookie('peteshow') : localStorage.getItem('peteshow')
1385
+ return (saved != undefined || saved != null) ? JSON.parse(saved) : {}
1386
+ }
1387
+
1388
+ Peteshow.clearSaved = function() {
1389
+ Peteshow.clearLocalStorage()
1390
+ Peteshow.clearCookies()
1391
+ initCommands()
1264
1392
  }
1265
1393
 
1266
1394
  Peteshow.clearLocalStorage = function() {
@@ -1268,6 +1396,11 @@ if (typeof define == 'function'){
1268
1396
  initCommands()
1269
1397
  }
1270
1398
 
1399
+ Peteshow.clearCookies = function() {
1400
+ $.removeCookie('peteshow')
1401
+ initCommands()
1402
+ }
1403
+
1271
1404
  randomSelectValue = function(i,select) {
1272
1405
  var options = $(select).find('option'),
1273
1406
  filters = _options.filter.toString().replace(new RegExp(',', 'g'), '|'),