semantic-ui-rails 0.0.1

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