html5forms-rails 0.1.3

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.
Files changed (93) hide show
  1. data/CHANGELOG.md +5 -0
  2. data/Gemfile +11 -0
  3. data/README.md +208 -0
  4. data/Rakefile +49 -0
  5. data/VERSION +1 -0
  6. data/demos/html5-form-demo.html +79 -0
  7. data/html5forms-rails.gemspec +142 -0
  8. data/lib/html5forms.rb +6 -0
  9. data/vendor/assets/images/colorpicker/blank.gif +0 -0
  10. data/vendor/assets/images/colorpicker/colorpicker_background.png +0 -0
  11. data/vendor/assets/images/colorpicker/colorpicker_hex.png +0 -0
  12. data/vendor/assets/images/colorpicker/colorpicker_hsb_b.png +0 -0
  13. data/vendor/assets/images/colorpicker/colorpicker_hsb_h.png +0 -0
  14. data/vendor/assets/images/colorpicker/colorpicker_hsb_s.png +0 -0
  15. data/vendor/assets/images/colorpicker/colorpicker_indic.gif +0 -0
  16. data/vendor/assets/images/colorpicker/colorpicker_overlay.png +0 -0
  17. data/vendor/assets/images/colorpicker/colorpicker_rgb_b.png +0 -0
  18. data/vendor/assets/images/colorpicker/colorpicker_rgb_g.png +0 -0
  19. data/vendor/assets/images/colorpicker/colorpicker_rgb_r.png +0 -0
  20. data/vendor/assets/images/colorpicker/colorpicker_select.gif +0 -0
  21. data/vendor/assets/images/colorpicker/colorpicker_submit.png +0 -0
  22. data/vendor/assets/images/colorpicker/custom_background.png +0 -0
  23. data/vendor/assets/images/colorpicker/custom_hex.png +0 -0
  24. data/vendor/assets/images/colorpicker/custom_hsb_b.png +0 -0
  25. data/vendor/assets/images/colorpicker/custom_hsb_h.png +0 -0
  26. data/vendor/assets/images/colorpicker/custom_hsb_s.png +0 -0
  27. data/vendor/assets/images/colorpicker/custom_indic.gif +0 -0
  28. data/vendor/assets/images/colorpicker/custom_rgb_b.png +0 -0
  29. data/vendor/assets/images/colorpicker/custom_rgb_g.png +0 -0
  30. data/vendor/assets/images/colorpicker/custom_rgb_r.png +0 -0
  31. data/vendor/assets/images/colorpicker/custom_submit.png +0 -0
  32. data/vendor/assets/images/colorpicker/select.png +0 -0
  33. data/vendor/assets/images/colorpicker/select2.png +0 -0
  34. data/vendor/assets/images/colorpicker/slider.png +0 -0
  35. data/vendor/assets/images/h5f/form_validation.png +0 -0
  36. data/vendor/assets/images/html5form-shim/asterisk.png +0 -0
  37. data/vendor/assets/images/html5form-shim/down.png +0 -0
  38. data/vendor/assets/images/html5form-shim/fail.png +0 -0
  39. data/vendor/assets/images/html5form-shim/ok.png +0 -0
  40. data/vendor/assets/images/html5forms/jscolor/arrow.gif +0 -0
  41. data/vendor/assets/images/html5forms/jscolor/cross.gif +0 -0
  42. data/vendor/assets/images/html5forms/jscolor/hs.png +0 -0
  43. data/vendor/assets/images/html5forms/jscolor/hv.png +0 -0
  44. data/vendor/assets/images/html5forms/slider/slider-1.png +0 -0
  45. data/vendor/assets/images/html5forms/slider/slider-disabled-1.png +0 -0
  46. data/vendor/assets/images/html5forms/slider/slider-disabled.png +0 -0
  47. data/vendor/assets/images/html5forms/slider/slider.png +0 -0
  48. data/vendor/assets/javascripts/colorpicker.js +484 -0
  49. data/vendor/assets/javascripts/colorpicker.min.js +9 -0
  50. data/vendor/assets/javascripts/h5f.js +328 -0
  51. data/vendor/assets/javascripts/h5f.min.js +4 -0
  52. data/vendor/assets/javascripts/html5forms/EventHelpers.min.js +15 -0
  53. data/vendor/assets/javascripts/html5forms/autocomplete.min.js +1 -0
  54. data/vendor/assets/javascripts/html5forms/cssQuery-p.min.js +6 -0
  55. data/vendor/assets/javascripts/html5forms/dev/EventHelpers.js +486 -0
  56. data/vendor/assets/javascripts/html5forms/dev/autocomplete.js +387 -0
  57. data/vendor/assets/javascripts/html5forms/dev/cssQuery-p.js +6 -0
  58. data/vendor/assets/javascripts/html5forms/dev/html5.js +121 -0
  59. data/vendor/assets/javascripts/html5forms/dev/html5Forms.js +892 -0
  60. data/vendor/assets/javascripts/html5forms/dev/html5Widgets.js +1417 -0
  61. data/vendor/assets/javascripts/html5forms/dev/jscolor.js +840 -0
  62. data/vendor/assets/javascripts/html5forms/dev/slider.js +797 -0
  63. data/vendor/assets/javascripts/html5forms/dev/timer.js +137 -0
  64. data/vendor/assets/javascripts/html5forms/dev/visibleIf.js +1100 -0
  65. data/vendor/assets/javascripts/html5forms/html5.min.js +2 -0
  66. data/vendor/assets/javascripts/html5forms/html5Forms.min.js +1 -0
  67. data/vendor/assets/javascripts/html5forms/html5Widgets.min.js +20 -0
  68. data/vendor/assets/javascripts/html5forms/jscolor.min.js +10 -0
  69. data/vendor/assets/javascripts/html5forms/slider.min.js +25 -0
  70. data/vendor/assets/javascripts/html5forms/timer.min.js +1 -0
  71. data/vendor/assets/javascripts/html5forms/visibleIf.min.js +19 -0
  72. data/vendor/assets/javascripts/html5forms.fallback.js +115 -0
  73. data/vendor/assets/javascripts/html5forms.fallback.min.js +11 -0
  74. data/vendor/assets/javascripts/jquery.html5form-shim.js +402 -0
  75. data/vendor/assets/javascripts/jquery.html5form.min.js +4 -0
  76. data/vendor/assets/javascripts/jquery.placehold.min.js +7 -0
  77. data/vendor/assets/javascripts/ui.spinner.js +649 -0
  78. data/vendor/assets/javascripts/ui.spinner.min.js +7 -0
  79. data/vendor/assets/javascripts/webforms2/webforms2-msie.js +1 -0
  80. data/vendor/assets/javascripts/webforms2/webforms2-p.js +14 -0
  81. data/vendor/assets/javascripts/webforms2/webforms2.js +14 -0
  82. data/vendor/assets/javascripts/webforms2/webforms2_src.js +3195 -0
  83. data/vendor/assets/stylesheets/colorpicker.css +161 -0
  84. data/vendor/assets/stylesheets/h5f.css +86 -0
  85. data/vendor/assets/stylesheets/html5form-shim.css +109 -0
  86. data/vendor/assets/stylesheets/html5forms/number.css +35 -0
  87. data/vendor/assets/stylesheets/html5forms/slider.css +169 -0
  88. data/vendor/assets/stylesheets/html5forms/slider_ie.css +41 -0
  89. data/vendor/assets/stylesheets/html5forms/visibleIf.css +23 -0
  90. data/vendor/assets/stylesheets/html5forms.layout.css +116 -0
  91. data/vendor/assets/stylesheets/ui.spinner.css +3 -0
  92. data/vendor/assets/stylesheets/webforms2.css +42 -0
  93. metadata +221 -0
