semantic_ui_rails 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/README.md +4 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/fonts/semantic/icons.eot +0 -0
  8. data/app/assets/fonts/semantic/icons.svg +450 -0
  9. data/app/assets/fonts/semantic/icons.ttf +0 -0
  10. data/app/assets/fonts/semantic/icons.woff +0 -0
  11. data/app/assets/images/semantic/loader-large-inverted.gif +0 -0
  12. data/app/assets/images/semantic/loader-large.gif +0 -0
  13. data/app/assets/images/semantic/loader-medium-inverted.gif +0 -0
  14. data/app/assets/images/semantic/loader-medium.gif +0 -0
  15. data/app/assets/images/semantic/loader-mini-inverted.gif +0 -0
  16. data/app/assets/images/semantic/loader-mini.gif +0 -0
  17. data/app/assets/images/semantic/loader-small-inverted.gif +0 -0
  18. data/app/assets/images/semantic/loader-small.gif +0 -0
  19. data/app/assets/javascript/semantic/accordion.js +411 -0
  20. data/app/assets/javascript/semantic/behavior/api.js +666 -0
  21. data/app/assets/javascript/semantic/behavior/colorize.js +271 -0
  22. data/app/assets/javascript/semantic/behavior/form.js +703 -0
  23. data/app/assets/javascript/semantic/behavior/state.js +752 -0
  24. data/app/assets/javascript/semantic/chatroom.js +766 -0
  25. data/app/assets/javascript/semantic/checkbox.js +348 -0
  26. data/app/assets/javascript/semantic/dimmer.js +524 -0
  27. data/app/assets/javascript/semantic/dropdown.js +707 -0
  28. data/app/assets/javascript/semantic/modal.js +478 -0
  29. data/app/assets/javascript/semantic/nag.js +542 -0
  30. data/app/assets/javascript/semantic/popup.js +721 -0
  31. data/app/assets/javascript/semantic/rating.js +358 -0
  32. data/app/assets/javascript/semantic/search.js +769 -0
  33. data/app/assets/javascript/semantic/shape.js +776 -0
  34. data/app/assets/javascript/semantic/sidebar.js +489 -0
  35. data/app/assets/javascript/semantic/tab.js +674 -0
  36. data/app/assets/javascript/semantic/transition.js +650 -0
  37. data/app/assets/javascript/semantic/video.js +459 -0
  38. data/app/assets/stylesheets/semantic/accordion.css +97 -0
  39. data/app/assets/stylesheets/semantic/breadcrumb.css +66 -0
  40. data/app/assets/stylesheets/semantic/button.css +993 -0
  41. data/app/assets/stylesheets/semantic/chatroom.css +242 -0
  42. data/app/assets/stylesheets/semantic/checkbox.css +300 -0
  43. data/app/assets/stylesheets/semantic/comment.css +178 -0
  44. data/app/assets/stylesheets/semantic/dimmer.css +185 -0
  45. data/app/assets/stylesheets/semantic/divider.css +155 -0
  46. data/app/assets/stylesheets/semantic/dropdown.css +415 -0
  47. data/app/assets/stylesheets/semantic/feed.css +126 -0
  48. data/app/assets/stylesheets/semantic/form.css +427 -0
  49. data/app/assets/stylesheets/semantic/grid.css +561 -0
  50. data/app/assets/stylesheets/semantic/header.css +277 -0
  51. data/app/assets/stylesheets/semantic/icon.css +811 -0
  52. data/app/assets/stylesheets/semantic/image.css +143 -0
  53. data/app/assets/stylesheets/semantic/input.css +225 -0
  54. data/app/assets/stylesheets/semantic/item.css +564 -0
  55. data/app/assets/stylesheets/semantic/label.css +687 -0
  56. data/app/assets/stylesheets/semantic/list.css +418 -0
  57. data/app/assets/stylesheets/semantic/loader.css +148 -0
  58. data/app/assets/stylesheets/semantic/menu.css +1409 -0
  59. data/app/assets/stylesheets/semantic/message.css +242 -0
  60. data/app/assets/stylesheets/semantic/modal.css +123 -0
  61. data/app/assets/stylesheets/semantic/nag.css +130 -0
  62. data/app/assets/stylesheets/semantic/popup.css +209 -0
  63. data/app/assets/stylesheets/semantic/progress.css +257 -0
  64. data/app/assets/stylesheets/semantic/rating.css +120 -0
  65. data/app/assets/stylesheets/semantic/reveal.css +283 -0
  66. data/app/assets/stylesheets/semantic/search.css +222 -0
  67. data/app/assets/stylesheets/semantic/segment.css +362 -0
  68. data/app/assets/stylesheets/semantic/shape.css +87 -0
  69. data/app/assets/stylesheets/semantic/sidebar.css +100 -0
  70. data/app/assets/stylesheets/semantic/step.css +240 -0
  71. data/app/assets/stylesheets/semantic/tab.css +52 -0
  72. data/app/assets/stylesheets/semantic/table.css +468 -0
  73. data/app/assets/stylesheets/semantic/transition.css +867 -0
  74. data/app/assets/stylesheets/semantic/video.css +81 -0
  75. data/lib/semantic_ui_rails/version.rb +3 -0
  76. data/lib/semantic_ui_rails.rb +7 -0
  77. data/semantic_ui_rails.gemspec +23 -0
  78. metadata +149 -0
