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,403 @@
1
+ /*
2
+ * # Semantic - Rating
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.rating = function(parameters) {
15
+ var
16
+ $allModules = $(this),
17
+ moduleSelector = $allModules.selector || '',
18
+
19
+ settings = $.extend(true, {}, $.fn.rating.settings, parameters),
20
+
21
+ namespace = settings.namespace,
22
+ className = settings.className,
23
+ metadata = settings.metadata,
24
+ selector = settings.selector,
25
+ error = settings.error,
26
+
27
+ eventNamespace = '.' + namespace,
28
+ moduleNamespace = 'module-' + namespace,
29
+
30
+ time = new Date().getTime(),
31
+ performance = [],
32
+
33
+ query = arguments[0],
34
+ methodInvoked = (typeof query == 'string'),
35
+ queryArguments = [].slice.call(arguments, 1),
36
+ invokedResponse
37
+ ;
38
+ $allModules
39
+ .each(function() {
40
+ var
41
+ $module = $(this),
42
+ $icon = $module.find(selector.icon),
43
+
44
+ element = this,
45
+ instance = $module.data(moduleNamespace),
46
+ module
47
+ ;
48
+
49
+ module = {
50
+
51
+ initialize: function() {
52
+ module.verbose('Initializing rating module', settings);
53
+
54
+ if(settings.interactive) {
55
+ module.enable();
56
+ }
57
+ else {
58
+ module.disable();
59
+ }
60
+
61
+ if(settings.initialRating) {
62
+ module.debug('Setting initial rating');
63
+ module.setRating(settings.initialRating);
64
+ }
65
+ if( $module.data(metadata.rating) ) {
66
+ module.debug('Rating found in metadata');
67
+ module.setRating( $module.data(metadata.rating) );
68
+ }
69
+ module.instantiate();
70
+ },
71
+
72
+ instantiate: function() {
73
+ module.verbose('Instantiating module', settings);
74
+ $module
75
+ .data(moduleNamespace, module)
76
+ ;
77
+ },
78
+
79
+ destroy: function() {
80
+ $module
81
+ .removeData(moduleNamespace)
82
+ ;
83
+ $icon
84
+ .off(eventNamespace)
85
+ ;
86
+ },
87
+
88
+ event: {
89
+ mouseenter: function() {
90
+ var
91
+ $activeIcon = $(this)
92
+ ;
93
+ $activeIcon
94
+ .nextAll()
95
+ .removeClass(className.hover)
96
+ ;
97
+ $module
98
+ .addClass(className.hover)
99
+ ;
100
+ $activeIcon
101
+ .addClass(className.hover)
102
+ .prevAll()
103
+ .addClass(className.hover)
104
+ ;
105
+ },
106
+ mouseleave: function() {
107
+ $module
108
+ .removeClass(className.hover)
109
+ ;
110
+ $icon
111
+ .removeClass(className.hover)
112
+ ;
113
+ },
114
+ click: function() {
115
+ var
116
+ $activeIcon = $(this),
117
+ currentRating = module.getRating(),
118
+ rating = $icon.index($activeIcon) + 1
119
+ ;
120
+ if(settings.clearable && currentRating == rating) {
121
+ module.clearRating();
122
+ }
123
+ else {
124
+ module.setRating( rating );
125
+ }
126
+ }
127
+ },
128
+
129
+ clearRating: function() {
130
+ module.debug('Clearing current rating');
131
+ module.setRating(0);
132
+ },
133
+
134
+ getRating: function() {
135
+ var
136
+ currentRating = $icon.filter('.' + className.active).size()
137
+ ;
138
+ module.verbose('Current rating retrieved', currentRating);
139
+ return currentRating;
140
+ },
141
+
142
+ enable: function() {
143
+ module.debug('Setting rating to interactive mode');
144
+ $icon
145
+ .on('mouseenter' + eventNamespace, module.event.mouseenter)
146
+ .on('mouseleave' + eventNamespace, module.event.mouseleave)
147
+ .on('click' + eventNamespace, module.event.click)
148
+ ;
149
+ $module
150
+ .addClass(className.active)
151
+ ;
152
+ },
153
+
154
+ disable: function() {
155
+ module.debug('Setting rating to read-only mode');
156
+ $icon
157
+ .off(eventNamespace)
158
+ ;
159
+ $module
160
+ .removeClass(className.active)
161
+ ;
162
+ },
163
+
164
+ setRating: function(rating) {
165
+ var
166
+ ratingIndex = (rating - 1 >= 0)
167
+ ? (rating - 1)
168
+ : 0,
169
+ $activeIcon = $icon.eq(ratingIndex)
170
+ ;
171
+ $module
172
+ .removeClass(className.hover)
173
+ ;
174
+ $icon
175
+ .removeClass(className.hover)
176
+ .removeClass(className.active)
177
+ ;
178
+ if(rating > 0) {
179
+ module.verbose('Setting current rating to', rating);
180
+ $activeIcon
181
+ .addClass(className.active)
182
+ .prevAll()
183
+ .addClass(className.active)
184
+ ;
185
+ }
186
+ $.proxy(settings.onRate, element)(rating);
187
+ },
188
+
189
+ setting: function(name, value) {
190
+ if(value !== undefined) {
191
+ if( $.isPlainObject(name) ) {
192
+ $.extend(true, settings, name);
193
+ }
194
+ else {
195
+ settings[name] = value;
196
+ }
197
+ }
198
+ else {
199
+ return settings[name];
200
+ }
201
+ },
202
+ internal: function(name, value) {
203
+ if(value !== undefined) {
204
+ if( $.isPlainObject(name) ) {
205
+ $.extend(true, module, name);
206
+ }
207
+ else {
208
+ module[name] = value;
209
+ }
210
+ }
211
+ else {
212
+ return module[name];
213
+ }
214
+ },
215
+ debug: function() {
216
+ if(settings.debug) {
217
+ if(settings.performance) {
218
+ module.performance.log(arguments);
219
+ }
220
+ else {
221
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
222
+ module.debug.apply(console, arguments);
223
+ }
224
+ }
225
+ },
226
+ verbose: function() {
227
+ if(settings.verbose && settings.debug) {
228
+ if(settings.performance) {
229
+ module.performance.log(arguments);
230
+ }
231
+ else {
232
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
233
+ module.verbose.apply(console, arguments);
234
+ }
235
+ }
236
+ },
237
+ error: function() {
238
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
239
+ module.error.apply(console, arguments);
240
+ },
241
+ performance: {
242
+ log: function(message) {
243
+ var
244
+ currentTime,
245
+ executionTime,
246
+ previousTime
247
+ ;
248
+ if(settings.performance) {
249
+ currentTime = new Date().getTime();
250
+ previousTime = time || currentTime;
251
+ executionTime = currentTime - previousTime;
252
+ time = currentTime;
253
+ performance.push({
254
+ 'Element' : element,
255
+ 'Name' : message[0],
256
+ 'Arguments' : [].slice.call(message, 1) || '',
257
+ 'Execution Time' : executionTime
258
+ });
259
+ }
260
+ clearTimeout(module.performance.timer);
261
+ module.performance.timer = setTimeout(module.performance.display, 100);
262
+ },
263
+ display: function() {
264
+ var
265
+ title = settings.name + ':',
266
+ totalTime = 0
267
+ ;
268
+ time = false;
269
+ clearTimeout(module.performance.timer);
270
+ $.each(performance, function(index, data) {
271
+ totalTime += data['Execution Time'];
272
+ });
273
+ title += ' ' + totalTime + 'ms';
274
+ if(moduleSelector) {
275
+ title += ' \'' + moduleSelector + '\'';
276
+ }
277
+ if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
278
+ console.groupCollapsed(title);
279
+ if(console.table) {
280
+ console.table(performance);
281
+ }
282
+ else {
283
+ $.each(performance, function(index, data) {
284
+ console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
285
+ });
286
+ }
287
+ console.groupEnd();
288
+ }
289
+ performance = [];
290
+ }
291
+ },
292
+ invoke: function(query, passedArguments, context) {
293
+ var
294
+ maxDepth,
295
+ found,
296
+ response
297
+ ;
298
+ passedArguments = passedArguments || queryArguments;
299
+ context = element || context;
300
+ if(typeof query == 'string' && instance !== undefined) {
301
+ query = query.split(/[\. ]/);
302
+ maxDepth = query.length - 1;
303
+ $.each(query, function(depth, value) {
304
+ var camelCaseValue = (depth != maxDepth)
305
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
306
+ : query
307
+ ;
308
+ if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) {
309
+ instance = instance[value];
310
+ }
311
+ else if( $.isPlainObject( instance[camelCaseValue] ) && (depth != maxDepth) ) {
312
+ instance = instance[camelCaseValue];
313
+ }
314
+ else if( instance[value] !== undefined ) {
315
+ found = instance[value];
316
+ return false;
317
+ }
318
+ else if( instance[camelCaseValue] !== undefined ) {
319
+ found = instance[camelCaseValue];
320
+ return false;
321
+ }
322
+ else {
323
+ module.error(error.method);
324
+ return false;
325
+ }
326
+ });
327
+ }
328
+ if ( $.isFunction( found ) ) {
329
+ response = found.apply(context, passedArguments);
330
+ }
331
+ else if(found !== undefined) {
332
+ response = found;
333
+ }
334
+ if($.isArray(invokedResponse)) {
335
+ invokedResponse.push(response);
336
+ }
337
+ else if(typeof invokedResponse == 'string') {
338
+ invokedResponse = [invokedResponse, response];
339
+ }
340
+ else if(response !== undefined) {
341
+ invokedResponse = response;
342
+ }
343
+ return found;
344
+ }
345
+ };
346
+
347
+ if(methodInvoked) {
348
+ if(instance === undefined) {
349
+ module.initialize();
350
+ }
351
+ module.invoke(query);
352
+ }
353
+ else {
354
+ if(instance !== undefined) {
355
+ module.destroy();
356
+ }
357
+ module.initialize();
358
+ }
359
+ })
360
+ ;
361
+
362
+ return (invokedResponse !== undefined)
363
+ ? invokedResponse
364
+ : this
365
+ ;
366
+ };
367
+
368
+ $.fn.rating.settings = {
369
+
370
+ name : 'Rating',
371
+ namespace : 'rating',
372
+
373
+ verbose : true,
374
+ debug : true,
375
+ performance : true,
376
+
377
+ initialRating : 0,
378
+ interactive : true,
379
+ clearable : false,
380
+
381
+ onRate : function(rating){},
382
+
383
+ error : {
384
+ method : 'The method you called is not defined'
385
+ },
386
+
387
+ metadata: {
388
+ rating: 'rating'
389
+ },
390
+
391
+ className : {
392
+ active : 'active',
393
+ hover : 'hover',
394
+ loading : 'loading'
395
+ },
396
+
397
+ selector : {
398
+ icon : '.icon'
399
+ }
400
+
401
+ };
402
+
403
+ })( jQuery, window , document );
@@ -0,0 +1,772 @@
1
+ /*
2
+ * # Semantic - Search
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.search = function(source, parameters) {
15
+ var
16
+ $allModules = $(this),
17
+ settings = $.extend(true, {}, $.fn.search.settings, parameters),
18
+
19
+
20
+ className = settings.className,
21
+ selector = settings.selector,
22
+ error = settings.error,
23
+ namespace = settings.namespace,
24
+
25
+ eventNamespace = '.' + namespace,
26
+ moduleNamespace = namespace + '-module',
27
+ moduleSelector = $allModules.selector || '',
28
+
29
+ time = new Date().getTime(),
30
+ performance = [],
31
+
32
+ query = arguments[0],
33
+ methodInvoked = (typeof query == 'string'),
34
+ queryArguments = [].slice.call(arguments, 1),
35
+ invokedResponse
36
+ ;
37
+ $(this)
38
+ .each(function() {
39
+ var
40
+ $module = $(this),
41
+ $prompt = $module.find(selector.prompt),
42
+ $searchButton = $module.find(selector.searchButton),
43
+ $results = $module.find(selector.results),
44
+ $result = $module.find(selector.result),
45
+ $category = $module.find(selector.category),
46
+
47
+ element = this,
48
+ instance = $module.data(moduleNamespace),
49
+
50
+ module
51
+ ;
52
+ module = {
53
+
54
+ initialize: function() {
55
+ module.verbose('Initializing module');
56
+ var
57
+ prompt = $prompt[0],
58
+ inputEvent = (prompt.oninput !== undefined)
59
+ ? 'input'
60
+ : (prompt.onpropertychange !== undefined)
61
+ ? 'propertychange'
62
+ : 'keyup'
63
+ ;
64
+ // attach events
65
+ $prompt
66
+ .on('focus' + eventNamespace, module.event.focus)
67
+ .on('blur' + eventNamespace, module.event.blur)
68
+ .on('keydown' + eventNamespace, module.handleKeyboard)
69
+ ;
70
+ if(settings.automatic) {
71
+ $prompt
72
+ .on(inputEvent + eventNamespace, module.search.throttle)
73
+ ;
74
+ }
75
+ $searchButton
76
+ .on('click' + eventNamespace, module.search.query)
77
+ ;
78
+ $results
79
+ .on('click' + eventNamespace, selector.result, module.results.select)
80
+ ;
81
+ module.instantiate();
82
+ },
83
+ instantiate: function() {
84
+ module.verbose('Storing instance of module', module);
85
+ instance = module;
86
+ $module
87
+ .data(moduleNamespace, module)
88
+ ;
89
+ },
90
+ destroy: function() {
91
+ module.verbose('Destroying instance');
92
+ $module
93
+ .removeData(moduleNamespace)
94
+ ;
95
+ },
96
+ event: {
97
+ focus: function() {
98
+ $module
99
+ .addClass(className.focus)
100
+ ;
101
+ module.results.show();
102
+ },
103
+ blur: function() {
104
+ module.search.cancel();
105
+ $module
106
+ .removeClass(className.focus)
107
+ ;
108
+ module.results.hide();
109
+ }
110
+ },
111
+ handleKeyboard: function(event) {
112
+ var
113
+ // force latest jq dom
114
+ $result = $module.find(selector.result),
115
+ $category = $module.find(selector.category),
116
+ keyCode = event.which,
117
+ keys = {
118
+ backspace : 8,
119
+ enter : 13,
120
+ escape : 27,
121
+ upArrow : 38,
122
+ downArrow : 40
123
+ },
124
+ activeClass = className.active,
125
+ currentIndex = $result.index( $result.filter('.' + activeClass) ),
126
+ resultSize = $result.size(),
127
+ newIndex
128
+ ;
129
+ // search shortcuts
130
+ if(keyCode == keys.escape) {
131
+ module.verbose('Escape key pressed, blurring search field');
132
+ $prompt
133
+ .trigger('blur')
134
+ ;
135
+ }
136
+ // result shortcuts
137
+ if($results.filter(':visible').size() > 0) {
138
+ if(keyCode == keys.enter) {
139
+ module.verbose('Enter key pressed, selecting active result');
140
+ if( $result.filter('.' + activeClass).exists() ) {
141
+ $.proxy(module.results.select, $result.filter('.' + activeClass) )();
142
+ event.preventDefault();
143
+ return false;
144
+ }
145
+ }
146
+ else if(keyCode == keys.upArrow) {
147
+ module.verbose('Up key pressed, changing active result');
148
+ newIndex = (currentIndex - 1 < 0)
149
+ ? currentIndex
150
+ : currentIndex - 1
151
+ ;
152
+ $category
153
+ .removeClass(activeClass)
154
+ ;
155
+ $result
156
+ .removeClass(activeClass)
157
+ .eq(newIndex)
158
+ .addClass(activeClass)
159
+ .closest($category)
160
+ .addClass(activeClass)
161
+ ;
162
+ event.preventDefault();
163
+ }
164
+ else if(keyCode == keys.downArrow) {
165
+ module.verbose('Down key pressed, changing active result');
166
+ newIndex = (currentIndex + 1 >= resultSize)
167
+ ? currentIndex
168
+ : currentIndex + 1
169
+ ;
170
+ $category
171
+ .removeClass(activeClass)
172
+ ;
173
+ $result
174
+ .removeClass(activeClass)
175
+ .eq(newIndex)
176
+ .addClass(activeClass)
177
+ .closest($category)
178
+ .addClass(activeClass)
179
+ ;
180
+ event.preventDefault();
181
+ }
182
+ }
183
+ else {
184
+ // query shortcuts
185
+ if(keyCode == keys.enter) {
186
+ module.verbose('Enter key pressed, executing query');
187
+ module.search.query();
188
+ $searchButton
189
+ .addClass(className.down)
190
+ ;
191
+ $prompt
192
+ .one('keyup', function(){
193
+ $searchButton
194
+ .removeClass(className.down)
195
+ ;
196
+ })
197
+ ;
198
+ }
199
+ }
200
+ },
201
+ search: {
202
+ cancel: function() {
203
+ var
204
+ xhr = $module.data('xhr') || false
205
+ ;
206
+ if( xhr && xhr.state() != 'resolved') {
207
+ module.debug('Cancelling last search');
208
+ xhr.abort();
209
+ }
210
+ },
211
+ throttle: function() {
212
+ var
213
+ searchTerm = $prompt.val(),
214
+ numCharacters = searchTerm.length
215
+ ;
216
+ clearTimeout(module.timer);
217
+ if(numCharacters >= settings.minCharacters) {
218
+ module.timer = setTimeout(module.search.query, settings.searchThrottle);
219
+ }
220
+ else {
221
+ module.results.hide();
222
+ }
223
+ },
224
+ query: function() {
225
+ var
226
+ searchTerm = $prompt.val(),
227
+ cachedHTML = module.search.cache.read(searchTerm)
228
+ ;
229
+ if(cachedHTML) {
230
+ module.debug("Reading result for '" + searchTerm + "' from cache");
231
+ module.results.add(cachedHTML);
232
+ }
233
+ else {
234
+ module.debug("Querying for '" + searchTerm + "'");
235
+ if(typeof source == 'object') {
236
+ module.search.local(searchTerm);
237
+ }
238
+ else {
239
+ module.search.remote(searchTerm);
240
+ }
241
+ $.proxy(settings.onSearchQuery, $module)(searchTerm);
242
+ }
243
+ },
244
+ local: function(searchTerm) {
245
+ var
246
+ results = [],
247
+ fullTextResults = [],
248
+ searchFields = $.isArray(settings.searchFields)
249
+ ? settings.searchFields
250
+ : [settings.searchFields],
251
+
252
+ searchRegExp = new RegExp('(?:\s|^)' + searchTerm, 'i'),
253
+ fullTextRegExp = new RegExp(searchTerm, 'i'),
254
+ searchHTML
255
+ ;
256
+ $module
257
+ .addClass(className.loading)
258
+ ;
259
+ // iterate through search fields in array order
260
+ $.each(searchFields, function(index, field) {
261
+ $.each(source, function(label, thing) {
262
+ if(typeof thing[field] == 'string' && ($.inArray(thing, results) == -1) && ($.inArray(thing, fullTextResults) == -1) ) {
263
+ if( searchRegExp.test( thing[field] ) ) {
264
+ results.push(thing);
265
+ }
266
+ else if( fullTextRegExp.test( thing[field] ) ) {
267
+ fullTextResults.push(thing);
268
+ }
269
+ }
270
+ });
271
+ });
272
+ searchHTML = module.results.generate({
273
+ results: $.merge(results, fullTextResults)
274
+ });
275
+ $module
276
+ .removeClass(className.loading)
277
+ ;
278
+ module.search.cache.write(searchTerm, searchHTML);
279
+ module.results.add(searchHTML);
280
+ },
281
+ remote: function(searchTerm) {
282
+ var
283
+ apiSettings = {
284
+ stateContext : $module,
285
+ url : source,
286
+ urlData: { query: searchTerm },
287
+ success : function(response) {
288
+ searchHTML = module.results.generate(response);
289
+ module.search.cache.write(searchTerm, searchHTML);
290
+ module.results.add(searchHTML);
291
+ },
292
+ failure : module.error
293
+ },
294
+ searchHTML
295
+ ;
296
+ module.search.cancel();
297
+ module.debug('Executing search');
298
+ $.extend(true, apiSettings, settings.apiSettings);
299
+ $.api(apiSettings);
300
+ },
301
+
302
+ cache: {
303
+ read: function(name) {
304
+ var
305
+ cache = $module.data('cache')
306
+ ;
307
+ return (settings.cache && (typeof cache == 'object') && (cache[name] !== undefined) )
308
+ ? cache[name]
309
+ : false
310
+ ;
311
+ },
312
+ write: function(name, value) {
313
+ var
314
+ cache = ($module.data('cache') !== undefined)
315
+ ? $module.data('cache')
316
+ : {}
317
+ ;
318
+ cache[name] = value;
319
+ $module
320
+ .data('cache', cache)
321
+ ;
322
+ }
323
+ }
324
+ },
325
+
326
+ results: {
327
+ generate: function(response) {
328
+ module.debug('Generating html from response', response);
329
+ var
330
+ template = settings.templates[settings.type],
331
+ html = ''
332
+ ;
333
+ if(($.isPlainObject(response.results) && !$.isEmptyObject(response.results)) || ($.isArray(response.results) && response.results.length > 0) ) {
334
+ if(settings.maxResults > 0) {
335
+ response.results = $.makeArray(response.results).slice(0, settings.maxResults);
336
+ }
337
+ if(response.results.length > 0) {
338
+ if($.isFunction(template)) {
339
+ html = template(response);
340
+ }
341
+ else {
342
+ module.error(error.noTemplate, false);
343
+ }
344
+ }
345
+ }
346
+ else {
347
+ html = module.message(error.noResults, 'empty');
348
+ }
349
+ $.proxy(settings.onResults, $module)(response);
350
+ return html;
351
+ },
352
+ add: function(html) {
353
+ if(settings.onResultsAdd == 'default' || $.proxy(settings.onResultsAdd, $results)(html) == 'default') {
354
+ $results
355
+ .html(html)
356
+ ;
357
+ }
358
+ module.results.show();
359
+ },
360
+ show: function() {
361
+ if( ($results.filter(':visible').size() === 0) && ($prompt.filter(':focus').size() > 0) && $results.html() !== '') {
362
+ $results
363
+ .stop()
364
+ .fadeIn(200)
365
+ ;
366
+ $.proxy(settings.onResultsOpen, $results)();
367
+ }
368
+ },
369
+ hide: function() {
370
+ if($results.filter(':visible').size() > 0) {
371
+ $results
372
+ .stop()
373
+ .fadeOut(200)
374
+ ;
375
+ $.proxy(settings.onResultsClose, $results)();
376
+ }
377
+ },
378
+ select: function(event) {
379
+ module.debug('Search result selected');
380
+ var
381
+ $result = $(this),
382
+ $title = $result.find('.title'),
383
+ title = $title.html()
384
+ ;
385
+ if(settings.onSelect == 'default' || $.proxy(settings.onSelect, this)(event) == 'default') {
386
+ var
387
+ $link = $result.find('a[href]').eq(0),
388
+ href = $link.attr('href') || false,
389
+ target = $link.attr('target') || false
390
+ ;
391
+ module.results.hide();
392
+ $prompt
393
+ .val(title)
394
+ ;
395
+ if(href) {
396
+ if(target == '_blank' || event.ctrlKey) {
397
+ window.open(href);
398
+ }
399
+ else {
400
+ window.location.href = (href);
401
+ }
402
+ }
403
+ }
404
+ }
405
+ },
406
+
407
+ setting: function(name, value) {
408
+ module.debug('Changing setting', name, value);
409
+ if(value !== undefined) {
410
+ if( $.isPlainObject(name) ) {
411
+ $.extend(true, settings, name);
412
+ }
413
+ else {
414
+ settings[name] = value;
415
+ }
416
+ }
417
+ else {
418
+ return settings[name];
419
+ }
420
+ },
421
+ internal: function(name, value) {
422
+ module.debug('Changing internal', name, value);
423
+ if(value !== undefined) {
424
+ if( $.isPlainObject(name) ) {
425
+ $.extend(true, module, name);
426
+ }
427
+ else {
428
+ module[name] = value;
429
+ }
430
+ }
431
+ else {
432
+ return module[name];
433
+ }
434
+ },
435
+ debug: function() {
436
+ if(settings.debug) {
437
+ if(settings.performance) {
438
+ module.performance.log(arguments);
439
+ }
440
+ else {
441
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
442
+ module.debug.apply(console, arguments);
443
+ }
444
+ }
445
+ },
446
+ verbose: function() {
447
+ if(settings.verbose && settings.debug) {
448
+ if(settings.performance) {
449
+ module.performance.log(arguments);
450
+ }
451
+ else {
452
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
453
+ module.verbose.apply(console, arguments);
454
+ }
455
+ }
456
+ },
457
+ error: function() {
458
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
459
+ module.error.apply(console, arguments);
460
+ },
461
+ performance: {
462
+ log: function(message) {
463
+ var
464
+ currentTime,
465
+ executionTime,
466
+ previousTime
467
+ ;
468
+ if(settings.performance) {
469
+ currentTime = new Date().getTime();
470
+ previousTime = time || currentTime;
471
+ executionTime = currentTime - previousTime;
472
+ time = currentTime;
473
+ performance.push({
474
+ 'Element' : element,
475
+ 'Name' : message[0],
476
+ 'Arguments' : [].slice.call(message, 1) || '',
477
+ 'Execution Time' : executionTime
478
+ });
479
+ }
480
+ clearTimeout(module.performance.timer);
481
+ module.performance.timer = setTimeout(module.performance.display, 100);
482
+ },
483
+ display: function() {
484
+ var
485
+ title = settings.name + ':',
486
+ totalTime = 0
487
+ ;
488
+ time = false;
489
+ clearTimeout(module.performance.timer);
490
+ $.each(performance, function(index, data) {
491
+ totalTime += data['Execution Time'];
492
+ });
493
+ title += ' ' + totalTime + 'ms';
494
+ if(moduleSelector) {
495
+ title += ' \'' + moduleSelector + '\'';
496
+ }
497
+ if($allModules.size() > 1) {
498
+ title += ' ' + '(' + $allModules.size() + ')';
499
+ }
500
+ if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
501
+ console.groupCollapsed(title);
502
+ if(console.table) {
503
+ console.table(performance);
504
+ }
505
+ else {
506
+ $.each(performance, function(index, data) {
507
+ console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
508
+ });
509
+ }
510
+ console.groupEnd();
511
+ }
512
+ performance = [];
513
+ }
514
+ },
515
+ invoke: function(query, passedArguments, context) {
516
+ var
517
+ maxDepth,
518
+ found,
519
+ response
520
+ ;
521
+ passedArguments = passedArguments || queryArguments;
522
+ context = element || context;
523
+ if(typeof query == 'string' && instance !== undefined) {
524
+ query = query.split(/[\. ]/);
525
+ maxDepth = query.length - 1;
526
+ $.each(query, function(depth, value) {
527
+ var camelCaseValue = (depth != maxDepth)
528
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
529
+ : query
530
+ ;
531
+ if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) {
532
+ instance = instance[value];
533
+ }
534
+ else if( $.isPlainObject( instance[camelCaseValue] ) && (depth != maxDepth) ) {
535
+ instance = instance[camelCaseValue];
536
+ }
537
+ else if( instance[value] !== undefined ) {
538
+ found = instance[value];
539
+ return false;
540
+ }
541
+ else if( instance[camelCaseValue] !== undefined ) {
542
+ found = instance[camelCaseValue];
543
+ return false;
544
+ }
545
+ else {
546
+ module.error(error.method);
547
+ return false;
548
+ }
549
+ });
550
+ }
551
+ if ( $.isFunction( found ) ) {
552
+ response = found.apply(context, passedArguments);
553
+ }
554
+ else if(found !== undefined) {
555
+ response = found;
556
+ }
557
+ if($.isArray(invokedResponse)) {
558
+ invokedResponse.push(response);
559
+ }
560
+ else if(typeof invokedResponse == 'string') {
561
+ invokedResponse = [invokedResponse, response];
562
+ }
563
+ else if(response !== undefined) {
564
+ invokedResponse = response;
565
+ }
566
+ return found;
567
+ }
568
+ };
569
+ if(methodInvoked) {
570
+ if(instance === undefined) {
571
+ module.initialize();
572
+ }
573
+ module.invoke(query);
574
+ }
575
+ else {
576
+ if(instance !== undefined) {
577
+ module.destroy();
578
+ }
579
+ module.initialize();
580
+ }
581
+
582
+ })
583
+ ;
584
+
585
+ return (invokedResponse !== undefined)
586
+ ? invokedResponse
587
+ : this
588
+ ;
589
+ };
590
+
591
+ $.fn.search.settings = {
592
+
593
+ name : 'Search Module',
594
+ namespace : 'search',
595
+
596
+ debug : true,
597
+ verbose : true,
598
+ performance : true,
599
+
600
+ // onSelect default action is defined in module
601
+ onSelect : 'default',
602
+ onResultsAdd : 'default',
603
+
604
+ onSearchQuery : function(){},
605
+ onResults : function(response){},
606
+
607
+ onResultsOpen : function(){},
608
+ onResultsClose : function(){},
609
+
610
+ automatic : 'true',
611
+ type : 'simple',
612
+ minCharacters : 3,
613
+ searchThrottle : 300,
614
+ maxResults : 7,
615
+ cache : true,
616
+
617
+ searchFields : [
618
+ 'title',
619
+ 'description'
620
+ ],
621
+
622
+ // api config
623
+ apiSettings: {
624
+
625
+ },
626
+
627
+ className: {
628
+ active : 'active',
629
+ down : 'down',
630
+ focus : 'focus',
631
+ empty : 'empty',
632
+ loading : 'loading'
633
+ },
634
+
635
+ error : {
636
+ noResults : 'Your search returned no results',
637
+ logging : 'Error in debug logging, exiting.',
638
+ noTemplate : 'A valid template name was not specified.',
639
+ serverError : 'There was an issue with querying the server.',
640
+ method : 'The method you called is not defined.'
641
+ },
642
+
643
+ selector : {
644
+ prompt : '.prompt',
645
+ searchButton : '.search.button',
646
+ results : '.results',
647
+ category : '.category',
648
+ result : '.result'
649
+ },
650
+
651
+ templates: {
652
+ message: function(message, type) {
653
+ var
654
+ html = ''
655
+ ;
656
+ if(message !== undefined && type !== undefined) {
657
+ html += ''
658
+ + '<div class="message ' + type +'">'
659
+ ;
660
+ // message type
661
+ if(type == 'empty') {
662
+ html += ''
663
+ + '<div class="header">No Results</div class="header">'
664
+ + '<div class="description">' + message + '</div class="description">'
665
+ ;
666
+ }
667
+ else {
668
+ html += ' <div class="description">' + message + '</div>';
669
+ }
670
+ html += '</div>';
671
+ }
672
+ return html;
673
+ },
674
+ categories: function(response) {
675
+ var
676
+ html = ''
677
+ ;
678
+ if(response.results !== undefined) {
679
+ // each category
680
+ $.each(response.results, function(index, category) {
681
+ if(category.results !== undefined && category.results.length > 0) {
682
+ html += ''
683
+ + '<div class="category">'
684
+ + '<div class="name">' + category.name + '</div>'
685
+ ;
686
+ // each item inside category
687
+ $.each(category.results, function(index, result) {
688
+ html += '<div class="result">';
689
+ html += '<a href="' + result.url + '"></a>';
690
+ if(result.image !== undefined) {
691
+ html+= ''
692
+ + '<div class="image">'
693
+ + ' <img src="' + result.image + '">'
694
+ + '</div>'
695
+ ;
696
+ }
697
+ html += '<div class="info">';
698
+ if(result.price !== undefined) {
699
+ html+= '<div class="price">' + result.price + '</div>';
700
+ }
701
+ if(result.title !== undefined) {
702
+ html+= '<div class="title">' + result.title + '</div>';
703
+ }
704
+ if(result.description !== undefined) {
705
+ html+= '<div class="description">' + result.description + '</div>';
706
+ }
707
+ html += ''
708
+ + '</div>'
709
+ + '</div>'
710
+ ;
711
+ });
712
+ html += ''
713
+ + '</div>'
714
+ ;
715
+ }
716
+ });
717
+ if(response.resultPage) {
718
+ html += ''
719
+ + '<a href="' + response.resultPage.url + '" class="all">'
720
+ + response.resultPage.text
721
+ + '</a>';
722
+ }
723
+ return html;
724
+ }
725
+ return false;
726
+ },
727
+ simple: function(response) {
728
+ var
729
+ html = ''
730
+ ;
731
+ if(response.results !== undefined) {
732
+
733
+ // each result
734
+ $.each(response.results, function(index, result) {
735
+ html += '<a class="result" href="' + result.url + '">';
736
+ if(result.image !== undefined) {
737
+ html+= ''
738
+ + '<div class="image">'
739
+ + ' <img src="' + result.image + '">'
740
+ + '</div>'
741
+ ;
742
+ }
743
+ html += '<div class="info">';
744
+ if(result.price !== undefined) {
745
+ html+= '<div class="price">' + result.price + '</div>';
746
+ }
747
+ if(result.title !== undefined) {
748
+ html+= '<div class="title">' + result.title + '</div>';
749
+ }
750
+ if(result.description !== undefined) {
751
+ html+= '<div class="description">' + result.description + '</div>';
752
+ }
753
+ html += ''
754
+ + '</div>'
755
+ + '</a>'
756
+ ;
757
+ });
758
+
759
+ if(response.resultPage) {
760
+ html += ''
761
+ + '<a href="' + response.resultPage.url + '" class="all">'
762
+ + response.resultPage.text
763
+ + '</a>';
764
+ }
765
+ return html;
766
+ }
767
+ return false;
768
+ }
769
+ }
770
+ };
771
+
772
+ })( jQuery, window , document );