@@ -0,0 +1,402 @@
1
+ /*
2
+ * HTML5 Form Shim
3
+ *
4
+ * @package HTML5 Form Shim
5
+ * @author $Author: sheiko $
6
+ * @version $Id: jquery.html5form.js, v 0.9 $
7
+ * @license GNU
8
+ * @copyright (c) Dmitry Sheiko http://www.dsheiko.com
9
+ */
10
+ (function( $ ) {
11
+
12
+ var ONINPUT_DELAY = 500,
13
+ Util = {
14
+ isString : function(value) {
15
+ return typeof(value)=='string' && isNaN(value);
16
+ },
17
+ isNumber : function(value) {
18
+ return !isNaN(parseFloat(value)) && isFinite(value);
19
+ },
20
+ log : function(val) {
21
+ var placeholder = $('.log');
22
+ if (placeholder.length) {
23
+ placeholder.html(placeholder.html() + val + '<br />');
24
+ }
25
+ }
26
+ },
27
+ Browser = {
28
+ /**
29
+ * List of supported types of input element
30
+ * Run through HTML5's new input types to see if the UA understands any.
31
+ * Implementation adopted from http://www.modernizr.com
32
+ */
33
+ supportedInputTypes: (function() {
34
+ var inputElem = document.createElement('input'),
35
+ types = (function(props) {
36
+ for ( var i = 0, types =[], len = props.length; i < len; i++ ) {
37
+ inputElem.setAttribute('type', props[i]);
38
+ types[props[i]] = !!(inputElem.type !== 'text');
39
+ }
40
+ return types;
41
+ })('search tel url email datetime date month week time datetime-local number range color'.split(' '));
42
+ return types;
43
+ }()),
44
+ /*
45
+ * List of supported properties of input element
46
+ * Run through HTML5's new input attributes to see if the UA understands any.
47
+ * Implementation adopted from http://www.modernizr.com
48
+ * spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
49
+ */
50
+ supportedInputProps: (function() {
51
+ var inputElem = document.createElement('input'),
52
+ attrs = (function( props ) {
53
+ for ( var i = 0, attrs = [], len = props.length; i < len; i++ ) {
54
+ attrs[ props[i] ] = !!(props[i] in inputElem);
55
+ }
56
+ return attrs;
57
+ })('autocomplete autofocus list placeholder max min multiple pattern required step'
58
+ .split(' '));
59
+ return attrs;
60
+ }())
61
+ },
62
+ App = {
63
+ init: function() {
64
+ // The scope extends with custom validators
65
+ $.extend(true, App, $.setCustomInputTypeValidator);
66
+ $("form").each(function(){
67
+ var _form = new App.Form($(this));
68
+ _form.init();
69
+ });
70
+ },
71
+ Form : function(form) {
72
+ var _private = {
73
+ form : form,
74
+ elements: [],
75
+ handleOnSubmit : function(e) {
76
+ e.preventDefault();
77
+ var context = e.data;
78
+ if (!context.isCustomValidation() && context.isNoValidate()) {
79
+ return;
80
+ }
81
+ for(var i in _private.elements) {
82
+ var element = _private.elements[i];
83
+ element.recheckSetCustomValidity(); // If a custom validation message defined (via AJAX) before form submitted
84
+ if ((typeof element.element.attr('required') !== 'undefined') &&
85
+ (element.element.val() === element.element.attr('placeholder')
86
+ || !element.element.val())) {
87
+ element.showTooltip("Please fill out this field");
88
+ context.setInvalid();
89
+ return;
90
+ }
91
+ if (!element.isValid()) {
92
+ element.showTooltip();
93
+ context.setInvalid();
94
+ return;
95
+ }
96
+ }
97
+ context.setValid();
98
+ },
99
+ normalizeName : function(str) {
100
+ str += '';
101
+ return str.charAt(0).toUpperCase() + (str.substr(1).toLowerCase());
102
+ }
103
+ };
104
+ return {
105
+ isCustomValidation: function() { return (typeof _private.form.attr('custom-validation') !== "undefined"); },
106
+ isNoValidate: function() { return (typeof _private.form.attr('novalidate') !== "undefined"); },
107
+ setValid: function() {
108
+ _private.form.addClass('valid').removeClass('invalid');
109
+ },
110
+ setInvalid: function() {
111
+ _private.form.addClass('invalid').removeClass('valid');
112
+ },
113
+ init : function() {
114
+ var context = this;
115
+ if (this.isCustomValidation()) {
116
+ _private.form.attr("novalidate", "novalidate");
117
+ }
118
+ _private.form.find("input, textarea").each(function(){
119
+ var instance = context.makeElementInstance($(this));
120
+ if (instance !== false) {
121
+ _private.elements.push(instance);
122
+ }
123
+ });
124
+ _private.form.bind('submit', this, _private.handleOnSubmit);
125
+ },
126
+ makeElementInstance : function(element) {
127
+ var instance = {}, textAliases = {
128
+ "Password": true, "Tel": true, "Search": true
129
+ },
130
+ type = _private.normalizeName(element.attr('type'));
131
+ type = (typeof textAliases[type] !== "undefined" ? "Text" : type);
132
+ if (typeof App[type] === "undefined") {
133
+ return false;
134
+ }
135
+ $.extend(true, instance, new App[type]);
136
+ $.extend(true, instance, App.Element_Abstract);
137
+ instance.process(element);
138
+ return instance;
139
+ }
140
+ }
141
+ },
142
+ Element_Abstract: {
143
+ element : null,
144
+ hasPlaceholder: false,
145
+ _delayedRequest: null,
146
+ _validityProps: "valueMissing typeMismatch patternMismatch rangeUnderflow rangeOverflow customError".split(" "),
147
+ validationMessage : {
148
+ valueMissing : "Please fill out this field",
149
+ typeMismatch : "",
150
+ patternMismatch : "The pattern is mismatched",
151
+ rangeUnderflow: "The value is too low",
152
+ rangeOverflow: "The value is too high",
153
+ customError: ""
154
+ },
155
+ getValidationMessage : function() {
156
+ var message = "";
157
+ for (var i in this._validityProps) {
158
+ message = (!this.validity[this._validityProps[i]] && this.validationMessage[this._validityProps[i]].length)
159
+ ? this.validationMessage[this._validityProps[i]] : message;
160
+ }
161
+ return message;
162
+ },
163
+ validity : {
164
+ valueMissing : true,
165
+ typeMismatch : true,
166
+ patternMismatch : true,
167
+ rangeUnderflow: true,
168
+ rangeOverflow: true,
169
+ customError: true
170
+ },
171
+ isValid : function() {
172
+ this.validity.customError = !(this.element.data('customvalidity')
173
+ && this.element.data('customvalidity').length);
174
+ return this.validity.valueMissing &&
175
+ this.validity.typeMismatch &&
176
+ this.validity.patternMismatch &&
177
+ this.validity.rangeUnderflow &&
178
+ this.validity.rangeOverflow &&
179
+ this.validity.customError;
180
+ },
181
+ handleOnInput: function(e) {
182
+ var context = e.data;
183
+ if (null !== this._delayedRequest) {
184
+ window.clearTimeout(this._delayedRequest);
185
+ }
186
+ this._delayedRequest = window.setTimeout(function(){
187
+ this._delayedRequest = null;
188
+ context.processOninput();
189
+ context.element.trigger("oninput", context);
190
+ context.checkValidity();
191
+ context.checkPatternValidity();
192
+ context.updateStatus();
193
+ }, ONINPUT_DELAY);
194
+ },
195
+ handleOnFocus : function(e) {
196
+ var context = (typeof e === 'undefined' ? this : e.data);
197
+ context.element.addClass('focus');
198
+ if (context.element.val() === context.element.attr('placeholder')) {
199
+ context.element.val('');
200
+ context.element.removeClass('placeholder');
201
+ }
202
+
203
+ },
204
+ handleOnBlur : function(e) {
205
+ var context = (typeof e === 'undefined' ? this : e.data);
206
+ context.element.removeClass('focus');
207
+ if (!context.element.val()) {
208
+ context.element.val(context.element.attr('placeholder'));
209
+ context.element.addClass('placeholder');
210
+ }
211
+ },
212
+ isset : function(prop) {
213
+ return (typeof this[prop] !== 'undefined');
214
+ },
215
+ issetAttr : function(attr) {
216
+ return (typeof this.element.attr(attr) !== 'undefined');
217
+ },
218
+ process: function(element) {
219
+ this.element = element;
220
+ if (this.isset("init")) {
221
+ this.init();
222
+ }
223
+ if (!Browser.supportedInputProps.placeholder) {
224
+ this.processPlaceholder();
225
+ this.element.bind('focusin', this, this.handleOnFocus);
226
+ this.element.bind('focusout', this, this.handleOnBlur);
227
+ }
228
+ if (!Browser.supportedInputProps.required) {
229
+ this.processRequired();
230
+ }
231
+ if (!Browser.supportedInputProps.autofocus) {
232
+ this.processAutofocus();
233
+ }
234
+ if (this.element.attr('custom-validation')) {
235
+ this.element.attr('novalidate', 'novalidate');
236
+ }
237
+ if (!Browser.supportedInputTypes[this.element.attr('type')]
238
+ || this.element.attr('custom-validation')) {
239
+ this.syncElementUI();
240
+ }
241
+ // When customError message is specified while intitialization
242
+ this.processSetCustomValidity();
243
+ },
244
+ syncElementUI: function() {
245
+ this.element.bind('change', this, this.handleOnInput);
246
+ this.element.bind('mouseup', this, this.handleOnInput);
247
+ this.element.bind('keydown', this, this.handleOnInput);
248
+ // @TODO: Context menu handling: this.element.get().oncontextmenu = _private.handleOnInput;
249
+
250
+ },
251
+ recheckSetCustomValidity: function() {
252
+ if (typeof this.element.data('customvalidity') !== "undefined"
253
+ && this.element.data('customvalidity').length) {
254
+ this.validationMessage.customError = this.element.data('customvalidity');
255
+ }
256
+ },
257
+ processSetCustomValidity: function() {
258
+ if (typeof this.element.data('customvalidity') !== "undefined"
259
+ && this.element.data('customvalidity').length) {
260
+ this.validationMessage.typeMismatch
261
+ = this.validationMessage.patternMismatch
262
+ = this.element.data('customvalidity');
263
+ this.element.data('customvalidity', ''); // by default valid
264
+ }
265
+ },
266
+ processRequired: function() {
267
+ if (typeof this.element.attr('required') !== 'undefined') {
268
+ this.element.addClass('required');
269
+ }
270
+ },
271
+ processAutofocus: function() {
272
+ if (this.issetAttr("autofocus")) {
273
+ this.element.focus();
274
+ this.handleOnFocus();
275
+ }
276
+ },
277
+ processPlaceholder: function() {
278
+ if (this.issetAttr("placeholder")) {
279
+ this.element.attr("autocomplete", "false");
280
+ this.hasPlaceholder = true;
281
+ this.handleOnBlur();
282
+ }
283
+ },
284
+ processOninput: function() {
285
+ if (this.issetAttr("oninput")) {
286
+ var callbackKey = this.element.attr("oninput"), pos = callbackKey.indexOf("(");
287
+ callbackKey = pos ? callbackKey.substr(0, pos) : callbackKey;
288
+ if (typeof window[callbackKey]) {
289
+ window[callbackKey](this.element);
290
+ }
291
+ }
292
+ },
293
+ checkPatternValidity: function() {
294
+ if (!this.element.attr('pattern')) {
295
+ return true;
296
+ }
297
+ if (this.element.attr('title')) {
298
+ this.validationMessage.patternMismatch = this.element.attr('title');
299
+ }
300
+ var pattern = new RegExp(this.element.attr('pattern'), 'g');
301
+ this.validity.patternMismatch = pattern.test(this.element.val());
302
+ },
303
+ updateStatus: function() {
304
+ this.element.removeClass('valid').removeClass('invalid');
305
+ this.element.addClass(this.isValid() ? 'valid' : 'invalid');
306
+ },
307
+ showTooltip : function(error) {
308
+ if (!error) {
309
+ error = this.getValidationMessage(this);
310
+ }
311
+ $.setCustomValidityCallback.apply(this.element, [error]);
312
+ }
313
+ },
314
+ Email: function() {
315
+ return {
316
+ init: function() {
317
+ this.validationMessage.typeMismatch = "Please enter a valid email address";
318
+ },
319
+ checkValidity: function() {
320
+ var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/g;
321
+ this.validity.typeMismatch = pattern.test(this.element.val());
322
+ }
323
+ }
324
+ },
325
+ Number: function() {
326
+ return {
327
+ init: function() {
328
+ this.validationMessage.typeMismatch = "Please enter a valid number";
329
+ },
330
+ checkValidity: function() {
331
+ this.validity.typeMismatch = Util.isNumber(this.element.val());
332
+ this.validity.rangeUnderflow = !(this.issetAttr('min')
333
+ && parseInt(this.element.val()) < parseInt(this.element.attr('min')));
334
+ this.validity.rangeOverflow = !(this.issetAttr('max')
335
+ && parseInt(this.element.val()) > parseInt(this.element.attr('max')));
336
+
337
+ return true;
338
+ }
339
+ }
340
+ },
341
+ Url: function() {
342
+ return {
343
+ init: function() {
344
+ this.validationMessage.typeMismatch = "Please enter a valid URL";
345
+ },
346
+ checkValidity: function() {
347
+ //The pattern is taken from http://stackoverflow.com/questions/2838404/javascript-regex-url-matching
348
+ var pattern = new RegExp('^(https?:\/\/)?'+ // protocol
349
+ '((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'+ // domain name
350
+ '((\d{1,3}\.){3}\d{1,3}))'+ // OR ip (v4) address
351
+ '(\:\d+)?(\/[-a-z\d%_.~+]*)*'+ // port and path
352
+ '(\?[;&a-z\d%_.~+=-]*)?'+ // query string
353
+ '(\#[-a-z\d_]*)?$','i'); // fragment locater
354
+ this.validity.typeMismatch = pattern.test(this.element.val());
355
+ }
356
+ }
357
+ },
358
+ Text: function() {
359
+ return {
360
+ checkValidity: function() {
361
+ }
362
+ }
363
+ }
364
+ };
365
+
366
+ /**
367
+ * Object containing custom validators like zipcode, username and so on
368
+ */
369
+ $.setCustomInputTypeValidator = {};
370
+
371
+ /**
372
+ * Renders tooltip when validation error happens on form submition
373
+ * Can be overriden
374
+ */
375
+ $.setCustomValidityCallback = function(error) {
376
+ var pos = this.position(),
377
+ tooltip = $('<div class="tooltip tooltip-e">'
378
+ + '<div class="tooltip-arrow tooltip-arrow-e"></div>'
379
+ + '<div class="tooltip-inner">' + error + '</div>'
380
+ + '</div>').appendTo(this.parent());
381
+ tooltip.css('top', pos.top - (tooltip.height() / 2) + 20 );
382
+ tooltip.css('left', pos.left - tooltip.width() - 12);
383
+ window.setTimeout(function(){
384
+ tooltip.remove();
385
+ }, 2500);
386
+ }
387
+ /**
388
+ * Shim for setCustomValidity DOM element method
389
+ */
390
+ $.fn.setCustomValidity = function(error) {
391
+ this.each(function() {
392
+ if (typeof $(this).get(0).setCustomValidity === 'function') {
393
+ $(this).get(0).setCustomValidity(error);
394
+ }
395
+ $(this).data('customvalidity', error);
396
+ });
397
+ }
398
+ // Document is ready
399
+ $(document).bind('ready.html5formshim', App.init);
400
+
401
+
402
+ })( jQuery );
@@ -0,0 +1,4 @@
1
+ /**
2
+ * jQuery HTML5form by http://www.matiasmancini.com.ar/jquery-plugin-ajax-form-validation-html5.html
3
+ */
4
+ (function($){$.fn.html5form=function(options){$(this).each(function(){var defaults={async:true,method:$(this).attr('method'),responseDiv:null,labels:'show',colorOn:'#000000',colorOff:'#a1a1a1',action:$(this).attr('action'),messages:false,emptyMessage:false,emailMessage:false,allBrowsers:true};var opts=$.extend({},defaults,options);if(!opts.allBrowsers){if($.browser.webkit&&parseInt($.browser.version)>=533){return false}if($.browser.mozilla&&parseInt($.browser.version)>=2){return false}if($.browser.opera&&parseInt($.browser.version)>=11){return false}}var form=$(this);var required=new Array();var email=new Array();function fillInput(input){if(input.attr('placeholder')&&input.attr('type')!='password'){input.val(input.attr('placeholder'));input.css('color',opts.colorOff)}else{if(!input.data('value')){if(input.val()!=''){input.data('value',input.val())}}else{input.val(input.data('value'))}input.css('color',opts.colorOn)}}if(opts.labels=='hide'){$(this).find('label').hide()}$.each($('select',this),function(){$(this).css('color',opts.colorOff);$(this).change(function(){$(this).css('color',opts.colorOn)})});$.each($(':input:visible:not(:button, :submit, :radio, :checkbox, select)',form),function(i){fillInput($(this));if(this.getAttribute('required')!=null){required[i]=$(this)}if(this.getAttribute('type')=='email'){email[i]=$(this)}$(this).bind('focus',function(ev){ev.preventDefault();if(this.value==$(this).attr('placeholder')){if(this.getAttribute('type')!='url'){$(this).attr('value','')}}$(this).css('color',opts.colorOn)});$(this).bind('blur',function(ev){ev.preventDefault();if(this.value==''){fillInput($(this))}else{if((this.getAttribute('type')=='url')&&($(this).val()==$(this).attr('placeholder'))){fillInput($(this))}}});$('textarea').filter(this).each(function(){if($(this).attr('maxlength')>0){$(this).keypress(function(ev){var cc=ev.charCode||ev.keyCode;if(cc==37||cc==39){return true}if(cc==8||cc==46){return true}if(this.value.length>=$(this).attr('maxlength')){return false}else{return true}})}})});$.each($('input:submit, input:image, input:button',this),function(){$(this).bind('click',function(ev){var emptyInput=null;var emailError=null;var input=$(':input:visible:not(:button, :submit, :radio, :checkbox, select)',form);$(required).each(function(key,value){if(value==undefined){return true}if(($(this).val()==$(this).attr('placeholder'))||($(this).val()=='')){emptyInput=$(this);if(opts.emptyMessage){$(opts.responseDiv).html('<p>'+opts.emptyMessage+'</p>')}else if(opts.messages=='es'){$(opts.responseDiv).html('<p>El campo '+$(this).attr('title')+' es requerido.</p>')}else if(opts.messages=='en'){$(opts.responseDiv).html('<p>The '+$(this).attr('title')+' field is required.</p>')}else if(opts.messages=='it'){$(opts.responseDiv).html('<p>Il campo '+$(this).attr('title')+' &eacute; richiesto.</p>')}else if(opts.messages=='de'){$(opts.responseDiv).html('<p>'+$(this).attr('title')+' ist ein Pflichtfeld.</p>')}else if(opts.messages=='fr'){$(opts.responseDiv).html('<p>Le champ '+$(this).attr('title')+' est requis.</p>')}else if(opts.messages=='nl'||opts.messages=='be'){$(opts.responseDiv).html('<p>'+$(this).attr('title')+' is een verplicht veld.</p>')}else if(opts.messages=='br'){$(opts.responseDiv).html('<p>O campo '+$(this).attr('title')+' &eacute; obrigat&oacute;rio.</p>')}else if(opts.messages=='br'){$(opts.responseDiv).html("<p>Insira um email v&aacute;lido por favor.</p>")}return false}return emptyInput});$(email).each(function(key,value){if(value==undefined){return true}if($(this).val().search(/[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/i)){emailError=$(this);return false}return emailError});if(!emptyInput&&!emailError){$(input).each(function(){if($(this).val()==$(this).attr('placeholder')){$(this).val('')}});if(opts.async){var formData=$(form).serialize();$.ajax({url:opts.action,type:opts.method,data:formData,success:function(data){if(opts.responseDiv){$(opts.responseDiv).html(data)}$(input).val('');$.each(form[0],function(){fillInput($(this).not(':hidden, :button, :submit, :radio, :checkbox, select'));$('select',form).each(function(){$(this).css('color',opts.colorOff);$(this).children('option:eq(0)').attr('selected','selected')});$(':radio, :checkbox',form).removeAttr('checked')})}})}else{$(form).submit()}}else{if(emptyInput){$(emptyInput).focus().select()}else if(emailError){if(opts.emailMessage){$(opts.responseDiv).html('<p>'+opts.emailMessage+'</p>')}else if(opts.messages=='es'){$(opts.responseDiv).html('<p>Ingrese una direcci&oacute;n de correo v&aacute;lida por favor.</p>')}else if(opts.messages=='en'){$(opts.responseDiv).html('<p>Please type a valid email address.</p>')}else if(opts.messages=='it'){$(opts.responseDiv).html("<p>L'indirizzo e-mail non &eacute; valido.</p>")}else if(opts.messages=='de'){$(opts.responseDiv).html("<p>Bitte eine g&uuml;ltige E-Mail-Adresse eintragen.</p>")}else if(opts.messages=='fr'){$(opts.responseDiv).html("<p>Entrez une adresse email valide s&rsquo;il vous plait.</p>")}else if(opts.messages=='nl'||opts.messages=='be'){$(opts.responseDiv).html('<p>Voert u alstublieft een geldig email adres in.</p>')}$(emailError).select()}else{alert('Unknown Error')}}return false})})})}})(jQuery);
@@ -0,0 +1,7 @@
1
+ /************************************************************************************
2
+ ** jQuery Placehold version 0.2
3
+ ** (cc) Jason Garber (http://sixtwothree.org and http://www.viget.com)
4
+ ** Licensed under the CC-GNU GPL (http://creativecommons.org/licenses/GPL/2.0/)
5
+ *************************************************************************************/
6
+
7
+ (function($){$.fn.placehold=function(options){var opts=$.extend({},$.fn.placehold.defaults,options),supported=$.fn.placehold.is_supported();function toggle(arr){for(i=0;i<arr.length;i++){arr[i].toggle()}}return this.each(function(){if(!supported){var elem=$(this),placeholder_attr=elem.attr("placeholder"),is_password=(elem.attr("type")=="password")?true:false;if(placeholder_attr){if(!elem.val()||elem.val()==placeholder_attr){elem.addClass(opts.placeholderClassName).val(placeholder_attr)}elem.focus(function(){if(elem.val()==placeholder_attr){elem.removeClass(opts.placeholderClassName).val("")}});elem.blur(function(){if(!elem.val()){if(is_password){toggle([elem,elem_stub])}elem.addClass(opts.placeholderClassName).val(placeholder_attr)}});elem.closest("form").submit(function(){if(elem.val()==placeholder_attr){if(is_password){toggle([elem,elem_stub])}elem.val("")}return true});if(is_password){var elem_stub=$('<input type="text" class="'+opts.placeholderClassName+'" value="'+placeholder_attr+'" />');elem_stub.focus(function(){toggle([elem,elem_stub]);elem.focus()});elem.hide().after(elem_stub)}}}})};$.fn.placehold.is_supported=function(){return"placeholder" in document.createElement("input")};$.fn.placehold.defaults={placeholderClassName:"placeholder"}})(jQuery);