semantic-ui 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/lib/semantic-ui.rb +8 -0
  3. data/lib/semantic-ui/version.rb +5 -0
  4. data/vendor/assets/fonts/icons.eot +0 -0
  5. data/vendor/assets/fonts/icons.svg +450 -0
  6. data/vendor/assets/fonts/icons.ttf +0 -0
  7. data/vendor/assets/fonts/icons.woff +0 -0
  8. data/vendor/assets/images/loader-large-inverted.gif +0 -0
  9. data/vendor/assets/images/loader-large.gif +0 -0
  10. data/vendor/assets/images/loader-medium-inverted.gif +0 -0
  11. data/vendor/assets/images/loader-medium.gif +0 -0
  12. data/vendor/assets/images/loader-mini-inverted.gif +0 -0
  13. data/vendor/assets/images/loader-mini.gif +0 -0
  14. data/vendor/assets/images/loader-small-inverted.gif +0 -0
  15. data/vendor/assets/images/loader-small.gif +0 -0
  16. data/vendor/assets/javascripts/modules/accordion.js +411 -0
  17. data/vendor/assets/javascripts/modules/behavior/api.js +666 -0
  18. data/vendor/assets/javascripts/modules/behavior/colorize.js +271 -0
  19. data/vendor/assets/javascripts/modules/behavior/form.js +703 -0
  20. data/vendor/assets/javascripts/modules/behavior/state.js +752 -0
  21. data/vendor/assets/javascripts/modules/chatroom.js +766 -0
  22. data/vendor/assets/javascripts/modules/checkbox.js +348 -0
  23. data/vendor/assets/javascripts/modules/dimmer.js +524 -0
  24. data/vendor/assets/javascripts/modules/dropdown.js +707 -0
  25. data/vendor/assets/javascripts/modules/modal.js +478 -0
  26. data/vendor/assets/javascripts/modules/nag.js +542 -0
  27. data/vendor/assets/javascripts/modules/popup.js +721 -0
  28. data/vendor/assets/javascripts/modules/rating.js +358 -0
  29. data/vendor/assets/javascripts/modules/search.js +769 -0
  30. data/vendor/assets/javascripts/modules/shape.js +776 -0
  31. data/vendor/assets/javascripts/modules/sidebar.js +489 -0
  32. data/vendor/assets/javascripts/modules/tab.js +674 -0
  33. data/vendor/assets/javascripts/modules/transition.js +650 -0
  34. data/vendor/assets/javascripts/modules/video.js +459 -0
  35. data/vendor/assets/javascripts/semantic-ui.js +1 -0
  36. data/vendor/assets/stylesheets/collections/breadcrumb.less +79 -0
  37. data/vendor/assets/stylesheets/collections/form.less +536 -0
  38. data/vendor/assets/stylesheets/collections/grid.less +655 -0
  39. data/vendor/assets/stylesheets/collections/menu.less +1765 -0
  40. data/vendor/assets/stylesheets/collections/message.less +337 -0
  41. data/vendor/assets/stylesheets/collections/table.less +532 -0
  42. data/vendor/assets/stylesheets/elements/button.less +1190 -0
  43. data/vendor/assets/stylesheets/elements/divider.less +200 -0
  44. data/vendor/assets/stylesheets/elements/header.less +325 -0
  45. data/vendor/assets/stylesheets/elements/icon.less +484 -0
  46. data/vendor/assets/stylesheets/elements/image.less +170 -0
  47. data/vendor/assets/stylesheets/elements/input.less +300 -0
  48. data/vendor/assets/stylesheets/elements/label.less +824 -0
  49. data/vendor/assets/stylesheets/elements/loader.less +178 -0
  50. data/vendor/assets/stylesheets/elements/progress.less +353 -0
  51. data/vendor/assets/stylesheets/elements/segment.less +465 -0
  52. data/vendor/assets/stylesheets/elements/step.less +294 -0
  53. data/vendor/assets/stylesheets/modules/accordion.less +135 -0
  54. data/vendor/assets/stylesheets/modules/chatroom.less +271 -0
  55. data/vendor/assets/stylesheets/modules/checkbox.less +380 -0
  56. data/vendor/assets/stylesheets/modules/dimmer.less +230 -0
  57. data/vendor/assets/stylesheets/modules/dropdown.less +506 -0
  58. data/vendor/assets/stylesheets/modules/modal.less +160 -0
  59. data/vendor/assets/stylesheets/modules/nag.less +175 -0
  60. data/vendor/assets/stylesheets/modules/popup.less +238 -0
  61. data/vendor/assets/stylesheets/modules/rating.less +151 -0
  62. data/vendor/assets/stylesheets/modules/reveal.less +367 -0
  63. data/vendor/assets/stylesheets/modules/search.less +275 -0
  64. data/vendor/assets/stylesheets/modules/shape.less +115 -0
  65. data/vendor/assets/stylesheets/modules/sidebar.less +147 -0
  66. data/vendor/assets/stylesheets/modules/tab.less +59 -0
  67. data/vendor/assets/stylesheets/modules/transition.less +839 -0
  68. data/vendor/assets/stylesheets/modules/video.less +99 -0
  69. data/vendor/assets/stylesheets/semantic-ui.less +1 -0
  70. data/vendor/assets/stylesheets/views/comment.less +221 -0
  71. data/vendor/assets/stylesheets/views/feed.less +151 -0
  72. data/vendor/assets/stylesheets/views/item.less +641 -0
  73. data/vendor/assets/stylesheets/views/list.less +508 -0
  74. data/vendor/assets/stylesheets/views/statistic.css +27 -0
  75. metadata +187 -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,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 );