@@ -0,0 +1,703 @@
1
+ /* ******************************
2
+ Form Validation Components
3
+ Author: Jack Lukic
4
+ Notes: First Commit April 08, 2012
5
+
6
+ Refactored May 28, 2013
7
+
8
+ Allows you to validate forms based on a form validation object
9
+ Form validation objects are bound by either data-validate="" metadata, or form id or name tags
10
+
11
+ ****************************** */
12
+
13
+ ;(function ( $, window, document, undefined ) {
14
+
15
+ $.fn.form = function(fields, parameters) {
16
+ var
17
+ $allModules = $(this),
18
+
19
+ settings = $.extend(true, {}, $.fn.form.settings, parameters),
20
+ validation = $.extend({}, $.fn.form.settings.defaults, fields),
21
+
22
+ namespace = settings.namespace,
23
+ metadata = settings.metadata,
24
+ selector = settings.selector,
25
+ className = settings.className,
26
+ error = settings.error,
27
+
28
+ eventNamespace = '.' + namespace,
29
+ moduleNamespace = 'module-' + namespace,
30
+
31
+ moduleSelector = $allModules.selector || '',
32
+
33
+ time = new Date().getTime(),
34
+ performance = [],
35
+
36
+ query = arguments[0],
37
+ methodInvoked = (typeof query == 'string'),
38
+ queryArguments = [].slice.call(arguments, 1),
39
+ invokedResponse
40
+ ;
41
+ $allModules
42
+ .each(function() {
43
+ var
44
+ $module = $(this),
45
+ $field = $(this).find(selector.field),
46
+ $group = $(this).find(selector.group),
47
+ $message = $(this).find(selector.message),
48
+ $prompt = $(this).find(selector.prompt),
49
+ $submit = $(this).find(selector.submit),
50
+
51
+ formErrors = [],
52
+
53
+ element = this,
54
+ instance = $module.data(moduleNamespace),
55
+ module
56
+ ;
57
+
58
+ module = {
59
+
60
+ initialize: function() {
61
+ module.verbose('Initializing form validation', $module, validation, settings);
62
+ if(settings.keyboardShortcuts) {
63
+ $field
64
+ .on('keydown' + eventNamespace, module.event.field.keydown)
65
+ ;
66
+ }
67
+ $module
68
+ .on('submit' + eventNamespace, module.validate.form)
69
+ ;
70
+ $field
71
+ .on('blur' + eventNamespace, module.event.field.blur)
72
+ ;
73
+ $submit
74
+ .on('click' + eventNamespace, module.submit)
75
+ ;
76
+ $field
77
+ .on(module.get.changeEvent() + eventNamespace, module.event.field.change)
78
+ ;
79
+ module.instantiate();
80
+ },
81
+
82
+ instantiate: function() {
83
+ module.verbose('Storing instance of module', module);
84
+ instance = module;
85
+ $module
86
+ .data(moduleNamespace, module)
87
+ ;
88
+ },
89
+
90
+ destroy: function() {
91
+ module.verbose('Destroying previous module', instance);
92
+ $module
93
+ .off(eventNamespace)
94
+ .removeData(moduleNamespace)
95
+ ;
96
+ },
97
+
98
+ refresh: function() {
99
+ module.verbose('Refreshing selector cache');
100
+ $field = $module.find(selector.field);
101
+ },
102
+
103
+ submit: function() {
104
+ module.verbose('Submitting form', $module);
105
+ $module
106
+ .submit()
107
+ ;
108
+ },
109
+
110
+ event: {
111
+ field: {
112
+ keydown: function(event) {
113
+ var
114
+ $field = $(this),
115
+ key = event.which,
116
+ keyCode = {
117
+ enter : 13,
118
+ escape : 27
119
+ }
120
+ ;
121
+ if( key == keyCode.escape) {
122
+ module.verbose('Escape key pressed blurring field');
123
+ $field
124
+ .blur()
125
+ ;
126
+ }
127
+ if(!event.ctrlKey && key == keyCode.enter && $field.is(selector.input) ) {
128
+ module.debug('Enter key pressed, submitting form');
129
+ $submit
130
+ .addClass(className.down)
131
+ ;
132
+ $field
133
+ .one('keyup' + eventNamespace, module.event.field.keyup)
134
+ ;
135
+ event.preventDefault();
136
+ return false;
137
+ }
138
+ },
139
+ keyup: function() {
140
+ module.verbose('Doing keyboard shortcut form submit');
141
+ $submit.removeClass(className.down);
142
+ module.submit();
143
+ },
144
+ blur: function() {
145
+ var
146
+ $field = $(this),
147
+ $fieldGroup = $field.closest($group)
148
+ ;
149
+ if( $fieldGroup.hasClass(className.error) ) {
150
+ module.debug('Revalidating field', $field, module.get.validation($field));
151
+ module.validate.field( module.get.validation($field) );
152
+ }
153
+ else if(settings.on == 'blur' || settings.on == 'change') {
154
+ module.validate.field( module.get.validation($field) );
155
+ }
156
+ },
157
+ change: function() {
158
+ var
159
+ $field = $(this),
160
+ $fieldGroup = $field.closest($group)
161
+ ;
162
+ if( $fieldGroup.hasClass(className.error) ) {
163
+ module.debug('Revalidating field', $field, module.get.validation($field));
164
+ module.validate.field( module.get.validation($field) );
165
+ }
166
+ else if(settings.on == 'change') {
167
+ module.validate.field( module.get.validation($field) );
168
+ }
169
+ }
170
+ }
171
+
172
+ },
173
+
174
+ get: {
175
+ changeEvent: function() {
176
+ return (document.createElement('input').oninput !== undefined)
177
+ ? 'input'
178
+ : (document.createElement('input').onpropertychange !== undefined)
179
+ ? 'propertychange'
180
+ : 'keyup'
181
+ ;
182
+ },
183
+ field: function(identifier) {
184
+ module.verbose('Finding field with identifier', identifier);
185
+ if( $field.filter('#' + identifier).size() > 0 ) {
186
+ return $field.filter('#' + identifier);
187
+ }
188
+ else if( $field.filter('[name="' + identifier +'"]').size() > 0 ) {
189
+ return $field.filter('[name="' + identifier +'"]');
190
+ }
191
+ else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').size() > 0 ) {
192
+ return $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]');
193
+ }
194
+ return $('<input/>');
195
+ },
196
+ validation: function($field) {
197
+ var
198
+ rules
199
+ ;
200
+ $.each(validation, function(fieldName, field) {
201
+ if( module.get.field(field.identifier).get(0) == $field.get(0) ) {
202
+ rules = field;
203
+ }
204
+ });
205
+ return rules || false;
206
+ }
207
+ },
208
+
209
+ has: {
210
+
211
+ field: function(identifier) {
212
+ module.verbose('Checking for existence of a field with identifier', identifier);
213
+ if( $field.filter('#' + identifier).size() > 0 ) {
214
+ return true;
215
+ }
216
+ else if( $field.filter('[name="' + identifier +'"]').size() > 0 ) {
217
+ return true;
218
+ }
219
+ else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').size() > 0 ) {
220
+ return true;
221
+ }
222
+ return false;
223
+ }
224
+
225
+ },
226
+
227
+ add: {
228
+ prompt: function(field, errors) {
229
+ var
230
+ $field = module.get.field(field.identifier),
231
+ $fieldGroup = $field.closest($group),
232
+ $prompt = $fieldGroup.find(selector.prompt),
233
+ promptExists = ($prompt.size() !== 0)
234
+ ;
235
+ module.verbose('Adding inline error', field);
236
+ $fieldGroup
237
+ .addClass(className.error)
238
+ ;
239
+ if(settings.inline) {
240
+ if(!promptExists) {
241
+ $prompt = settings.templates.prompt(errors);
242
+ $prompt
243
+ .appendTo($fieldGroup)
244
+ ;
245
+ }
246
+ $prompt
247
+ .html(errors[0])
248
+ ;
249
+ if(!promptExists) {
250
+ if(settings.transition && $.fn.transition !== undefined) {
251
+ module.verbose('Displaying error with css transition', settings.transition);
252
+ $prompt.transition(settings.transition + ' in', settings.duration);
253
+ }
254
+ else {
255
+ module.verbose('Displaying error with fallback javascript animation');
256
+ $prompt
257
+ .fadeIn(settings.duration)
258
+ ;
259
+ }
260
+ }
261
+ }
262
+ },
263
+ errors: function(errors) {
264
+ module.debug('Adding form error messages', errors);
265
+ $message
266
+ .html( settings.templates.error(errors) )
267
+ ;
268
+ }
269
+ },
270
+
271
+ remove: {
272
+ prompt: function(field) {
273
+ var
274
+ $field = module.get.field(field.identifier),
275
+ $fieldGroup = $field.closest($group),
276
+ $prompt = $fieldGroup.find(selector.prompt)
277
+ ;
278
+ $fieldGroup
279
+ .removeClass(className.error)
280
+ ;
281
+ if(settings.inline && $prompt.is(':visible')) {
282
+ module.verbose('Removing prompt for field', field);
283
+ if(settings.transition && $.fn.transition !== undefined) {
284
+ $prompt.transition(settings.transition + ' out', settings.duration, function() {
285
+ $prompt.remove();
286
+ });
287
+ }
288
+ else {
289
+ $prompt
290
+ .fadeOut(settings.duration, function(){
291
+ $prompt.remove();
292
+ })
293
+ ;
294
+ }
295
+ }
296
+ }
297
+ },
298
+
299
+ validate: {
300
+
301
+ form: function(event) {
302
+ var
303
+ allValid = true
304
+ ;
305
+ // reset errors
306
+ formErrors = [];
307
+ $.each(validation, function(fieldName, field) {
308
+ if( !( module.validate.field(field) ) ) {
309
+ allValid = false;
310
+ }
311
+ });
312
+ if(allValid) {
313
+ module.debug('Form has no validation errors, submitting');
314
+ $module
315
+ .removeClass(className.error)
316
+ .addClass(className.success)
317
+ ;
318
+ $.proxy(settings.onSuccess, this)(event);
319
+ }
320
+ else {
321
+ module.debug('Form has errors');
322
+ $module.addClass(className.error);
323
+ if(!settings.inline) {
324
+ module.add.errors(formErrors);
325
+ }
326
+ return $.proxy(settings.onFailure, this)(formErrors);
327
+ }
328
+ },
329
+
330
+ // takes a validation object and returns whether field passes validation
331
+ field: function(field) {
332
+ var
333
+ $field = module.get.field(field.identifier),
334
+ fieldValid = true,
335
+ fieldErrors = []
336
+ ;
337
+ if(field.rules !== undefined) {
338
+ $.each(field.rules, function(index, rule) {
339
+ if( module.has.field(field.identifier) && !( module.validate.rule(field, rule) ) ) {
340
+ module.debug('Field is invalid', field.identifier, rule.type);
341
+ fieldErrors.push(rule.prompt);
342
+ fieldValid = false;
343
+ }
344
+ });
345
+ }
346
+ if(fieldValid) {
347
+ module.remove.prompt(field, fieldErrors);
348
+ $.proxy(settings.onValid, $field)();
349
+ }
350
+ else {
351
+ formErrors = formErrors.concat(fieldErrors);
352
+ module.add.prompt(field, fieldErrors);
353
+ $.proxy(settings.onInvalid, $field)(fieldErrors);
354
+ return false;
355
+ }
356
+ return true;
357
+ },
358
+
359
+ // takes validation rule and returns whether field passes rule
360
+ rule: function(field, validation) {
361
+ var
362
+ $field = module.get.field(field.identifier),
363
+ type = validation.type,
364
+ value = $field.val(),
365
+
366
+ bracketRegExp = /\[(.*?)\]/i,
367
+ bracket = bracketRegExp.exec(type),
368
+ isValid = true,
369
+ ancillary,
370
+ functionType
371
+ ;
372
+ // if bracket notation is used, pass in extra parameters
373
+ if(bracket !== undefined && bracket !== null) {
374
+ ancillary = bracket[1];
375
+ functionType = type.replace(bracket[0], '');
376
+ isValid = $.proxy(settings.rules[functionType], $module)(value, ancillary);
377
+ }
378
+ // normal notation
379
+ else {
380
+ isValid = (type == 'checked')
381
+ ? $field.filter(':checked').size() > 0
382
+ : settings.rules[type](value)
383
+ ;
384
+ }
385
+ return isValid;
386
+ }
387
+ },
388
+
389
+ setting: function(name, value) {
390
+ module.debug('Changing setting', name, value);
391
+ if(value !== undefined) {
392
+ if( $.isPlainObject(name) ) {
393
+ $.extend(true, settings, name);
394
+ }
395
+ else {
396
+ settings[name] = value;
397
+ }
398
+ }
399
+ else {
400
+ return settings[name];
401
+ }
402
+ },
403
+ internal: function(name, value) {
404
+ module.debug('Changing internal', name, value);
405
+ if(value !== undefined) {
406
+ if( $.isPlainObject(name) ) {
407
+ $.extend(true, module, name);
408
+ }
409
+ else {
410
+ module[name] = value;
411
+ }
412
+ }
413
+ else {
414
+ return module[name];
415
+ }
416
+ },
417
+ debug: function() {
418
+ if(settings.debug) {
419
+ if(settings.performance) {
420
+ module.performance.log(arguments);
421
+ }
422
+ else {
423
+ module.debug = Function.prototype.bind.call(console.info, console, settings.moduleName + ':');
424
+ module.debug.apply(console, arguments);
425
+ }
426
+ }
427
+ },
428
+ verbose: function() {
429
+ if(settings.verbose && settings.debug) {
430
+ if(settings.performance) {
431
+ module.performance.log(arguments);
432
+ }
433
+ else {
434
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.moduleName + ':');
435
+ module.verbose.apply(console, arguments);
436
+ }
437
+ }
438
+ },
439
+ error: function() {
440
+ module.error = Function.prototype.bind.call(console.error, console, settings.moduleName + ':');
441
+ module.error.apply(console, arguments);
442
+ },
443
+ performance: {
444
+ log: function(message) {
445
+ var
446
+ currentTime,
447
+ executionTime,
448
+ previousTime
449
+ ;
450
+ if(settings.performance) {
451
+ currentTime = new Date().getTime();
452
+ previousTime = time || currentTime;
453
+ executionTime = currentTime - previousTime;
454
+ time = currentTime;
455
+ performance.push({
456
+ 'Element' : element,
457
+ 'Name' : message[0],
458
+ 'Arguments' : [].slice.call(message, 1) || '',
459
+ 'Execution Time' : executionTime
460
+ });
461
+ }
462
+ clearTimeout(module.performance.timer);
463
+ module.performance.timer = setTimeout(module.performance.display, 100);
464
+ },
465
+ display: function() {
466
+ var
467
+ title = settings.name + ':',
468
+ totalTime = 0
469
+ ;
470
+ time = false;
471
+ clearTimeout(module.performance.timer);
472
+ $.each(performance, function(index, data) {
473
+ totalTime += data['Execution Time'];
474
+ });
475
+ title += ' ' + totalTime + 'ms';
476
+ if(moduleSelector) {
477
+ title += ' \'' + moduleSelector + '\'';
478
+ }
479
+ if($allModules.size() > 1) {
480
+ title += ' ' + '(' + $allModules.size() + ')';
481
+ }
482
+ if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
483
+ console.groupCollapsed(title);
484
+ if(console.table) {
485
+ console.table(performance);
486
+ }
487
+ else {
488
+ $.each(performance, function(index, data) {
489
+ console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
490
+ });
491
+ }
492
+ console.groupEnd();
493
+ }
494
+ performance = [];
495
+ }
496
+ },
497
+ invoke: function(query, passedArguments, context) {
498
+ var
499
+ maxDepth,
500
+ found,
501
+ response
502
+ ;
503
+ passedArguments = passedArguments || queryArguments;
504
+ context = element || context;
505
+ if(typeof query == 'string' && instance !== undefined) {
506
+ query = query.split(/[\. ]/);
507
+ maxDepth = query.length - 1;
508
+ $.each(query, function(depth, value) {
509
+ var camelCaseValue = (depth != maxDepth)
510
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
511
+ : query
512
+ ;
513
+ if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) {
514
+ instance = instance[value];
515
+ }
516
+ else if( $.isPlainObject( instance[camelCaseValue] ) && (depth != maxDepth) ) {
517
+ instance = instance[camelCaseValue];
518
+ }
519
+ else if( instance[value] !== undefined ) {
520
+ found = instance[value];
521
+ return false;
522
+ }
523
+ else if( instance[camelCaseValue] !== undefined ) {
524
+ found = instance[camelCaseValue];
525
+ return false;
526
+ }
527
+ else {
528
+ module.error(error.method);
529
+ return false;
530
+ }
531
+ });
532
+ }
533
+ if ( $.isFunction( found ) ) {
534
+ response = found.apply(context, passedArguments);
535
+ }
536
+ else if(found !== undefined) {
537
+ response = found;
538
+ }
539
+ if($.isArray(invokedResponse)) {
540
+ invokedResponse.push(response);
541
+ }
542
+ else if(typeof invokedResponse == 'string') {
543
+ invokedResponse = [invokedResponse, response];
544
+ }
545
+ else if(response !== undefined) {
546
+ invokedResponse = response;
547
+ }
548
+ return found;
549
+ }
550
+ };
551
+ if(methodInvoked) {
552
+ if(instance === undefined) {
553
+ module.initialize();
554
+ }
555
+ module.invoke(query);
556
+ }
557
+ else {
558
+ if(instance !== undefined) {
559
+ module.destroy();
560
+ }
561
+ module.initialize();
562
+ }
563
+
564
+ })
565
+ ;
566
+
567
+ return (invokedResponse !== undefined)
568
+ ? invokedResponse
569
+ : this
570
+ ;
571
+ };
572
+
573
+ $.fn.form.settings = {
574
+
575
+ name : 'Form',
576
+ namespace : 'form',
577
+
578
+ debug : true,
579
+ verbose : true,
580
+ performance : true,
581
+
582
+
583
+ keyboardShortcuts : true,
584
+ on : 'submit',
585
+ inline : false,
586
+
587
+ transition : 'scale',
588
+ duration : 150,
589
+
590
+
591
+ onValid : function() {},
592
+ onInvalid : function() {},
593
+ onSuccess : function() { return true; },
594
+ onFailure : function() { return false; },
595
+
596
+ metadata : {
597
+ validate: 'validate'
598
+ },
599
+
600
+ selector : {
601
+ message : '.error.message',
602
+ field : 'input, textarea, select',
603
+ group : '.field',
604
+ input : 'input',
605
+ prompt : '.prompt',
606
+ submit : '.submit'
607
+ },
608
+
609
+ className : {
610
+ error : 'error',
611
+ success : 'success',
612
+ down : 'down',
613
+ label : 'ui label prompt'
614
+ },
615
+
616
+ // errors
617
+ error: {
618
+ method : 'The method you called is not defined.'
619
+ },
620
+
621
+
622
+
623
+ templates: {
624
+ error: function(errors) {
625
+ var
626
+ html = '<ul class="list">'
627
+ ;
628
+ $.each(errors, function(index, value) {
629
+ html += '<li>' + value + '</li>';
630
+ });
631
+ html += '</ul>';
632
+ return $(html);
633
+ },
634
+ prompt: function(errors) {
635
+ return $('<div/>')
636
+ .addClass('ui red pointing prompt label')
637
+ .html(errors[0])
638
+ ;
639
+ }
640
+ },
641
+
642
+ rules: {
643
+ empty: function(value) {
644
+ return !(value === undefined || '' === value);
645
+ },
646
+ email: function(value){
647
+ var
648
+ emailRegExp = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")
649
+ ;
650
+ return emailRegExp.test(value);
651
+ },
652
+ length: function(value, requiredLength) {
653
+ return (value !== undefined)
654
+ ? (value.length >= requiredLength)
655
+ : false
656
+ ;
657
+ },
658
+ not: function(value, notValue) {
659
+ return (value != notValue);
660
+ },
661
+ contains: function(value, text) {
662
+ return (value.search(text) !== -1);
663
+ },
664
+ is: function(value, text) {
665
+ return (value == text);
666
+ },
667
+ maxLength: function(value, maxLength) {
668
+ return (value !== undefined)
669
+ ? (value.length <= maxLength)
670
+ : false
671
+ ;
672
+ },
673
+ match: function(value, fieldIdentifier) {
674
+ // use either id or name of field
675
+ var
676
+ $form = $(this),
677
+ matchingValue
678
+ ;
679
+ if($form.find('#' + fieldIdentifier).size() > 0) {
680
+ matchingValue = $form.find('#' + fieldIdentifier).val();
681
+ }
682
+ else if($form.find('[name=' + fieldIdentifier +']').size() > 0) {
683
+ matchingValue = $form.find('[name=' + fieldIdentifier + ']').val();
684
+ }
685
+ else if( $form.find('[data-validate="'+ fieldIdentifier +'"]').size() > 0 ) {
686
+ matchingValue = $form.find('[data-validate="'+ fieldIdentifier +'"]').val();
687
+ }
688
+ return (matchingValue !== undefined)
689
+ ? ( value.toString() == matchingValue.toString() )
690
+ : false
691
+ ;
692
+ },
693
+ url: function(value) {
694
+ var
695
+ urlRegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
696
+ ;
697
+ return urlRegExp.test(value);
698
+ }
699
+ }
700
+
701
+ };
702
+
703
+ })( jQuery, window , document );