semantic-ui-sass 0.0.1

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